diff options
author | taroplus <taroplus@users.noreply.github.com> | 2021-11-15 11:16:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-15 11:16:45 -0800 |
commit | 927175ea20929675f5985a05ad32fb346462c3e5 (patch) | |
tree | 4b762f8ed88e5eee44a62cf689457b5f371eb7f3 /tests | |
parent | 6748c373be9ef54e221265a502a3cee3bbf8cef1 (diff) | |
download | flatbuffers-927175ea20929675f5985a05ad32fb346462c3e5.tar.gz flatbuffers-927175ea20929675f5985a05ad32fb346462c3e5.tar.bz2 flatbuffers-927175ea20929675f5985a05ad32fb346462c3e5.zip |
[Java] lookup by byteArray is giving back wrong entry (#6915)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/JavaTest.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/JavaTest.java b/tests/JavaTest.java index ce5751e8..0f2ad12d 100644 --- a/tests/JavaTest.java +++ b/tests/JavaTest.java @@ -1097,6 +1097,30 @@ class JavaTest { TestEq(m.get(key4).asString(), utf8keys[4]); } + public static void testFlexBuffersMapLookup() { + FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512), + FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS); + + String key0 = "123"; + String key1 = "1234"; + String key2 = "12345"; + String[] keys = new String[]{key0, key1, key2}; + + int map = builder.startMap(); + + for (int i=0; i< keys.length; i++) { + builder.putString(keys[i], keys[i]); // Testing key and string reuse. + } + builder.endMap(null, map); + builder.finish(); + + FlexBuffers.Map m = FlexBuffers.getRoot(builder.getBuffer()).asMap(); + for (int i=0; i< keys.length; i++) { + TestEq(m.get(keys[i]).asString(), keys[i]); + TestEq(m.get(keys[i].getBytes(StandardCharsets.UTF_8)).asString(), keys[i]); + } + } + public static void TestFlexBuffers() { testSingleElementByte(); testSingleElementShort(); @@ -1121,6 +1145,7 @@ class JavaTest { testDeprecatedTypedVectorString(); testBuilderGrowth(); testFlexBuffersUtf8Map(); + testFlexBuffersMapLookup(); } static void TestVectorOfBytes() { |