summaryrefslogtreecommitdiff
path: root/tests/test.hpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-29 07:17:30 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-29 07:17:30 +0000
commitfc602fd37554f5e2d58fcee71a58e380d23d22d4 (patch)
tree2955c7999c2053c06a81c21a79fd55670bb6940e /tests/test.hpp
parent0640f87859a5a676b41783be4741a62f4d1ea266 (diff)
tests: Supported all pugixml compilation modes
git-svn-id: http://pugixml.googlecode.com/svn/trunk@191 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test.hpp')
-rw-r--r--tests/test.hpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/test.hpp b/tests/test.hpp
index 5bbfbbd..b1e470e 100644
--- a/tests/test.hpp
+++ b/tests/test.hpp
@@ -4,7 +4,7 @@
#include <string.h>
#include <math.h>
#include <float.h>
-#include <sstream>
+#include <string>
#include "../src/pugixml.hpp"
@@ -18,14 +18,25 @@ template <typename Node> inline bool test_node_name_value(const Node& node, cons
return test_string_equal(node.name(), name) && test_string_equal(node.value(), value);
}
+struct xml_writer_string: public pugi::xml_writer
+{
+ std::string result;
+
+ virtual void write(const void* data, size_t size)
+ {
+ result += std::string(static_cast<const char*>(data), size);
+ }
+};
+
inline bool test_node(const pugi::xml_node& node, const char* contents, const char* indent, unsigned int flags)
{
- std::ostringstream oss;
- node.print(oss, indent, flags);
+ xml_writer_string writer;
+ node.print(writer, indent, flags);
- return oss.str() == contents;
+ return writer.result == contents;
}
+#ifndef PUGIXML_NO_XPATH
inline bool test_xpath_string(const pugi::xml_node& node, const char* query, const char* expected)
{
pugi::xpath_query q(query);
@@ -72,6 +83,7 @@ inline bool test_xpath_fail_compile(const char* query)
return true;
}
}
+#endif
struct test_runner
{
@@ -150,10 +162,12 @@ struct dummy_fixture {};
#define CHECK_NODE_EX(node, expected, indent, flags) CHECK_TEXT(test_node(node, expected, indent, flags), STR(node) " contents does not match " STR(expected))
#define CHECK_NODE(node, expected) CHECK_NODE_EX(node, expected, "", pugi::format_raw)
+#ifndef PUGIXML_NO_XPATH
#define CHECK_XPATH_STRING(node, query, expected) CHECK_TEXT(test_xpath_string(node, query, expected), STR(query) " does not evaluate to " STR(expected) " in context " STR(node))
#define CHECK_XPATH_BOOLEAN(node, query, expected) CHECK_TEXT(test_xpath_boolean(node, query, expected), STR(query) " does not evaluate to " STR(expected) " in context " STR(node))
#define CHECK_XPATH_NUMBER(node, query, expected) CHECK_TEXT(test_xpath_number(node, query, expected), STR(query) " does not evaluate to " STR(expected) " in context " STR(node))
#define CHECK_XPATH_NUMBER_NAN(node, query) CHECK_TEXT(test_xpath_number_nan(node, query), STR(query) " does not evaluate to NaN in context " STR(node))
#define CHECK_XPATH_FAIL(query) CHECK_TEXT(test_xpath_fail_compile(query), STR(query) " should not compile")
+#endif
#endif