MCPcopy Create free account
hub / github.com/crownengine/crown / test_json

Function test_json

src/core/unit_tests.cpp:1333–1397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1331}
1332
1333static void test_json()
1334{
1335 memory_globals::init();
1336 {
1337 JsonValueType::Enum t = json::type("null");
1338 ENSURE(t == JsonValueType::NIL);
1339 }
1340 {
1341 JsonValueType::Enum t = json::type("true");
1342 ENSURE(t == JsonValueType::BOOL);
1343 }
1344 {
1345 JsonValueType::Enum t = json::type("false");
1346 ENSURE(t == JsonValueType::BOOL);
1347 }
1348 {
1349 JsonValueType::Enum t = json::type("3.14");
1350 ENSURE(t == JsonValueType::NUMBER);
1351 }
1352 {
1353 JsonValueType::Enum t = json::type("\"foo\"");
1354 ENSURE(t == JsonValueType::STRING);
1355 }
1356 {
1357 JsonValueType::Enum t = json::type("[]");
1358 ENSURE(t == JsonValueType::ARRAY);
1359 }
1360 {
1361 JsonValueType::Enum t = json::type("{}");
1362 ENSURE(t == JsonValueType::OBJECT);
1363 }
1364 {
1365 const s32 a = json::parse_int("3.14");
1366 ENSURE(a == 3);
1367 }
1368 {
1369 const f32 a = json::parse_float("3.14");
1370 ENSURE(fequal(a, 3.14f));
1371 }
1372 {
1373 const bool a = json::parse_bool("true");
1374 ENSURE(a == true);
1375 }
1376 {
1377 const bool a = json::parse_bool("false");
1378 ENSURE(a == false);
1379 }
1380 {
1381 TempAllocator1024 ta;
1382 DynamicString str(ta);
1383 json::parse_string(str, "\"This is JSON\"");
1384 ENSURE(strcmp(str.c_str(), "This is JSON") == 0);
1385 }
1386 {
1387 TempAllocator1024 ta;
1388 JsonObject obj(ta);
1389 json::parse_object(obj, "{\"foo\":{\"}\":false}}");
1390 }

Callers

nothing calls this directly

Calls 10

strcmpFunction · 0.85
initFunction · 0.70
shutdownFunction · 0.70
typeFunction · 0.50
parse_intFunction · 0.50
parse_floatFunction · 0.50
parse_boolFunction · 0.50
parse_stringFunction · 0.50
parse_objectFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected