summaryrefslogtreecommitdiff
path: root/tests/test_xpath.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-06 20:28:36 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-06 20:28:36 +0000
commitf542c5ebb8068ccd4f9176684eb62183afbe7e5c (patch)
tree6121507407cbab62c60047dc32e2332eb02844ca /tests/test_xpath.cpp
parentefee7df3f43c01504b4dd7c86f9ec72bcf318f05 (diff)
Integrated changes from unicode branch to trunk
git-svn-id: http://pugixml.googlecode.com/svn/trunk@383 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_xpath.cpp')
-rw-r--r--tests/test_xpath.cpp96
1 files changed, 76 insertions, 20 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 5f23f44..7ef34ec 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -2,46 +2,52 @@
#include "common.hpp"
+#include <float.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <string>
+
TEST_XML(xpath_document_order, "<node><child1 attr1='value1' attr2='value2'/><child2 attr1='value1'>test</child2></node>")
{
CHECK(xml_node().document_order() == 0);
- CHECK(doc.child("node").document_order() == 0);
+ CHECK(doc.child(STR("node")).document_order() == 0);
CHECK(doc.document_order() == 0);
doc.precompute_document_order();
CHECK(doc.document_order() == 1);
- CHECK(doc.child("node").document_order() == 2);
- CHECK(doc.child("node").child("child1").document_order() == 3);
- CHECK(doc.child("node").child("child1").attribute("attr1").document_order() == 4);
- CHECK(doc.child("node").child("child1").attribute("attr2").document_order() == 5);
- CHECK(doc.child("node").child("child2").document_order() == 6);
- CHECK(doc.child("node").child("child2").attribute("attr1").document_order() == 7);
- CHECK(doc.child("node").child("child2").first_child().document_order() == 8);
+ CHECK(doc.child(STR("node")).document_order() == 2);
+ CHECK(doc.child(STR("node")).child(STR("child1")).document_order() == 3);
+ CHECK(doc.child(STR("node")).child(STR("child1")).attribute(STR("attr1")).document_order() == 4);
+ CHECK(doc.child(STR("node")).child(STR("child1")).attribute(STR("attr2")).document_order() == 5);
+ CHECK(doc.child(STR("node")).child(STR("child2")).document_order() == 6);
+ CHECK(doc.child(STR("node")).child(STR("child2")).attribute(STR("attr1")).document_order() == 7);
+ CHECK(doc.child(STR("node")).child(STR("child2")).first_child().document_order() == 8);
}
TEST(xpath_allocator_many_pages)
{
- std::string query = "0";
+ pugi::string_t query = STR("0");
- for (int i = 0; i < 128; ++i) query += "+string-length('abcdefgh')";
+ for (int i = 0; i < 128; ++i) query += STR("+string-length('abcdefgh')");
CHECK_XPATH_NUMBER(xml_node(), query.c_str(), 1024);
}
TEST(xpath_allocator_large_page)
{
- std::string query;
+ pugi::string_t query;
- for (int i = 0; i < 1024; ++i) query += "abcdefgh";
+ for (int i = 0; i < 1024; ++i) query += STR("abcdefgh");
- CHECK_XPATH_NUMBER(xml_node(), ("string-length('" + query + "')").c_str(), 8192);
+ CHECK_XPATH_NUMBER(xml_node(), (STR("string-length('") + query + STR("')")).c_str(), 8192);
}
TEST_XML(xpath_sort_complex, "<node><child1 attr1='value1' attr2='value2'/><child2 attr1='value1'>test</child2></node>")
{
// just some random union order, it should not matter probably?
- xpath_node_set ns = doc.child("node").select_nodes("child1 | child2 | child1/@* | . | child2/@* | child2/text()");
+ xpath_node_set ns = doc.child(STR("node")).select_nodes(STR("child1 | child2 | child1/@* | . | child2/@* | child2/text()"));
ns.sort(false);
xpath_node_set sorted = ns;
@@ -57,7 +63,7 @@ TEST_XML(xpath_sort_complex, "<node><child1 attr1='value1' attr2='value2'/><chil
TEST_XML(xpath_sort_children, "<node><child><subchild id='1'/></child><child><subchild id='2'/></child></node>")
{
- xpath_node_set ns = doc.child("node").select_nodes("child/subchild[@id=1] | child/subchild[@id=2]");
+ xpath_node_set ns = doc.child(STR("node")).select_nodes(STR("child/subchild[@id=1] | child/subchild[@id=2]"));
ns.sort(false);
xpath_node_set sorted = ns;
@@ -73,15 +79,15 @@ TEST_XML(xpath_sort_children, "<node><child><subchild id='1'/></child><child><su
TEST_XML(xpath_sort_attributes, "<node/>")
{
- xml_node n = doc.child("node");
+ xml_node n = doc.child(STR("node"));
// we need to insert attributes manually since unsorted node sets are (always?) sorted via pointers because of remove_duplicates,
// so we need to have different document and pointer order to cover all comparator cases
- n.append_attribute("attr2");
- n.append_attribute("attr3");
- n.insert_attribute_before("attr1", n.attribute("attr2"));
+ n.append_attribute(STR("attr2"));
+ n.append_attribute(STR("attr3"));
+ n.insert_attribute_before(STR("attr1"), n.attribute(STR("attr2")));
- xpath_node_set ns = n.select_nodes("@*");
+ xpath_node_set ns = n.select_nodes(STR("@*"));
ns.sort(true);
xpath_node_set reverse_sorted = ns;
@@ -95,4 +101,54 @@ TEST_XML(xpath_sort_attributes, "<node/>")
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 5 % 4 % 3;
}
+TEST(xpath_long_numbers_parse)
+{
+ const pugi::char_t* str_flt_max = STR("340282346638528860000000000000000000000");
+ const pugi::char_t* str_flt_max_dec = STR("340282346638528860000000000000000000000.000000");
+
+ const pugi::char_t* str_dbl_max = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
+ const pugi::char_t* str_dbl_max_dec = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000");
+
+ xml_node c;
+
+ // check parsing
+ CHECK_XPATH_NUMBER(c, str_flt_max, FLT_MAX);
+ CHECK_XPATH_NUMBER(c, str_flt_max_dec, FLT_MAX);
+ CHECK_XPATH_NUMBER(c, str_dbl_max, DBL_MAX);
+ CHECK_XPATH_NUMBER(c, str_dbl_max_dec, DBL_MAX);
+}
+
+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;
+}
+
+TEST(xpath_long_numbers_stringize)
+{
+ const pugi::char_t* str_flt_max = STR("340282346638528860000000000000000000000");
+ const pugi::char_t* str_flt_max_dec = STR("340282346638528860000000000000000000000.000000");
+
+ const pugi::char_t* str_dbl_max = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
+ const pugi::char_t* str_dbl_max_dec = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000");
+
+ xml_node c;
+
+ CHECK(test_xpath_string_prefix(c, str_flt_max, str_flt_max, 16));
+ CHECK(test_xpath_string_prefix(c, str_flt_max_dec, str_flt_max, 16));
+
+#ifndef __BORLANDC__ // printf with %f format still results in 1.xxxe+308 form
+ CHECK(test_xpath_string_prefix(c, str_dbl_max, str_dbl_max, 16));
+ CHECK(test_xpath_string_prefix(c, str_dbl_max_dec, str_dbl_max, 16));
+#endif
+}
+
#endif