// ArduinoJson - https://arduinojson.org // Copyright © 2014-2024, Benoit BLANCHON // MIT License #include #include #include using ArduinoJson::detail::is_base_of; static std::string allocatorLog; struct CustomAllocator { CustomAllocator() { allocatorLog = ""; } void* allocate(size_t n) { allocatorLog += "A"; return malloc(n); } void deallocate(void* p) { free(p); allocatorLog += "D"; } void* reallocate(void* p, size_t n) { allocatorLog += "R"; return realloc(p, n); } }; TEST_CASE("BasicJsonDocument") { allocatorLog.clear(); SECTION("is a JsonDocument") { REQUIRE( is_base_of>::value == true); } SECTION("deserialize / serialize") { BasicJsonDocument doc(256); deserializeJson(doc, "{\"hello\":\"world\"}"); REQUIRE(doc.as() == "{\"hello\":\"world\"}"); doc.clear(); REQUIRE(allocatorLog == "ARAARDDD"); } SECTION("copy") { BasicJsonDocument doc(256); doc["hello"] = "world"; auto copy = doc; REQUIRE(copy.as() == "{\"hello\":\"world\"}"); REQUIRE(allocatorLog == "AA"); } SECTION("capacity") { BasicJsonDocument doc(256); REQUIRE(doc.capacity() == 256); } SECTION("garbageCollect()") { BasicJsonDocument doc(256); doc.garbageCollect(); } }