2015-02-07 16:05:48 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2015
|
2014-11-03 18:23:39 +01:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2015-07-10 22:11:26 +02:00
|
|
|
#define ARDUINOJSON_ENABLE_STD_STREAM
|
2014-11-04 09:51:25 +01:00
|
|
|
#include <ArduinoJson/JsonVariant.hpp>
|
2014-11-03 18:23:39 +01:00
|
|
|
|
|
|
|
using namespace ArduinoJson;
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
class JsonVariant_Comparison_Tests : public ::testing::Test {
|
2014-11-03 18:23:39 +01:00
|
|
|
protected:
|
|
|
|
template <typename T>
|
|
|
|
void testValue(T low, T mid, T high) {
|
|
|
|
setValueTo(mid);
|
|
|
|
mustBeEqualTo(mid);
|
|
|
|
mustBeGreaterThan(low);
|
|
|
|
mustBeLessThan(high);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename T>
|
|
|
|
void setValueTo(T expected) {
|
2014-11-04 10:38:33 +01:00
|
|
|
actual = expected;
|
2014-11-03 18:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void mustBeEqualTo(T expected) {
|
2014-11-04 10:38:33 +01:00
|
|
|
EXPECT_EQ(expected, actual); // operator==
|
|
|
|
EXPECT_EQ(actual, expected); // operator==
|
|
|
|
EXPECT_LE(expected, actual); // operator<=
|
|
|
|
EXPECT_LE(actual, expected); // operator<=
|
|
|
|
EXPECT_GE(expected, actual); // operator>=
|
|
|
|
EXPECT_GE(actual, expected); // operator>=
|
2014-11-03 18:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void mustBeGreaterThan(T expected) {
|
2014-11-04 10:38:33 +01:00
|
|
|
EXPECT_GT(actual, expected); // operator>
|
|
|
|
EXPECT_LT(expected, actual); // operator<
|
|
|
|
EXPECT_NE(actual, expected); // operator!=
|
|
|
|
EXPECT_NE(expected, actual); // operator!=
|
2014-11-03 18:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void mustBeLessThan(T expected) {
|
2014-11-04 10:38:33 +01:00
|
|
|
EXPECT_LT(actual, expected); // operator<
|
|
|
|
EXPECT_GT(expected, actual); // operator<
|
|
|
|
EXPECT_NE(actual, expected); // operator!=
|
|
|
|
EXPECT_NE(expected, actual); // operator!=
|
2014-11-03 18:23:39 +01:00
|
|
|
}
|
|
|
|
|
2014-11-04 10:38:33 +01:00
|
|
|
JsonVariant actual;
|
2014-11-03 18:23:39 +01:00
|
|
|
};
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, Double) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<double>(123.44, 123.45, 123.46);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, Float) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<float>(123.44f, 123.45f, 123.46f);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, SChar) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<signed char>(122, 123, 124);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, SInt) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<signed int>(122, 123, 124);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, SLong) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<signed long>(122L, 123L, 124L);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, SShort) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<signed short>(122, 123, 124);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, UChar) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<unsigned char>(122, 123, 124);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, UInt) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<unsigned int>(122, 123, 124);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, ULong) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<unsigned long>(122L, 123L, 124L);
|
|
|
|
}
|
|
|
|
|
2014-11-04 09:51:25 +01:00
|
|
|
TEST_F(JsonVariant_Comparison_Tests, UShort) {
|
2014-11-03 18:23:39 +01:00
|
|
|
testValue<unsigned short>(122, 123, 124);
|
|
|
|
}
|