summaryrefslogtreecommitdiff
path: root/tests/helpers.hpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-11-08 13:52:55 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-11-08 13:52:55 +0000
commit48bbb9f4dd9e6581e61d4d60e132cdb4415f813e (patch)
tree2cab46e9c96b3209161ce60154a11599e26d582b /tests/helpers.hpp
parentc8a8b30bddf0df8f137203b0a1533c46358000be (diff)
tests: Extracted generic tests in a separate header, better filter tests, some API tests added
git-svn-id: http://pugixml.googlecode.com/svn/trunk@221 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/helpers.hpp')
-rw-r--r--tests/helpers.hpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/helpers.hpp b/tests/helpers.hpp
new file mode 100644
index 0000000..1481ccd
--- /dev/null
+++ b/tests/helpers.hpp
@@ -0,0 +1,90 @@
+#pragma once
+
+#include "common.hpp"
+
+#include <utility>
+
+template <typename T> static void generic_bool_ops_test(const T& obj)
+{
+ T null;
+
+ CHECK(!null);
+ CHECK(obj);
+ CHECK(!!obj);
+
+ bool b1 = null, b2 = obj;
+
+ CHECK(!b1);
+ CHECK(b2);
+
+ CHECK(obj && true);
+ CHECK(obj || false);
+ CHECK(obj && obj);
+ CHECK(obj || obj);
+}
+
+template <typename T> static void generic_eq_ops_test(const T& obj1, const T& obj2)
+{
+ T null = T();
+
+ // operator==
+ CHECK(null == null);
+ CHECK(obj1 == obj1);
+ CHECK(!(null == obj1));
+ CHECK(!(null == obj2));
+ CHECK(T(null) == null);
+ CHECK(T(obj1) == obj1);
+
+ // operator!=
+ CHECK(!(null != null));
+ CHECK(!(obj1 != obj1));
+ CHECK(null != obj1);
+ CHECK(null != obj2);
+ CHECK(!(T(null) != null));
+ CHECK(!(T(obj1) != obj1));
+}
+
+template <typename T> static void generic_rel_ops_test(T obj1, T obj2)
+{
+ T null = T();
+
+ // obj1 < obj2 (we use operator<, but there is no other choice
+ if (obj1 > obj2) std::swap(obj1, obj2);
+
+ // operator<
+ CHECK(null < obj1);
+ CHECK(null < obj2);
+ CHECK(obj1 < obj2);
+ CHECK(!(null < null));
+ CHECK(!(obj1 < obj1));
+ CHECK(!(obj1 < null));
+ CHECK(!(obj2 < obj1));
+
+ // operator<=
+ CHECK(null <= obj1);
+ CHECK(null <= obj2);
+ CHECK(obj1 <= obj2);
+ CHECK(null <= null);
+ CHECK(obj1 <= obj1);
+ CHECK(!(obj1 <= null));
+ CHECK(!(obj2 <= obj1));
+
+ // operator>
+ CHECK(obj1 > null);
+ CHECK(obj2 > null);
+ CHECK(obj2 > obj1);
+ CHECK(!(null > null));
+ CHECK(!(obj1 > obj1));
+ CHECK(!(null > obj1));
+ CHECK(!(obj1 > obj2));
+
+ // operator>=
+ CHECK(obj1 >= null);
+ CHECK(obj2 >= null);
+ CHECK(obj2 >= obj1);
+ CHECK(null >= null);
+ CHECK(obj1 >= obj1);
+ CHECK(!(null >= obj1));
+ CHECK(!(obj1 >= obj2));
+}
+