| 30 | } |
| 31 | |
| 32 | void TestStructSimple(const char* msg, uint32_t msg_size) |
| 33 | { |
| 34 | // Load |
| 35 | dmStructDDF::Struct* message; |
| 36 | dmDDF::Result e = dmDDF::LoadMessage((void*) msg, msg_size, &dmStructDDF_Struct_DESCRIPTOR, (void**)&message); |
| 37 | ASSERT_EQ(dmDDF::RESULT_OK, e); |
| 38 | |
| 39 | dmStructDDF::Struct::FieldsEntry* hello = FindEntry(message, "hello"); |
| 40 | ASSERT_STREQ("world", hello->m_Value->m_Kind.m_String); |
| 41 | |
| 42 | dmStructDDF::Struct::FieldsEntry* number = FindEntry(message, "number"); |
| 43 | ASSERT_NEAR(1337.0, number->m_Value->m_Kind.m_Number, 0.001); |
| 44 | |
| 45 | dmStructDDF::Struct::FieldsEntry* boolean = FindEntry(message, "boolean"); |
| 46 | ASSERT_TRUE(boolean->m_Value->m_Kind.m_Bool); |
| 47 | |
| 48 | dmStructDDF::Struct::FieldsEntry* nothing = FindEntry(message, "nothing"); |
| 49 | ASSERT_EQ(dmStructDDF::NULL_VALUE, nothing->m_Value->m_Kind.m_Null); |
| 50 | |
| 51 | // Save |
| 52 | std::string save_str; |
| 53 | e = DDFSaveToString(message, &dmStructDDF_Struct_DESCRIPTOR, save_str); |
| 54 | ASSERT_EQ(dmDDF::RESULT_OK, e); |
| 55 | |
| 56 | dmStructDDF::Struct* saved_message; |
| 57 | e = dmDDF::LoadMessage((void*) save_str.c_str(), save_str.size(), &dmStructDDF_Struct_DESCRIPTOR, (void**)&saved_message); |
| 58 | ASSERT_EQ(dmDDF::RESULT_OK, e); |
| 59 | |
| 60 | dmStructDDF::Struct::FieldsEntry* hello2 = FindEntry(saved_message, "hello"); |
| 61 | ASSERT_STREQ("world", hello2->m_Value->m_Kind.m_String); |
| 62 | |
| 63 | dmStructDDF::Struct::FieldsEntry* number2 = FindEntry(saved_message, "number"); |
| 64 | ASSERT_NEAR(1337.0, number2->m_Value->m_Kind.m_Number, 0.001); |
| 65 | |
| 66 | dmStructDDF::Struct::FieldsEntry* boolean2 = FindEntry(saved_message, "boolean"); |
| 67 | ASSERT_TRUE(boolean2->m_Value->m_Kind.m_Bool); |
| 68 | |
| 69 | dmStructDDF::Struct::FieldsEntry* nothing2 = FindEntry(saved_message, "nothing"); |
| 70 | ASSERT_EQ(dmStructDDF::NULL_VALUE, nothing2->m_Value->m_Kind.m_Null); |
| 71 | |
| 72 | dmDDF::FreeMessage(message); |
| 73 | dmDDF::FreeMessage(saved_message); |
| 74 | } |
| 75 | |
| 76 | void TestStructNested(const char* msg, uint32_t msg_size) |
| 77 | { |
no test coverage detected