Catch a null schema more gracefully
We were dereferencing the null pointer. It gives a rather cryptic
error. We can do a lot better.
Change-Id: I1aae2109cee6aa9f972d4e149a5779df42ab7d36
diff --git a/aos/flatbuffer_introspection_test.cc b/aos/flatbuffer_introspection_test.cc
index 4214202..9dacd41 100644
--- a/aos/flatbuffer_introspection_test.cc
+++ b/aos/flatbuffer_introspection_test.cc
@@ -464,5 +464,20 @@
"}");
}
+// Tests that a nullptr buffer prints nullptr.
+TEST_F(FlatbufferIntrospectionTest, NullptrData) {
+ EXPECT_EQ("null", FlatbufferToJson(schema_, nullptr));
+}
+
+// Tests that a null schema gets caught.
+TEST(FlatbufferIntrospectionDeathTest, NullSchema) {
+ EXPECT_DEATH(
+ {
+ FlatbufferToJson(static_cast<const reflection::Schema *>(nullptr),
+ nullptr);
+ },
+ "Need to provide a schema");
+}
+
} // namespace testing
} // namespace aos