From f22d0647a2beea8ae01650a7fed7abade081133f Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 8 Nov 2009 10:14:29 +0000 Subject: tests: Added node test tests, added abbreviated step/axis tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@212 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath_paths.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'tests') diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp index e44045d..5cc48c4 100644 --- a/tests/test_xpath_paths.cpp +++ b/tests/test_xpath_paths.cpp @@ -189,4 +189,136 @@ TEST_XML(xpath_paths_axes_ancestor_or_self, "") +{ + doc.precompute_document_order(); + + xml_node c; + xml_node n = doc.child("node"); + + // @ axis + CHECK_XPATH_NODESET(c, "@attr"); + CHECK_XPATH_NODESET(n, "@attr") % 3; + + // no axis - child implied + CHECK_XPATH_NODESET(c, "foo"); + CHECK_XPATH_NODESET(n, "foo") % 4; + CHECK_XPATH_NODESET(doc, "node()") % 2; + + // @ axis should disable all other axis specifiers + CHECK_XPATH_FAIL("@child::foo"); + CHECK_XPATH_FAIL("@attribute::foo"); +} + +TEST_XML(xpath_paths_nodetest_all, "") +{ + doc.precompute_document_order(); + + xml_node c; + xml_node n = doc.child("node"); + + CHECK_XPATH_NODESET(c, "*"); + CHECK_XPATH_NODESET(c, "child::*"); + + CHECK_XPATH_NODESET(n, "*") % 5 % 6 % 7 % 8; + CHECK_XPATH_NODESET(n, "child::*") % 5 % 6 % 7 % 8; + CHECK_XPATH_NODESET(n, "attribute::*") % 3 % 4; +} + +TEST_XML_FLAGS(xpath_paths_nodetest_name, "", parse_default | parse_pi) +{ + doc.precompute_document_order(); + + xml_node c; + xml_node n = doc.child("node"); + + CHECK_XPATH_NODESET(c, "c1"); + CHECK_XPATH_NODESET(c, "child::c1"); + + CHECK_XPATH_NODESET(n, "c1") % 5; + CHECK_XPATH_NODESET(n, "x:c2") % 6; + + CHECK_XPATH_NODESET(n, "child::c1") % 5; + CHECK_XPATH_NODESET(n, "child::x:c2") % 6; + + CHECK_XPATH_NODESET(n, "attribute::a1") % 3; + CHECK_XPATH_NODESET(n, "attribute::x:a2") % 4; + CHECK_XPATH_NODESET(n, "@x:a2") % 4; +} + +TEST_XML(xpath_paths_nodetest_all_in_namespace, "") +{ + doc.precompute_document_order(); + + xml_node c; + xml_node n = doc.child("node"); + + CHECK_XPATH_NODESET(c, "x:*"); + CHECK_XPATH_NODESET(c, "child::x:*"); + + CHECK_XPATH_NODESET(n, "x:*") % 6 % 8; + CHECK_XPATH_NODESET(n, "child::x:*") % 6 % 8; + + CHECK_XPATH_NODESET(n, "attribute::x:*") % 4; + CHECK_XPATH_NODESET(n, "@x:*") % 4; + + CHECK_XPATH_FAIL(":*"); + CHECK_XPATH_FAIL("@:*"); +} + +TEST_XML_FLAGS(xpath_paths_nodetest_type, "pcdata", parse_default | parse_pi | parse_comments) +{ + doc.precompute_document_order(); + + xml_node c; + xml_node n = doc.child("node"); + + // check on empty nodes + CHECK_XPATH_NODESET(c, "node()"); + CHECK_XPATH_NODESET(c, "text()"); + CHECK_XPATH_NODESET(c, "comment()"); + CHECK_XPATH_NODESET(c, "processing-instruction()"); + CHECK_XPATH_NODESET(c, "processing-instruction('foobar')"); + + // child axis + CHECK_XPATH_NODESET(n, "node()") % 4 % 5 % 6 % 7 % 8 % 9; + CHECK_XPATH_NODESET(n, "text()") % 4 % 9; + CHECK_XPATH_NODESET(n, "comment()") % 8; + CHECK_XPATH_NODESET(n, "processing-instruction()") % 6 % 7; + CHECK_XPATH_NODESET(n, "processing-instruction('pi2')") % 7; + + // attribute axis + CHECK_XPATH_NODESET(n, "@node()") % 3; + CHECK_XPATH_NODESET(n, "@text()"); + CHECK_XPATH_NODESET(n, "@comment()"); + CHECK_XPATH_NODESET(n, "@processing-instruction()"); + CHECK_XPATH_NODESET(n, "@processing-instruction('pi2')"); + + // incorrect 'argument' number + CHECK_XPATH_FAIL("node('')"); + CHECK_XPATH_FAIL("text('')"); + CHECK_XPATH_FAIL("comment('')"); + CHECK_XPATH_FAIL("processing-instruction(1)"); + CHECK_XPATH_FAIL("processing-instruction('', '')"); +} + +TEST_XML(xpath_paths_step_abbrev, "") +{ + doc.precompute_document_order(); + + xml_node c; + xml_node n = doc.child("node"); + + CHECK_XPATH_NODESET(c, "."); + CHECK_XPATH_NODESET(c, ".."); + + CHECK_XPATH_NODESET(n, ".") % 2; + CHECK_XPATH_NODESET(n, "..") % 1; + CHECK_XPATH_NODESET(n, "../node") % 2; + CHECK_XPATH_NODESET(n.child("foo"), "..") % 2; + + CHECK_XPATH_FAIL(".node"); + CHECK_XPATH_FAIL("..node"); +} + #endif -- cgit v1.2.3