From 79ed320f894c406dd3548e7d34cadd07fa82fb53 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 17 Nov 2014 08:35:34 -0800 Subject: tests: Don't use /dev/tty The behavior on OSX is different - we don't get a I/O error so the test is useless. --- tests/test_document.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 2774a07..2cc39a6 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -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); } -- cgit v1.2.3 From e9956ae3a6593efc6f8cb344a00432ece51d1574 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 17 Nov 2014 19:52:23 -0800 Subject: Rename xml_document::load to load_string This should completely eliminate the confusion between load and load_file. Of course, for compatibility reasons we have to preserve the old variant - it will be deprecated in a future version and subsequently removed. --- tests/test.hpp | 2 +- tests/test_document.cpp | 23 +-- tests/test_dom_modify.cpp | 4 +- tests/test_memory.cpp | 2 +- tests/test_parse.cpp | 328 +++++++++++++++++++++---------------------- tests/test_parse_doctype.cpp | 20 +-- tests/test_write.cpp | 2 +- tests/test_xpath.cpp | 6 +- 8 files changed, 197 insertions(+), 190 deletions(-) (limited to 'tests') 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 2cc39a6..4228602 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(""))); + CHECK(doc.load_string(STR(""))); 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(""))); + CHECK(doc.load_string(STR(""))); CHECK(doc.first_child()); std::basic_ifstream fs1("filedoesnotexist"); @@ -261,7 +261,7 @@ TEST(document_load_string) { pugi::xml_document doc; - CHECK(doc.load(STR(""))); + CHECK(doc.load_string(STR(""))); CHECK_NODE(doc, STR("")); } @@ -308,7 +308,7 @@ TEST(document_load_file_error) TEST(document_load_file_error_previous) { pugi::xml_document doc; - CHECK(doc.load(STR(""))); + CHECK(doc.load_string(STR(""))); CHECK(doc.first_child()); CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found); @@ -590,7 +590,7 @@ TEST(document_parse_result_description) TEST(document_load_fail) { xml_document doc; - CHECK(!doc.load(STR(""))); + CHECK(!doc.load_string(STR(""))); CHECK(doc.child(STR("foo")).child(STR("bar"))); } @@ -1079,7 +1079,7 @@ TEST(document_load_exceptions) try { pugi::xml_document doc; - if (!doc.load(STR("") CHECK(!doc.first_child()); CHECK_NODE(doc, STR("")); - CHECK(doc.load(STR(""))); + CHECK(doc.load_string(STR(""))); CHECK(doc.first_child()); CHECK_NODE(doc, STR("")); @@ -1268,7 +1268,7 @@ TEST(document_alignment) { xml_document* doc = new (buf + offset) xml_document; - CHECK(doc->load(STR(""))); + CHECK(doc->load_string(STR(""))); CHECK_NODE(*doc, STR("")); doc->~xml_document(); @@ -1308,3 +1308,10 @@ TEST(document_convert_out_of_memory) delete[] files[j].data; } } + +TEST(document_deprecated_load) +{ + xml_document doc; + CHECK(doc.load(STR(""))); + CHECK_NODE(doc, STR("")); +} diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 45cf3ea..8665af9 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1289,7 +1289,7 @@ TEST(dom_node_copy_stackless) data += STR(""); 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 +1324,7 @@ TEST(dom_node_copy_copyless) TEST(dom_node_copy_copyless_mix) { xml_document doc; - CHECK(doc.load(STR("pcdata"), parse_full)); + CHECK(doc.load_string(STR("pcdata"), parse_full)); xml_node child = doc.child(STR("node")).child(STR("child")); 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(""))); + CHECK(doc.load_string(STR(""))); CHECK(allocate_count == 2 && deallocate_count == 0); diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index c45b783..321b84c 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(""), flags)); + CHECK(doc.load_string(STR(""), flags)); CHECK(!doc.first_child()); - CHECK(doc.load(STR(" value?>"), flags)); + CHECK(doc.load_string(STR(" 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(""), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR(""), 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(""), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR(""), 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(" "), flags).status == status_bad_pi); - CHECK(doc.load(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(" "), flags).status == status_bad_pi); + CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); - CHECK(doc.load(STR(""), parse_fragment | parse_pi).status == status_bad_pi); - CHECK(doc.load(STR(""), parse_fragment | parse_pi).status == status_bad_pi); + CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); + CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); + CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); } TEST(parse_comments_skip) { xml_document doc; - CHECK(doc.load(STR(""), parse_fragment)); + CHECK(doc.load_string(STR(""), parse_fragment)); CHECK(!doc.first_child()); } TEST(parse_comments_parse) { xml_document doc; - CHECK(doc.load(STR(""), parse_fragment | parse_comments)); + CHECK(doc.load_string(STR(""), 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(""), parse_fragment | parse_comments)); + CHECK(doc.load_string(STR(""), 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(""), parse_fragment | parse_comments | parse_eol)); + CHECK(doc.load_string(STR(""), 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(""), 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(""), parse_fragment)); + CHECK(doc.load_string(STR(""), parse_fragment)); CHECK(!doc.first_child()); } TEST(parse_cdata_skip_contents) { xml_document doc; - CHECK(doc.load(STR("hello, world!"), parse_fragment)); + CHECK(doc.load_string(STR("hello, world!"), parse_fragment)); CHECK_NODE(doc, STR("hello, world!")); } TEST(parse_cdata_parse) { xml_document doc; - CHECK(doc.load(STR(""), parse_fragment | parse_cdata)); + CHECK(doc.load_string(STR(""), 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(""), parse_fragment | parse_cdata)); + CHECK(doc.load_string(STR(""), 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(""), parse_fragment | parse_cdata | parse_eol)); + CHECK(doc.load_string(STR(""), 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(""), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR(""), flags).status == status_bad_cdata); + CHECK(doc.load_string(STR(""), 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(" "), parse_minimal)); + CHECK(doc.load_string(STR(" "), 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(" "), parse_minimal | parse_ws_pcdata)); + CHECK(doc.load_string(STR(" "), 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("\r\rval1\rval2\r\nval3\nval4\r\r"), parse_minimal)); + CHECK(doc.load_string(STR("\r\rval1\rval2\r\nval3\nval4\r\r"), 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("\r\rval1\rval2\r\nval3\nval4\r\r"), parse_minimal | parse_eol)); + CHECK(doc.load_string(STR("\r\rval1\rval2\r\nval3\nval4\r\r"), 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("prepost"), parse_minimal)); + CHECK(doc.load_string(STR("prepost"), 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("pcdata"), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("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(" "), flags[i] | parse_trim_pcdata)); + CHECK(doc.load_string(STR(" "), 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("<>&'""), parse_minimal)); + CHECK(doc.load_string(STR("<>&'""), parse_minimal)); CHECK_STRING(doc.child(STR("node")).attribute(STR("id")).value(), STR("<>&'"")); } TEST(parse_escapes_parse) { xml_document doc; - CHECK(doc.load(STR("<>&'""), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("<>&'""), 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(" "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR(" "), 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("&#/; &#:;&#a;&#A; "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&#/; &#:;&#a;&#A; "), 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("&#x/; &#x:;&#x@; &#xG;&#x`; &#xg;"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&#x/; &#x:;&#x@; &#xG;&#x`; &#xg;"), 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("  - - "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("  - - "), 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("&q &qu &quo " "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&q &qu &quo " "), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&q &qu &quo " ")); - CHECK(doc.load(STR("&a &ap &apo &apos "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&a &ap &apo &apos "), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&a &ap &apo &apos ")); - CHECK(doc.load(STR("&a &am & "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&a &am & "), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&a &am & ")); - CHECK(doc.load(STR("&l < "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&l < "), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&l < ")); - CHECK(doc.load(STR("&g > "), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&g > "), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("&g > ")); } TEST(parse_escapes_unicode) { xml_document doc; - CHECK(doc.load(STR("γγ𤭢"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("γγ𤭢"), 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("g;&#ab;""), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("g;&#ab;""), parse_minimal | parse_escapes)); CHECK_STRING(doc.child_value(STR("node")), STR("g;&#ab;"")); - CHECK(!doc.load(STR("&#;&#x;&;&#x-;&#-;"), parse_minimal | parse_escapes)); + CHECK(doc.load_string(STR("&#;&#x;&;&#x-;&#-;"), 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(""), flags)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal | parse_eol)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal | parse_wconv_attribute)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal | parse_eol | parse_wconv_attribute)); + CHECK(doc.load_string(STR(""), 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(""), flags)); + CHECK(doc.load_string(STR(""), 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(""), flags)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), 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(""), flags)); + CHECK(doc.load_string(STR(""), 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(""), parse_minimal)); + CHECK(doc.load_string(STR(""), parse_minimal)); CHECK_NODE(doc, STR("")); } TEST(parse_tag_hierarchy) { xml_document doc; - CHECK(doc.load(STR(""), parse_minimal)); + CHECK(doc.load_string(STR(""), parse_minimal)); CHECK_NODE(doc, STR("")); } 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_bad_start_element); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR("<"), parse_minimal).status == status_unrecognized_tag); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_end_element_mismatch); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_end_element); - CHECK(doc.load(STR(""), parse_minimal).status == status_bad_start_element); - CHECK(doc.load(STR(""), 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_bad_start_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR("<"), parse_minimal).status == status_unrecognized_tag); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_end_element_mismatch); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_end_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_start_element); + CHECK(doc.load_string(STR(""), parse_minimal).status == status_bad_start_element); } TEST(parse_declaration_cases) { xml_document doc; - CHECK(doc.load(STR(""), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR(""), parse_fragment | parse_pi)); CHECK(!doc.first_child()); } TEST(parse_declaration_attr_cases) { xml_document doc; - CHECK(doc.load(STR(""), parse_fragment | parse_pi)); + CHECK(doc.load_string(STR(""), 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(""), flags)); + CHECK(doc.load_string(STR(""), flags)); CHECK(!doc.first_child()); - CHECK(doc.load(STR(" ?>"), flags)); + CHECK(doc.load_string(STR(" ?>"), flags)); CHECK(!doc.first_child()); } } @@ -827,7 +827,7 @@ TEST(parse_declaration_skip) TEST(parse_declaration_parse) { xml_document doc; - CHECK(doc.load(STR(""), parse_fragment | parse_declaration)); + CHECK(doc.load_string(STR(""), parse_fragment | parse_declaration)); xml_node d1 = doc.first_child(); xml_node d2 = doc.last_child(); @@ -850,21 +850,21 @@ TEST(parse_declaration_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_string(STR(""), flags).status == status_bad_pi); + CHECK(doc.load_string(STR(""), flags).status == status_bad_pi); } - CHECK(doc.load(STR(""), parse_fragment | parse_declaration).status == status_bad_attribute); - CHECK(doc.load(STR(""), parse_fragment | parse_declaration).status == status_bad_pi); + CHECK(doc.load_string(STR(""), parse_fragment | parse_declaration).status == status_bad_attribute); + CHECK(doc.load_string(STR(""), 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_string(STR("")).status == status_no_document_element && !doc.first_child()); + CHECK(doc.load_string(STR(""), parse_fragment) && !doc.first_child()); } TEST(parse_out_of_memory) @@ -872,7 +872,7 @@ TEST(parse_out_of_memory) test_runner::_memory_fail_threshold = 256; xml_document doc; - CHECK(doc.load(STR("")).status == status_out_of_memory); + CHECK(doc.load_string(STR("")).status == status_out_of_memory); CHECK(!doc.first_child()); } @@ -928,7 +928,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; } @@ -1065,7 +1065,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..14268f6 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(""), decl, STR("")) || !test_node(doc, STR(""), 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(" "), 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(" &a%b&#c?>"), parse_full | parse_fragment) && doc.first_child().type() == node_pi && doc.first_child() == doc.last_child()); + CHECK(doc.load_string(STR(" "), 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(" &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,15 @@ TEST_XML_FLAGS(parse_doctype_value, " ")).status == status_bad_doctype); - CHECK(doc.load(STR(""), parse_doctype).status == status_bad_doctype); + CHECK(doc.load_string(STR("")).status == status_bad_doctype); + CHECK(doc.load_string(STR(""), parse_doctype).status == status_bad_doctype); } TEST(parse_doctype_error_ignore) { xml_document doc; - CHECK(doc.load(STR(""); 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..e410882 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, "") TEST(xpath_sort_crossdoc) { xml_document doc1; - CHECK(doc1.load(STR(""))); + CHECK(doc1.load_string(STR(""))); xml_document doc2; - CHECK(doc2.load(STR(""))); + CHECK(doc2.load_string(STR(""))); xpath_node_set ns1 = doc1.select_nodes(STR("*")); CHECK(ns1.size() == 1); -- cgit v1.2.3 From 3c048bbb5e64605cc4e3aa15e0a536eaf00f3c6f Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 17 Nov 2014 22:45:38 -0800 Subject: tests: Fix version test --- tests/test_version.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') 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 -- cgit v1.2.3 From 417048d8cb8eb7cf3f4391aacd915b654f98c18e Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 19 Nov 2014 16:34:57 -0800 Subject: tests: Fix tests on various compilers Some compilers don't handle NaNs properly. Some compilers don't implement fmod in a IEEE-compatible way. Some compilers have exception handling codegen bugs (DMC...). --- tests/test_xpath.cpp | 2 ++ tests/test_xpath_operators.cpp | 4 ++++ tests/test_xpath_paths.cpp | 6 ++++++ 3 files changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index e410882..f5b4c66 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -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_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, "< 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, "") @@ -480,7 +483,10 @@ TEST_XML(xpath_paths_predicate_position_eq, " 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, "") -- cgit v1.2.3 From 125aa55061ccde4ae7351a9a6c7270a15c9e0204 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 20 Nov 2014 23:39:40 -0800 Subject: Fix node_declaration copying with empty name node_copy_string relied on the fact that target node had an empty name and value. Normally this is a safe assumption (and a good one to make since it makes copying faster), however it was not checked and there was one case when it did not hold. Since we're reusing the logic for inserting nodes, newly inserted declaration nodes had the name set automatically to xml, which in our case violates the assumption and is counter-productive since we'll override the name right after setting it. For now the best solution is to do the same insertion manually - that results in some code duplication that we can refactor later (same logic is partially shared by _move variants anyway so on a level duplicating is not that bad). --- tests/test_dom_modify.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 8665af9..7863718 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1426,3 +1426,15 @@ TEST_XML(dom_node_set_deallocate, "text") CHECK_NODE(doc, STR("<: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("")); +} -- cgit v1.2.3