Skip to content

Commit 21c32ce

Browse files
committed
Dev: add kotlin support for SwiftValue
1 parent d3a47b1 commit 21c32ce

6 files changed

Lines changed: 180 additions & 217 deletions

File tree

sample/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ android {
4545
}
4646
}
4747

48+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
49+
kotlinOptions {
50+
jvmTarget = '1.8'
51+
freeCompilerArgs += '-Xuse-experimental=kotlin.ExperimentalUnsignedTypes'
52+
}
53+
}
54+
4855
dependencies {
4956
kapt project(':compiler')
5057
implementation project(':library')

sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleValueTest.java

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.readdle.swiftjava.sample
2+
3+
import android.support.test.runner.AndroidJUnit4
4+
import com.readdle.codegen.anotation.JavaSwift
5+
import com.readdle.codegen.anotation.SwiftError
6+
import com.readdle.swiftjava.sample.SampleValue.Companion.funcThrows
7+
import com.readdle.swiftjava.sample.SampleValue.Companion.randomValue
8+
import org.junit.Assert
9+
import org.junit.Before
10+
import org.junit.Test
11+
import org.junit.runner.RunWith
12+
import java.util.*
13+
14+
@RunWith(AndroidJUnit4::class)
15+
class SampleValueTest {
16+
@Before
17+
fun setUp() {
18+
System.loadLibrary("SampleAppCore")
19+
JavaSwift.init()
20+
}
21+
22+
@Test
23+
fun testGetRandomValue() {
24+
val sampleValue = randomValue.copy()
25+
Assert.assertNotNull(sampleValue)
26+
Assert.assertTrue(sampleValue.string.isNotEmpty())
27+
Assert.assertTrue(sampleValue.integer == 32)
28+
Assert.assertTrue(sampleValue.int8.toInt() == 8)
29+
Assert.assertTrue(sampleValue.int16.toInt() == 16)
30+
Assert.assertTrue(sampleValue.int32 == 32)
31+
Assert.assertTrue(sampleValue.int64 == 64L)
32+
Assert.assertTrue(sampleValue.uint == 32U)
33+
Assert.assertTrue(sampleValue.uint8.toUInt() == 8U)
34+
Assert.assertTrue(sampleValue.uint16.toUInt() == 16U)
35+
Assert.assertTrue(sampleValue.uint32 == 32U)
36+
Assert.assertTrue(sampleValue.uint64.toUInt() == 64U)
37+
Assert.assertTrue(sampleValue.objectArray.isEmpty())
38+
Assert.assertTrue(sampleValue.stringArray.size == 3)
39+
Assert.assertTrue(sampleValue.numberArray.size == 3)
40+
Assert.assertTrue(sampleValue.arrayInArray[0].size == 3)
41+
Assert.assertTrue(sampleValue.dictInArray[0].size == 3)
42+
Assert.assertTrue(sampleValue.dictSampleClass.isEmpty())
43+
Assert.assertTrue(sampleValue.dictStrings.size == 1)
44+
Assert.assertTrue(sampleValue.dictNumbers.size == 1)
45+
Assert.assertTrue(sampleValue.dict64Numbers.size == 1)
46+
Assert.assertTrue(sampleValue.dictInDict.size == 1)
47+
Assert.assertTrue(sampleValue.arrayInDict.size == 1)
48+
Assert.assertTrue(sampleValue.set.size == 3)
49+
Assert.assertTrue(sampleValue.setValues.isEmpty())
50+
}
51+
52+
@Test
53+
fun testSaveValue() {
54+
val sampleValue = randomValue
55+
sampleValue.string = UUID.randomUUID().toString()
56+
sampleValue.saveValue()
57+
}
58+
59+
@Test
60+
fun testIsSame() {
61+
val otherValue = randomValue
62+
val sampleValue = randomValue
63+
sampleValue.string = otherValue.string
64+
Assert.assertTrue(sampleValue.isSame(otherValue))
65+
}
66+
67+
@Test
68+
fun testThrows() {
69+
try {
70+
funcThrows()
71+
Assert.fail()
72+
} catch (swiftError: SwiftError) {
73+
Assert.assertTrue(swiftError.message != null)
74+
}
75+
}
76+
}

sample/src/main/java/com/readdle/swiftjava/sample/SampleDelegateAndroid.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.util.Log
77
import java.nio.ByteBuffer
88

99
@SwiftDelegate(protocols = ["SampleDelegate"])
10-
//@UseExperimental(ExperimentalUnsignedTypes::class)
1110
abstract class SampleDelegateAndroid {
1211

1312
// Swift JNI private native pointer

sample/src/main/java/com/readdle/swiftjava/sample/SampleValue.java

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)