summaryrefslogtreecommitdiff
path: root/tests/test_xpath_api.cpp
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/test_xpath_api.cpp
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/test_xpath_api.cpp')
-rw-r--r--tests/test_xpath_api.cpp36
1 files changed, 36 insertions, 0 deletions
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