...

Source file src/cmd/fix/jnitype_test.go

Documentation: cmd/fix

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  func init() {
     8  	addTestCases(jniTests, jnifix)
     9  }
    10  
    11  var jniTests = []testCase{
    12  	{
    13  		Name: "jni.localVariable",
    14  		In: `package main
    15  
    16  // typedef struct _jobject* jobject;
    17  import "C"
    18  
    19  func f() {
    20  	var x C.jobject = nil
    21  	x = nil
    22  	x, x = nil, nil
    23  }
    24  `,
    25  		Out: `package main
    26  
    27  // typedef struct _jobject* jobject;
    28  import "C"
    29  
    30  func f() {
    31  	var x C.jobject = 0
    32  	x = 0
    33  	x, x = 0, 0
    34  }
    35  `,
    36  	},
    37  	{
    38  		Name: "jni.globalVariable",
    39  		In: `package main
    40  
    41  // typedef struct _jobject* jobject;
    42  import "C"
    43  
    44  var x C.jobject = nil
    45  
    46  func f() {
    47  	x = nil
    48  }
    49  `,
    50  		Out: `package main
    51  
    52  // typedef struct _jobject* jobject;
    53  import "C"
    54  
    55  var x C.jobject = 0
    56  
    57  func f() {
    58  	x = 0
    59  }
    60  `,
    61  	},
    62  	{
    63  		Name: "jni.EqualArgument",
    64  		In: `package main
    65  
    66  // typedef struct _jobject* jobject;
    67  import "C"
    68  
    69  var x C.jobject
    70  var y = x == nil
    71  var z = x != nil
    72  `,
    73  		Out: `package main
    74  
    75  // typedef struct _jobject* jobject;
    76  import "C"
    77  
    78  var x C.jobject
    79  var y = x == 0
    80  var z = x != 0
    81  `,
    82  	},
    83  	{
    84  		Name: "jni.StructField",
    85  		In: `package main
    86  
    87  // typedef struct _jobject* jobject;
    88  import "C"
    89  
    90  type T struct {
    91  	x C.jobject
    92  }
    93  
    94  var t = T{x: nil}
    95  `,
    96  		Out: `package main
    97  
    98  // typedef struct _jobject* jobject;
    99  import "C"
   100  
   101  type T struct {
   102  	x C.jobject
   103  }
   104  
   105  var t = T{x: 0}
   106  `,
   107  	},
   108  	{
   109  		Name: "jni.FunctionArgument",
   110  		In: `package main
   111  
   112  // typedef struct _jobject* jobject;
   113  import "C"
   114  
   115  func f(x C.jobject) {
   116  }
   117  
   118  func g() {
   119  	f(nil)
   120  }
   121  `,
   122  		Out: `package main
   123  
   124  // typedef struct _jobject* jobject;
   125  import "C"
   126  
   127  func f(x C.jobject) {
   128  }
   129  
   130  func g() {
   131  	f(0)
   132  }
   133  `,
   134  	},
   135  	{
   136  		Name: "jni.ArrayElement",
   137  		In: `package main
   138  
   139  // typedef struct _jobject* jobject;
   140  import "C"
   141  
   142  var x = [3]C.jobject{nil, nil, nil}
   143  `,
   144  		Out: `package main
   145  
   146  // typedef struct _jobject* jobject;
   147  import "C"
   148  
   149  var x = [3]C.jobject{0, 0, 0}
   150  `,
   151  	},
   152  	{
   153  		Name: "jni.SliceElement",
   154  		In: `package main
   155  
   156  // typedef struct _jobject* jobject;
   157  import "C"
   158  
   159  var x = []C.jobject{nil, nil, nil}
   160  `,
   161  		Out: `package main
   162  
   163  // typedef struct _jobject* jobject;
   164  import "C"
   165  
   166  var x = []C.jobject{0, 0, 0}
   167  `,
   168  	},
   169  	{
   170  		Name: "jni.MapKey",
   171  		In: `package main
   172  
   173  // typedef struct _jobject* jobject;
   174  import "C"
   175  
   176  var x = map[C.jobject]int{nil: 0}
   177  `,
   178  		Out: `package main
   179  
   180  // typedef struct _jobject* jobject;
   181  import "C"
   182  
   183  var x = map[C.jobject]int{0: 0}
   184  `,
   185  	},
   186  	{
   187  		Name: "jni.MapValue",
   188  		In: `package main
   189  
   190  // typedef struct _jobject* jobject;
   191  import "C"
   192  
   193  var x = map[int]C.jobject{0: nil}
   194  `,
   195  		Out: `package main
   196  
   197  // typedef struct _jobject* jobject;
   198  import "C"
   199  
   200  var x = map[int]C.jobject{0: 0}
   201  `,
   202  	},
   203  }
   204  

View as plain text