Skip to content

Commit 04b2d9e

Browse files
committed
move tests
1 parent dc619ae commit 04b2d9e

File tree

5 files changed

+89
-65
lines changed

5 files changed

+89
-65
lines changed

Samples/JExtractJNISampleApp/Sources/MySwiftLibrary/MySwiftClass.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,6 @@ public class MySwiftClass {
9191
return self.x + other.longValue()
9292
}
9393

94-
public func optionalBool(input: Optional<Bool>) -> Bool? {
95-
return input
96-
}
97-
98-
public func optionalByte(input: Optional<Int8>) -> Int8? {
99-
return input
100-
}
101-
102-
public func optionalChar(input: Optional<UInt16>) -> UInt16? {
103-
return input
104-
}
105-
106-
public func optionalShort(input: Optional<Int16>) -> Int16? {
107-
return input
108-
}
109-
110-
public func optionalInt(input: Optional<Int32>) -> Int32? {
111-
return input
112-
}
113-
11494
// public func optionalMethodClass(input: MySwiftClass?) -> <Optional<MySwiftClass>> {
11595
// if let input {
11696
// return MySwiftClass(x: input.x * 10, y: input.y * 10)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public func optionalBool(input: Optional<Bool>) -> Bool? {
16+
return input
17+
}
18+
19+
public func optionalByte(input: Optional<Int8>) -> Int8? {
20+
return input
21+
}
22+
23+
public func optionalChar(input: Optional<UInt16>) -> UInt16? {
24+
return input
25+
}
26+
27+
public func optionalShort(input: Optional<Int16>) -> Int16? {
28+
return input
29+
}
30+
31+
public func optionalInt(input: Optional<Int32>) -> Int32? {
32+
return input
33+
}

Samples/JExtractJNISampleApp/src/test/java/com/example/swift/MySwiftClassTest.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -153,51 +153,6 @@ void addXWithJavaLong() {
153153
}
154154
}
155155

156-
@Test
157-
void optionalBool() {
158-
try (var arena = new ConfinedSwiftMemorySession()) {
159-
MySwiftClass c1 = MySwiftClass.init(20, 10, arena);
160-
assertEquals(Optional.empty(), c1.optionalBool(Optional.empty()));
161-
assertEquals(Optional.of(true), c1.optionalBool(Optional.of(true)));
162-
}
163-
}
164-
165-
@Test
166-
void optionalByte() {
167-
try (var arena = new ConfinedSwiftMemorySession()) {
168-
MySwiftClass c1 = MySwiftClass.init(20, 10, arena);
169-
assertEquals(Optional.empty(), c1.optionalByte(Optional.empty()));
170-
assertEquals(Optional.of((byte) 1) , c1.optionalByte(Optional.of((byte) 1)));
171-
}
172-
}
173-
174-
@Test
175-
void optionalChar() {
176-
try (var arena = new ConfinedSwiftMemorySession()) {
177-
MySwiftClass c1 = MySwiftClass.init(20, 10, arena);
178-
assertEquals(Optional.empty(), c1.optionalChar(Optional.empty()));
179-
assertEquals(Optional.of((char) 42), c1.optionalChar(Optional.of((char) 42)));
180-
}
181-
}
182-
183-
@Test
184-
void optionalShort() {
185-
try (var arena = new ConfinedSwiftMemorySession()) {
186-
MySwiftClass c1 = MySwiftClass.init(20, 10, arena);
187-
assertEquals(Optional.empty(), c1.optionalShort(Optional.empty()));
188-
assertEquals(Optional.of((short) -250), c1.optionalShort(Optional.of((short) -250)));
189-
}
190-
}
191-
192-
@Test
193-
void optionalInt() {
194-
try (var arena = new ConfinedSwiftMemorySession()) {
195-
MySwiftClass c1 = MySwiftClass.init(20, 10, arena);
196-
assertEquals(OptionalInt.empty(), c1.optionalInt(OptionalInt.empty()));
197-
assertEquals(OptionalInt.of(999), c1.optionalInt(OptionalInt.of(999)));
198-
}
199-
}
200-
201156
// @Test
202157
// void optionalMethodClass() {
203158
// try (var arena = new ConfinedSwiftMemorySession()) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
package com.example.swift;
16+
17+
import org.junit.jupiter.api.Test;
18+
19+
import java.util.Optional;
20+
import java.util.OptionalInt;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
25+
public class OptionalsTest {
26+
@Test
27+
void optionalBool() {
28+
assertEquals(Optional.empty(), MySwiftLibrary.optionalBool(Optional.empty()));
29+
assertEquals(Optional.of(true), MySwiftLibrary.optionalBool(Optional.of(true)));
30+
}
31+
32+
@Test
33+
void optionalByte() {
34+
assertEquals(Optional.empty(), MySwiftLibrary.optionalByte(Optional.empty()));
35+
assertEquals(Optional.of((byte) 1) , MySwiftLibrary.optionalByte(Optional.of((byte) 1)));
36+
}
37+
38+
@Test
39+
void optionalChar() {
40+
assertEquals(Optional.empty(), MySwiftLibrary.optionalChar(Optional.empty()));
41+
assertEquals(Optional.of((char) 42), MySwiftLibrary.optionalChar(Optional.of((char) 42)));
42+
}
43+
44+
@Test
45+
void optionalShort() {
46+
assertEquals(Optional.empty(), MySwiftLibrary.optionalShort(Optional.empty()));
47+
assertEquals(Optional.of((short) -250), MySwiftLibrary.optionalShort(Optional.of((short) -250)));
48+
}
49+
50+
@Test
51+
void optionalInt() {
52+
assertEquals(OptionalInt.empty(), MySwiftLibrary.optionalInt(OptionalInt.empty()));
53+
assertEquals(OptionalInt.of(999), MySwiftLibrary.optionalInt(OptionalInt.of(999)));
54+
}
55+
}

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extension JNISwift2JavaGenerator {
6363
private func printModule(_ printer: inout CodePrinter) {
6464
printHeader(&printer)
6565
printPackage(&printer)
66+
printImports(&printer)
6667

6768
printModuleClass(&printer) { printer in
6869
printer.print(

0 commit comments

Comments
 (0)