Skip to content

Commit ab14504

Browse files
committed
Dev: update sample tests
1 parent bcfd3c3 commit ab14504

9 files changed

Lines changed: 200 additions & 42 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
9+
classpath 'com.android.tools.build:gradle:3.1.0'
1010
classpath 'com.readdle.android.swift:swift-android-gradle:1.1.2'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
1212
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Jan 02 19:01:34 EET 2018
1+
#Sun Apr 29 18:40:15 EEST 2018
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.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

sample/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ dependencies {
3030
annotationProcessor project(':compiler')
3131
implementation project(':library')
3232

33-
implementation 'com.android.support:appcompat-v7:27.0.2'
34-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
33+
implementation 'com.android.support:appcompat-v7:27.1.1'
34+
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
3535
testImplementation 'junit:junit:4.12'
36-
androidTestImplementation 'com.android.support.test:runner:1.0.1'
37-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
36+
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
37+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
38+
androidTestImplementation 'com.android.support.test:rules:1.0.2'
39+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3840
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import android.support.test.runner.AndroidJUnit4;
1616
import android.test.suitebuilder.annotation.LargeTest;
1717

18+
import java.util.UUID;
19+
1820
@RunWith(AndroidJUnit4.class)
1921
@LargeTest
2022
public class SampleReferenceTest {
@@ -41,10 +43,8 @@ public void testGetRandomValue() {
4143

4244
@Test
4345
public void testSaveValue() {
44-
SampleValue sampleValue = new SampleValue();
45-
sampleValue.str1 = "str1";
46-
sampleValue.str2 = "str2";
47-
sampleValue.str3 = "str3";
46+
SampleValue sampleValue = SampleValue.getRandomValue();
47+
sampleValue.string = UUID.randomUUID().toString();
4848
sampleReference.saveValue(sampleValue);
4949
}
5050

@@ -75,7 +75,7 @@ void onSetSampleValue(SampleValue value) {
7575
};
7676
sampleReference.setDelegate(delegateAndroid);
7777
Assert.assertTrue(System.currentTimeMillis() - sampleReference.tick() < 1000);
78-
Assert.assertTrue(delegateAndroid.sampleValue.equals(sampleReference.getRandomValue()));
78+
Assert.assertTrue(!delegateAndroid.sampleValue.string.isEmpty());
7979
Assert.assertTrue(isFlag[0]);
8080
Assert.assertNull(sampleReference.funcWithNil());
8181
delegateAndroid.release();

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import android.support.test.runner.AndroidJUnit4;
1212
import android.test.suitebuilder.annotation.LargeTest;
1313

14+
import java.math.BigInteger;
15+
import java.util.UUID;
16+
1417
@RunWith(AndroidJUnit4.class)
1518
@LargeTest
1619
public class SampleValueTest {
@@ -23,25 +26,50 @@ public void setUp() {
2326

2427
@Test
2528
public void testGetRandomValue() {
26-
Assert.assertNotNull(SampleValue.getRandomValue());
29+
SampleValue sampleValue = SampleValue.getRandomValue().copy();
30+
Assert.assertNotNull(sampleValue);
31+
Assert.assertTrue(!sampleValue.string.isEmpty());
32+
Assert.assertTrue(sampleValue.integer == 32);
33+
Assert.assertTrue(sampleValue.int8 == 8);
34+
Assert.assertTrue(sampleValue.int16 == 16);
35+
Assert.assertTrue(sampleValue.int32 == 32);
36+
Assert.assertTrue(sampleValue.int64 == 64);
37+
Assert.assertTrue(sampleValue.uint == 32);
38+
Assert.assertTrue(sampleValue.uint8 == 8);
39+
Assert.assertTrue(sampleValue.uint16 == 16);
40+
Assert.assertTrue(sampleValue.uint32 == 32);
41+
Assert.assertTrue(sampleValue.uint64.equals(BigInteger.valueOf(64)));
42+
43+
Assert.assertTrue(sampleValue.objectArray.isEmpty());
44+
Assert.assertTrue(sampleValue.stringArray.size() == 3);
45+
Assert.assertTrue(sampleValue.numberArray.size() == 3);
46+
Assert.assertTrue(sampleValue.arrayInArray.get(0).size() == 3);
47+
Assert.assertTrue(sampleValue.dictInArray.get(0).size() == 3);
48+
49+
Assert.assertTrue(sampleValue.dictSampleClass.isEmpty());
50+
Assert.assertTrue(sampleValue.dictStrings.size() == 1);
51+
Assert.assertTrue(sampleValue.dictNumbers.size() == 1);
52+
Assert.assertTrue(sampleValue.dict64Numbers.size() == 1);
53+
Assert.assertTrue(sampleValue.dictInDict.size() == 1);
54+
Assert.assertTrue(sampleValue.arrayInDict.size() == 1);
55+
56+
Assert.assertTrue(sampleValue.set.size() == 3);
57+
Assert.assertTrue(sampleValue.setValues.isEmpty());
58+
2759
}
2860

2961
@Test
3062
public void testSaveValue() {
31-
SampleValue sampleValue = new SampleValue();
32-
sampleValue.str1 = "str1";
33-
sampleValue.str2 = "str2";
34-
sampleValue.str3 = "str3";
63+
SampleValue sampleValue = SampleValue.getRandomValue();
64+
sampleValue.string = UUID.randomUUID().toString();
3565
sampleValue.saveValue();
3666
}
3767

3868
@Test
3969
public void testIsSame() {
4070
SampleValue otherValue = SampleValue.getRandomValue();
41-
SampleValue sampleValue = new SampleValue();
42-
sampleValue.str1 = otherValue.str1;
43-
sampleValue.str2 = otherValue.str2;
44-
sampleValue.str3 = otherValue.str3;
71+
SampleValue sampleValue = SampleValue.getRandomValue();
72+
sampleValue.string = otherValue.string;
4573
Assert.assertTrue(sampleValue.isSame(otherValue));
4674
}
4775

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

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,81 @@
55
import com.readdle.codegen.anotation.SwiftValue;
66

77
import android.support.annotation.NonNull;
8+
import android.support.annotation.Nullable;
89

10+
import java.math.BigInteger;
11+
import java.util.ArrayList;
12+
import java.util.HashMap;
13+
import java.util.HashSet;
914
import java.util.Objects;
1015

1116
@SwiftValue
1217
public class SampleValue {
1318

1419
@NonNull
15-
public String str1;
20+
public String string;
1621
@NonNull
17-
public String str2;
22+
Integer integer;
1823
@NonNull
19-
public String str3;
24+
Byte int8;
25+
@NonNull
26+
Short int16;
27+
@NonNull
28+
Integer int32;
29+
@NonNull
30+
Long int64;
31+
32+
@NonNull
33+
Long uint;
34+
@NonNull
35+
Short uint8;
36+
@NonNull
37+
Integer uint16;
38+
@NonNull
39+
Long uint32;
40+
@NonNull
41+
BigInteger uint64;
42+
43+
@NonNull
44+
ArrayList<SampleValue> objectArray;
45+
@NonNull
46+
ArrayList<String> stringArray;
47+
@NonNull
48+
ArrayList<Integer> numberArray;
49+
@NonNull
50+
ArrayList<ArrayList<Integer>> arrayInArray;
51+
@NonNull
52+
ArrayList<HashMap<Integer, Integer>> dictInArray;
53+
54+
@NonNull
55+
HashMap<String, SampleValue> dictSampleClass;
56+
@NonNull
57+
HashMap<String, String> dictStrings;
58+
@NonNull
59+
HashMap<Integer, Integer> dictNumbers;
60+
@NonNull
61+
HashMap<BigInteger, BigInteger> dict64Numbers;
62+
@NonNull
63+
HashMap<BigInteger, HashMap<BigInteger, BigInteger>> dictInDict;
64+
@NonNull
65+
HashMap<BigInteger, ArrayList<BigInteger>> arrayInDict;
66+
67+
@NonNull
68+
HashSet<Integer> set;
69+
@NonNull
70+
HashSet<SampleValue> setValues;
2071

2172
// Swift JNI constructor
22-
public SampleValue() {
73+
private SampleValue() {
2374

2475
}
2576

2677
@NonNull
2778
public static native SampleValue getRandomValue();
2879

80+
@NonNull
81+
public native SampleValue copy();
82+
2983
public native void saveValue();
3084

3185
@NonNull @SwiftFunc("isSame(other:)")
@@ -38,13 +92,41 @@ public boolean equals(Object o) {
3892
if (this == o) return true;
3993
if (!(o instanceof SampleValue)) return false;
4094
SampleValue that = (SampleValue) o;
41-
return Objects.equals(str1, that.str1) &&
42-
Objects.equals(str2, that.str2) &&
43-
Objects.equals(str3, that.str3);
95+
return Objects.equals(string, that.string);
4496
}
4597

4698
@Override
4799
public int hashCode() {
48-
return Objects.hash(str1, str2, str3);
100+
return Objects.hash(string);
101+
}
102+
103+
@Override
104+
public String toString() {
105+
return "SampleValue{" +
106+
"string='" + string + '\'' +
107+
", integer=" + integer +
108+
", int8=" + int8 +
109+
", int16=" + int16 +
110+
", int32=" + int32 +
111+
", int64=" + int64 +
112+
", uint=" + uint +
113+
", uint8=" + uint8 +
114+
", uint16=" + uint16 +
115+
", uint32=" + uint32 +
116+
", uint64=" + uint64 +
117+
", objectArray=" + objectArray +
118+
", stringArray=" + stringArray +
119+
", numberArray=" + numberArray +
120+
", arrayInArray=" + arrayInArray +
121+
", dictInArray=" + dictInArray +
122+
", dictSampleClass=" + dictSampleClass +
123+
", dictStrings=" + dictStrings +
124+
", dictNumbers=" + dictNumbers +
125+
", dict64Numbers=" + dict64Numbers +
126+
", dictInDict=" + dictInDict +
127+
", arrayInDict=" + arrayInDict +
128+
", set=" + set +
129+
", setValues=" + setValues +
130+
'}';
49131
}
50132
}

sample/src/main/swift/Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ let package = Package(
5757
products: addGenerated([
5858
]),
5959
dependencies: [
60-
.package(url: "https://github.com/andriydruk/java_swift.git", .branch("master")),
61-
.package(url: "https://github.com/andriydruk/swift-java.git", .branch("master")),
62-
.package(url: "https://github.com/andriydruk/swift-java-coder.git", .branch("master")),
63-
.package(url: "https://github.com/andriydruk/swift-anycodable.git", .branch("master")),
60+
.package(url: "https://github.com/andriydruk/java_swift.git", .exact("2.1.2")),
61+
.package(url: "https://github.com/andriydruk/swift-java.git", .exact("0.1.2")),
62+
.package(url: "https://github.com/andriydruk/swift-java-coder.git", .exact("1.0.2")),
63+
.package(url: "https://github.com/andriydruk/swift-anycodable.git", .exact("1.0.0")),
6464
],
6565
targets: addGenerated([
6666
.target(name: packageName, dependencies: ["AnyCodable"])

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public class SampleReference {
5151
}
5252

5353
public func getRandomValue() -> SampleValue {
54-
return SampleValue(str1: "1", str2: "2", str3: "3")
54+
return SampleValue(string: UUID().uuidString)
5555
}
5656

5757
public func saveValue(_ value: SampleValue) {
58-
NSLog("SampleValue: \(value.str1), \(value.str2), \(value.str3)")
58+
NSLog("save SampleValue: \(value.string)")
5959
}
6060

6161
public func funcThrows() throws {
Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,70 @@
11
import Foundation
22

3-
public struct SampleValue: Codable {
3+
public struct SampleValue: Codable, Hashable {
44

5-
public var str1: String
6-
public var str2: String
7-
public var str3: String
5+
public var string: String
6+
7+
public var integer: Int = 32
8+
public var int8: Int8 = 8
9+
public var int16: Int16 = 16
10+
public var int32: Int32 = 32
11+
public var int64: Int64 = 64
12+
13+
public var uint: UInt = 32
14+
public var uint8: UInt8 = 8
15+
public var uint16: UInt16 = 16
16+
public var uint32: UInt32 = 32
17+
public var uint64: UInt64 = 64
18+
19+
public var objectArray: [SampleValue] = []
20+
public var stringArray: [String] = ["one", "two", "free"]
21+
public var numberArray: [Int] = [1, 2, 3]
22+
public var arrayInArray: [[Int]] = [[1, 2, 3]]
23+
public var dictInArray: [[Int:Int]] = [[1: 1, 2: 2, 3: 3]]
24+
25+
public var dictSampleClass: [String: SampleValue] = [:]
26+
public var dictStrings: [String: String] = ["oneKey": "oneValue"]
27+
public var dictNumbers: [Int: Int] = [123: 2]
28+
public var dict64Numbers: [UInt64: UInt64] = [123: 2]
29+
public var dictInDict: [UInt64: [UInt64: UInt64]] = [123: [123: 2]]
30+
public var arrayInDict: [UInt64: [UInt64]] = [123: [1, 2, 3]]
31+
32+
public var set = Set<Int>(arrayLiteral: 1, 2, 3)
33+
public var setValues = Set<SampleValue>();
34+
35+
public init(string: String) {
36+
self.string = string
37+
}
838

939
public static func getRandomValue() -> SampleValue {
10-
return SampleValue(str1: "1", str2: "2", str3: "3")
40+
return SampleValue(string: UUID().uuidString)
1141
}
1242

1343
public func saveValue() {
14-
NSLog("SampleValue: \(str1), \(str2), \(str3)")
44+
NSLog("save SampleValue: \(string)")
1545
}
1646

1747
public func isSame(other: SampleValue) -> Bool {
18-
return str1 == other.str1 && str2 == other.str2 && str3 == other.str3
48+
return self == other
1949
}
2050

2151
public static func funcThrows() throws {
2252
throw NSError(domain: "Error", code: 1)
2353
}
54+
55+
//MARK: - dump hashable impl
56+
public var hashValue: Int {
57+
return string.hashValue
58+
}
59+
60+
public static func ==(lhs: SampleValue, rhs: SampleValue) -> Bool {
61+
return lhs.string == rhs.string
62+
}
63+
64+
public func copy() -> SampleValue {
65+
var copy = self
66+
copy.string = UUID().uuidString
67+
return copy
68+
}
69+
2470
}

0 commit comments

Comments
 (0)