From 97a761615f6db3be5f87b258e5288c09d445942c Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 30 May 2010 20:17:05 +0000 Subject: tests: Extended wchar_t mode tests (broken UTF16 test, some tests were erroneously utf8-only), added final Xalan tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@475 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_write.cpp | 43 +++++-- tests/test_xpath_xalan_4.cpp | 4 +- tests/test_xpath_xalan_5.cpp | 293 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 325 insertions(+), 15 deletions(-) create mode 100644 tests/test_xpath_xalan_5.cpp (limited to 'tests') diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 64e50b5..cb75c74 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -179,6 +179,26 @@ TEST(write_encoding_huge) CHECK(test_write_narrow(doc, format_default, encoding_utf8, s_utf8.c_str(), s_utf8.length())); } + +TEST(write_encoding_huge_invalid) +{ + size_t wcharsize = sizeof(wchar_t); + + if (wcharsize == 2) + { + const unsigned int N = 16000; + + // make a large utf16 name consisting of leading surrogate chars + std::basic_string s_utf16; + + for (unsigned int i = 0; i < N; ++i) s_utf16 += static_cast(0xd852); + + xml_document doc; + doc.append_child().set_name(s_utf16.c_str()); + + CHECK(test_write_narrow(doc, format_default, encoding_utf8, "< />\n", 5)); + } +} #else TEST(write_encoding_huge) { @@ -208,14 +228,12 @@ TEST(write_encoding_huge_invalid) const unsigned int N = 16000; // make a large utf8 name consisting of non-leading chars - std::string s_utf8 = "<"; + std::string s_utf8; for (unsigned int i = 0; i < N; ++i) s_utf8 += "\x82"; - s_utf8 += "/>"; - xml_document doc; - CHECK(doc.load_buffer(&s_utf8[0], s_utf8.length(), parse_default, encoding_utf8)); + doc.append_child().set_name(s_utf8.c_str()); std::string s_utf16 = std::string("\x00<\x00 \x00/\x00>\x00\n", 10); @@ -305,16 +323,17 @@ TEST(write_unicode_invalid_utf8) // invalid 5-byte input CHECK(test_write_unicode_invalid("a\xf8_", L"a_")); } +#endif TEST(write_no_name_element) { xml_document doc; xml_node root = doc.append_child(); root.append_child(); - root.append_child().append_child(node_pcdata).set_value("text"); + root.append_child().append_child(node_pcdata).set_value(STR("text")); - CHECK_NODE(doc, "<:anonymous><:anonymous /><:anonymous>text"); - CHECK_NODE_EX(doc, "<:anonymous>\n\t<:anonymous />\n\t<:anonymous>text\n\n", "\t", format_default); + CHECK_NODE(doc, STR("<:anonymous><:anonymous /><:anonymous>text")); + CHECK_NODE_EX(doc, STR("<:anonymous>\n\t<:anonymous />\n\t<:anonymous>text\n\n"), STR("\t"), format_default); } TEST(write_no_name_pi) @@ -322,16 +341,14 @@ TEST(write_no_name_pi) xml_document doc; doc.append_child(node_pi); - CHECK_NODE(doc, ""); + CHECK_NODE(doc, STR("")); } TEST(write_no_name_attribute) { xml_document doc; - doc.append_child().set_name("root"); - doc.child("root").append_attribute(""); + doc.append_child().set_name(STR("root")); + doc.child(STR("root")).append_attribute(STR("")); - CHECK_NODE(doc, ""); + CHECK_NODE(doc, STR("")); } - -#endif diff --git a/tests/test_xpath_xalan_4.cpp b/tests/test_xpath_xalan_4.cpp index 681ac5f..10784da 100644 --- a/tests/test_xpath_xalan_4.cpp +++ b/tests/test_xpath_xalan_4.cpp @@ -4,7 +4,7 @@ TEST_XML(xpath_xalan_position_1, "1234") { - xml_node c = doc.child("doc"); + xml_node c = doc.child(STR("doc")); CHECK_XPATH_BOOLEAN(c, STR("position()=1"), true); CHECK_XPATH_NODESET(c, STR("*[position()=4]")) % 9; @@ -12,7 +12,7 @@ TEST_XML(xpath_xalan_position_1, "1234") TEST_XML_FLAGS(xpath_xalan_position_2, "111912632827256345", parse_default | parse_comments | parse_pi) { - xml_node c = doc.child("doc"); + xml_node c = doc.child(STR("doc")); CHECK_XPATH_NODESET(c, STR("*[@test and position()=8]")) % 27; CHECK_XPATH_NODESET(c, STR("*[@test][position()=4]/num")) % 29; diff --git a/tests/test_xpath_xalan_5.cpp b/tests/test_xpath_xalan_5.cpp new file mode 100644 index 0000000..c1e7b18 --- /dev/null +++ b/tests/test_xpath_xalan_5.cpp @@ -0,0 +1,293 @@ +#ifndef PUGIXML_NO_XPATH + +#include "common.hpp" + +TEST_XML(xpath_xalan_select_1, "") +{ + CHECK_XPATH_STRING(doc, STR("/doc/a/b/@attr"), STR("test")); +} + +TEST_XML(xpath_xalan_select_2, "doremifasolatidoG#AAbBbCC#D") +{ + xml_node c = doc.child(STR("doc")); + + // This should come out fasolatido: + CHECK_XPATH_NODESET(c, STR("fa")) % 12; + // This should come out doremifasolatido: + CHECK_XPATH_NODESET(c, STR("mi | do | fa | re")) % 3 % 6 % 8 % 12; + // This should come out do-do-remi-mi1-mi2fasolatido-fa--so-: + CHECK_XPATH_NODESET(c, STR("mi[@mi2='mi2'] | do | fa/so/@so | fa | mi/@* | re | fa/@fa | do/@do")) % 3 % 4 % 6 % 8 % 9 % 10 % 12 % 13 % 16; + // This should come out solatidoG#: + CHECK_XPATH_NODESET(c, STR(".//*[@so]")) % 15 % 23; + // This should come out relatidoABb: + CHECK_XPATH_NODESET(c, STR("*//la | //Bflat | re")) % 6 % 18 % 28 % 31; + // This should come out domitiACD: + CHECK_XPATH_NODESET(c, STR("fa/../mi | Aflat/natural/la | Csharp//* | /doc/do | *//ti")) % 3 % 8 % 20 % 28 % 34 % 37; +} + +TEST_XML(xpath_xalan_select_3, "preceding sibling number 1current nodefollowing sibling number 3cousin 1cousin 2cousin 3") +{ + CHECK_XPATH_NODESET(doc.child(STR("doc")).child(STR("sub1")).child(STR("child2")), STR("preceding-sibling::child1|//child3")) % 4 % 8 % 15; +} + +TEST_XML(xpath_xalan_select_4, "bad1bad2bad3bad4OKbad5") +{ + xml_node c = doc.child(STR("doc")); + + CHECK_XPATH_NODESET(c, STR("child::sub")) % 11; + CHECK_XPATH_NODESET(c, STR("child ::sub")) % 11; + CHECK_XPATH_NODESET(c, STR("child:: sub")) % 11; + CHECK_XPATH_NODESET(c, STR("child :: sub")) % 11; +} + +TEST_XML_FLAGS(xpath_xalan_select_5, "bad0bad1bad2", parse_default | parse_comments) +{ + xml_node c = doc.child(STR("doc")); + + CHECK_XPATH_NODESET(c, STR("comment()")) % 4; + CHECK_XPATH_NODESET(c, STR("comment ()")) % 4; + CHECK_XPATH_NODESET(c, STR("comment ( ) ")) % 4; + CHECK_XPATH_NUMBER(c, STR("string-length()"), 12); + CHECK_XPATH_NUMBER(c, STR("string-length ()"), 12); + CHECK_XPATH_NUMBER(c, STR("string-length ( ) "), 12); +} + +TEST_XML(xpath_xalan_select_6, "
9
") +{ + xml_node c = doc.child(STR("div")); + + CHECK_XPATH_NUMBER(doc, STR("div +3"), 12); + CHECK_XPATH_NUMBER(doc, STR("* +3"), 12); + CHECK_XPATH_NUMBER(c, STR("@div - 5"), 15); + CHECK_XPATH_NUMBER(c, STR("@div -5"), 15); + CHECK_XPATH_NUMBER(c, STR("@div-5"), 12); + CHECK_XPATH_NUMBER(c, STR("@*-5"), 15); + CHECK_XPATH_NUMBER(doc, STR("16-div"), 7); + CHECK_XPATH_NUMBER(doc, STR("25-*"), 16); + CHECK_XPATH_NUMBER(doc, STR("54 div*"), 6); + CHECK_XPATH_NUMBER(doc, STR("(* - 4) div 2"), 2.5); + CHECK_XPATH_NUMBER(doc, STR("' 6 ' div 2"), 3); + CHECK_XPATH_NUMBER(doc, STR("' 6 '*div"), 54); + // CHECK_XPATH_NUMBER(doc, STR("5.*."), 45); $$ should work + // CHECK_XPATH_NUMBER(doc, STR("5.+."), 14); $$ should work +} + +TEST_XML(xpath_xalan_select_7, "
9
8
") +{ + xml_node c = doc.child(STR("doc")); + + CHECK_XPATH_NUMBER(c, STR("attribute :: div"), 20); + CHECK_XPATH_NUMBER(c, STR("attribute :: *"), 20); + CHECK_XPATH_NUMBER(c, STR("attribute*(div - 4)"), 40); + CHECK_XPATH_NUMBER(c, STR("(* - 4)**"), 45); +} + +TEST_XML(xpath_xalan_select_8, "x
7
y
9
z
5
") +{ + CHECK_XPATH_NODESET(doc, STR("doc/a[div=9]")) % 7; +} + +TEST_XML(xpath_xalan_select_9, "7379929920") +{ + CHECK_XPATH_NODESET(doc, STR("doc/a[*=9]")) % 9 % 15 % 21; +} + +TEST_XML(xpath_xalan_select_10, "child1child2") +{ + CHECK_XPATH_NODESET(doc, STR("/doc/sub1/child1|/doc/sub2/child2")) % 4 % 7; + CHECK_XPATH_NODESET(doc.child(STR("doc")), STR("sub1/child1|/doc/sub2/child2")) % 4 % 7; + CHECK_XPATH_NODESET(doc.child(STR("doc")), STR("sub1/child1|sub2/child2")) % 4 % 7; + CHECK_XPATH_NODESET(doc, STR("//self::child1|//self::child2")) % 4 % 7; + CHECK_XPATH_NODESET(doc, STR("//child1|//child2")) % 4 % 7; + CHECK_XPATH_NODESET(doc, STR("//child1|//child2|//child3")) % 4 % 7 % 10; +} + +TEST_XML(xpath_xalan_select_11, "descendant number 1descendant number 2") +{ + CHECK_XPATH_NODESET(doc, STR("//child1/ancestor::sub1|//child1/ancestor::sub2")) % 3 % 7; +} + +TEST_XML(xpath_xalan_select_12, "child number 1grandchild number 1child number 2grandchild number 2child number 3grandchild number 3child number 4grandchild number 4") +{ + CHECK_XPATH_NODESET(doc, STR("//child/ancestor-or-self::sub | //child/ancestor-or-self::sub-sub")) % 3 % 7 % 15 % 19 % 31; +} + +TEST_XML(xpath_xalan_select_13, "Carmelo MontanezNineDavid MarstonSevenMary BradyTenLynne RosenthalFive") +{ + CHECK_XPATH_NODESET(doc, STR("doc/book/author[name/@real='no']|doc/book/author[name/@real='yes']")) % 4 % 20; + CHECK_XPATH_NODESET(doc, STR("doc/book/author[(name/@real='no' and position()=1)]|doc/book/author[(name/@real='yes' and position()=last())]")) % 4 % 20; + CHECK_XPATH_NODESET(doc, STR("doc/book/author[name='Mary Brady']|doc/book/author[name/@real='no']")) % 4 % 20; + CHECK_XPATH_NODESET(doc, STR("doc/book/author/name|doc/book/author/bibliography/author/name")) % 5 % 13 % 21 % 28; + CHECK_XPATH_NODESET(doc, STR("doc/book/author/name|doc/book/author/bibliography/author/chapters")) % 5 % 13 % 21 % 30; + CHECK_XPATH_NODESET(doc, STR("doc/book/author/name|doc/book/author/noElement")) % 5 % 13 % 21; + CHECK_XPATH_NODESET(doc, STR("//noChild1|//noChild2")); +} + +TEST_XML(xpath_xalan_select_14, "child number 1child number 2") +{ + xml_node c = doc.child(STR("doc")); + + CHECK_XPATH_NODESET(c, STR("child::sub1|child::sub2")) % 3 % 7; + CHECK_XPATH_NODESET(c, STR("descendant::child1|descendant::child2")) % 5 % 9; + CHECK_XPATH_NODESET(c, STR("descendant-or-self::sub1|descendant-or-self::sub2")) % 3 % 7; + CHECK_XPATH_NODESET(c.child(STR("sub2")), STR("preceding-sibling::sub1|following-sibling::sub3")) % 3 % 11; +} + +TEST_XML(xpath_xalan_select_15, "Selection of this child is an error.Selection of this child is an error.Selection of this child is an error.Selection of this child is an error.EFGSelection of this child is an error.Selection of this child is an error.JKSelection of this child is an error.Selection of this child is an error.NOP") +{ + xml_node c = doc.child(STR("doc")); + + CHECK_XPATH_NODESET(c, STR("child[@wide='3']|child[@deep='3']")) % 15 % 18 % 22 % 35 % 39 % 51 % 54 % 58; + CHECK_XPATH_NODESET(c, STR("child[@deep='3']|child[@wide='3']")) % 15 % 18 % 22 % 35 % 39 % 51 % 54 % 58; +} + +TEST_XML(xpath_xalan_select_16, "1234") +{ + CHECK_XPATH_NUMBER(doc, STR("count(doc/a/attribute::*)"), 9); + CHECK_XPATH_NUMBER(doc, STR("count(//@*)"), 9); + CHECK_XPATH_NUMBER(doc, STR("count(//@squish)"), 3); +} + +TEST_XML(xpath_xalan_select_17, "") +{ + xml_node c = doc.child(STR("directions")); + + CHECK_XPATH_NODESET(c, STR("north/* | north/dup1 | north/dup2")) % 4 % 5 % 6 % 7 % 8; + CHECK_XPATH_NODESET(c, STR("north/dup2 | north/dup1 | north/*")) % 4 % 5 % 6 % 7 % 8; + CHECK_XPATH_NODESET(c, STR("//north/dup2 | south/preceding-sibling::*[4]/* | north/dup1 | north/*")) % 4 % 5 % 6 % 7 % 8; + CHECK_XPATH_NODESET(c, STR("north/dup2 | south/preceding-sibling::*[4]/* | north/*")) % 4 % 5 % 6 % 7 % 8; +} + +TEST_XML(xpath_xalan_select_18, "HelloThereWorld") +{ + CHECK_XPATH_NODESET(doc, STR("/para/font[@color='green']")) % 6; + CHECK_XPATH_NODESET(doc.child(STR("para")), STR("/para/font[@color='green']")) % 6; + CHECK_XPATH_NODESET(doc.child(STR("para")).last_child(), STR("/para/font[@color='green']")) % 6; +} + +TEST_XML_FLAGS(xpath_xalan_select_19, "1in-a2345678in-c9", parse_default | parse_comments | parse_pi) +{ + CHECK_XPATH_NODESET(doc, STR("//*")) % 2 % 4 % 8 % 10 % 12 % 18; + CHECK_XPATH_NODESET(doc, STR("//node()")) % 2 % 3 % 4 % 5 % 6 % 7 % 8 % 9 % 10 % 11 % 12 % 13 % 14 % 15 % 16 % 17 % 18 % 19 % 20 % 21; + CHECK_XPATH_NODESET(doc, STR("//text()")) % 3 % 5 % 6 % 9 % 11 % 13 % 14 % 15 % 17 % 19 % 20; + CHECK_XPATH_NODESET(doc, STR("//comment()")) % 7 % 16; + CHECK_XPATH_NODESET(doc, STR("//processing-instruction()")) % 21; +} + +TEST_XML(xpath_xalan_bugzilla_1, "15152252") +{ + CHECK_XPATH_NODESET(doc, STR("/report/colData[@colId='F' and not(.=preceding::colData)]")) % 3; +} + +TEST(xpath_xalan_error_boolean) +{ + CHECK_XPATH_FAIL(STR("nt(true())")); + CHECK_XPATH_FAIL(STR("not(troo())")); + CHECK_XPATH_FAIL(STR("troo() and (2 = 2)")); + CHECK_XPATH_FAIL(STR("troo() or (2 = 2)")); + CHECK_XPATH_FAIL(STR("2 = troo()")); + CHECK_XPATH_FAIL(STR("boolean(troo())")); + CHECK_XPATH_FAIL(STR("true(doc)")); + CHECK_XPATH_FAIL(STR("false(doc)")); + CHECK_XPATH_FAIL(STR("not()")); + CHECK_XPATH_FAIL(STR("not(false(), doc)")); + CHECK_XPATH_FAIL(STR("boolean()")); + CHECK_XPATH_FAIL(STR("boolean(false(), doc)")); + CHECK_XPATH_FAIL(STR("lang()")); + CHECK_XPATH_FAIL(STR("lang('en','us')")); +} + +TEST(xpath_xalan_error_conditional) +{ + CHECK_XPATH_FAIL(STR("")); + CHECK_XPATH_FAIL(STR("@name='John' | @name='Joe'")); + CHECK_XPATH_FAIL(STR("\x95not(name(.)='')")); +} + +TEST(xpath_xalan_error_match) +{ + CHECK_XPATH_FAIL(STR("//")); + CHECK_XPATH_FAIL(STR("section1|")); + CHECK_XPATH_FAIL(STR("|section1")); +} + +TEST(xpath_xalan_error_math) +{ + CHECK_XPATH_FAIL(STR("6 quo 4")); + CHECK_XPATH_FAIL(STR("-troo()")); + CHECK_XPATH_FAIL(STR("number(troo())")); + CHECK_XPATH_FAIL(STR("5 * troo()")); + CHECK_XPATH_FAIL(STR("12 div troo()")); + CHECK_XPATH_FAIL(STR("number(8,doc)")); + CHECK_XPATH_FAIL(STR("sum(doc, 8)")); + CHECK_XPATH_FAIL(STR("sum()")); + CHECK_XPATH_FAIL(STR("floor(8,7)")); + CHECK_XPATH_FAIL(STR("floor()")); + CHECK_XPATH_FAIL(STR("ceiling(8,7)")); + CHECK_XPATH_FAIL(STR("ceiling()")); + CHECK_XPATH_FAIL(STR("round(8,7)")); + CHECK_XPATH_FAIL(STR("round()")); +} + +TEST(xpath_xalan_error_namespace) +{ + CHECK_XPATH_FAIL(STR("local-name(baz2:b,..)")); + CHECK_XPATH_FAIL(STR("namespace-uri(baz2:b,..)")); + CHECK_XPATH_FAIL(STR("name(a,b)")); + CHECK_XPATH_FAIL(STR(":foo")); + // CHECK_XPATH_FAIL(STR("*:foo")); $$ should not compile +} + +TEST(xpath_xalan_error_position) +{ + CHECK_XPATH_FAIL(STR("*[last(*,2)]")); + CHECK_XPATH_FAIL(STR("position(b)=1")); + CHECK_XPATH_FAIL(STR("count()")); + CHECK_XPATH_FAIL(STR("count(*,4)")); + CHECK_XPATH_FAIL(STR("position()=last(a)")); +} + +TEST(xpath_xalan_error_select) +{ + CHECK_XPATH_FAIL(STR("")); + CHECK_XPATH_FAIL(STR("count(troo())")); + CHECK_XPATH_FAIL(STR("c::sub")); + CHECK_XPATH_FAIL(STR("c()")); + CHECK_XPATH_FAIL(STR("(* - 4) foo 2")); + CHECK_XPATH_FAIL(STR("5 . + *")); + CHECK_XPATH_FAIL(STR("4/.")); + CHECK_XPATH_FAIL(STR("true()/.")); + CHECK_XPATH_FAIL(STR("item//[@type='x']")); + CHECK_XPATH_FAIL(STR("//")); + CHECK_XPATH_FAIL(STR("item//")); + CHECK_XPATH_FAIL(STR("count(//)")); + CHECK_XPATH_FAIL(STR("substring-after(//,'0')")); + CHECK_XPATH_FAIL(STR("//+17")); + CHECK_XPATH_FAIL(STR("//|subitem")); + CHECK_XPATH_FAIL(STR("..[near-north]")); +} + +TEST(xpath_xalan_error_string) +{ + CHECK_XPATH_FAIL(STR("string(troo())")); + CHECK_XPATH_FAIL(STR("string-length(troo())")); + CHECK_XPATH_FAIL(STR("normalize-space(a,'\t\r\n ab cd ')")); + CHECK_XPATH_FAIL(STR("contains('ENCYCLOPEDIA')")); + CHECK_XPATH_FAIL(STR("contains('ENCYCLOPEDIA','LOPE',doc)")); + CHECK_XPATH_FAIL(STR("starts-with('ENCYCLOPEDIA')")); + CHECK_XPATH_FAIL(STR("starts-with('ENCYCLOPEDIA','LOPE',doc)")); + CHECK_XPATH_FAIL(STR("substring-before('ENCYCLOPEDIA')")); + CHECK_XPATH_FAIL(STR("substring-before('ENCYCLOPEDIA','LOPE',doc)")); + CHECK_XPATH_FAIL(STR("substring-after('ENCYCLOPEDIA')")); + CHECK_XPATH_FAIL(STR("substring-after('ENCYCLOPEDIA','LOPE',doc)")); + CHECK_XPATH_FAIL(STR("substring('ENCYCLOPEDIA')")); + CHECK_XPATH_FAIL(STR("substring('ENCYCLOPEDIA',4,5,2)")); + CHECK_XPATH_FAIL(STR("concat('x')")); + CHECK_XPATH_FAIL(STR("string-length('ENCYCLOPEDIA','PEDI')")); + CHECK_XPATH_FAIL(STR("translate('bar','abc')")); + CHECK_XPATH_FAIL(STR("translate('bar','abc','ABC','output')")); + CHECK_XPATH_FAIL(STR("string(22,44)")); + CHECK_XPATH_FAIL(STR("concat(/*)")); +} + +#endif -- cgit v1.2.3