Source file src/cmd/fix/jnitype_test.go

     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  import "C"
    17  
    18  func f() {
    19  	var x C.jobject = nil
    20  	x = nil
    21  	x, x = nil, nil
    22  }
    23  `,
    24  		Out: `package main
    25  
    26  import "C"
    27  
    28  func f() {
    29  	var x C.jobject = 0
    30  	x = 0
    31  	x, x = 0, 0
    32  }
    33  `,
    34  	},
    35  	{
    36  		Name: "jni.globalVariable",
    37  		In: `package main
    38  
    39  import "C"
    40  
    41  var x C.jobject = nil
    42  
    43  func f() {
    44  	x = nil
    45  }
    46  `,
    47  		Out: `package main
    48  
    49  import "C"
    50  
    51  var x C.jobject = 0
    52  
    53  func f() {
    54  	x = 0
    55  }
    56  `,
    57  	},
    58  	{
    59  		Name: "jni.EqualArgument",
    60  		In: `package main
    61  
    62  import "C"
    63  
    64  var x C.jobject
    65  var y = x == nil
    66  var z = x != nil
    67  `,
    68  		Out: `package main
    69  
    70  import "C"
    71  
    72  var x C.jobject
    73  var y = x == 0
    74  var z = x != 0
    75  `,
    76  	},
    77  	{
    78  		Name: "jni.StructField",
    79  		In: `package main
    80  
    81  import "C"
    82  
    83  type T struct {
    84  	x C.jobject
    85  }
    86  
    87  var t = T{x: nil}
    88  `,
    89  		Out: `package main
    90  
    91  import "C"
    92  
    93  type T struct {
    94  	x C.jobject
    95  }
    96  
    97  var t = T{x: 0}
    98  `,
    99  	},
   100  	{
   101  		Name: "jni.FunctionArgument",
   102  		In: `package main
   103  
   104  import "C"
   105  
   106  func f(x C.jobject) {
   107  }
   108  
   109  func g() {
   110  	f(nil)
   111  }
   112  `,
   113  		Out: `package main
   114  
   115  import "C"
   116  
   117  func f(x C.jobject) {
   118  }
   119  
   120  func g() {
   121  	f(0)
   122  }
   123  `,
   124  	},
   125  	{
   126  		Name: "jni.ArrayElement",
   127  		In: `package main
   128  
   129  import "C"
   130  
   131  var x = [3]C.jobject{nil, nil, nil}
   132  `,
   133  		Out: `package main
   134  
   135  import "C"
   136  
   137  var x = [3]C.jobject{0, 0, 0}
   138  `,
   139  	},
   140  	{
   141  		Name: "jni.SliceElement",
   142  		In: `package main
   143  
   144  import "C"
   145  
   146  var x = []C.jobject{nil, nil, nil}
   147  `,
   148  		Out: `package main
   149  
   150  import "C"
   151  
   152  var x = []C.jobject{0, 0, 0}
   153  `,
   154  	},
   155  	{
   156  		Name: "jni.MapKey",
   157  		In: `package main
   158  
   159  import "C"
   160  
   161  var x = map[C.jobject]int{nil: 0}
   162  `,
   163  		Out: `package main
   164  
   165  import "C"
   166  
   167  var x = map[C.jobject]int{0: 0}
   168  `,
   169  	},
   170  	{
   171  		Name: "jni.MapValue",
   172  		In: `package main
   173  
   174  import "C"
   175  
   176  var x = map[int]C.jobject{0: nil}
   177  `,
   178  		Out: `package main
   179  
   180  import "C"
   181  
   182  var x = map[int]C.jobject{0: 0}
   183  `,
   184  	},
   185  }
   186  

View as plain text