Fixed return type of JsonArray::is<T>() and some others (issue #121)

This commit is contained in:
Benoit Blanchon
2015-09-19 16:25:18 +02:00
parent 155dd653e7
commit 7cf6fe6d62
7 changed files with 19 additions and 4 deletions

View File

@ -39,11 +39,13 @@ class JsonArray_Container_Tests : public ::testing::Test {
private:
template <typename T>
void itemMustEqual(int index, T expected) {
EXPECT_TRUE(_array[index].is<T>());
EXPECT_EQ(expected, _array[index].as<T>());
}
template <typename T>
void itemMustReference(int index, const T& expected) {
EXPECT_TRUE(_array[index].is<T&>());
EXPECT_EQ(&expected, &_array[index].as<T&>());
}
};

View File

@ -61,6 +61,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreIntegers) {
_object["hello"] = 123;
_object.set("world", 456);
EXPECT_TRUE(_object["hello"].is<int>());
EXPECT_FALSE(_object["hello"].is<double>());
EXPECT_EQ(123, _object["hello"].as<int>());
EXPECT_EQ(456, _object["world"].as<int>());
}
@ -69,6 +71,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreDoubles) {
_object["hello"] = 123.45;
_object.set("world", 456.78);
EXPECT_TRUE(_object["hello"].is<double>());
EXPECT_FALSE(_object["hello"].is<long>());
EXPECT_EQ(123.45, _object["hello"].as<double>());
EXPECT_EQ(456.78, _object["world"].as<double>());
}
@ -77,6 +81,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreBooleans) {
_object["hello"] = true;
_object.set("world", false);
EXPECT_TRUE(_object["hello"].is<bool>());
EXPECT_FALSE(_object["hello"].is<long>());
EXPECT_TRUE(_object["hello"].as<bool>());
EXPECT_FALSE(_object["world"].as<bool>());
}
@ -85,6 +91,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreStrings) {
_object["hello"] = "h3110";
_object.set("world", "w0r1d");
EXPECT_TRUE(_object["hello"].is<const char*>());
EXPECT_FALSE(_object["hello"].is<long>());
EXPECT_STREQ("h3110", _object["hello"].as<const char*>());
EXPECT_STREQ("w0r1d", _object["world"].as<const char*>());
}
@ -96,6 +104,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreArrays) {
_object["hello"] = array1;
_object.set("world", array2);
EXPECT_TRUE(_object["hello"].is<JsonArray&>());
EXPECT_FALSE(_object["hello"].is<JsonObject&>());
EXPECT_EQ(&array1, &_object["hello"].asArray());
EXPECT_EQ(&array2, &_object["world"].asArray());
}
@ -107,6 +117,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreObjects) {
_object["hello"] = object1;
_object.set("world", object2);
EXPECT_TRUE(_object["hello"].is<JsonObject&>());
EXPECT_FALSE(_object["hello"].is<JsonArray&>());
EXPECT_EQ(&object1, &_object["hello"].asObject());
EXPECT_EQ(&object2, &_object["world"].asObject());
}