Skip to content

Commit 537a72a

Browse files
committed
Dev: add Int32 test
1 parent 8333a7e commit 537a72a

3 files changed

Lines changed: 153 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.readdle.swiftjava.sample;
2+
3+
import android.support.test.runner.AndroidJUnit4;
4+
5+
import com.readdle.codegen.anotation.JavaSwift;
6+
7+
import org.junit.Assert;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
12+
@RunWith(AndroidJUnit4.class)
13+
public class Int32Tests {
14+
15+
@Before
16+
public void setUp() {
17+
System.loadLibrary("SampleAppCore");
18+
JavaSwift.init();
19+
SwiftEnvironment.initEnvironment();
20+
}
21+
22+
@Test
23+
public void testEncode() {
24+
Int32TestStruct result = Int32Test.testEncode();
25+
Assert.assertEquals(result, new Int32TestStruct());
26+
}
27+
28+
@Test
29+
public void testDecode() {
30+
Int32TestStruct goodParam = new Int32TestStruct();
31+
Int32TestStruct badParam = new Int32TestStruct(42, 42, 42, 42, 42);
32+
Assert.assertTrue(Int32Test.testDecode(goodParam));
33+
Assert.assertFalse(Int32Test.testDecode(badParam));
34+
}
35+
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.readdle.swiftjava.sample
2+
3+
import com.readdle.codegen.anotation.SwiftReference
4+
import com.readdle.codegen.anotation.SwiftValue
5+
import java.lang.annotation.Native
6+
7+
@SwiftValue
8+
data class Int32TestStruct(var zero: Int = 0,
9+
var max: Int = Int.MAX_VALUE,
10+
var min: Int = Int.MIN_VALUE,
11+
var optional: Int? = 0,
12+
var optionalNil: Int? = null)
13+
14+
@SwiftReference
15+
class Int32Test private constructor() {
16+
17+
companion object {
18+
19+
@JvmStatic
20+
external fun testEncode(): Int32TestStruct
21+
22+
@JvmStatic
23+
external fun testDecode(value: Int32TestStruct): Boolean
24+
}
25+
26+
@Native
27+
var nativePointer: Long = 0
28+
29+
external fun release()
30+
31+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// Created by Andrew on 2/4/18.
3+
//
4+
5+
import Foundation
6+
7+
public struct Int32TestStruct: Codable, Hashable {
8+
public var zero: Int32 = Int32.zero
9+
public var max: Int32 = Int32.max
10+
public var min: Int32 = Int32.min
11+
public var optional: Int32? = Int32.zero
12+
public var optionalNil: Int32? = nil
13+
}
14+
15+
public protocol Int32TestParamProtocol {
16+
func testParam(_ param: Int32) -> Bool
17+
}
18+
19+
public protocol Int32TestReturnTypeProtocol {
20+
func testReturnType() -> Int32
21+
}
22+
23+
public protocol Int32TestOptionalParamProtocol {
24+
func testOptionalParam(_ param: Int32?) -> Bool
25+
}
26+
27+
public protocol Int32TestOptionalReturnTypeProtocol {
28+
func testOptionalReturnType() -> Int32?
29+
}
30+
31+
public class Int32Test {
32+
33+
public static func testZero() -> Int32 {
34+
return 0
35+
}
36+
37+
public static func testMin() -> Int32 {
38+
return Int32.min
39+
}
40+
41+
public static func testMax() -> Int32 {
42+
return Int32.max
43+
}
44+
45+
public static func testParam(_ param: Int32) -> Bool {
46+
return param == Int32.max
47+
}
48+
49+
public static func testReturnType() -> Int32 {
50+
return Int32.max
51+
}
52+
53+
public static func testOptionalParam(_ param: Int32?) -> Bool {
54+
return param == Int32.max
55+
}
56+
57+
public static func testOptionalReturnType() -> Int32? {
58+
return Int32.max
59+
}
60+
61+
public static func testProtocolParam(_ callback: Int32TestParamProtocol) -> Bool {
62+
return callback.testParam(Int32.max)
63+
}
64+
65+
public static func testProtocolReturnType(_ callback: Int32TestReturnTypeProtocol) -> Int32 {
66+
return callback.testReturnType()
67+
}
68+
69+
public static func testProtocolOptionalParam(_ callback: Int32TestOptionalParamProtocol) -> Bool {
70+
return callback.testOptionalParam(Int32.max)
71+
}
72+
73+
public static func testProtocolOptionalReturnType(_ callback: Int32TestOptionalReturnTypeProtocol) -> Int32? {
74+
return callback.testOptionalReturnType()
75+
}
76+
77+
public static func testEncode() -> Int32TestStruct {
78+
return Int32TestStruct()
79+
}
80+
81+
public static func testDecode(_ value: Int32TestStruct) -> Bool {
82+
return value == Int32TestStruct()
83+
}
84+
85+
86+
}

0 commit comments

Comments
 (0)