JsonVariant_Storage_Tests.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright Benoit Blanchon 2014-2015
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include <gtest/gtest.h>
  7. #include <ArduinoJson.h>
  8. class JsonVariant_Storage_Tests : public ::testing::Test {
  9. protected:
  10. template <typename T>
  11. void testValue(T expected) {
  12. _actual.set(expected);
  13. EXPECT_EQ(expected, _actual.as<T>());
  14. }
  15. template <typename T>
  16. void testReference(T &expected) {
  17. _actual.set(expected);
  18. EXPECT_EQ(expected, _actual.as<T &>());
  19. }
  20. private:
  21. JsonVariant _actual;
  22. };
  23. TEST_F(JsonVariant_Storage_Tests, Double) { testValue<double>(123.45); }
  24. TEST_F(JsonVariant_Storage_Tests, False) { testValue<bool>(false); }
  25. TEST_F(JsonVariant_Storage_Tests, Float) { testValue<float>(123.45f); }
  26. TEST_F(JsonVariant_Storage_Tests, Null) { testValue<const char *>(NULL); }
  27. TEST_F(JsonVariant_Storage_Tests, SChar) { testValue<signed char>(123); }
  28. TEST_F(JsonVariant_Storage_Tests, SInt) { testValue<signed int>(123); }
  29. TEST_F(JsonVariant_Storage_Tests, SLong) { testValue<signed long>(123L); }
  30. TEST_F(JsonVariant_Storage_Tests, SShort) { testValue<signed short>(123); }
  31. TEST_F(JsonVariant_Storage_Tests, String) { testValue<const char *>("hello"); }
  32. TEST_F(JsonVariant_Storage_Tests, True) { testValue<bool>(true); }
  33. TEST_F(JsonVariant_Storage_Tests, UChar) { testValue<unsigned char>(123); }
  34. TEST_F(JsonVariant_Storage_Tests, UInt) { testValue<unsigned int>(123U); }
  35. TEST_F(JsonVariant_Storage_Tests, ULong) { testValue<unsigned long>(123UL); }
  36. TEST_F(JsonVariant_Storage_Tests, UShort) { testValue<unsigned short>(123); }
  37. TEST_F(JsonVariant_Storage_Tests, CanStoreObject) {
  38. DynamicJsonBuffer jsonBuffer;
  39. JsonObject &object = jsonBuffer.createObject();
  40. testReference(object);
  41. }