Skip to content

Commit 8333a7e

Browse files
committed
Dev: add Int16 test
1 parent 3881e50 commit 8333a7e

3 files changed

Lines changed: 274 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 Int16Tests {
14+
15+
@Before
16+
public void setUp() {
17+
System.loadLibrary("SampleAppCore");
18+
JavaSwift.init();
19+
SwiftEnvironment.initEnvironment();
20+
}
21+
22+
@Test
23+
public void testZero() {
24+
Assert.assertEquals(Int16Test.testZero(), 0);
25+
}
26+
27+
@Test
28+
public void testMin() {
29+
Assert.assertEquals(Int16Test.testMin(), Short.MIN_VALUE);
30+
}
31+
32+
@Test
33+
public void testMax() {
34+
Assert.assertEquals(Int16Test.testMax(), Short.MAX_VALUE);
35+
}
36+
37+
@Test
38+
public void testParam() {
39+
Assert.assertTrue(Int16Test.testParam(Short.MAX_VALUE));
40+
Assert.assertFalse(Int16Test.testParam(Short.MIN_VALUE));
41+
}
42+
43+
@Test
44+
public void testReturnType() {
45+
Assert.assertEquals(Int16Test.testReturnType(), Short.MAX_VALUE);
46+
}
47+
48+
@Test
49+
public void testOptionalParam() {
50+
Assert.assertTrue(Int16Test.testOptionalParam(Short.MAX_VALUE));
51+
Assert.assertFalse(Int16Test.testOptionalParam(Short.MIN_VALUE));
52+
}
53+
54+
public void testOptionalReturnType() {
55+
Short result = Int16Test.testOptionalReturnType();
56+
Assert.assertNotNull(result);
57+
Assert.assertEquals(result.shortValue(), Short.MAX_VALUE);
58+
}
59+
60+
@Test
61+
public void testProtocolParam() {
62+
boolean result = Int16Test.testProtocolParam(param -> param == Short.MAX_VALUE);
63+
Assert.assertTrue(result);
64+
}
65+
66+
@Test
67+
public void testProtocolReturnType() {
68+
short result = Int16Test.testProtocolReturnType(() -> (short) 42);
69+
Assert.assertEquals(result, 42);
70+
}
71+
72+
@Test
73+
public void testProtocolOptionalParam() {
74+
boolean result = Int16Test.testProtocolOptionalParam(param -> param != null && param == Short.MAX_VALUE);
75+
Assert.assertTrue(result);
76+
}
77+
78+
@Test
79+
public void testProtocolOptionalReturnType() {
80+
Short result = Int16Test.testProtocolOptionalReturnType(() -> (short) 42);
81+
Assert.assertNotNull(result);
82+
Assert.assertEquals(result.shortValue(), 42);
83+
}
84+
85+
@Test
86+
public void testEncode() {
87+
Int16TestStruct result = Int16Test.testEncode();
88+
Assert.assertEquals(result, new Int16TestStruct());
89+
}
90+
91+
@Test
92+
public void testDecode() {
93+
Int16TestStruct goodParam = new Int16TestStruct();
94+
Int16TestStruct badParam = new Int16TestStruct((short) 42, (short) 42, (short) 42, (short) 42, (short) 42);
95+
Assert.assertTrue(Int16Test.testDecode(goodParam));
96+
Assert.assertFalse(Int16Test.testDecode(badParam));
97+
}
98+
99+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.readdle.swiftjava.sample
2+
3+
import com.readdle.codegen.anotation.SwiftCallbackFunc
4+
import com.readdle.codegen.anotation.SwiftDelegate
5+
import com.readdle.codegen.anotation.SwiftReference
6+
import com.readdle.codegen.anotation.SwiftValue
7+
import java.lang.annotation.Native
8+
9+
@SwiftValue
10+
data class Int16TestStruct(var zero: Short = 0,
11+
var max: Short = Short.MAX_VALUE,
12+
var min: Short = Short.MIN_VALUE,
13+
var optional: Short? = 0,
14+
var optionalNil: Short? = null)
15+
16+
@SwiftReference
17+
class Int16Test private constructor() {
18+
19+
@SwiftDelegate(protocols = ["Int16TestParamProtocol"])
20+
interface Int16ParamProtocol {
21+
@SwiftCallbackFunc
22+
fun testParam(param: Short): Boolean
23+
}
24+
25+
@SwiftDelegate(protocols = ["Int16TestReturnTypeProtocol"])
26+
interface Int16ReturnTypeProtocol {
27+
@SwiftCallbackFunc
28+
fun testReturnType(): Short
29+
}
30+
31+
@SwiftDelegate(protocols = ["Int16TestOptionalParamProtocol"])
32+
interface Int16OptionalParamProtocol {
33+
@SwiftCallbackFunc
34+
fun testOptionalParam(param: Short?): Boolean
35+
}
36+
37+
@SwiftDelegate(protocols = ["Int16TestOptionalReturnTypeProtocol"])
38+
interface Int16OptionalReturnTypeProtocol {
39+
@SwiftCallbackFunc
40+
fun testOptionalReturnType(): Short?
41+
}
42+
43+
companion object {
44+
@JvmStatic
45+
external fun testZero(): Short
46+
47+
@JvmStatic
48+
external fun testMin(): Short
49+
50+
@JvmStatic
51+
external fun testMax(): Short
52+
53+
@JvmStatic
54+
external fun testParam(param: Short): Boolean
55+
56+
@JvmStatic
57+
external fun testReturnType(): Short
58+
59+
@JvmStatic
60+
external fun testOptionalParam(param: Short?): Boolean
61+
62+
@JvmStatic
63+
external fun testOptionalReturnType(): Short?
64+
65+
@JvmStatic
66+
external fun testProtocolParam(callback: Int16ParamProtocol): Boolean
67+
68+
@JvmStatic
69+
external fun testProtocolReturnType(callback: Int16ReturnTypeProtocol): Short
70+
71+
@JvmStatic
72+
external fun testProtocolOptionalParam(callback: Int16OptionalParamProtocol): Boolean
73+
74+
@JvmStatic
75+
external fun testProtocolOptionalReturnType(callback: Int16OptionalReturnTypeProtocol): Short?
76+
77+
@JvmStatic
78+
external fun testEncode(): Int16TestStruct
79+
80+
@JvmStatic
81+
external fun testDecode(value: Int16TestStruct): Boolean
82+
}
83+
84+
@Native
85+
var nativePointer: Long = 0
86+
87+
external fun release()
88+
89+
}
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 Int16TestStruct: Codable, Hashable {
8+
public var zero: Int16 = Int16.zero
9+
public var max: Int16 = Int16.max
10+
public var min: Int16 = Int16.min
11+
public var optional: Int16? = Int16.zero
12+
public var optionalNil: Int16? = nil
13+
}
14+
15+
public protocol Int16TestParamProtocol {
16+
func testParam(_ param: Int16) -> Bool
17+
}
18+
19+
public protocol Int16TestReturnTypeProtocol {
20+
func testReturnType() -> Int16
21+
}
22+
23+
public protocol Int16TestOptionalParamProtocol {
24+
func testOptionalParam(_ param: Int16?) -> Bool
25+
}
26+
27+
public protocol Int16TestOptionalReturnTypeProtocol {
28+
func testOptionalReturnType() -> Int16?
29+
}
30+
31+
public class Int16Test {
32+
33+
public static func testZero() -> Int16 {
34+
return 0
35+
}
36+
37+
public static func testMin() -> Int16 {
38+
return Int16.min
39+
}
40+
41+
public static func testMax() -> Int16 {
42+
return Int16.max
43+
}
44+
45+
public static func testParam(_ param: Int16) -> Bool {
46+
return param == Int16.max
47+
}
48+
49+
public static func testReturnType() -> Int16 {
50+
return Int16.max
51+
}
52+
53+
public static func testOptionalParam(_ param: Int16?) -> Bool {
54+
return param == Int16.max
55+
}
56+
57+
public static func testOptionalReturnType() -> Int16? {
58+
return Int16.max
59+
}
60+
61+
public static func testProtocolParam(_ callback: Int16TestParamProtocol) -> Bool {
62+
return callback.testParam(Int16.max)
63+
}
64+
65+
public static func testProtocolReturnType(_ callback: Int16TestReturnTypeProtocol) -> Int16 {
66+
return callback.testReturnType()
67+
}
68+
69+
public static func testProtocolOptionalParam(_ callback: Int16TestOptionalParamProtocol) -> Bool {
70+
return callback.testOptionalParam(Int16.max)
71+
}
72+
73+
public static func testProtocolOptionalReturnType(_ callback: Int16TestOptionalReturnTypeProtocol) -> Int16? {
74+
return callback.testOptionalReturnType()
75+
}
76+
77+
public static func testEncode() -> Int16TestStruct {
78+
return Int16TestStruct()
79+
}
80+
81+
public static func testDecode(_ value: Int16TestStruct) -> Bool {
82+
return value == Int16TestStruct()
83+
}
84+
85+
86+
}

0 commit comments

Comments
 (0)