Minor changes

This commit is contained in:
Benoit Blanchon
2014-11-04 10:38:33 +01:00
parent c4cda780d5
commit 4a17e8c34b
3 changed files with 44 additions and 43 deletions

View File

@ -23,36 +23,36 @@ class JsonVariant_Comparison_Tests : public ::testing::Test {
private:
template <typename T>
void setValueTo(T expected) {
jsonValue = expected;
actual = expected;
}
template <typename T>
void mustBeEqualTo(T expected) {
EXPECT_EQ(expected, jsonValue); // operator==
EXPECT_EQ(jsonValue, expected); // operator==
EXPECT_LE(expected, jsonValue); // operator<=
EXPECT_LE(jsonValue, expected); // operator<=
EXPECT_GE(expected, jsonValue); // operator>=
EXPECT_GE(jsonValue, expected); // operator>=
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>=
}
template <typename T>
void mustBeGreaterThan(T expected) {
EXPECT_GT(jsonValue, expected); // operator>
EXPECT_LT(expected, jsonValue); // operator<
EXPECT_NE(jsonValue, expected); // operator!=
EXPECT_NE(expected, jsonValue); // operator!=
EXPECT_GT(actual, expected); // operator>
EXPECT_LT(expected, actual); // operator<
EXPECT_NE(actual, expected); // operator!=
EXPECT_NE(expected, actual); // operator!=
}
template <typename T>
void mustBeLessThan(T expected) {
EXPECT_LT(jsonValue, expected); // operator<
EXPECT_GT(expected, jsonValue); // operator<
EXPECT_NE(jsonValue, expected); // operator!=
EXPECT_NE(expected, jsonValue); // operator!=
EXPECT_LT(actual, expected); // operator<
EXPECT_GT(expected, actual); // operator<
EXPECT_NE(actual, expected); // operator!=
EXPECT_NE(expected, actual); // operator!=
}
JsonVariant jsonValue;
JsonVariant actual;
};
TEST_F(JsonVariant_Comparison_Tests, Double) {

View File

@ -14,58 +14,58 @@ using namespace ArduinoJson;
class JsonVariant_Copy_Tests : public ::testing::Test {
protected:
StaticJsonBuffer<200> json;
JsonVariant jsonValue1;
JsonVariant jsonValue2;
JsonVariant variant1;
JsonVariant variant2;
};
TEST_F(JsonVariant_Copy_Tests, IntegersAreCopiedByValue) {
jsonValue1 = 123;
jsonValue2 = jsonValue1;
jsonValue1 = 456;
variant1 = 123;
variant2 = variant1;
variant1 = 456;
EXPECT_EQ(123, jsonValue2.as<int>());
EXPECT_EQ(123, variant2.as<int>());
}
TEST_F(JsonVariant_Copy_Tests, DoublesAreCopiedByValue) {
jsonValue1 = 123.45;
jsonValue2 = jsonValue1;
jsonValue1 = 456.78;
variant1 = 123.45;
variant2 = variant1;
variant1 = 456.78;
EXPECT_EQ(123.45, jsonValue2.as<double>());
EXPECT_EQ(123.45, variant2.as<double>());
}
TEST_F(JsonVariant_Copy_Tests, BooleansAreCopiedByValue) {
jsonValue1 = true;
jsonValue2 = jsonValue1;
jsonValue1 = false;
variant1 = true;
variant2 = variant1;
variant1 = false;
EXPECT_TRUE(jsonValue2.as<bool>());
EXPECT_TRUE(variant2.as<bool>());
}
TEST_F(JsonVariant_Copy_Tests, StringsAreCopiedByValue) {
jsonValue1 = "hello";
jsonValue2 = jsonValue1;
jsonValue1 = "world";
variant1 = "hello";
variant2 = variant1;
variant1 = "world";
EXPECT_STREQ("hello", jsonValue2.as<const char *>());
EXPECT_STREQ("hello", variant2.as<const char *>());
}
TEST_F(JsonVariant_Copy_Tests, ObjectsAreCopiedByReference) {
JsonObject &object = json.createObject();
jsonValue1 = object;
variant1 = object;
object["hello"] = "world";
EXPECT_EQ(1, jsonValue1.asObject().size());
EXPECT_EQ(1, variant1.asObject().size());
}
TEST_F(JsonVariant_Copy_Tests, ArraysAreCopiedByReference) {
JsonArray &array = json.createArray();
jsonValue1 = array;
variant1 = array;
array.add("world");
EXPECT_EQ(1, jsonValue1.asArray().size());
EXPECT_EQ(1, variant1.asArray().size());
}

View File

@ -15,17 +15,18 @@ class JsonVariant_Storage_Tests : public ::testing::Test {
protected:
template <typename T>
void testValue(T expected) {
jsonValue.set(expected);
EXPECT_EQ(expected, jsonValue.as<T>());
actual.set(expected);
EXPECT_EQ(expected, actual.as<T>());
}
template <typename T>
void testReference(T &expected) {
jsonValue.set(expected);
EXPECT_EQ(expected, jsonValue.as<T &>());
actual.set(expected);
EXPECT_EQ(expected, actual.as<T &>());
}
JsonVariant jsonValue;
private:
JsonVariant actual;
};
TEST_F(JsonVariant_Storage_Tests, Double) { testValue<double>(123.45); }