// ArduinoJson - arduinojson.org // Copyright Benoit Blanchon 2014-2018 // MIT License #include #include #include #include template void checkValue(T expected) { DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); variant.set(expected); REQUIRE(expected == variant.as()); } template void checkReference(T &expected) { JsonVariant variant = expected; REQUIRE(expected == variant.as()); } template void checkNumericType() { DynamicJsonDocument docMin(4096), docMax(4096); JsonVariant variantMin = docMin.to(); JsonVariant variantMax = docMax.to(); T min = std::numeric_limits::min(); T max = std::numeric_limits::max(); variantMin.set(min); variantMax.set(max); REQUIRE(min == variantMin.as()); REQUIRE(max == variantMax.as()); } TEST_CASE("JsonVariant set()/get()") { #if ARDUINOJSON_USE_LONG_LONG SECTION("SizeOfJsonInteger") { REQUIRE(8 == sizeof(JsonInteger)); } #endif SECTION("Null") { checkValue(NULL); } SECTION("const char*") { checkValue("hello"); } SECTION("std::string") { checkValue("hello"); } SECTION("False") { checkValue(false); } SECTION("True") { checkValue(true); } SECTION("Double") { checkNumericType(); } SECTION("Float") { checkNumericType(); } SECTION("Char") { checkNumericType(); } SECTION("SChar") { checkNumericType(); } SECTION("SInt") { checkNumericType(); } SECTION("SLong") { checkNumericType(); } SECTION("SShort") { checkNumericType(); } SECTION("UChar") { checkNumericType(); } SECTION("UInt") { checkNumericType(); } SECTION("ULong") { checkNumericType(); } SECTION("UShort") { checkNumericType(); } #if ARDUINOJSON_USE_LONG_LONG SECTION("LongLong") { checkNumericType(); } SECTION("ULongLong") { checkNumericType(); } #endif SECTION("Int8") { checkNumericType(); } SECTION("Uint8") { checkNumericType(); } SECTION("Int16") { checkNumericType(); } SECTION("Uint16") { checkNumericType(); } SECTION("Int32") { checkNumericType(); } SECTION("Uint32") { checkNumericType(); } #if ARDUINOJSON_USE_LONG_LONG SECTION("Int64") { checkNumericType(); } SECTION("Uint64") { checkNumericType(); } #endif SECTION("CanStoreObject") { DynamicJsonDocument doc(4096); JsonObject object = doc.to(); checkValue(object); } }