Files
ArduinoJson/test/JsonVariant_Storage_Tests.cpp

49 lines
1.7 KiB
C++
Raw Normal View History

2015-02-07 16:05:48 +01:00
// Copyright Benoit Blanchon 2014-2015
2014-11-04 09:51:25 +01:00
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#include <gtest/gtest.h>
#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) {
_actual.set(expected);
EXPECT_EQ(expected, _actual.as<T>());
2014-11-04 09:51:25 +01:00
}
template <typename T>
void testReference(T &expected) {
_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:
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) {
DynamicJsonBuffer jsonBuffer;
JsonObject &object = jsonBuffer.createObject();
2014-11-04 09:51:25 +01:00
testReference(object);
}