| 146 | } |
| 147 | |
| 148 | void TestStructJSON(const char* msg, uint32_t msg_size) |
| 149 | { |
| 150 | // Load |
| 151 | dmStructDDF::Struct* message; |
| 152 | dmDDF::Result e = dmDDF::LoadMessage((void*) msg, msg_size, &dmStructDDF_Struct_DESCRIPTOR, (void**)&message); |
| 153 | ASSERT_EQ(dmDDF::RESULT_OK, e); |
| 154 | |
| 155 | dmStructDDF::Struct::FieldsEntry* name = FindEntry(message, "name"); |
| 156 | ASSERT_STREQ("engine", name->m_Value->m_Kind.m_String); |
| 157 | |
| 158 | dmStructDDF::Struct::FieldsEntry* version = FindEntry(message, "version"); |
| 159 | ASSERT_NEAR(3.0, version->m_Value->m_Kind.m_Number, 0.001); |
| 160 | |
| 161 | dmStructDDF::Struct::FieldsEntry* features = FindEntry(message, "features"); |
| 162 | ASSERT_EQ(2, features->m_Value->m_Kind.m_List->m_Values.m_Count); |
| 163 | |
| 164 | dmStructDDF::Struct::FieldsEntry* config = FindEntry(message, "config"); |
| 165 | ASSERT_TRUE(config->m_Value->m_Kind.m_Struct.m_Fields[0].m_Value->m_Kind.m_Bool); |
| 166 | |
| 167 | dmStructDDF::Struct::FieldsEntry* debug = FindEntry(&config->m_Value->m_Kind.m_Struct, "debug"); |
| 168 | ASSERT_TRUE(debug->m_Value->m_Kind.m_Bool); |
| 169 | |
| 170 | // Save |
| 171 | std::string save_str; |
| 172 | e = DDFSaveToString(message, &dmStructDDF_Struct_DESCRIPTOR, save_str); |
| 173 | ASSERT_EQ(dmDDF::RESULT_OK, e); |
| 174 | |
| 175 | dmStructDDF::Struct* saved_message; |
| 176 | e = dmDDF::LoadMessage((void*) save_str.c_str(), save_str.size(), &dmStructDDF_Struct_DESCRIPTOR, (void**)&saved_message); |
| 177 | ASSERT_EQ(dmDDF::RESULT_OK, e); |
| 178 | |
| 179 | dmStructDDF::Struct::FieldsEntry* name2 = FindEntry(saved_message, "name"); |
| 180 | ASSERT_STREQ("engine", name2->m_Value->m_Kind.m_String); |
| 181 | |
| 182 | dmStructDDF::Struct::FieldsEntry* version2 = FindEntry(saved_message, "version"); |
| 183 | ASSERT_NEAR(3.0, version2->m_Value->m_Kind.m_Number, 0.001); |
| 184 | |
| 185 | dmStructDDF::Struct::FieldsEntry* features2 = FindEntry(saved_message, "features"); |
| 186 | ASSERT_EQ(2, features2->m_Value->m_Kind.m_List->m_Values.m_Count); |
| 187 | |
| 188 | dmStructDDF::Struct::FieldsEntry* config2 = FindEntry(saved_message, "config"); |
| 189 | ASSERT_TRUE(config2->m_Value->m_Kind.m_Struct.m_Fields[0].m_Value->m_Kind.m_Bool); |
| 190 | |
| 191 | dmStructDDF::Struct::FieldsEntry* debug2 = FindEntry(&config2->m_Value->m_Kind.m_Struct, "debug"); |
| 192 | ASSERT_TRUE(debug2->m_Value->m_Kind.m_Bool); |
| 193 | |
| 194 | dmDDF::FreeMessage(saved_message); |
| 195 | dmDDF::FreeMessage(message); |
| 196 | } |
no test coverage detected