2014-11-04 09:51:25 +01:00
|
|
|
// Copyright Benoit Blanchon 2014
|
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2014-11-11 16:54:46 +01:00
|
|
|
#include <ArduinoJson.h>
|
2014-11-04 09:51:25 +01:00
|
|
|
|
|
|
|
class JsonVariant_Storage_Tests : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
template <typename T>
|
|
|
|
void testValue(T expected) {
|
2014-12-20 15:42:43 +01:00
|
|
|
_actual.set(expected);
|
|
|
|
EXPECT_EQ(expected, _actual.as<T>());
|
2014-11-04 09:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void testReference(T &expected) {
|
2014-12-20 15:42:43 +01:00
|
|
|
_actual.set(expected);
|
|
|
|
EXPECT_EQ(expected, _actual.as<T &>());
|
2014-11-04 09:51:25 +01:00
|
|
|
}
|
|
|
|
|
2014-11-04 10:38:33 +01:00
|
|
|
private:
|
2014-12-20 15:42:43 +01:00
|
|
|
JsonVariant _actual;
|
2014-11-04 09:51:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, Double) { testValue<double>(123.45); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, False) { testValue<bool>(false); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, Float) { testValue<float>(123.45f); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, Null) { testValue<const char *>(NULL); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, SChar) { testValue<signed char>(123); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, SInt) { testValue<signed int>(123); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, SLong) { testValue<signed long>(123L); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, SShort) { testValue<signed short>(123); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, String) { testValue<const char *>("hello"); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, True) { testValue<bool>(true); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, UChar) { testValue<unsigned char>(123); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, UInt) { testValue<unsigned int>(123U); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, ULong) { testValue<unsigned long>(123UL); }
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, UShort) { testValue<unsigned short>(123); }
|
|
|
|
|
|
|
|
TEST_F(JsonVariant_Storage_Tests, CanStoreObject) {
|
2014-12-20 15:42:43 +01:00
|
|
|
DynamicJsonBuffer jsonBuffer;
|
|
|
|
JsonObject &object = jsonBuffer.createObject();
|
2014-11-04 09:51:25 +01:00
|
|
|
|
|
|
|
testReference(object);
|
|
|
|
}
|