Skip to content

Commit 52d4d92

Browse files
committed
fix tests since we changed how we get env
1 parent e7c0635 commit 52d4d92

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

Tests/JExtractSwiftTests/JNI/JNIStructTests.swift

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,19 @@ struct JNIStructTests {
6363
"""
6464
@Override
6565
protected Runnable $createDestroyFunction() {
66-
long $selfPointer = this.pointer();
66+
long self$ = this.$memoryAddress();
67+
if (CallTraces.TRACE_DOWNCALLS) {
68+
CallTraces.traceDowncall("MyStruct.$createDestroyFunction",
69+
"this", this,
70+
"self", self$);
71+
}
6772
return new Runnable() {
6873
@Override
6974
public void run() {
70-
MyStruct.$destroy($selfPointer);
75+
if (CallTraces.TRACE_DOWNCALLS) {
76+
CallTraces.traceDowncall("MyStruct.$destroy", "self", self$);
77+
}
78+
MyStruct.$destroy(self$);
7179
}
7280
};
7381
}
@@ -90,8 +98,8 @@ struct JNIStructTests {
9098
* }
9199
*/
92100
public static MyStruct init(long x, long y, SwiftArena swiftArena$) {
93-
long selfPointer = MyStruct.allocatingInit(x, y);
94-
return new MyStruct(selfPointer, swiftArena$);
101+
long self$ = MyStruct.allocatingInit(x, y);
102+
return new MyStruct(self$, swiftArena$);
95103
}
96104
""",
97105
"""
@@ -112,9 +120,9 @@ struct JNIStructTests {
112120
"""
113121
@_cdecl("Java_com_example_swift_MyStruct_allocatingInit__JJ")
114122
func Java_com_example_swift_MyStruct_allocatingInit__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, y: jlong) -> jlong {
115-
let selfPointer = UnsafeMutablePointer<MyStruct>.allocate(capacity: 1)
116-
selfPointer.initialize(to: MyStruct(x: Int64(fromJNI: x, in: environment!), y: Int64(fromJNI: y, in: environment!)))
117-
return Int64(Int(bitPattern: selfPointer)).getJNIValue(in: environment)
123+
let self$ = UnsafeMutablePointer<MyStruct>.allocate(capacity: 1)
124+
self$.initialize(to: MyStruct(x: Int64(fromJNI: x, in: environment!), y: Int64(fromJNI: y, in: environment!)))
125+
return Int64(Int(bitPattern: self$)).getJNIValue(in: environment)
118126
}
119127
"""
120128
]
@@ -127,14 +135,21 @@ struct JNIStructTests {
127135
input: source,
128136
.jni,
129137
.swift,
130-
detectChunkByInitialLines: 1,
131138
expectedChunks: [
132139
"""
133140
@_cdecl("Java_com_example_swift_MyStruct__00024destroy__J")
134141
func Java_com_example_swift_MyStruct__00024destroy__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) {
135-
let pointer = UnsafeMutablePointer<MyStruct>(bitPattern: Int(Int64(fromJNI: selfPointer, in: environment!)))!
136-
pointer.deinitialize(count: 1)
137-
pointer.deallocate()
142+
guard let env$ = environment else {
143+
fatalError("Missing JNIEnv in downcall to \\(#function)")
144+
}
145+
assert(selfPointer != 0, "selfPointer memory address was null")
146+
let selfBits$ = Int(Int64(fromJNI: selfPointer, in: env$))
147+
assert(selfBits$ != 0, "$self memory address was null: selfPointer = \\(selfPointer)" )
148+
guard let self$ = UnsafeMutablePointer<MyStruct>(bitPattern: selfBits$) else {
149+
fatalError("Missing self pointer in call to \\(#function)!")
150+
}
151+
self$.deinitialize(count: 1)
152+
self$.deallocate()
138153
}
139154
"""
140155
]
@@ -156,8 +171,8 @@ struct JNIStructTests {
156171
* }
157172
*/
158173
public void doSomething(long x) {
159-
long selfPointer = this.pointer();
160-
MyStruct.$doSomething(x, selfPointer);
174+
long self$ = this.$memoryAddress();
175+
MyStruct.$doSomething(x, self$);
161176
}
162177
""",
163178
"""
@@ -178,7 +193,15 @@ struct JNIStructTests {
178193
"""
179194
@_cdecl("Java_com_example_swift_MyStruct__00024doSomething__JJ")
180195
func Java_com_example_swift_MyStruct__00024doSomething__JJ(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, x: jlong, selfPointer: jlong) {
181-
let self$ = UnsafeMutablePointer<MyStruct>(bitPattern: Int(Int64(fromJNI: selfPointer, in: environment!)))!
196+
guard let env$ = environment else {
197+
fatalError("Missing JNIEnv in downcall to \\(#function)")
198+
}
199+
assert(selfPointer != 0, "selfPointer memory address was null")
200+
let selfBits$ = Int(Int64(fromJNI: selfPointer, in: env$))
201+
assert(selfBits$ != 0, "$self memory address was null: selfPointer = \\(selfPointer)" )
202+
guard let self$ = UnsafeMutablePointer<MyStruct>(bitPattern: selfBits$) else {
203+
fatalError("Missing self pointer in call to \\(#function)!")
204+
}
182205
self$.pointee.doSomething(x: Int64(fromJNI: x, in: environment!))
183206
}
184207
""",

Tests/JExtractSwiftTests/MethodImportTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ final class MethodImportTests {
168168
}
169169

170170
assertOutput(
171-
dump: true,
172171
output,
173172
expected:
174173
"""
@@ -212,7 +211,6 @@ final class MethodImportTests {
212211
}
213212

214213
assertOutput(
215-
dump: true,
216214
output,
217215
expected:
218216
"""
@@ -256,7 +254,6 @@ final class MethodImportTests {
256254
}
257255

258256
assertOutput(
259-
dump: true,
260257
output,
261258
expected:
262259
"""

0 commit comments

Comments
 (0)