Skip to content

Commit a0f315e

Browse files
committed
Dev: add tests for primitives issue
1 parent c62a089 commit a0f315e

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.readdle.swiftjava.sample
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import com.readdle.codegen.anotation.JavaSwift
5+
import com.readdle.swiftjava.sample.SwiftEnvironment.Companion.initEnvironment
6+
import org.junit.Assert
7+
import org.junit.Before
8+
import org.junit.Test
9+
import org.junit.runner.RunWith
10+
11+
@RunWith(AndroidJUnit4::class)
12+
class Issue31Tests {
13+
14+
@Before
15+
fun setUp() {
16+
System.loadLibrary("SampleAppCore")
17+
JavaSwift.init()
18+
initEnvironment()
19+
}
20+
21+
@Test
22+
fun testValueTypeNanBug() {
23+
val progress = Issue31TestProgress(elapsed = 8, total = 8)
24+
Assert.assertNotEquals(Double.NaN, progress.percentage)
25+
Assert.assertNotEquals(Double.NaN, progress.calculatePercentage())
26+
}
27+
28+
@Test
29+
fun testReferenceTypeNanBug() {
30+
val progress = Issue31ReferenceTestProgress.init(elapsed = 8, total = 8)
31+
Assert.assertNotEquals(Double.NaN, progress.percentage)
32+
Assert.assertNotEquals(Double.NaN, progress.calculatePercentage())
33+
}
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.readdle.swiftjava.sample
2+
3+
import com.readdle.codegen.anotation.SwiftFunc
4+
import com.readdle.codegen.anotation.SwiftGetter
5+
import com.readdle.codegen.anotation.SwiftReference
6+
import com.readdle.codegen.anotation.SwiftValue
7+
8+
@SwiftValue
9+
data class Issue31TestProgress(
10+
var elapsed: Int = 0,
11+
var total: Int = 1
12+
) {
13+
@get:SwiftGetter
14+
val percentage: Double external get
15+
16+
@SwiftFunc
17+
external fun calculatePercentage(): Double
18+
}
19+
20+
@SwiftReference
21+
class Issue31ReferenceTestProgress private constructor() {
22+
// Swift JNI private native pointer
23+
private val nativePointer = 0L
24+
25+
// Swift JNI release method
26+
external fun release()
27+
28+
@get:SwiftGetter
29+
val percentage: Double external get
30+
31+
@SwiftFunc
32+
external fun calculatePercentage(): Double
33+
34+
companion object {
35+
@JvmStatic
36+
@SwiftFunc("init(elapsed:total:)")
37+
external fun init(elapsed: Int, total: Int): Issue31ReferenceTestProgress
38+
}
39+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Foundation
2+
3+
public struct Issue31TestProgress: Codable {
4+
public let elapsed: Int
5+
public let total: Int
6+
7+
public var percentage: Double {
8+
return 1.0
9+
}
10+
11+
public init(elapsed: Int, total: Int) {
12+
self.elapsed = elapsed
13+
self.total = total
14+
}
15+
16+
public func calculatePercentage() -> Double {
17+
return percentage
18+
}
19+
}
20+
21+
public class Issue31ReferenceTestProgress: Codable {
22+
public let elapsed: Int
23+
public let total: Int
24+
25+
public var percentage: Double {
26+
return 1.0
27+
}
28+
29+
public init(elapsed: Int, total: Int) {
30+
self.elapsed = elapsed
31+
self.total = total
32+
}
33+
34+
public func calculatePercentage() -> Double {
35+
return percentage
36+
}
37+
}

0 commit comments

Comments
 (0)