Commit 676f0712 authored by Raman's avatar Raman Committed by GitHub

Update test.cpp

parent db99c1aa
...@@ -814,14 +814,14 @@ void ErrorTest() { ...@@ -814,14 +814,14 @@ void ErrorTest() {
TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "more than once"); TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "more than once");
} }
float TestValue(const char *json) { template<typename T> T TestValue(const char *json) {
flatbuffers::Parser parser; flatbuffers::Parser parser;
// Simple schema. // Simple schema.
TEST_EQ(parser.Parse("table X { Y:float; } root_type X;"), true); TEST_EQ(parser.Parse(std::string("table X { Y:" + std::string(typeid(T).name()) + "; } root_type X;").c_str()), true);
TEST_EQ(parser.Parse(json), true); TEST_EQ(parser.Parse(json), true);
auto root = flatbuffers::GetRoot<float>(parser.builder_.GetBufferPointer()); auto root = flatbuffers::GetRoot<T>(parser.builder_.GetBufferPointer());
// root will point to the table, which is a 32bit vtable offset followed // root will point to the table, which is a 32bit vtable offset followed
// by a float: // by a float:
TEST_EQ(sizeof(flatbuffers::soffset_t), 4); // Test assumes 32bit offsets TEST_EQ(sizeof(flatbuffers::soffset_t), 4); // Test assumes 32bit offsets
...@@ -833,13 +833,13 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; } ...@@ -833,13 +833,13 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; }
// Additional parser testing not covered elsewhere. // Additional parser testing not covered elsewhere.
void ValueTest() { void ValueTest() {
// Test scientific notation numbers. // Test scientific notation numbers.
TEST_EQ(FloatCompare(TestValue("{ Y:0.0314159e+2 }"), 3.14159), true); TEST_EQ(FloatCompare(TestValue<float>("{ Y:0.0314159e+2 }"), 3.14159), true);
// Test conversion functions. // Test conversion functions.
TEST_EQ(FloatCompare(TestValue("{ Y:cos(rad(180)) }"), -1), true); TEST_EQ(FloatCompare(TestValue<float>("{ Y:cos(rad(180)) }"), -1), true);
// Test negative hex constant. // Test negative hex constant.
TEST_EQ(TestValue("{ Y:-0x80 }") == -128, true); TEST_EQ(TestValue<int>("{ Y:-0x80 }") == -128, true);
} }
void EnumStringsTest() { void EnumStringsTest() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment