Skip to content

Commit e4ee9e1

Browse files
committed
Dev: add Int64 test
1 parent 537a72a commit e4ee9e1

File tree

3 files changed

+274
-0
lines changed

3 files changed

+274
-0
lines changed
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 Int64Tests {
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(Int64Test.testZero(), 0);
25+
}
26+
27+
@Test
28+
public void testMin() {
29+
Assert.assertEquals(Int64Test.testMin(), Long.MIN_VALUE);
30+
}
31+
32+
@Test
33+
public void testMax() {
34+
Assert.assertEquals(Int64Test.testMax(), Long.MAX_VALUE);
35+
}
36+
37+
@Test
38+
public void testParam() {
39+
Assert.assertTrue(Int64Test.testParam(Long.MAX_VALUE));
40+
Assert.assertFalse(Int64Test.testParam(Long.MIN_VALUE));
41+
}
42+
43+
@Test
44+
public void testReturnType() {
45+
Assert.assertEquals(Int64Test.testReturnType(), Long.MAX_VALUE);
46+
}
47+
48+
@Test
49+
public void testOptionalParam() {
50+
Assert.assertTrue(Int64Test.testOptionalParam(Long.MAX_VALUE));
51+
Assert.assertFalse(Int64Test.testOptionalParam(Long.MIN_VALUE));
52+
}
53+
54+
public void testOptionalReturnType() {
55+
Long result = Int64Test.testOptionalReturnType();
56+
Assert.assertNotNull(result);
57+
Assert.assertEquals(result.shortValue(), Long.MAX_VALUE);
58+
}
59+
60+
@Test
61+
public void testProtocolParam() {
62+
boolean result = Int64Test.testProtocolParam(param -> param == Long.MAX_VALUE);
63+
Assert.assertTrue(result);
64+
}
65+
66+
@Test
67+
public void testProtocolReturnType() {
68+
long result = Int64Test.testProtocolReturnType(() -> (long) 42);
69+
Assert.assertEquals(result, 42);
70+
}
71+
72+
@Test
73+
public void testProtocolOptionalParam() {
74+
boolean result = Int64Test.testProtocolOptionalParam(param -> param != null && param == Long.MAX_VALUE);
75+
Assert.assertTrue(result);
76+
}
77+
78+
@Test
79+
public void testProtocolOptionalReturnType() {
80+
Long result = Int64Test.testProtocolOptionalReturnType(() -> (long) 42);
81+
Assert.assertNotNull(result);
82+
Assert.assertEquals(result.shortValue(), 42);
83+
}
84+
85+
@Test
86+
public void testEncode() {
87+
Int64TestStruct result = Int64Test.testEncode();
88+
Assert.assertEquals(result, new Int64TestStruct());
89+
}
90+
91+
@Test
92+
public void testDecode() {
93+
Int64TestStruct goodParam = new Int64TestStruct();
94+
Int64TestStruct badParam = new Int64TestStruct(42, 42, 42, (long) 42, (long) 42);
95+
Assert.assertTrue(Int64Test.testDecode(goodParam));
96+
Assert.assertFalse(Int64Test.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 Int64TestStruct(var zero: Long = 0,
11+
var max: Long = Long.MAX_VALUE,
12+
var min: Long = Long.MIN_VALUE,
13+
var optional: Long? = 0,
14+
var optionalNil: Long? = null)
15+
16+
@SwiftReference
17+
class Int64Test private constructor() {
18+
19+
@SwiftDelegate(protocols = ["Int64TestParamProtocol"])
20+
interface Int64ParamProtocol {
21+
@SwiftCallbackFunc
22+
fun testParam(param: Long): Boolean
23+
}
24+
25+
@SwiftDelegate(protocols = ["Int64TestReturnTypeProtocol"])
26+
interface Int64ReturnTypeProtocol {
27+
@SwiftCallbackFunc
28+
fun testReturnType(): Long
29+
}
30+
31+
@SwiftDelegate(protocols = ["Int64TestOptionalParamProtocol"])
32+
interface Int64OptionalParamProtocol {
33+
@SwiftCallbackFunc
34+
fun testOptionalParam(param: Long?): Boolean
35+
}
36+
37+
@SwiftDelegate(protocols = ["Int64TestOptionalReturnTypeProtocol"])
38+
interface Int64OptionalReturnTypeProtocol {
39+
@SwiftCallbackFunc
40+
fun testOptionalReturnType(): Long?
41+
}
42+
43+
companion object {
44+
@JvmStatic
45+
external fun testZero(): Long
46+
47+
@JvmStatic
48+
external fun testMin(): Long
49+
50+
@JvmStatic
51+
external fun testMax(): Long
52+
53+
@JvmStatic
54+
external fun testParam(param: Long): Boolean
55+
56+
@JvmStatic
57+
external fun testReturnType(): Long
58+
59+
@JvmStatic
60+
external fun testOptionalParam(param: Long?): Boolean
61+
62+
@JvmStatic
63+
external fun testOptionalReturnType(): Long?
64+
65+
@JvmStatic
66+
external fun testProtocolParam(callback: Int64ParamProtocol): Boolean
67+
68+
@JvmStatic
69+
external fun testProtocolReturnType(callback: Int64ReturnTypeProtocol): Long
70+
71+
@JvmStatic
72+
external fun testProtocolOptionalParam(callback: Int64OptionalParamProtocol): Boolean
73+
74+
@JvmStatic
75+
external fun testProtocolOptionalReturnType(callback: Int64OptionalReturnTypeProtocol): Long?
76+
77+
@JvmStatic
78+
external fun testEncode(): Int64TestStruct
79+
80+
@JvmStatic
81+
external fun testDecode(value: Int64TestStruct): 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 Int64TestStruct: Codable, Hashable {
8+
public var zero: Int64 = Int64.zero
9+
public var max: Int64 = Int64.max
10+
public var min: Int64 = Int64.min
11+
public var optional: Int64? = Int64.zero
12+
public var optionalNil: Int64? = nil
13+
}
14+
15+
public protocol Int64TestParamProtocol {
16+
func testParam(_ param: Int64) -> Bool
17+
}
18+
19+
public protocol Int64TestReturnTypeProtocol {
20+
func testReturnType() -> Int64
21+
}
22+
23+
public protocol Int64TestOptionalParamProtocol {
24+
func testOptionalParam(_ param: Int64?) -> Bool
25+
}
26+
27+
public protocol Int64TestOptionalReturnTypeProtocol {
28+
func testOptionalReturnType() -> Int64?
29+
}
30+
31+
public class Int64Test {
32+
33+
public static func testZero() -> Int64 {
34+
return 0
35+
}
36+
37+
public static func testMin() -> Int64 {
38+
return Int64.min
39+
}
40+
41+
public static func testMax() -> Int64 {
42+
return Int64.max
43+
}
44+
45+
public static func testParam(_ param: Int64) -> Bool {
46+
return param == Int64.max
47+
}
48+
49+
public static func testReturnType() -> Int64 {
50+
return Int64.max
51+
}
52+
53+
public static func testOptionalParam(_ param: Int64?) -> Bool {
54+
return param == Int64.max
55+
}
56+
57+
public static func testOptionalReturnType() -> Int64? {
58+
return Int64.max
59+
}
60+
61+
public static func testProtocolParam(_ callback: Int64TestParamProtocol) -> Bool {
62+
return callback.testParam(Int64.max)
63+
}
64+
65+
public static func testProtocolReturnType(_ callback: Int64TestReturnTypeProtocol) -> Int64 {
66+
return callback.testReturnType()
67+
}
68+
69+
public static func testProtocolOptionalParam(_ callback: Int64TestOptionalParamProtocol) -> Bool {
70+
return callback.testOptionalParam(Int64.max)
71+
}
72+
73+
public static func testProtocolOptionalReturnType(_ callback: Int64TestOptionalReturnTypeProtocol) -> Int64? {
74+
return callback.testOptionalReturnType()
75+
}
76+
77+
public static func testEncode() -> Int64TestStruct {
78+
return Int64TestStruct()
79+
}
80+
81+
public static func testDecode(_ value: Int64TestStruct) -> Bool {
82+
return value == Int64TestStruct()
83+
}
84+
85+
86+
}

0 commit comments

Comments
 (0)