mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 20:12:16 +02:00
Minor changes
This commit is contained in:
@ -23,36 +23,36 @@ class JsonVariant_Comparison_Tests : public ::testing::Test {
|
|||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void setValueTo(T expected) {
|
void setValueTo(T expected) {
|
||||||
jsonValue = expected;
|
actual = expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void mustBeEqualTo(T expected) {
|
void mustBeEqualTo(T expected) {
|
||||||
EXPECT_EQ(expected, jsonValue); // operator==
|
EXPECT_EQ(expected, actual); // operator==
|
||||||
EXPECT_EQ(jsonValue, expected); // operator==
|
EXPECT_EQ(actual, expected); // operator==
|
||||||
EXPECT_LE(expected, jsonValue); // operator<=
|
EXPECT_LE(expected, actual); // operator<=
|
||||||
EXPECT_LE(jsonValue, expected); // operator<=
|
EXPECT_LE(actual, expected); // operator<=
|
||||||
EXPECT_GE(expected, jsonValue); // operator>=
|
EXPECT_GE(expected, actual); // operator>=
|
||||||
EXPECT_GE(jsonValue, expected); // operator>=
|
EXPECT_GE(actual, expected); // operator>=
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void mustBeGreaterThan(T expected) {
|
void mustBeGreaterThan(T expected) {
|
||||||
EXPECT_GT(jsonValue, expected); // operator>
|
EXPECT_GT(actual, expected); // operator>
|
||||||
EXPECT_LT(expected, jsonValue); // operator<
|
EXPECT_LT(expected, actual); // operator<
|
||||||
EXPECT_NE(jsonValue, expected); // operator!=
|
EXPECT_NE(actual, expected); // operator!=
|
||||||
EXPECT_NE(expected, jsonValue); // operator!=
|
EXPECT_NE(expected, actual); // operator!=
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void mustBeLessThan(T expected) {
|
void mustBeLessThan(T expected) {
|
||||||
EXPECT_LT(jsonValue, expected); // operator<
|
EXPECT_LT(actual, expected); // operator<
|
||||||
EXPECT_GT(expected, jsonValue); // operator<
|
EXPECT_GT(expected, actual); // operator<
|
||||||
EXPECT_NE(jsonValue, expected); // operator!=
|
EXPECT_NE(actual, expected); // operator!=
|
||||||
EXPECT_NE(expected, jsonValue); // operator!=
|
EXPECT_NE(expected, actual); // operator!=
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonVariant jsonValue;
|
JsonVariant actual;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(JsonVariant_Comparison_Tests, Double) {
|
TEST_F(JsonVariant_Comparison_Tests, Double) {
|
||||||
|
@ -14,58 +14,58 @@ using namespace ArduinoJson;
|
|||||||
class JsonVariant_Copy_Tests : public ::testing::Test {
|
class JsonVariant_Copy_Tests : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
StaticJsonBuffer<200> json;
|
StaticJsonBuffer<200> json;
|
||||||
JsonVariant jsonValue1;
|
JsonVariant variant1;
|
||||||
JsonVariant jsonValue2;
|
JsonVariant variant2;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(JsonVariant_Copy_Tests, IntegersAreCopiedByValue) {
|
TEST_F(JsonVariant_Copy_Tests, IntegersAreCopiedByValue) {
|
||||||
jsonValue1 = 123;
|
variant1 = 123;
|
||||||
jsonValue2 = jsonValue1;
|
variant2 = variant1;
|
||||||
jsonValue1 = 456;
|
variant1 = 456;
|
||||||
|
|
||||||
EXPECT_EQ(123, jsonValue2.as<int>());
|
EXPECT_EQ(123, variant2.as<int>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonVariant_Copy_Tests, DoublesAreCopiedByValue) {
|
TEST_F(JsonVariant_Copy_Tests, DoublesAreCopiedByValue) {
|
||||||
jsonValue1 = 123.45;
|
variant1 = 123.45;
|
||||||
jsonValue2 = jsonValue1;
|
variant2 = variant1;
|
||||||
jsonValue1 = 456.78;
|
variant1 = 456.78;
|
||||||
|
|
||||||
EXPECT_EQ(123.45, jsonValue2.as<double>());
|
EXPECT_EQ(123.45, variant2.as<double>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonVariant_Copy_Tests, BooleansAreCopiedByValue) {
|
TEST_F(JsonVariant_Copy_Tests, BooleansAreCopiedByValue) {
|
||||||
jsonValue1 = true;
|
variant1 = true;
|
||||||
jsonValue2 = jsonValue1;
|
variant2 = variant1;
|
||||||
jsonValue1 = false;
|
variant1 = false;
|
||||||
|
|
||||||
EXPECT_TRUE(jsonValue2.as<bool>());
|
EXPECT_TRUE(variant2.as<bool>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonVariant_Copy_Tests, StringsAreCopiedByValue) {
|
TEST_F(JsonVariant_Copy_Tests, StringsAreCopiedByValue) {
|
||||||
jsonValue1 = "hello";
|
variant1 = "hello";
|
||||||
jsonValue2 = jsonValue1;
|
variant2 = variant1;
|
||||||
jsonValue1 = "world";
|
variant1 = "world";
|
||||||
|
|
||||||
EXPECT_STREQ("hello", jsonValue2.as<const char *>());
|
EXPECT_STREQ("hello", variant2.as<const char *>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonVariant_Copy_Tests, ObjectsAreCopiedByReference) {
|
TEST_F(JsonVariant_Copy_Tests, ObjectsAreCopiedByReference) {
|
||||||
JsonObject &object = json.createObject();
|
JsonObject &object = json.createObject();
|
||||||
|
|
||||||
jsonValue1 = object;
|
variant1 = object;
|
||||||
|
|
||||||
object["hello"] = "world";
|
object["hello"] = "world";
|
||||||
|
|
||||||
EXPECT_EQ(1, jsonValue1.asObject().size());
|
EXPECT_EQ(1, variant1.asObject().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonVariant_Copy_Tests, ArraysAreCopiedByReference) {
|
TEST_F(JsonVariant_Copy_Tests, ArraysAreCopiedByReference) {
|
||||||
JsonArray &array = json.createArray();
|
JsonArray &array = json.createArray();
|
||||||
|
|
||||||
jsonValue1 = array;
|
variant1 = array;
|
||||||
|
|
||||||
array.add("world");
|
array.add("world");
|
||||||
|
|
||||||
EXPECT_EQ(1, jsonValue1.asArray().size());
|
EXPECT_EQ(1, variant1.asArray().size());
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,18 @@ class JsonVariant_Storage_Tests : public ::testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void testValue(T expected) {
|
void testValue(T expected) {
|
||||||
jsonValue.set(expected);
|
actual.set(expected);
|
||||||
EXPECT_EQ(expected, jsonValue.as<T>());
|
EXPECT_EQ(expected, actual.as<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void testReference(T &expected) {
|
void testReference(T &expected) {
|
||||||
jsonValue.set(expected);
|
actual.set(expected);
|
||||||
EXPECT_EQ(expected, jsonValue.as<T &>());
|
EXPECT_EQ(expected, actual.as<T &>());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonVariant jsonValue;
|
private:
|
||||||
|
JsonVariant actual;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(JsonVariant_Storage_Tests, Double) { testValue<double>(123.45); }
|
TEST_F(JsonVariant_Storage_Tests, Double) { testValue<double>(123.45); }
|
||||||
|
Reference in New Issue
Block a user