[209] | 1 | // Copyright Benoit Blanchon 2014-2016
|
---|
| 2 | // MIT License
|
---|
| 3 | //
|
---|
| 4 | // Arduino JSON library
|
---|
| 5 | // https://github.com/bblanchon/ArduinoJson
|
---|
| 6 | // If you like this project, please add a star!
|
---|
| 7 |
|
---|
| 8 | #include <gtest/gtest.h>
|
---|
| 9 | #include <ArduinoJson/JsonVariant.hpp>
|
---|
| 10 |
|
---|
| 11 | using namespace ArduinoJson;
|
---|
| 12 |
|
---|
| 13 | class JsonVariant_Comparison_Tests : public ::testing::Test {
|
---|
| 14 | protected:
|
---|
| 15 | template <typename T>
|
---|
| 16 | void testValue(T low, T mid, T high) {
|
---|
| 17 | setValueTo(mid);
|
---|
| 18 | mustBeEqualTo(mid);
|
---|
| 19 | mustBeGreaterThan(low);
|
---|
| 20 | mustBeLessThan(high);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | private:
|
---|
| 24 | template <typename T>
|
---|
| 25 | void setValueTo(T expected) {
|
---|
| 26 | actual = expected;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | template <typename T>
|
---|
| 30 | void mustBeEqualTo(T expected) {
|
---|
| 31 | EXPECT_EQ(expected, actual); // operator==
|
---|
| 32 | EXPECT_EQ(actual, expected); // operator==
|
---|
| 33 | EXPECT_LE(expected, actual); // operator<=
|
---|
| 34 | EXPECT_LE(actual, expected); // operator<=
|
---|
| 35 | EXPECT_GE(expected, actual); // operator>=
|
---|
| 36 | EXPECT_GE(actual, expected); // operator>=
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | template <typename T>
|
---|
| 40 | void mustBeGreaterThan(T expected) {
|
---|
| 41 | EXPECT_GT(actual, expected); // operator>
|
---|
| 42 | EXPECT_LT(expected, actual); // operator<
|
---|
| 43 | EXPECT_NE(actual, expected); // operator!=
|
---|
| 44 | EXPECT_NE(expected, actual); // operator!=
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | template <typename T>
|
---|
| 48 | void mustBeLessThan(T expected) {
|
---|
| 49 | EXPECT_LT(actual, expected); // operator<
|
---|
| 50 | EXPECT_GT(expected, actual); // operator<
|
---|
| 51 | EXPECT_NE(actual, expected); // operator!=
|
---|
| 52 | EXPECT_NE(expected, actual); // operator!=
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | JsonVariant actual;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | TEST_F(JsonVariant_Comparison_Tests, Double) {
|
---|
| 59 | testValue<double>(123.44, 123.45, 123.46);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | TEST_F(JsonVariant_Comparison_Tests, Float) {
|
---|
| 63 | testValue<float>(123.44f, 123.45f, 123.46f);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | TEST_F(JsonVariant_Comparison_Tests, SChar) {
|
---|
| 67 | testValue<signed char>(122, 123, 124);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | TEST_F(JsonVariant_Comparison_Tests, SInt) {
|
---|
| 71 | testValue<signed int>(122, 123, 124);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | TEST_F(JsonVariant_Comparison_Tests, SLong) {
|
---|
| 75 | testValue<signed long>(122L, 123L, 124L);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | TEST_F(JsonVariant_Comparison_Tests, SShort) {
|
---|
| 79 | testValue<signed short>(122, 123, 124);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | TEST_F(JsonVariant_Comparison_Tests, UChar) {
|
---|
| 83 | testValue<unsigned char>(122, 123, 124);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | TEST_F(JsonVariant_Comparison_Tests, UInt) {
|
---|
| 87 | testValue<unsigned int>(122, 123, 124);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | TEST_F(JsonVariant_Comparison_Tests, ULong) {
|
---|
| 91 | testValue<unsigned long>(122L, 123L, 124L);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | TEST_F(JsonVariant_Comparison_Tests, UShort) {
|
---|
| 95 | testValue<unsigned short>(122, 123, 124);
|
---|
| 96 | }
|
---|