Update test.cpp
This commit is contained in:
parent
98c7a0c169
commit
0d56276102
|
@ -814,11 +814,11 @@ void ErrorTest() {
|
|||
TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "more than once");
|
||||
}
|
||||
|
||||
template<typename T> T TestValue(const char *json) {
|
||||
template<typename T> T TestValue(const char *json, const char *type_name) {
|
||||
flatbuffers::Parser parser;
|
||||
|
||||
// Simple schema.
|
||||
TEST_EQ(parser.Parse(std::string("table X { Y:" + std::string(typeid(T).name()) + "; } root_type X;").c_str()), true);
|
||||
TEST_EQ(parser.Parse(std::string("table X { Y:" + std::string(type_name) + "; } root_type X;").c_str()), true);
|
||||
|
||||
TEST_EQ(parser.Parse(json), true);
|
||||
auto root = flatbuffers::GetRoot<T>(parser.builder_.GetBufferPointer());
|
||||
|
@ -833,13 +833,13 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; }
|
|||
// Additional parser testing not covered elsewhere.
|
||||
void ValueTest() {
|
||||
// Test scientific notation numbers.
|
||||
TEST_EQ(FloatCompare(TestValue<float>("{ Y:0.0314159e+2 }"), (float)3.14159), true);
|
||||
TEST_EQ(FloatCompare(TestValue<float>("{ Y:0.0314159e+2 }","float"), (float)3.14159), true);
|
||||
|
||||
// Test conversion functions.
|
||||
TEST_EQ(FloatCompare(TestValue<float>("{ Y:cos(rad(180)) }"), -1), true);
|
||||
TEST_EQ(FloatCompare(TestValue<float>("{ Y:cos(rad(180)) }","float"), -1), true);
|
||||
|
||||
// Test negative hex constant.
|
||||
TEST_EQ(TestValue<int>("{ Y:-0x80 }") == -128, true);
|
||||
TEST_EQ(TestValue<int>("{ Y:-0x80 }","int") == -128, true);
|
||||
}
|
||||
|
||||
void EnumStringsTest() {
|
||||
|
|
Loading…
Reference in New Issue