Skip to content

Commit f98db0d

Browse files
author
Anton Pogonets
committed
Add double indirection injection test
1 parent b8a51a7 commit f98db0d

10 files changed

Lines changed: 125 additions & 7 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.3.0'
10-
classpath 'com.readdle.android.swift:gradle:1.1.10'
9+
classpath 'com.android.tools.build:gradle:3.4.0'
10+
classpath 'com.readdle.android.swift:gradle:1.2.0'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
1212
}
1313
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun Apr 29 18:40:15 EEST 2018
1+
#Tue May 07 18:52:08 EEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

library/src/main/java/com/readdle/codegen/anotation/JavaSwift.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class JavaSwift {
44

5-
private JavaSwift() {}
5+
private JavaSwift() {}
66

77
public static native void init();
88

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.Before;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
@RunWith(AndroidJUnit4.class)
12+
public class ProtocolsTest {
13+
14+
@Before
15+
public void setUp() {
16+
System.loadLibrary("SampleAppCore");
17+
JavaSwift.init();
18+
}
19+
20+
@Test
21+
public void testProtocols() {
22+
Service.registerProvider(new ProviderImpl());
23+
}
24+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.readdle.swiftjava.sample;
22

3+
import android.support.test.runner.AndroidJUnit4;
4+
35
import com.readdle.codegen.anotation.JavaSwift;
46
import com.readdle.codegen.anotation.SwiftError;
57

@@ -8,8 +10,6 @@
810
import org.junit.Test;
911
import org.junit.runner.RunWith;
1012

11-
import android.support.test.runner.AndroidJUnit4;
12-
1313
import java.math.BigInteger;
1414
import java.util.UUID;
1515

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.readdle.swiftjava.sample;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.readdle.codegen.anotation.SwiftCallbackFunc;
6+
import com.readdle.codegen.anotation.SwiftDelegate;
7+
8+
@SwiftDelegate(protocols = {"Provider"})
9+
public interface Provider {
10+
@SwiftCallbackFunc("fill(storage:)")
11+
void fillStorage(@NonNull Storage storage);
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.readdle.swiftjava.sample;
2+
3+
import android.support.annotation.NonNull;
4+
5+
public class ProviderImpl implements Provider {
6+
public void fillStorage(@NonNull Storage storage) {
7+
storage.add("Hello");
8+
storage.add("from");
9+
storage.add("java");
10+
storage.release();
11+
}
12+
}
13+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.readdle.swiftjava.sample;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.readdle.codegen.anotation.SwiftFunc;
6+
import com.readdle.codegen.anotation.SwiftReference;
7+
8+
import java.lang.annotation.Native;
9+
10+
@SwiftReference
11+
public class Service {
12+
@Native
13+
private long nativePointer = 0L;
14+
15+
private Service() {
16+
}
17+
18+
public native void release();
19+
20+
@NonNull
21+
public static native Service init();
22+
23+
@SwiftFunc("register(provider:)")
24+
native static void registerProvider(@NonNull Provider provider);
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.readdle.swiftjava.sample;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.readdle.codegen.anotation.SwiftReference;
6+
7+
import java.lang.annotation.Native;
8+
9+
// This is protocol on swift side
10+
@SwiftReference
11+
public class Storage {
12+
@Native
13+
private long nativePointer = 0L;
14+
15+
private Storage() {
16+
}
17+
18+
public native void release();
19+
20+
@NonNull
21+
public static native Storage init();
22+
23+
native void add(@NonNull String str);
24+
}
25+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public protocol Provider {
2+
func fill(storage: Storage)
3+
}
4+
5+
public protocol Storage {
6+
func add(_ str: String)
7+
}
8+
9+
class StorageImpl: Storage {
10+
func add(_ str: String) {
11+
print(str)
12+
}
13+
}
14+
15+
public class Service {
16+
public class func register(provider: Provider) {
17+
provider.fill(storage: StorageImpl())
18+
}
19+
}

0 commit comments

Comments
 (0)