Skip to content

Commit 2b9ed7b

Browse files
Test four-byte UTF-8.
1 parent a55115f commit 2b9ed7b

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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
17+
private static final String TEST_STRING = "😁";
18+
19+
@Test
20+
public void putGetAndQuery_works() {
21+
// Put
22+
TestEntity put = putTestEntity(TEST_STRING, 1);
23+
putTestEntity("🚀", 2); // U+1F680
24+
assertEquals(2, getTestEntityBox().count());
25+
26+
// Get
27+
TestEntity get = getTestEntityBox().get(put.getId());
28+
assertEquals(TEST_STRING, get.getSimpleString());
29+
30+
// Query String with equals
31+
List<TestEntity> results = getTestEntityBox().query(
32+
TestEntity_.simpleString.equal(TEST_STRING)
33+
).build().find();
34+
assertEquals(1, results.size());
35+
assertEquals(TEST_STRING, results.get(0).getSimpleString());
36+
37+
// Query String array
38+
List<TestEntity> resultsArray = getTestEntityBox().query(
39+
TestEntity_.simpleStringArray.containsElement(TEST_STRING)
40+
).build().find();
41+
assertEquals(1, resultsArray.size());
42+
assertEquals(TEST_STRING, resultsArray.get(0).getSimpleString());
43+
}
44+
}
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)