Skip to content

Commit 2e7d37d

Browse files
committed
Merge remote-tracking branch 'origin/118-full-utf-8-tests' into dev
2 parents d3b96d0 + 7ac7bbe commit 2e7d37d

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

tests/objectbox-java-test/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ apply plugin: 'kotlin'
33

44
uploadArchives.enabled = false
55

6-
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
7-
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
86
tasks.withType(JavaCompile) {
7+
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
8+
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
99
options.release.set(8)
10+
// Note: Gradle defaults to the platform default encoding, make sure to always use UTF-8 for UTF-8 tests.
11+
options.encoding = "UTF-8"
1012
}
1113

1214
// Produce Java 8 byte code, would default to Java 6.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.objectbox;
2+
3+
import io.objectbox.annotation.IndexType;
4+
5+
/**
6+
* Same as {@link Utf8Test}, but with index on simpleString.
7+
*/
8+
public class Utf8HashIndexTest extends Utf8Test {
9+
10+
@Override
11+
protected BoxStore createBoxStore() {
12+
return createBoxStore(IndexType.HASH);
13+
}
14+
15+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.objectbox;
2+
3+
import org.junit.Test;
4+
5+
import java.util.List;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
/**
10+
* The Java VM does not recognize the four-byte format of standard UTF-8;
11+
* it uses its own two-times-three-byte format instead. Test to ensure these
12+
* supplementary characters (code points above U+FFFF) are properly supported.
13+
*/
14+
public class Utf8Test extends AbstractObjectBoxTest {
15+
16+
// U+1F600, U+1F601, U+1F602
17+
private static final String TEST_STRING = "😀😃😂 Hello";
18+
19+
@Test
20+
public void putGetAndQuery_works() {
21+
// Java stores UTF-16 internally (2 chars per emoji)
22+
assertEquals(3 * 2 + 6, TEST_STRING.length());
23+
24+
// Put
25+
TestEntity put = putTestEntity(TEST_STRING, 1);
26+
putTestEntity("🚀🚁🚄", 2); // U+1F680, U+1F681, U+1F684
27+
putTestEntity("😀🚁🚄", 3); // U+1F600, U+1F681, U+1F684
28+
assertEquals(3, getTestEntityBox().count());
29+
30+
// Get
31+
TestEntity get = getTestEntityBox().get(put.getId());
32+
assertEquals(TEST_STRING, get.getSimpleString());
33+
34+
// Query String with equals
35+
List<TestEntity> results = getTestEntityBox().query(
36+
TestEntity_.simpleString.equal(TEST_STRING)
37+
).build().find();
38+
assertEquals(1, results.size());
39+
assertEquals(TEST_STRING, results.get(0).getSimpleString());
40+
41+
// Query String with starts with
42+
List<TestEntity> resultsStartsWith = getTestEntityBox().query(
43+
TestEntity_.simpleString.startsWith("😀") // U+1F600
44+
).build().find();
45+
assertEquals(2, resultsStartsWith.size());
46+
assertEquals(1, resultsStartsWith.get(0).getSimpleInt());
47+
assertEquals(3, resultsStartsWith.get(1).getSimpleInt());
48+
49+
// Query String array
50+
List<TestEntity> resultsArray = getTestEntityBox().query(
51+
TestEntity_.simpleStringArray.containsElement(TEST_STRING)
52+
).build().find();
53+
assertEquals(1, resultsArray.size());
54+
assertEquals(TEST_STRING, resultsArray.get(0).getSimpleString());
55+
}
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.objectbox;
2+
3+
import io.objectbox.annotation.IndexType;
4+
5+
/**
6+
* Same as {@link Utf8Test}, but with index on simpleString.
7+
*/
8+
public class Utf8ValueIndexTest extends Utf8Test {
9+
10+
@Override
11+
protected BoxStore createBoxStore() {
12+
return createBoxStore(IndexType.VALUE);
13+
}
14+
15+
}

0 commit comments

Comments
 (0)