Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormiloyip <miloyip@gmail.com>2014-07-31 14:43:59 +0400
committermiloyip <miloyip@gmail.com>2014-07-31 14:43:59 +0400
commit71c8402549136ff12a20c040ba8b336c960a906c (patch)
tree6535a7907d5231450b09df94e3ead499c2589f4b /test
parent0f7d2dad519a115c0405aa83f7788cec455d870f (diff)
Add equal-to and non-equal-to operators
Diffstat (limited to 'test')
-rw-r--r--test/unittest/valuetest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp
index 8eaf84a9..3bd0afcf 100644
--- a/test/unittest/valuetest.cpp
+++ b/test/unittest/valuetest.cpp
@@ -44,6 +44,58 @@ TEST(Value, assignment_operator) {
EXPECT_EQ(y.GetString(),mstr);
}
+template <typename A, typename B>
+void TestEqual(const A& a, const B& b) {
+ EXPECT_TRUE (a == b);
+ EXPECT_FALSE(a != b);
+ EXPECT_TRUE (b == a);
+ EXPECT_FALSE(b != a);
+}
+
+template <typename A, typename B>
+void TestUnequal(const A& a, const B& b) {
+ EXPECT_FALSE(a == b);
+ EXPECT_TRUE (a != b);
+ EXPECT_FALSE(b == a);
+ EXPECT_TRUE (b != a);
+}
+
+TEST(Value, equalto_operator) {
+ Value::AllocatorType allocator;
+ Value x(kObjectType);
+ x.AddMember("hello", "world", allocator)
+ .AddMember("t", Value(true).Move(), allocator)
+ .AddMember("f", Value(false).Move(), allocator)
+ .AddMember("n", Value(kNullType).Move(), allocator)
+ .AddMember("i", 123, allocator)
+ .AddMember("pi", 3.14, allocator)
+ .AddMember("a", Value(kArrayType).Move().PushBack(1, allocator).PushBack(2, allocator).PushBack(3, allocator), allocator);
+
+ // Test templated operator==() and operator!=()
+ TestEqual(x["hello"], "world");
+ const char* cc = "world";
+ TestEqual(x["hello"], cc);
+ char* c = strdup("world");
+ TestEqual(x["hello"], c);
+ free(c);
+
+ TestEqual(x["t"], true);
+ TestEqual(x["f"], false);
+ TestEqual(x["i"], 123);
+ TestEqual(x["pi"], 3.14);
+
+ // Test operator==()
+ Value y;
+ y.CopyFrom(x, allocator);
+ TestEqual(x, y);
+
+ // Swapping member order should be fine.
+ y.RemoveMember("t");
+ TestUnequal(x, y);
+ y.AddMember("t", Value(true).Move(), allocator);
+ TestEqual(x, y);
+}
+
template <typename Value>
void TestCopyFrom() {
typename Value::AllocatorType a;