diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test.cpp b/tests/test.cpp index e636f1f3..df9cf08b 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -859,6 +859,44 @@ void UnicodeTest() { "\\u5225\\u30B5\\u30A4\\u30C8\\x01\\x80\"}", true); } +void UnicodeSurrogatesTest() { + flatbuffers::Parser parser; + + TEST_EQ( + parser.Parse( + "table T { F:string (id: 0); }" + "root_type T;" + "{ F:\"\\uD83D\\uDCA9\"}"), true); + auto root = flatbuffers::GetRoot<flatbuffers::Table>( + parser.builder_.GetBufferPointer()); + auto string = root->GetPointer<flatbuffers::String *>( + flatbuffers::FieldIndexToOffset(0)); + TEST_EQ(strcmp(string->c_str(), "\xF0\x9F\x92\xA9"), 0); +} + +void UnicodeInvalidSurrogatesTest() { + TestError( + "table T { F:string; }" + "root_type T;" + "{ F:\"\\uD800\"}", "unpaired high surrogate"); + TestError( + "table T { F:string; }" + "root_type T;" + "{ F:\"\\uD800abcd\"}", "unpaired high surrogate"); + TestError( + "table T { F:string; }" + "root_type T;" + "{ F:\"\\uD800\\n\"}", "unpaired high surrogate"); + TestError( + "table T { F:string; }" + "root_type T;" + "{ F:\"\\uD800\\uD800\"}", "multiple high surrogates"); + TestError( + "table T { F:string; }" + "root_type T;" + "{ F:\"\\uDC00\"}", "unpaired low surrogate"); +} + void UnknownFieldsTest() { flatbuffers::IDLOptions opts; opts.skip_unexpected_fields_in_json = true; @@ -907,6 +945,8 @@ int main(int /*argc*/, const char * /*argv*/[]) { EnumStringsTest(); IntegerOutOfRangeTest(); UnicodeTest(); + UnicodeSurrogatesTest(); + UnicodeInvalidSurrogatesTest(); UnknownFieldsTest(); if (!testing_fails) { |