Skip to content

Commit ea1b5c2

Browse files
committed
Dev: add test for local table overflow with Data func
1 parent 90fdb24 commit ea1b5c2

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,16 @@ public void testNullPointerAfterRelease() {
249249
Assert.assertTrue(error.getMessage().equals("java.lang.NullPointerException: 1"));
250250
}
251251
}
252+
253+
// Run on Android 7.0 to fail
254+
@Test
255+
public void testLocalTableOverflow3() {
256+
sampleReference.oneMoreReferenceTableOverflow(new SampleDelegateAndroid() {
257+
@Override
258+
void onSetSampleValue(SampleValue value) {
259+
// empty
260+
}
261+
});
262+
}
252263

253264
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import android.support.annotation.Nullable;
88
import android.util.Log;
99

10+
import java.nio.ByteBuffer;
11+
1012
@SwiftDelegate(protocols = {"SampleDelegate"})
1113
public abstract class SampleDelegateAndroid {
1214

@@ -72,7 +74,11 @@ public String throwableFuncWithReturnType(@NonNull Boolean flag) throws Exceptio
7274
}
7375
}
7476

75-
77+
@SwiftCallbackFunc @NonNull
78+
public ByteBuffer funcWithData() {
79+
byte[] tenBytes = new byte[10];
80+
return ByteBuffer.wrap(tenBytes);
81+
}
7682

7783
abstract void onSetSampleValue(SampleValue value);
7884

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,6 @@ public interface CompletionBlock {
147147

148148
public native void saveCustomSampleValue(@NonNull CustomSampleValue value);
149149

150+
public native void oneMoreReferenceTableOverflow(@NonNull SampleDelegateAndroid delegate);
151+
150152
}

sample/src/main/swift/Sources/SampleAppCore/SampleReference.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public protocol SampleDelegate: class {
1515
func throwableFunc(_ flag: Bool) throws
1616

1717
func throwableFuncWithReturnType(_ flag: Bool) throws -> String
18+
19+
func funcWithData() -> Data
1820
}
1921

2022
public protocol SampleBlockDelegate {
@@ -147,4 +149,14 @@ public class SampleReference {
147149
NSLog("save SampleValue: \(value.string)")
148150
}
149151

152+
public func oneMoreReferenceTableOverflow(_ delegate: SampleDelegate) {
153+
// For table overflow test
154+
for i in 0 ..< 512 {
155+
let data = delegate.funcWithData()
156+
if data.count != 10 {
157+
fatalError("Wrong data count \(data.count) != 10")
158+
}
159+
}
160+
}
161+
150162
}

0 commit comments

Comments
 (0)