diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/allocator.cpp | 44 | ||||
-rw-r--r-- | tests/autotest-local.pl | 4 | ||||
-rw-r--r-- | tests/autotest-remote-host.pl | 2 | ||||
-rw-r--r-- | tests/autotest-report.pl | 4 | ||||
-rw-r--r-- | tests/data/тест.xml | 1 | ||||
-rw-r--r-- | tests/test.cpp | 15 | ||||
-rw-r--r-- | tests/test.hpp | 2 | ||||
-rw-r--r-- | tests/test_document.cpp | 37 | ||||
-rw-r--r-- | tests/test_dom_modify.cpp | 115 | ||||
-rw-r--r-- | tests/test_dom_text.cpp | 14 | ||||
-rw-r--r-- | tests/test_dom_traverse.cpp | 37 | ||||
-rw-r--r-- | tests/test_header_only.cpp | 16 | ||||
-rw-r--r-- | tests/test_memory.cpp | 2 | ||||
-rw-r--r-- | tests/test_parse.cpp | 345 | ||||
-rw-r--r-- | tests/test_parse_doctype.cpp | 60 | ||||
-rw-r--r-- | tests/test_version.cpp | 2 | ||||
-rw-r--r-- | tests/test_write.cpp | 4 | ||||
-rw-r--r-- | tests/test_xpath.cpp | 8 | ||||
-rw-r--r-- | tests/test_xpath_functions.cpp | 8 | ||||
-rw-r--r-- | tests/test_xpath_operators.cpp | 4 | ||||
-rw-r--r-- | tests/test_xpath_paths.cpp | 6 | ||||
-rw-r--r-- | tests/writer_string.cpp | 2 |
22 files changed, 508 insertions, 224 deletions
diff --git a/tests/allocator.cpp b/tests/allocator.cpp index 094d5e5..74bbf10 100644 --- a/tests/allocator.cpp +++ b/tests/allocator.cpp @@ -66,6 +66,50 @@ namespace VirtualProtect(rptr, aligned_size + PAGE_SIZE, PAGE_NOACCESS, &old_flags); } } +#elif defined(__APPLE__) || defined(__linux__) +# include <sys/mman.h> + +namespace +{ + const size_t PAGE_SIZE = 4096; + + size_t align_to_page(size_t value) + { + return (value + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + } + + void* allocate_page_aligned(size_t size) + { + return mmap(0, size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + } + + void* allocate(size_t size) + { + size_t aligned_size = align_to_page(size); + + void* ptr = allocate_page_aligned(aligned_size + PAGE_SIZE); + if (!ptr) return 0; + + char* end = static_cast<char*>(ptr) + aligned_size; + + int res = mprotect(end, PAGE_SIZE, PROT_NONE); + assert(res == 0); + (void)!res; + + return end - size; + } + + void deallocate(void* ptr, size_t size) + { + size_t aligned_size = align_to_page(size); + + void* rptr = static_cast<char*>(ptr) + size - aligned_size; + + int res = mprotect(rptr, aligned_size + PAGE_SIZE, PROT_NONE); + assert(res == 0); + (void)!res; + } +} #else # include <stdlib.h> diff --git a/tests/autotest-local.pl b/tests/autotest-local.pl index a419bb0..60f8b20 100644 --- a/tests/autotest-local.pl +++ b/tests/autotest-local.pl @@ -65,8 +65,8 @@ if ($fast) print "### autotest begin " . scalar localtime() . "\n"; -# print SVN revision info -print "### autotest revision $1\n" if (`svn info` =~ /Revision:\s+(\d+)/); +# print Git revision info +print "### autotest revision $1\n" if (`git rev-parse HEAD` =~ /(.+)/); # get CPU info $cpucount = &getcpucount(); diff --git a/tests/autotest-remote-host.pl b/tests/autotest-remote-host.pl index 5abef1e..63dfe68 100644 --- a/tests/autotest-remote-host.pl +++ b/tests/autotest-remote-host.pl @@ -32,6 +32,6 @@ exit unless $client; select $client; -&execprint('svn up') == 0 || die "error updating from repo\n"; +&execprint('git pull') == 0 || die "error updating from repo\n"; &execprint('perl tests/autotest-local.pl') == 0 || die "error launching tests\n"; system($exitcmd); diff --git a/tests/autotest-report.pl b/tests/autotest-report.pl index b5ebd8c..9eebf39 100644 --- a/tests/autotest-report.pl +++ b/tests/autotest-report.pl @@ -128,7 +128,7 @@ while (<>) $defines{$_} = 1 foreach (split /,/, $defineset); &insertindex(\%configurations, $fullconf); } - elsif (/^### autotest revision (\d+)/) + elsif (/^### autotest revision (.+)/) { if (defined $revision && $revision != $1) { @@ -224,6 +224,6 @@ $date = localtime; print <<END; </table><br> -Generated on $date from Subversion r$revision +Generated on $date from Git $revision </body></html> END diff --git a/tests/data/тест.xml b/tests/data/тест.xml new file mode 100644 index 0000000..6187c16 --- /dev/null +++ b/tests/data/тест.xml @@ -0,0 +1 @@ +<node/>
\ No newline at end of file diff --git a/tests/test.cpp b/tests/test.cpp index eb901db..6347984 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -71,6 +71,15 @@ bool test_double_nan(double value) } #ifndef PUGIXML_NO_XPATH +static size_t strlength(const pugi::char_t* s) +{ +#ifdef PUGIXML_WCHAR_MODE + return wcslen(s); +#else + return strlen(s); +#endif +} + bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, pugi::xpath_variable_set* variables, const pugi::char_t* expected) { pugi::xpath_query q(query, variables); @@ -81,7 +90,11 @@ bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, size_t size = q.evaluate_string(result, capacity, node); - if (size <= capacity) return test_string_equal(result, expected); + if (size != strlength(expected) + 1) + return false; + + if (size <= capacity) + return test_string_equal(result, expected); std::basic_string<pugi::char_t> buffer(size, ' '); diff --git a/tests/test.hpp b/tests/test.hpp index 509b0cd..4222638 100644 --- a/tests/test.hpp +++ b/tests/test.hpp @@ -95,7 +95,7 @@ struct dummy_fixture {}; \ test_fixture_##name() \ { \ - CHECK(doc.load(PUGIXML_TEXT(xml), flags)); \ + CHECK(doc.load_string(PUGIXML_TEXT(xml), flags)); \ } \ \ private: \ diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 2774a07..ebcdcd1 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -158,7 +158,7 @@ TEST(document_load_stream_exceptions) TEST(document_load_stream_error_previous) { pugi::xml_document doc; - CHECK(doc.load(STR("<node/>"))); + CHECK(doc.load_string(STR("<node/>"))); CHECK(doc.first_child()); std::ifstream fs1("filedoesnotexist"); @@ -169,7 +169,7 @@ TEST(document_load_stream_error_previous) TEST(document_load_stream_wide_error_previous) { pugi::xml_document doc; - CHECK(doc.load(STR("<node/>"))); + CHECK(doc.load_string(STR("<node/>"))); CHECK(doc.first_child()); std::basic_ifstream<wchar_t> fs1("filedoesnotexist"); @@ -261,7 +261,7 @@ TEST(document_load_string) { pugi::xml_document doc; - CHECK(doc.load(STR("<node/>"))); + CHECK(doc.load_string(STR("<node/>"))); CHECK_NODE(doc, STR("<node />")); } @@ -301,10 +301,6 @@ TEST(document_load_file_error) CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found); -#ifndef _WIN32 - CHECK(doc.load_file("/dev/tty").status == status_io_error); -#endif - test_runner::_memory_fail_threshold = 1; CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory); } @@ -312,7 +308,7 @@ TEST(document_load_file_error) TEST(document_load_file_error_previous) { pugi::xml_document doc; - CHECK(doc.load(STR("<node/>"))); + CHECK(doc.load_string(STR("<node/>"))); CHECK(doc.first_child()); CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found); @@ -327,6 +323,16 @@ TEST(document_load_file_wide_ascii) CHECK_NODE(doc, STR("<node />")); } +#if !defined(__DMC__) && !defined(__MWERKS__) && !(defined(__MINGW32__) && defined(__STRICT_ANSI__) && !defined(__MINGW64_VERSION_MAJOR)) +TEST(document_load_file_wide_unicode) +{ + pugi::xml_document doc; + + CHECK(doc.load_file(L"tests/data/\x0442\x0435\x0441\x0442.xml")); + CHECK_NODE(doc, STR("<node />")); +} +#endif + TEST(document_load_file_wide_out_of_memory) { test_runner::_memory_fail_threshold = 1; @@ -594,7 +600,7 @@ TEST(document_parse_result_description) TEST(document_load_fail) { xml_document doc; - CHECK(!doc.load(STR("<foo><bar/>"))); + CHECK(!doc.load_string(STR("<foo><bar/>"))); CHECK(doc.child(STR("foo")).child(STR("bar"))); } @@ -1083,7 +1089,7 @@ TEST(document_load_exceptions) try { pugi::xml_document doc; - if (!doc.load(STR("<node attribute='value"))) throw std::bad_alloc(); + if (!doc.load_string(STR("<node attribute='value"))) throw std::bad_alloc(); CHECK_FORCE_FAIL("Expected parsing failure"); } @@ -1118,7 +1124,7 @@ TEST_XML(document_reset, "<node><child/></node>") CHECK(!doc.first_child()); CHECK_NODE(doc, STR("")); - CHECK(doc.load(STR("<node/>"))); + CHECK(doc.load_string(STR("<node/>"))); CHECK(doc.first_child()); CHECK_NODE(doc, STR("<node />")); @@ -1272,7 +1278,7 @@ TEST(document_alignment) { xml_document* doc = new (buf + offset) xml_document; - CHECK(doc->load(STR("<node />"))); + CHECK(doc->load_string(STR("<node />"))); CHECK_NODE(*doc, STR("<node />")); doc->~xml_document(); @@ -1312,3 +1318,10 @@ TEST(document_convert_out_of_memory) delete[] files[j].data; } } + +TEST(document_deprecated_load) +{ + xml_document doc; + CHECK(doc.load(STR("<node/>"))); + CHECK_NODE(doc, STR("<node />")); +} diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 45cf3ea..5167358 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -3,6 +3,8 @@ #include <limits> #include <string> +#include <math.h> + TEST_XML(dom_attr_assign, "<node/>") { xml_node node = doc.child(STR("node")); @@ -21,10 +23,13 @@ TEST_XML(dom_attr_assign, "<node/>") node.append_attribute(STR("attr6")) = 0.5; xml_attribute() = 0.5; - node.append_attribute(STR("attr7")) = true; + node.append_attribute(STR("attr7")) = 0.25f; + xml_attribute() = 0.25f; + + node.append_attribute(STR("attr8")) = true; xml_attribute() = true; - CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"true\" />")); + CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />")); } TEST_XML(dom_attr_set_name, "<node attr='value' />") @@ -55,10 +60,13 @@ TEST_XML(dom_attr_set_value, "<node/>") CHECK(node.append_attribute(STR("attr6")).set_value(0.5)); CHECK(!xml_attribute().set_value(0.5)); - CHECK(node.append_attribute(STR("attr7")).set_value(true)); + CHECK(node.append_attribute(STR("attr7")).set_value(0.25f)); + CHECK(!xml_attribute().set_value(0.25f)); + + CHECK(node.append_attribute(STR("attr8")).set_value(true)); CHECK(!xml_attribute().set_value(true)); - CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"true\" />")); + CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />")); } #ifdef PUGIXML_HAS_LONG_LONG @@ -93,6 +101,17 @@ TEST_XML(dom_attr_set_value_llong, "<node/>") } #endif +TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />") +{ + xml_node node = doc.child(STR("node")); + + node.attribute(STR("attr1")) = std::numeric_limits<float>::max(); + node.attribute(STR("attr2")) = std::numeric_limits<double>::max(); + + CHECK(test_node(node, STR("<node attr1=\"3.40282347e+038\" attr2=\"1.7976931348623157e+308\" />"), STR(""), pugi::format_raw) || + test_node(node, STR("<node attr1=\"3.40282347e+38\" attr2=\"1.7976931348623157e+308\" />"), STR(""), pugi::format_raw)); +} + TEST_XML(dom_node_set_name, "<node>text</node>") { CHECK(doc.child(STR("node")).set_name(STR("n"))); @@ -746,17 +765,6 @@ TEST_XML_FLAGS(dom_node_copy_types, "<?xml version='1.0'?><!DOCTYPE id><root><?p CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>")); } -TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />") -{ - xml_node node = doc.child(STR("node")); - - node.attribute(STR("attr1")) = std::numeric_limits<float>::max(); - node.attribute(STR("attr2")) = std::numeric_limits<double>::max(); - - CHECK(test_node(node, STR("<node attr1=\"3.40282e+038\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw) || - test_node(node, STR("<node attr1=\"3.40282e+38\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw)); -} - TEST(dom_node_declaration_name) { xml_document doc; @@ -1289,7 +1297,7 @@ TEST(dom_node_copy_stackless) data += STR("</a>"); xml_document doc; - CHECK(doc.load(data.c_str())); + CHECK(doc.load_string(data.c_str())); xml_document copy; CHECK(copy.append_copy(doc.first_child())); @@ -1324,7 +1332,7 @@ TEST(dom_node_copy_copyless) TEST(dom_node_copy_copyless_mix) { xml_document doc; - CHECK(doc.load(STR("<node>pcdata<?name value?><child attr1=\"\" attr2=\"value2\" /></node>"), parse_full)); + CHECK(doc.load_string(STR("<node>pcdata<?name value?><child attr1=\"\" attr2=\"value2\" /></node>"), parse_full)); xml_node child = doc.child(STR("node")).child(STR("child")); @@ -1426,3 +1434,76 @@ TEST_XML(dom_node_set_deallocate, "<node attr='value'>text</node>") CHECK_NODE(doc, STR("<:anonymous :anonymous=\"\"></:anonymous>")); } + +TEST(dom_node_copy_declaration_empty_name) +{ + xml_document doc1; + xml_node decl1 = doc1.append_child(node_declaration); + decl1.set_name(STR("")); + + xml_document doc2; + xml_node decl2 = doc2.append_copy(decl1); + + CHECK_STRING(decl2.name(), STR("")); +} + +TEST(dom_fp_roundtrip_min_max) +{ + xml_document doc; + xml_node node = doc.append_child(STR("node")); + xml_attribute attr = node.append_attribute(STR("attr")); + + node.text().set(std::numeric_limits<float>::min()); + CHECK(node.text().as_float() == std::numeric_limits<float>::min()); + + attr.set_value(std::numeric_limits<float>::max()); + CHECK(attr.as_float() == std::numeric_limits<float>::max()); + + attr.set_value(std::numeric_limits<double>::min()); + CHECK(attr.as_double() == std::numeric_limits<double>::min()); + + node.text().set(std::numeric_limits<double>::max()); + CHECK(node.text().as_double() == std::numeric_limits<double>::max()); +} + +const double fp_roundtrip_base[] = +{ + 0.31830988618379067154, + 0.43429448190325182765, + 0.57721566490153286061, + 0.69314718055994530942, + 0.70710678118654752440, + 0.78539816339744830962, +}; + +TEST(dom_fp_roundtrip_float) +{ + xml_document doc; + + for (int e = -125; e <= 128; ++e) + { + for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i) + { + float value = ldexpf(static_cast<float>(fp_roundtrip_base[i]), e); + + doc.text().set(value); + CHECK(doc.text().as_float() == value); + } + } +} + +TEST(dom_fp_roundtrip_double) +{ + xml_document doc; + + for (int e = -1021; e <= 1024; ++e) + { + for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i) + { + double value = ldexp(fp_roundtrip_base[i], e); + + doc.text().set(value); + CHECK(doc.text().as_double() == value); + } + } +} diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp index fb65b03..007334a 100644 --- a/tests/test_dom_text.cpp +++ b/tests/test_dom_text.cpp @@ -263,10 +263,13 @@ TEST_XML(dom_text_assign, "<node/>") node.append_child(STR("text6")).text() = 0.5;
xml_text() = 0.5;
- node.append_child(STR("text7")).text() = true;
+ node.append_child(STR("text7")).text() = 0.25f;
+ xml_text() = 0.25f;
+
+ node.append_child(STR("text8")).text() = true;
xml_text() = true;
- CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>true</text7></node>"));
+ CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
}
TEST_XML(dom_text_set_value, "<node/>")
@@ -287,10 +290,13 @@ TEST_XML(dom_text_set_value, "<node/>") CHECK(node.append_child(STR("text6")).text().set(0.5));
CHECK(!xml_text().set(0.5));
- CHECK(node.append_child(STR("text7")).text().set(true));
+ CHECK(node.append_child(STR("text7")).text().set(0.25f));
+ CHECK(!xml_text().set(0.25f));
+
+ CHECK(node.append_child(STR("text8")).text().set(true));
CHECK(!xml_text().set(true));
- CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>true</text7></node>"));
+ CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
}
#ifdef PUGIXML_HAS_LONG_LONG
diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 83afec8..721a079 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -924,6 +924,43 @@ TEST_XML_FLAGS(dom_offset_debug, "<?xml?><!DOCTYPE><?pi?><!--comment--><node>pcd CHECK((cit++)->offset_debug() == 58); } +TEST(dom_offset_debug_encoding) +{ + char buf[] = { 0, '<', 0, 'n', 0, '/', 0, '>' }; + + xml_document doc; + CHECK(doc.load_buffer(buf, sizeof(buf))); + + CHECK(doc.offset_debug() == 0); + CHECK(doc.first_child().offset_debug() == 1); +} + +TEST_XML(dom_offset_debug_append, "<node/>") +{ + xml_node c1 = doc.first_child(); + xml_node c2 = doc.append_child(STR("node")); + xml_node c3 = doc.append_child(node_pcdata); + + CHECK(doc.offset_debug() == 0); + CHECK(c1.offset_debug() == 1); + CHECK(c2.offset_debug() == -1); + CHECK(c3.offset_debug() == -1); + + c1.set_name(STR("nodenode")); + CHECK(c1.offset_debug() == -1); +} + +TEST_XML(dom_offset_debug_append_buffer, "<node/>") +{ + CHECK(doc.offset_debug() == 0); + CHECK(doc.first_child().offset_debug() == 1); + + CHECK(doc.append_buffer("<node/>", 7)); + CHECK(doc.offset_debug() == -1); + CHECK(doc.first_child().offset_debug() == -1); + CHECK(doc.last_child().offset_debug() == -1); +} + TEST_XML(dom_internal_object, "<node attr='value'>value</node>") { xml_node node = doc.child(STR("node")); diff --git a/tests/test_header_only.cpp b/tests/test_header_only.cpp new file mode 100644 index 0000000..f1990dd --- /dev/null +++ b/tests/test_header_only.cpp @@ -0,0 +1,16 @@ +#define PUGIXML_HEADER_ONLY +#define pugi pugih + +#include "common.hpp" + +// Check header guards +#include "../src/pugixml.hpp" +#include "../src/pugixml.hpp" + +TEST(header_only) +{ + xml_document doc; + CHECK(doc.load_string(STR("<node/>"))); + CHECK_STRING(doc.first_child().name(), STR("node")); + CHECK(doc.first_child() == doc.select_node(STR("//*")).node()); +} diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp index 32d395b..bd80ca1 100644 --- a/tests/test_memory.cpp +++ b/tests/test_memory.cpp @@ -39,7 +39,7 @@ TEST(memory_custom_memory_management) CHECK(allocate_count == 0 && deallocate_count == 0); - CHECK(doc.load(STR("<node />"))); + CHECK(doc.load_string(STR("<node />"))); CHECK(allocate_count == 2 && deallocate_count == 0); diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 56ea049..500e44c 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -12,10 +12,10 @@ TEST(parse_pi_skip) { unsigned int flags = flag_sets[i]; - CHECK(doc.load(STR("<?pi?><?pi value?>"), flags)); + CHECK(doc.load_string(STR("<?pi?><?pi value?>"), flags)); CHECK(!doc.first_child()); - CHECK(doc.load(STR("<?pi <tag/> value?>"), flags)); + CHECK(doc.load_string(STR("<?pi <tag/> value?>"), flags)); CHECK(!doc.first_child()); } } @@ -23,7 +23,7 @@ TEST(parse_pi_skip) TEST(parse_pi_parse) { xml_document doc; - CHECK(doc.load(STR("<?pi1?><?pi2 value?>"), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR("<?pi1?><?pi2 value?>"), parse_fragment | parse_pi)); xml_node pi1 = doc.first_child(); xml_node pi2 = doc.last_child(); @@ -40,7 +40,7 @@ TEST(parse_pi_parse) TEST(parse_pi_parse_spaces) { xml_document doc; - CHECK(doc.load(STR("<?target \r\n\t value ?>"), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR("<?target \r\n\t value ?>"), parse_fragment | parse_pi)); xml_node pi = doc.first_child(); @@ -59,46 +59,46 @@ TEST(parse_pi_error) { unsigned int flags = flag_sets[i]; - CHECK(doc.load(STR("<?"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<??"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?>"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?#?>"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name>"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name ?"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name?"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name? "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name? "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value ?"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value ? "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value ? >"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name value ? > "), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name&"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?name&?"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<??"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?>"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?#?>"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name>"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name ?"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name?"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name? "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name? "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value ?"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value ? "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value ? >"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name value ? > "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name&"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name&?"), flags).status == status_bad_pi); } - CHECK(doc.load(STR("<?xx#?>"), parse_fragment | parse_pi).status == status_bad_pi); - CHECK(doc.load(STR("<?name&?>"), parse_fragment | parse_pi).status == status_bad_pi); - CHECK(doc.load(STR("<?name& x?>"), parse_fragment | parse_pi).status == status_bad_pi); + CHECK(doc.load_string(STR("<?xx#?>"), parse_fragment | parse_pi).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name&?>"), parse_fragment | parse_pi).status == status_bad_pi); + CHECK(doc.load_string(STR("<?name& x?>"), parse_fragment | parse_pi).status == status_bad_pi); } TEST(parse_comments_skip) { xml_document doc; - CHECK(doc.load(STR("<!----><!--value-->"), parse_fragment)); + CHECK(doc.load_string(STR("<!----><!--value-->"), parse_fragment)); CHECK(!doc.first_child()); } TEST(parse_comments_parse) { xml_document doc; - CHECK(doc.load(STR("<!----><!--value-->"), parse_fragment | parse_comments)); + CHECK(doc.load_string(STR("<!----><!--value-->"), parse_fragment | parse_comments)); xml_node c1 = doc.first_child(); xml_node c2 = doc.last_child(); @@ -115,7 +115,7 @@ TEST(parse_comments_parse) TEST(parse_comments_parse_no_eol) { xml_document doc; - CHECK(doc.load(STR("<!--\r\rval1\rval2\r\nval3\nval4\r\r-->"), parse_fragment | parse_comments)); + CHECK(doc.load_string(STR("<!--\r\rval1\rval2\r\nval3\nval4\r\r-->"), parse_fragment | parse_comments)); xml_node c = doc.first_child(); CHECK(c.type() == node_comment); @@ -125,7 +125,7 @@ TEST(parse_comments_parse_no_eol) TEST(parse_comments_parse_eol) { xml_document doc; - CHECK(doc.load(STR("<!--\r\rval1\rval2\r\nval3\nval4\r\r-->"), parse_fragment | parse_comments | parse_eol)); + CHECK(doc.load_string(STR("<!--\r\rval1\rval2\r\nval3\nval4\r\r-->"), parse_fragment | parse_comments | parse_eol)); xml_node c = doc.first_child(); CHECK(c.type() == node_comment); @@ -142,33 +142,33 @@ TEST(parse_comments_error) { unsigned int flags = flag_sets[i]; - CHECK(doc.load(STR("<!-"), flags).status == status_bad_comment); - CHECK(doc.load(STR("<!--"), flags).status == status_bad_comment); - CHECK(doc.load(STR("<!--v"), flags).status == status_bad_comment); - CHECK(doc.load(STR("<!-->"), flags).status == status_bad_comment); - CHECK(doc.load(STR("<!--->"), flags).status == status_bad_comment); - CHECK(doc.load(STR("<!-- <!-- --><!- -->"), flags).status == status_bad_comment); + CHECK(doc.load_string(STR("<!-"), flags).status == status_bad_comment); + CHECK(doc.load_string(STR("<!--"), flags).status == status_bad_comment); + CHECK(doc.load_string(STR("<!--v"), flags).status == status_bad_comment); + CHECK(doc.load_string(STR("<!-->"), flags).status == status_bad_comment); + CHECK(doc.load_string(STR("<!--->"), flags).status == status_bad_comment); + CHECK(doc.load_string(STR("<!-- <!-- --><!- -->"), flags).status == status_bad_comment); } } TEST(parse_cdata_skip) { xml_document doc; - CHECK(doc.load(STR("<![CDATA[]]><![CDATA[value]]>"), parse_fragment)); + CHECK(doc.load_string(STR("<![CDATA[]]><![CDATA[value]]>"), parse_fragment)); CHECK(!doc.first_child()); } TEST(parse_cdata_skip_contents) { xml_document doc; - CHECK(doc.load(STR("<node><![CDATA[]]>hello<![CDATA[value]]>, world!</node>"), parse_fragment)); + CHECK(doc.load_string(STR("<node><![CDATA[]]>hello<![CDATA[value]]>, world!</node>"), parse_fragment)); CHECK_NODE(doc, STR("<node>hello, world!</node>")); } TEST(parse_cdata_parse) { xml_document doc; - CHECK(doc.load(STR("<![CDATA[]]><![CDATA[value]]>"), parse_fragment | parse_cdata)); + CHECK(doc.load_string(STR("<![CDATA[]]><![CDATA[value]]>"), parse_fragment | parse_cdata)); xml_node c1 = doc.first_child(); xml_node c2 = doc.last_child(); @@ -185,7 +185,7 @@ TEST(parse_cdata_parse) TEST(parse_cdata_parse_no_eol) { xml_document doc; - CHECK(doc.load(STR("<![CDATA[\r\rval1\rval2\r\nval3\nval4\r\r]]>"), parse_fragment | parse_cdata)); + CHECK(doc.load_string(STR("<![CDATA[\r\rval1\rval2\r\nval3\nval4\r\r]]>"), parse_fragment | parse_cdata)); xml_node c = doc.first_child(); CHECK(c.type() == node_cdata); @@ -195,7 +195,7 @@ TEST(parse_cdata_parse_no_eol) TEST(parse_cdata_parse_eol) { xml_document doc; - CHECK(doc.load(STR("<![CDATA[\r\rval1\rval2\r\nval3\nval4\r\r]]>"), parse_fragment | parse_cdata | parse_eol)); + CHECK(doc.load_string(STR("<![CDATA[\r\rval1\rval2\r\nval3\nval4\r\r]]>"), parse_fragment | parse_cdata | parse_eol)); xml_node c = doc.first_child(); CHECK(c.type() == node_cdata); @@ -212,29 +212,29 @@ TEST(parse_cdata_error) { unsigned int flags = flag_sets[i]; - CHECK(doc.load(STR("<!["), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![C"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CD"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDA"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDAT"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA["), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA[]"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA[data"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA[data]"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA[data]]"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA[>"), flags).status == status_bad_cdata); - CHECK(doc.load(STR("<![CDATA[ <![CDATA[]]><![CDATA ]]>"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<!["), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![C"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CD"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDA"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDAT"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA["), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA[]"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA[data"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA[data]"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA[data]]"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA[>"), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR("<![CDATA[ <![CDATA[]]><![CDATA ]]>"), flags).status == status_bad_cdata); } } TEST(parse_ws_pcdata_skip) { xml_document doc; - CHECK(doc.load(STR(" "), parse_fragment)); + CHECK(doc.load_string(STR(" "), parse_fragment)); CHECK(!doc.first_child()); - CHECK(doc.load(STR("<root> <node> </node> </root>"), parse_minimal)); + CHECK(doc.load_string(STR("<root> <node> </node> </root>"), parse_minimal)); xml_node root = doc.child(STR("root")); @@ -245,7 +245,7 @@ TEST(parse_ws_pcdata_skip) TEST(parse_ws_pcdata_parse) { xml_document doc; - CHECK(doc.load(STR("<root> <node> </node> </root>"), parse_minimal | parse_ws_pcdata)); + CHECK(doc.load_string(STR("<root> <node> </node> </root>"), parse_minimal | parse_ws_pcdata)); xml_node root = doc.child(STR("root")); @@ -334,7 +334,7 @@ TEST(parse_ws_pcdata_permutations) unsigned int flags[] = {parse_default, parse_default | parse_ws_pcdata, parse_default | parse_ws_pcdata_single}; xml_document doc; - CHECK((td.nodes > 0) == doc.load(td.source, flags[flag])); + CHECK((td.nodes > 0) == doc.load_string(td.source, flags[flag])); CHECK_NODE(doc, td.result); int nodes = get_tree_node_count(doc); @@ -385,7 +385,7 @@ TEST(parse_ws_pcdata_fragment_permutations) unsigned int flags[] = {parse_default, parse_default | parse_ws_pcdata, parse_default | parse_ws_pcdata_single}; xml_document doc; - CHECK((td.nodes > 0) == doc.load(td.source, flags[flag] | parse_fragment)); + CHECK((td.nodes > 0) == doc.load_string(td.source, flags[flag] | parse_fragment)); CHECK_NODE(doc, td.result); int nodes = get_tree_node_count(doc); @@ -398,7 +398,7 @@ TEST(parse_ws_pcdata_fragment_permutations) TEST(parse_pcdata_no_eol) { xml_document doc; - CHECK(doc.load(STR("<root>\r\rval1\rval2\r\nval3\nval4\r\r</root>"), parse_minimal)); + CHECK(doc.load_string(STR("<root>\r\rval1\rval2\r\nval3\nval4\r\r</root>"), parse_minimal)); CHECK_STRING(doc.child_value(STR("root")), STR("\r\rval1\rval2\r\nval3\nval4\r\r")); } @@ -406,7 +406,7 @@ TEST(parse_pcdata_no_eol) TEST(parse_pcdata_eol) { xml_document doc; - CHECK(doc.load(STR("<root>\r\rval1\rval2\r\nval3\nval4\r\r</root>"), parse_minimal | parse_eol)); + CHECK(doc.load_string(STR("<root>\r\rval1\rval2\r\nval3\nval4\r\r</root>"), parse_minimal | parse_eol)); CHECK_STRING(doc.child_value(STR("root")), STR("\n\nval1\nval2\nval3\nval4\n\n")); } @@ -414,7 +414,7 @@ TEST(parse_pcdata_eol) TEST(parse_pcdata_skip_ext) { xml_document doc; - CHECK(doc.load(STR("pre<root/>post"), parse_minimal)); + CHECK(doc.load_string(STR("pre<root/>post"), parse_minimal)); CHECK(doc.first_child() == doc.last_child()); CHECK(doc.first_child().type() == node_element); } @@ -422,7 +422,7 @@ TEST(parse_pcdata_skip_ext) TEST(parse_pcdata_error) { xml_document doc; - CHECK(doc.load(STR("<root>pcdata"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<root>pcdata"), parse_minimal).status == status_end_element_mismatch); } TEST(parse_pcdata_trim) @@ -460,7 +460,7 @@ TEST(parse_pcdata_trim) const test_data_t& td = test_data[i]; xml_document doc; - CHECK(doc.load(td.source, td.flags | parse_trim_pcdata)); + CHECK(doc.load_string(td.source, td.flags | parse_trim_pcdata)); const pugi::char_t* value = doc.child(STR("node")) ? doc.child_value(STR("node")) : doc.text().get(); CHECK_STRING(value, td.result); @@ -474,7 +474,7 @@ TEST(parse_pcdata_trim_empty) for (size_t i = 0; i < sizeof(flags) / sizeof(flags[0]); ++i) { xml_document doc; - CHECK(doc.load(STR("<node> </node>"), flags[i] | parse_trim_pcdata)); + CHECK(doc.load_string(STR("<node> </node>"), flags[i] | parse_trim_pcdata)); xml_node node = doc.child(STR("node")); CHECK(node); @@ -485,14 +485,14 @@ TEST(parse_pcdata_trim_empty) TEST(parse_escapes_skip) { xml_document doc; - CHECK(doc.load(STR("<node id='<>&'"'><>&'"</node>"), parse_minimal)); + CHECK(doc.load_string(STR("<node id='<>&'"'><>&'"</node>"), parse_minimal)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("<>&'"")); } TEST(parse_escapes_parse) { xml_document doc; - CHECK(doc.load(STR("<node id='<>&'"'><>&'"</node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node id='<>&'"'><>&'"</node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("<>&'\"")); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("<>&'\"")); } @@ -500,28 +500,28 @@ TEST(parse_escapes_parse) TEST(parse_escapes_code) { xml_document doc; - CHECK(doc.load(STR("<node>  </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>  </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("\01 ")); } TEST(parse_escapes_code_exhaustive_dec) { xml_document doc; - CHECK(doc.load(STR("<node>&#/;	&#:;&#a;&#A;
</node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&#/;	&#:;&#a;&#A;
</node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&#/;\x1\x2\x3\x4\x5\x6\x7\x8\x9&#:;&#a;&#A;
")); } TEST(parse_escapes_code_exhaustive_hex) { xml_document doc; - CHECK(doc.load(STR("<node>&#x/;	&#x:;&#x@;

&#xG;&#x`;

&#xg;</node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&#x/;	&#x:;&#x@;

&#xG;&#x`;

&#xg;</node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&#x/;\x1\x2\x3\x4\x5\x6\x7\x8\x9&#x:;&#x@;\xa\xb\xc\xd\xe\xf&#xG;&#x`;\xa\xb\xc\xd\xe\xf&#xg;")); } TEST(parse_escapes_code_restore) { xml_document doc; - CHECK(doc.load(STR("<node>  - - </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>  - - </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("  - - ")); } @@ -529,26 +529,26 @@ TEST(parse_escapes_char_restore) { xml_document doc; - CHECK(doc.load(STR("<node>&q &qu &quo " </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&q &qu &quo " </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&q &qu &quo " ")); - CHECK(doc.load(STR("<node>&a &ap &apo &apos </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&a &ap &apo &apos </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&a &ap &apo &apos ")); - CHECK(doc.load(STR("<node>&a &am & </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&a &am & </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&a &am & ")); - CHECK(doc.load(STR("<node>&l < </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&l < </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&l < ")); - CHECK(doc.load(STR("<node>&g > </node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&g > </node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&g > ")); } TEST(parse_escapes_unicode) { xml_document doc; - CHECK(doc.load(STR("<node>γγ𤭢</node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>γγ𤭢</node>"), parse_minimal | parse_escapes)); #ifdef PUGIXML_WCHAR_MODE const pugi::char_t* v = doc.child_value(STR("node")); @@ -564,23 +564,23 @@ TEST(parse_escapes_unicode) TEST(parse_escapes_error) { xml_document doc; - CHECK(doc.load(STR("<node>g;&#ab;"</node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>g;&#ab;"</node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("g;&#ab;"")); - CHECK(!doc.load(STR("<node id='"))); - CHECK(!doc.load(STR("<node id='&g"))); - CHECK(!doc.load(STR("<node id='>"))); - CHECK(!doc.load(STR("<node id='&l"))); - CHECK(!doc.load(STR("<node id='<"))); - CHECK(!doc.load(STR("<node id='&a"))); - CHECK(!doc.load(STR("<node id='&"))); - CHECK(!doc.load(STR("<node id='&apos"))); + CHECK(!doc.load_string(STR("<node id='"))); + CHECK(!doc.load_string(STR("<node id='&g"))); + CHECK(!doc.load_string(STR("<node id='>"))); + CHECK(!doc.load_string(STR("<node id='&l"))); + CHECK(!doc.load_string(STR("<node id='<"))); + CHECK(!doc.load_string(STR("<node id='&a"))); + CHECK(!doc.load_string(STR("<node id='&"))); + CHECK(!doc.load_string(STR("<node id='&apos"))); } TEST(parse_escapes_code_invalid) { xml_document doc; - CHECK(doc.load(STR("<node>&#;&#x;&;&#x-;&#-;</node>"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<node>&#;&#x;&;&#x-;&#-;</node>"), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&#;&#x;&;&#x-;&#-;")); } @@ -598,7 +598,7 @@ TEST(parse_escapes_attribute) flags |= (eol ? parse_eol : 0); flags |= (wconv ? parse_wconv_attribute : 0); - CHECK(doc.load(STR("<node id='"'/>"), flags)); + CHECK(doc.load_string(STR("<node id='"'/>"), flags)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("\"")); } } @@ -606,7 +606,7 @@ TEST(parse_escapes_attribute) TEST(parse_attribute_spaces) { xml_document doc; - CHECK(doc.load(STR("<node id1='v1' id2 ='v2' id3= 'v3' id4 = 'v4' id5 \n\r\t = \r\t\n 'v5' />"), parse_minimal)); + CHECK(doc.load_string(STR("<node id1='v1' id2 ='v2' id3= 'v3' id4 = 'v4' id5 \n\r\t = \r\t\n 'v5' />"), parse_minimal)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id1")).value(), STR("v1")); CHECK_STRING(doc.child(STR("node")).attribute(STR("id2")).value(), STR("v2")); CHECK_STRING(doc.child(STR("node")).attribute(STR("id3")).value(), STR("v3")); @@ -617,7 +617,7 @@ TEST(parse_attribute_spaces) TEST(parse_attribute_quot) { xml_document doc; - CHECK(doc.load(STR("<node id1='v1' id2=\"v2\"/>"), parse_minimal)); + CHECK(doc.load_string(STR("<node id1='v1' id2=\"v2\"/>"), parse_minimal)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id1")).value(), STR("v1")); CHECK_STRING(doc.child(STR("node")).attribute(STR("id2")).value(), STR("v2")); } @@ -625,28 +625,28 @@ TEST(parse_attribute_quot) TEST(parse_attribute_no_eol_no_wconv) { xml_document doc; - CHECK(doc.load(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal)); + CHECK(doc.load_string(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR(" \t\r\rval1 \rval2\r\nval3\nval4\r\r")); } TEST(parse_attribute_eol_no_wconv) { xml_document doc; - CHECK(doc.load(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal | parse_eol)); + CHECK(doc.load_string(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal | parse_eol)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR(" \t\n\nval1 \nval2\nval3\nval4\n\n")); } TEST(parse_attribute_no_eol_wconv) { xml_document doc; - CHECK(doc.load(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal | parse_wconv_attribute)); + CHECK(doc.load_string(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal | parse_wconv_attribute)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR(" val1 val2 val3 val4 ")); } TEST(parse_attribute_eol_wconv) { xml_document doc; - CHECK(doc.load(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal | parse_eol | parse_wconv_attribute)); + CHECK(doc.load_string(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), parse_minimal | parse_eol | parse_wconv_attribute)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR(" val1 val2 val3 val4 ")); } @@ -658,7 +658,7 @@ TEST(parse_attribute_wnorm) for (int wconv = 0; wconv < 2; ++wconv) { unsigned int flags = parse_minimal | parse_wnorm_attribute | (eol ? parse_eol : 0) | (wconv ? parse_wconv_attribute : 0); - CHECK(doc.load(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), flags)); + CHECK(doc.load_string(STR("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>"), flags)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("val1 val2 val3 val4")); } } @@ -679,7 +679,7 @@ TEST(parse_attribute_variations) flags |= (wconv ? parse_wconv_attribute : 0); flags |= (escapes ? parse_escapes : 0); - CHECK(doc.load(STR("<node id='1'/>"), flags)); + CHECK(doc.load_string(STR("<node id='1'/>"), flags)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("1")); } } @@ -688,24 +688,24 @@ TEST(parse_attribute_variations) TEST(parse_attribute_error) { xml_document doc; - CHECK(doc.load(STR("<node id"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id "), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id "), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id "), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id/"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id?/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id=/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id='/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id=\"/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id=\"'/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id='\"/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id='\"/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node #/>"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node#/>"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node id1='1'id2='2'/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node id&='1'/>"), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR("<node &='1'/>"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node id"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id "), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id "), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id "), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id/"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id?/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id=/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id='/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id=\"/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id=\"'/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id='\"/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id='\"/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node #/>"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node#/>"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node id1='1'id2='2'/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id&='1'/>"), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node &='1'/>"), parse_minimal).status == status_bad_start_element); } TEST(parse_attribute_termination_error) @@ -722,7 +722,7 @@ TEST(parse_attribute_termination_error) flags |= (eol ? parse_eol : 0); flags |= (wconv ? parse_wconv_attribute : 0); - CHECK(doc.load(STR("<node id='value"), flags).status == status_bad_attribute); + CHECK(doc.load_string(STR("<node id='value"), flags).status == status_bad_attribute); } } @@ -740,7 +740,7 @@ TEST(parse_attribute_quot_inside) flags |= (eol ? parse_eol : 0); flags |= (wconv ? parse_wconv_attribute : 0); - CHECK(doc.load(STR("<node id1='\"' id2=\"'\"/>"), flags)); + CHECK(doc.load_string(STR("<node id1='\"' id2=\"'\"/>"), flags)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id1")).value(), STR("\"")); CHECK_STRING(doc.child(STR("node")).attribute(STR("id2")).value(), STR("'")); } @@ -749,60 +749,60 @@ TEST(parse_attribute_quot_inside) TEST(parse_tag_single) { xml_document doc; - CHECK(doc.load(STR("<node/><node /><node\n/>"), parse_minimal)); + CHECK(doc.load_string(STR("<node/><node /><node\n/>"), parse_minimal)); CHECK_NODE(doc, STR("<node /><node /><node />")); } TEST(parse_tag_hierarchy) { xml_document doc; - CHECK(doc.load(STR("<node><n1><n2/></n1><n3><n4><n5></n5></n4></n3 \r\n></node>"), parse_minimal)); + CHECK(doc.load_string(STR("<node><n1><n2/></n1><n3><n4><n5></n5></n4></n3 \r\n></node>"), parse_minimal)); CHECK_NODE(doc, STR("<node><n1><n2 /></n1><n3><n4><n5 /></n4></n3></node>")); } TEST(parse_tag_error) { xml_document doc; - CHECK(doc.load(STR("<"), parse_minimal).status == status_unrecognized_tag); - CHECK(doc.load(STR("<!"), parse_minimal).status == status_unrecognized_tag); - CHECK(doc.load(STR("<!D"), parse_minimal).status == status_unrecognized_tag); - CHECK(doc.load(STR("<#"), parse_minimal).status == status_unrecognized_tag); - CHECK(doc.load(STR("<node#"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node/"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node /"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node / "), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node / >"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node/ >"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("</ node>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("</node"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("</node "), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("<node></ node>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("<node></node"), parse_minimal).status == status_bad_end_element); - CHECK(doc.load(STR("<node></node "), parse_minimal).status == status_bad_end_element); - CHECK(doc.load(STR("<node></nodes>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("<node>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("<node/><"), parse_minimal).status == status_unrecognized_tag); - CHECK(doc.load(STR("<node attr='value'>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("</></node>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("</node>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("</>"), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("<node></node v>"), parse_minimal).status == status_bad_end_element); - CHECK(doc.load(STR("<node&/>"), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR("<node& v='1'/>"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<"), parse_minimal).status == status_unrecognized_tag); + CHECK(doc.load_string(STR("<!"), parse_minimal).status == status_unrecognized_tag); + CHECK(doc.load_string(STR("<!D"), parse_minimal).status == status_unrecognized_tag); + CHECK(doc.load_string(STR("<#"), parse_minimal).status == status_unrecognized_tag); + CHECK(doc.load_string(STR("<node#"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node/"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node /"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node / "), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node / >"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node/ >"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("</ node>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("</node"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("</node "), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<node></ node>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<node></node"), parse_minimal).status == status_bad_end_element); + CHECK(doc.load_string(STR("<node></node "), parse_minimal).status == status_bad_end_element); + CHECK(doc.load_string(STR("<node></nodes>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<node>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<node/><"), parse_minimal).status == status_unrecognized_tag); + CHECK(doc.load_string(STR("<node attr='value'>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("</></node>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("</node>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("</>"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<node></node v>"), parse_minimal).status == status_bad_end_element); + CHECK(doc.load_string(STR("<node&/>"), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR("<node& v='1'/>"), parse_minimal).status == status_bad_start_element); } TEST(parse_declaration_cases) { xml_document doc; - CHECK(doc.load(STR("<?xml?><?xmL?><?xMl?><?xML?><?Xml?><?XmL?><?XMl?><?XML?>"), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR("<?xml?><?xmL?><?xMl?><?xML?><?Xml?><?XmL?><?XMl?><?XML?>"), parse_fragment | parse_pi)); CHECK(!doc.first_child()); } TEST(parse_declaration_attr_cases) { xml_document doc; - CHECK(doc.load(STR("<?xml ?><?xmL ?><?xMl ?><?xML ?><?Xml ?><?XmL ?><?XMl ?><?XML ?>"), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR("<?xml ?><?xmL ?><?xMl ?><?xML ?><?Xml ?><?XmL ?><?XMl ?><?XML ?>"), parse_fragment | parse_pi)); CHECK(!doc.first_child()); } @@ -816,10 +816,10 @@ TEST(parse_declaration_skip) { unsigned int flags = flag_sets[i]; - CHECK(doc.load(STR("<?xml?><?xml version='1.0'?>"), flags)); + CHECK(doc.load_string(STR("<?xml?><?xml version='1.0'?>"), flags)); CHECK(!doc.first_child()); - CHECK(doc.load(STR("<?xml <tag/> ?>"), flags)); + CHECK(doc.load_string(STR("<?xml <tag/> ?>"), flags)); CHECK(!doc.first_child()); } } @@ -827,7 +827,7 @@ TEST(parse_declaration_skip) TEST(parse_declaration_parse) { xml_document doc; - CHECK(doc.load(STR("<?xml?><?xml version='1.0'?>"), parse_fragment | parse_declaration)); + CHECK(doc.load_string(STR("<?xml?><?xml version='1.0'?>"), parse_fragment | parse_declaration)); xml_node d1 = doc.first_child(); xml_node d2 = doc.last_child(); @@ -850,23 +850,36 @@ TEST(parse_declaration_error) { unsigned int flags = flag_sets[i]; - CHECK(doc.load(STR("<?xml"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?xml?"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?xml>"), flags).status == status_bad_pi); - CHECK(doc.load(STR("<?xml version='1>"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?xml"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?xml?"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?xml>"), flags).status == status_bad_pi); + CHECK(doc.load_string(STR("<?xml version='1>"), flags).status == status_bad_pi); } - CHECK(doc.load(STR("<?xml version='1?>"), parse_fragment | parse_declaration).status == status_bad_attribute); - CHECK(doc.load(STR("<foo><?xml version='1'?></foo>"), parse_fragment | parse_declaration).status == status_bad_pi); + CHECK(doc.load_string(STR("<?xml version='1?>"), parse_fragment | parse_declaration).status == status_bad_attribute); + CHECK(doc.load_string(STR("<foo><?xml version='1'?></foo>"), parse_fragment | parse_declaration).status == status_bad_pi); } TEST(parse_empty) { xml_document doc; - CHECK(doc.load(STR("")).status == status_no_document_element && !doc.first_child()); - CHECK(doc.load(STR(""), parse_fragment) && !doc.first_child()); - CHECK(doc.load_buffer(NULL, 12).status == status_no_document_element); - CHECK(doc.load_buffer("foo", 0).status == status_no_document_element); + + CHECK(doc.load_string(STR("")).status == status_no_document_element && !doc.first_child()); + CHECK(doc.load_string(STR(""), parse_fragment) && !doc.first_child()); +} + +TEST(parse_load_buffer_null) +{ + xml_document doc; + + CHECK(doc.load_buffer(0, 12).status == status_no_document_element && !doc.first_child()); +} + +TEST(parse_load_buffer_empty) +{ + xml_document doc; + + CHECK(doc.load_buffer("foo", 0).status == status_no_document_element); } TEST(parse_out_of_memory) @@ -874,7 +887,7 @@ TEST(parse_out_of_memory) test_runner::_memory_fail_threshold = 256; xml_document doc; - CHECK(doc.load(STR("<foo a='1'/>")).status == status_out_of_memory); + CHECK(doc.load_string(STR("<foo a='1'/>")).status == status_out_of_memory); CHECK(!doc.first_child()); } @@ -930,7 +943,7 @@ TEST(parse_out_of_memory_halfway_attr) static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset) { xml_document doc; - xml_parse_result res = doc.load(contents, options); + xml_parse_result res = doc.load_string(contents, options); return res.status == status && res.offset == offset; } @@ -1067,7 +1080,7 @@ TEST(parse_bom_fragment_invalid_utf32) TEST(parse_pcdata_gap_fragment) { xml_document doc; - CHECK(doc.load(STR("a&b"), parse_fragment | parse_escapes)); + CHECK(doc.load_string(STR("a&b"), parse_fragment | parse_escapes)); CHECK_STRING(doc.text().get(), STR("a&b")); } diff --git a/tests/test_parse_doctype.cpp b/tests/test_parse_doctype.cpp index f8619fd..901890c 100644 --- a/tests/test_parse_doctype.cpp +++ b/tests/test_parse_doctype.cpp @@ -20,7 +20,7 @@ static xml_parse_result load_concat(xml_document& doc, const char_t* a, const ch strcat(buffer, c); #endif - return doc.load(buffer, parse_fragment); + return doc.load_string(buffer, parse_fragment); } static bool test_doctype_wf(const char_t* decl) @@ -41,7 +41,7 @@ static bool test_doctype_wf(const char_t* decl) if (!load_concat(doc, STR("<nodea/>"), decl, STR("<nodeb/>")) || !test_node(doc, STR("<nodea /><nodeb />"), STR(""), format_raw)) return false; // check load-store contents preservation - CHECK(doc.load(decl, parse_doctype | parse_fragment)); + CHECK(doc.load_string(decl, parse_doctype | parse_fragment)); CHECK_NODE(doc, decl); return true; @@ -281,8 +281,8 @@ TEST(parse_doctype_xmlconf_oasis_1) // not actually a doctype :) xml_document doc; - CHECK(doc.load(STR("<!--a <!DOCTYPE <?- ]]>-<[ CDATA [ \"- -'- -<doc>--> <!---->"), parse_full | parse_fragment) && doc.first_child().type() == node_comment && doc.last_child().type() == node_comment && doc.first_child().next_sibling() == doc.last_child()); - CHECK(doc.load(STR("<?xmla <!DOCTYPE <[ CDATA [</doc> &a%b&#c?>"), parse_full | parse_fragment) && doc.first_child().type() == node_pi && doc.first_child() == doc.last_child()); + CHECK(doc.load_string(STR("<!--a <!DOCTYPE <?- ]]>-<[ CDATA [ \"- -'- -<doc>--> <!---->"), parse_full | parse_fragment) && doc.first_child().type() == node_comment && doc.last_child().type() == node_comment && doc.first_child().next_sibling() == doc.last_child()); + CHECK(doc.load_string(STR("<?xmla <!DOCTYPE <[ CDATA [</doc> &a%b&#c?>"), parse_full | parse_fragment) && doc.first_child().type() == node_pi && doc.first_child() == doc.last_child()); } TEST(parse_doctype_xmlconf_xmltest_1) @@ -310,15 +310,55 @@ TEST_XML_FLAGS(parse_doctype_value, "<!DOCTYPE doc [ <!ELEMENT doc (#PCDATA)> <! TEST(parse_doctype_error_toplevel) { xml_document doc; - CHECK(doc.load(STR("<node><!DOCTYPE></node>")).status == status_bad_doctype); - CHECK(doc.load(STR("<node><!DOCTYPE></node>"), parse_doctype).status == status_bad_doctype); + CHECK(doc.load_string(STR("<node><!DOCTYPE></node>")).status == status_bad_doctype); + CHECK(doc.load_string(STR("<node><!DOCTYPE></node>"), parse_doctype).status == status_bad_doctype); } TEST(parse_doctype_error_ignore) { xml_document doc; - CHECK(doc.load(STR("<!DOCTYPE root [ <![IGNORE[ ")).status == status_bad_doctype); - CHECK(doc.load(STR("<!DOCTYPE root [ <![IGNORE[ "), parse_doctype).status == status_bad_doctype); - CHECK(doc.load(STR("<!DOCTYPE root [ <![IGNORE[ <![INCLUDE[")).status == status_bad_doctype); - CHECK(doc.load(STR("<!DOCTYPE root [ <![IGNORE[ <![INCLUDE["), parse_doctype).status == status_bad_doctype); + CHECK(doc.load_string(STR("<!DOCTYPE root [ <![IGNORE[ ")).status == status_bad_doctype); + CHECK(doc.load_string(STR("<!DOCTYPE root [ <![IGNORE[ "), parse_doctype).status == status_bad_doctype); + CHECK(doc.load_string(STR("<!DOCTYPE root [ <![IGNORE[ <![INCLUDE[")).status == status_bad_doctype); + CHECK(doc.load_string(STR("<!DOCTYPE root [ <![IGNORE[ <![INCLUDE["), parse_doctype).status == status_bad_doctype); +} + +TEST(parse_doctype_stackless_group) +{ + std::basic_string<char_t> str; + + int count = 100000; + + str += STR("<!DOCTYPE "); + + for (int i = 0; i < count; ++i) + str += STR("<!G "); + + for (int j = 0; j < count; ++j) + str += STR(">"); + + str += STR(">"); + + xml_document doc; + CHECK(doc.load_string(str.c_str(), parse_fragment)); +} + +TEST(parse_doctype_stackless_ignore) +{ + std::basic_string<char_t> str; + + int count = 100000; + + str += STR("<!DOCTYPE "); + + for (int i = 0; i < count; ++i) + str += STR("<![IGNORE[ "); + + for (int j = 0; j < count; ++j) + str += STR("]]>"); + + str += STR(">"); + + xml_document doc; + CHECK(doc.load_string(str.c_str(), parse_fragment)); } diff --git a/tests/test_version.cpp b/tests/test_version.cpp index 622a100..24036fc 100644 --- a/tests/test_version.cpp +++ b/tests/test_version.cpp @@ -1,5 +1,5 @@ #include "../src/pugixml.hpp"
-#if PUGIXML_VERSION != 140
+#if PUGIXML_VERSION != 150
#error Unexpected pugixml version
#endif
diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 8fc88e1..da83745 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -171,7 +171,7 @@ struct test_writer: xml_writer virtual void write(const void* data, size_t size) { CHECK(size % sizeof(pugi::char_t) == 0); - contents += std::basic_string<pugi::char_t>(static_cast<const pugi::char_t*>(data), static_cast<const pugi::char_t*>(data) + size / sizeof(pugi::char_t)); + contents.append(static_cast<const pugi::char_t*>(data), size / sizeof(pugi::char_t)); } }; @@ -483,7 +483,7 @@ TEST(write_stackless) data += STR("</a>"); xml_document doc; - CHECK(doc.load(data.c_str())); + CHECK(doc.load_string(data.c_str())); CHECK_NODE(doc, data.c_str()); } diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index a65ee37..f5b4c66 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -13,7 +13,7 @@ static void load_document_copy(xml_document& doc, const char_t* text) { xml_document source; - CHECK(source.load(text)); + CHECK(source.load_string(text)); doc.append_copy(source.first_child()); } @@ -551,10 +551,10 @@ TEST_XML(xpath_sort_append_buffer, "<node /><node />") TEST(xpath_sort_crossdoc) { xml_document doc1; - CHECK(doc1.load(STR("<node />"))); + CHECK(doc1.load_string(STR("<node />"))); xml_document doc2; - CHECK(doc2.load(STR("<node />"))); + CHECK(doc2.load_string(STR("<node />"))); xpath_node_set ns1 = doc1.select_nodes(STR("*")); CHECK(ns1.size() == 1); @@ -639,9 +639,11 @@ TEST(xpath_allocate_string_out_of_memory) #else try { + #ifndef __DMC__ // DigitalMars exception handling crashes instead of catching the exception... xpath_query q(query.c_str()); CHECK_FORCE_FAIL("Expected out of memory exception"); + #endif } catch (const std::bad_alloc&) { diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index 678bc2e..eb43bb5 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -570,6 +570,14 @@ TEST(xpath_string_translate_table) CHECK_XPATH_STRING(c, STR("translate('abcde', 'abcd', concat('ABC', 'D'))"), STR("ABCDe")); } +TEST(xpath_string_translate_remove) +{ + xml_node c; + + CHECK_XPATH_STRING(c, STR("translate('000000755', '0', '')"), STR("755")); + CHECK_XPATH_STRING(c, STR("translate('000000755', concat('0', ''), '')"), STR("755")); +} + TEST_XML(xpath_nodeset_last, "<node><c1/><c1/><c2/><c3/><c3/><c3/><c3/></node>") { xml_node n = doc.child(STR("node")); diff --git a/tests/test_xpath_operators.cpp b/tests/test_xpath_operators.cpp index 57e3755..450af5d 100644 --- a/tests/test_xpath_operators.cpp +++ b/tests/test_xpath_operators.cpp @@ -492,6 +492,7 @@ TEST(xpath_operators_mod) CHECK_XPATH_NUMBER(c, STR("-5 mod 3"), -2); CHECK_XPATH_NUMBER(c, STR("-5 mod -3"), -2); +#if !defined(__BORLANDC__) // If either operand is NaN, the result is NaN CHECK_XPATH_NUMBER_NAN(c, STR("(0 div 0) mod 3")); CHECK_XPATH_NUMBER_NAN(c, STR("3 mod (0 div 0)")); @@ -505,14 +506,17 @@ TEST(xpath_operators_mod) CHECK_XPATH_NUMBER_NAN(c, STR("-1 mod 0")); CHECK_XPATH_NUMBER_NAN(c, STR("(1 div 0) mod 0")); CHECK_XPATH_NUMBER_NAN(c, STR("(-1 div 0) mod 0")); +#endif // If the dividend is finite and the divisor is an infinity, the result equals the dividend +#if !defined(_MSC_VER) && !defined(__MINGW32__) CHECK_XPATH_NUMBER(c, STR("1 mod (1 div 0)"), 1); CHECK_XPATH_NUMBER(c, STR("1 mod (-1 div 0)"), 1); CHECK_XPATH_NUMBER(c, STR("-1 mod (1 div 0)"), -1); CHECK_XPATH_NUMBER(c, STR("0 mod (1 div 0)"), 0); CHECK_XPATH_NUMBER(c, STR("0 mod (-1 div 0)"), 0); CHECK_XPATH_NUMBER(c, STR("100000 mod (1 div 0)"), 100000); +#endif // If the dividend is a zero and the divisor is finite, the result equals the dividend. CHECK_XPATH_NUMBER(c, STR("0 mod 1000000"), 0); diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp index e51a395..69215d8 100644 --- a/tests/test_xpath_paths.cpp +++ b/tests/test_xpath_paths.cpp @@ -460,7 +460,10 @@ TEST_XML(xpath_paths_predicate_number_out_of_range, "<node><chapter/><chapter/>< CHECK_XPATH_NODESET(n, STR("following-sibling::chapter[-1 div 0]")); CHECK_XPATH_NODESET(n, STR("following-sibling::chapter[1000000000000]")); CHECK_XPATH_NODESET(n, STR("following-sibling::chapter[1 div 0]")); + +#ifndef MSVC6_NAN_BUG CHECK_XPATH_NODESET(n, STR("following-sibling::chapter[0 div 0]")); +#endif } TEST_XML(xpath_paths_predicate_constant_boolean, "<node><chapter/><chapter/><chapter/><chapter/><chapter/></node>") @@ -480,7 +483,10 @@ TEST_XML(xpath_paths_predicate_position_eq, "<node><chapter/><chapter/><chapter> CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=1]")) % 3; CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=2+2]")) % 7; CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=last()]")) % 8; + +#ifndef MSVC6_NAN_BUG CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=string()]")) % 5; +#endif } TEST_XML(xpath_paths_predicate_several, "<node><employee/><employee secretary=''/><employee assistant=''/><employee secretary='' assistant=''/><employee assistant='' secretary=''/></node>") diff --git a/tests/writer_string.cpp b/tests/writer_string.cpp index a09678b..661c792 100644 --- a/tests/writer_string.cpp +++ b/tests/writer_string.cpp @@ -15,7 +15,7 @@ static bool test_narrow(const std::string& result, const char* expected, size_t void xml_writer_string::write(const void* data, size_t size) { - contents += std::string(static_cast<const char*>(data), size); + contents.append(static_cast<const char*>(data), size); } std::string xml_writer_string::as_narrow() const |