summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:25:05 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:25:05 +0000
commit049fa3906db2786943617bb1b0ce3225be9a772f (patch)
tree3a502c3c0f3e93f4f3b3022eb13aa2e0bdf47705 /tests
parent91777e5c172c401ff25bd5a37067c5caca78dc63 (diff)
tests: Added new evaluate_string tests, fixed tests for NO_STL mode
git-svn-id: http://pugixml.googlecode.com/svn/trunk@661 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/test.cpp11
-rw-r--r--tests/test_xpath.cpp20
-rw-r--r--tests/test_xpath_api.cpp36
3 files changed, 55 insertions, 12 deletions
diff --git a/tests/test.cpp b/tests/test.cpp
index c60619a..96a81e4 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -58,7 +58,16 @@ bool test_xpath_string(const pugi::xml_node& node, const pugi::char_t* query, co
{
pugi::xpath_query q(query);
- return q.evaluate_string(node) == expected;
+ const size_t capacity = 64;
+ pugi::char_t result[capacity];
+
+ size_t size = q.evaluate_string(result, capacity, node);
+
+ if (size <= capacity) return test_string_equal(result, expected);
+
+ std::basic_string<pugi::char_t> buffer(size, ' ');
+
+ return q.evaluate_string(&buffer[0], size, node) == size && test_string_equal(buffer.c_str(), expected);
}
bool test_xpath_boolean(const pugi::xml_node& node, const pugi::char_t* query, bool expected)
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 7db9ea5..a2e8200 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -18,7 +18,7 @@ static void load_document_copy(xml_document& doc, const char_t* text)
TEST(xpath_allocator_many_pages)
{
- pugi::string_t query = STR("0");
+ std::basic_string<char_t> query = STR("0");
for (int i = 0; i < 128; ++i) query += STR("+string-length('abcdefgh')");
@@ -27,7 +27,7 @@ TEST(xpath_allocator_many_pages)
TEST(xpath_allocator_large_page)
{
- pugi::string_t query;
+ std::basic_string<char_t> query;
for (int i = 0; i < 1024; ++i) query += STR("abcdefgh");
@@ -139,16 +139,14 @@ TEST(xpath_long_numbers_parse)
static bool test_xpath_string_prefix(const pugi::xml_node& node, const pugi::char_t* query, const pugi::char_t* expected, size_t match_length)
{
-#ifdef PUGIXML_WCHAR_MODE
- size_t expected_length = wcslen(expected);
-#else
- size_t expected_length = strlen(expected);
-#endif
-
pugi::xpath_query q(query);
- pugi::string_t value = q.evaluate_string(node);
- return value.length() == expected_length && value.compare(0, match_length, expected, match_length) == 0;
+ pugi::char_t result[32];
+ size_t size = q.evaluate_string(result, sizeof(result) / sizeof(result[0]), node);
+
+ size_t expected_length = std::char_traits<pugi::char_t>::length(expected);
+
+ return size == expected_length + 1 && std::char_traits<pugi::char_t>::compare(result, expected, match_length) == 0;
}
TEST(xpath_long_numbers_stringize)
@@ -170,7 +168,7 @@ TEST(xpath_long_numbers_stringize)
TEST(xpath_denorm_numbers)
{
- pugi::string_t query;
+ std::basic_string<pugi::char_t> query;
// 10^-318 - double denormal
for (int i = 0; i < 106; ++i)
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index b5b63a7..8fc4d94 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -135,7 +135,13 @@ TEST_XML(xpath_api_evaluate, "<node attr='3'/>")
CHECK(q.evaluate_boolean(doc));
CHECK(q.evaluate_number(doc) == 3);
+
+ char_t string[3];
+ CHECK(q.evaluate_string(string, 3, doc) == 2 && string[0] == '3' && string[1] == 0);
+
+#ifndef PUGIXML_NO_STL
CHECK(q.evaluate_string(doc) == STR("3"));
+#endif
xpath_node_set ns = q.evaluate_node_set(doc);
CHECK(ns.size() == 1 && ns[0].attribute() == doc.child(STR("node")).attribute(STR("attr")));
@@ -170,6 +176,36 @@ TEST(xpath_api_evaluate_node_set_fail)
#endif
}
+TEST(xpath_api_evaluate_string)
+{
+ xpath_query q(STR("\"0123456789\""));
+
+ std::basic_string<char_t> base = STR("xxxxxxxxxxxxxxxx");
+
+ // test for enough space
+ std::basic_string<char_t> s0 = base;
+ CHECK(q.evaluate_string(&s0[0], 16, xml_node()) == 11 && memcmp(&s0[0], STR("0123456789\0xxxxx"), 16 * sizeof(char_t)) == 0);
+
+ // test for just enough space
+ std::basic_string<char_t> s1 = base;
+ CHECK(q.evaluate_string(&s1[0], 11, xml_node()) == 11 && memcmp(&s1[0], STR("0123456789\0xxxxx"), 16 * sizeof(char_t)) == 0);
+
+ // test for just not enough space
+ std::basic_string<char_t> s2 = base;
+ CHECK(q.evaluate_string(&s2[0], 10, xml_node()) == 11 && memcmp(&s2[0], STR("0123456789xxxxxx"), 16 * sizeof(char_t)) == 0);
+
+ // test for not enough space
+ std::basic_string<char_t> s3 = base;
+ CHECK(q.evaluate_string(&s3[0], 5, xml_node()) == 11 && memcmp(&s3[0], STR("01234xxxxxxxxxxx"), 16 * sizeof(char_t)) == 0);
+
+ // test for single character buffer
+ std::basic_string<char_t> s4 = base;
+ CHECK(q.evaluate_string(&s4[0], 1, xml_node()) == 11 && memcmp(&s4[0], STR("0xxxxxxxxxxxxxxx"), 16 * sizeof(char_t)) == 0);
+
+ // test for empty buffer
+ CHECK(q.evaluate_string(0, 0, xml_node()) == 11);
+}
+
TEST(xpath_api_return_type)
{
#ifdef PUGIXML_NO_EXCEPTIONS