Skip to content

Commit d5c1038

Browse files
committed
Dev: start working on new primitives tests with Int8Test
1 parent b82255b commit d5c1038

3 files changed

Lines changed: 248 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)