Catch more invalid corner cases in JsonToFlatbuffer
If you had something which was supposed to be an array of tables and the
JSON was just an object, then there were no obvious errors until you got
a mangled flatbuffer at the end.
Change-Id: I8f584c8a75ec711231cb385fa4439966a0fdafa9
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/json_to_flatbuffer_test.cc b/aos/json_to_flatbuffer_test.cc
index 4918281..6772826 100644
--- a/aos/json_to_flatbuffer_test.cc
+++ b/aos/json_to_flatbuffer_test.cc
@@ -215,6 +215,13 @@
EXPECT_TRUE(JsonAndBack("{ \"apps\": [ { }, { } ] }"));
}
+// Test mixing up whether a field is an object or a vector.
+TEST_F(JsonToFlatbufferTest, IncorrectVectorOfTables) {
+ EXPECT_FALSE(
+ JsonAndBack("{ \"single_application\": [ {\"name\": \"woot\"} ] }"));
+ EXPECT_FALSE(JsonAndBack("{ \"apps\": { \"name\": \"woot\" } }"));
+}
+
// Test that we can parse an empty message.
TEST_F(JsonToFlatbufferTest, EmptyMessage) {
// Empty message works.