diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-10-27 22:29:14 -0700 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-10-27 22:29:14 -0700 |
commit | 6229138d80380d582f16931d36b279807dcb82dd (patch) | |
tree | 2c9cfe604a0d7e14830229a50a157bc19c64943a /tests/test_write.cpp | |
parent | c64d4820b142e6df93ccf612d0e4717159a36591 (diff) |
Optimize node printing by using raw pointers
This lets us do fewer null pointer checks (making printing 2% faster with -O3)
and removes a lot of function calls (making printing 20% faster with -O0).
Diffstat (limited to 'tests/test_write.cpp')
-rw-r--r-- | tests/test_write.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 98650ac..8fc88e1 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -51,6 +51,15 @@ TEST_XML(write_cdata_inner, "<node><![CDATA[value]]></node>") CHECK_NODE_EX(doc, STR("<node><![CDATA[value]]></node>\n"), STR(""), 0); } +TEST(write_cdata_null) +{ + xml_document doc; + doc.append_child(node_cdata); + doc.append_child(STR("node")).append_child(node_cdata); + + CHECK_NODE(doc, STR("<![CDATA[]]><node><![CDATA[]]></node>")); +} + TEST_XML_FLAGS(write_comment, "<!--text-->", parse_comments | parse_fragment) { CHECK_NODE(doc, STR("<!--text-->")); @@ -80,12 +89,32 @@ TEST(write_comment_invalid) CHECK_NODE(doc, STR("<!--- ->- -->")); } +TEST(write_comment_null) +{ + xml_document doc; + doc.append_child(node_comment); + + CHECK_NODE(doc, STR("<!---->")); +} + TEST_XML_FLAGS(write_pi, "<?name value?>", parse_pi | parse_fragment) { CHECK_NODE(doc, STR("<?name value?>")); CHECK_NODE_EX(doc, STR("<?name value?>\n"), STR(""), 0); } +TEST(write_pi_null) +{ + xml_document doc; + xml_node node = doc.append_child(node_pi); + + CHECK_NODE(doc, STR("<?:anonymous?>")); + + node.set_value(STR("value")); + + CHECK_NODE(doc, STR("<?:anonymous value?>")); +} + TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", parse_declaration | parse_fragment) { CHECK_NODE(doc, STR("<?xml version=\"2.0\"?>")); @@ -98,6 +127,14 @@ TEST_XML_FLAGS(write_doctype, "<!DOCTYPE id [ foo ]>", parse_doctype | parse_fra CHECK_NODE_EX(doc, STR("<!DOCTYPE id [ foo ]>\n"), STR(""), 0); } +TEST(write_doctype_null) +{ + xml_document doc; + doc.append_child(node_doctype); + + CHECK_NODE(doc, STR("<!DOCTYPE>")); +} + TEST_XML(write_escape, "<node attr=''>text</node>") { doc.child(STR("node")).attribute(STR("attr")) = STR("<>'\"&\x04\r\n\t"); @@ -460,3 +497,16 @@ TEST_XML(write_indent_custom, "<node attr='1'><child><sub>text</sub></child></no CHECK_NODE_EX(doc, STR("<node attr=\"1\">\nABCD<child>\nABCDABCD<sub>text</sub>\nABCD</child>\n</node>\n"), STR("ABCD"), format_indent); CHECK_NODE_EX(doc, STR("<node attr=\"1\">\nABCDE<child>\nABCDEABCDE<sub>text</sub>\nABCDE</child>\n</node>\n"), STR("ABCDE"), format_indent); } + +TEST(write_pcdata_null) +{ + xml_document doc; + doc.append_child(STR("node")).append_child(node_pcdata); + + CHECK_NODE(doc, STR("<node></node>")); + CHECK_NODE_EX(doc, STR("<node></node>\n"), STR("\t"), format_indent); + + doc.first_child().append_child(node_pcdata); + + CHECK_NODE_EX(doc, STR("<node>\n\t\n\t\n</node>\n"), STR("\t"), format_indent); +} |