// Copyright Benoit Blanchon 2014-2016 // MIT License // // Arduino JSON library // https://github.com/bblanchon/ArduinoJson // If you like this project, please add a star! #include #include #include #include class JsonVariant_Storage_Tests : public ::testing::Test { protected: template void testValue(T expected) { JsonVariant variant = expected; EXPECT_EQ(expected, variant.as()); } template void testReference(T &expected) { JsonVariant variant = expected; EXPECT_EQ(expected, variant.as()); } template void testNumericType() { T min = std::numeric_limits::min(); T max = std::numeric_limits::max(); JsonVariant variantMin(min); JsonVariant variantMax(max); EXPECT_EQ(min, variantMin.as()); EXPECT_EQ(max, variantMax.as()); } }; #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 TEST_F(JsonVariant_Storage_Tests, SizeOfJsonInteger) { ASSERT_EQ(8, sizeof(Internals::JsonInteger)); } #endif TEST_F(JsonVariant_Storage_Tests, Null) { testValue(NULL); } TEST_F(JsonVariant_Storage_Tests, String) { testValue("hello"); } TEST_F(JsonVariant_Storage_Tests, False) { testValue(false); } TEST_F(JsonVariant_Storage_Tests, True) { testValue(true); } TEST_F(JsonVariant_Storage_Tests, Double) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Float) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, SChar) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, SInt) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, SLong) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, SShort) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, UChar) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, UInt) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, ULong) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, UShort) { testNumericType(); } #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 TEST_F(JsonVariant_Storage_Tests, LongLong) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, ULongLong) { testNumericType(); } #endif TEST_F(JsonVariant_Storage_Tests, Int8) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Uint8) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Int16) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Uint16) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Int32) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Uint32) { testNumericType(); } #if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64 TEST_F(JsonVariant_Storage_Tests, Int64) { testNumericType(); } TEST_F(JsonVariant_Storage_Tests, Uint64) { testNumericType(); } #endif TEST_F(JsonVariant_Storage_Tests, CanStoreObject) { DynamicJsonBuffer jsonBuffer; JsonObject &object = jsonBuffer.createObject(); testReference(object); }