diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-10-20 20:25:35 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-10-20 20:25:35 +0000 |
commit | c026597234aa371a106409271885f0cdb3c7bae3 (patch) | |
tree | 3b5e6dc79a7b1faeb57bfd4a91bb34b529dc00c6 | |
parent | a2249c1304564c96ddd1c052043f8d5ef53e2112 (diff) |
tests: Added more tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@162 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r-- | Jamfile.jam | 2 | ||||
-rw-r--r-- | tests/test_document.cpp | 30 | ||||
-rw-r--r-- | tests/test_parse.cpp | 50 | ||||
-rw-r--r-- | tests/test_write.cpp | 27 |
4 files changed, 100 insertions, 9 deletions
diff --git a/Jamfile.jam b/Jamfile.jam index 420a3e0..29abdd5 100644 --- a/Jamfile.jam +++ b/Jamfile.jam @@ -10,7 +10,7 @@ include "Jamrules.jam" ; BUILD = build/mingw/debug ;
CCFLAGS = -fprofile-arcs -ftest-coverage ;
LDFLAGS = -fprofile-arcs ;
-GCOVFLAGS = -n ;
+GCOVFLAGS = ;
Library pugixml : src/pugixml.cpp src/pugixpath.cpp ;
Application tests : tests/main.cpp [ Glob tests : test_*.cpp ] : pugixml ;
diff --git a/tests/test_document.cpp b/tests/test_document.cpp index e839b2f..2b7d950 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -129,3 +129,33 @@ TEST(document_parse_transfer_ownership) CHECK(doc.parse(transfer_ownership_tag(), text));
CHECK_NODE(doc, "<node />");
}
+
+TEST(document_parse_result_bool)
+{
+ xml_parse_result result;
+
+ result.status = status_ok;
+ CHECK(result);
+ CHECK(!!result);
+ CHECK(result == true);
+
+ for (int i = 1; i < 20; ++i)
+ {
+ result.status = (xml_parse_status)i;
+ CHECK(!result);
+ CHECK(result == false);
+ }
+}
+
+TEST(document_parse_result_description)
+{
+ xml_parse_result result;
+
+ for (int i = 0; i < 20; ++i)
+ {
+ result.status = (xml_parse_status)i;
+
+ CHECK(result.description() != 0);
+ CHECK(result.description()[0] != 0);
+ }
+}
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 3d81953..eeabf38 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -233,6 +233,12 @@ TEST(parse_pcdata_skip_ext) CHECK(doc.first_child().type() == node_element);
}
+TEST(parse_pcdata_error)
+{
+ xml_document doc;
+ CHECK(doc.load("<root>pcdata", parse_minimal).status == status_end_element_mismatch);
+}
+
TEST(parse_escapes_skip)
{
xml_document doc;
@@ -269,6 +275,17 @@ TEST(parse_escapes_error) CHECK_STRING(doc.child_value("node"), "g;&#ab;"");
}
+TEST(parse_attribute_spaces)
+{
+ xml_document doc;
+ CHECK(doc.load("<node id1='v1' id2 ='v2' id3= 'v3' id4 = 'v4' id5 \n\r\t = \r\t\n 'v5' />", parse_minimal));
+ CHECK_STRING(doc.child("node").attribute("id1").value(), "v1");
+ CHECK_STRING(doc.child("node").attribute("id2").value(), "v2");
+ CHECK_STRING(doc.child("node").attribute("id3").value(), "v3");
+ CHECK_STRING(doc.child("node").attribute("id4").value(), "v4");
+ CHECK_STRING(doc.child("node").attribute("id5").value(), "v5");
+}
+
TEST(parse_attribute_quot)
{
xml_document doc;
@@ -308,8 +325,35 @@ TEST(parse_attribute_eol_wconv) TEST(parse_attribute_wnorm)
{
xml_document doc;
- CHECK(doc.load("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>", parse_minimal | parse_wnorm_attribute));
- CHECK_STRING(doc.child("node").attribute("id").value(), "val1 val2 val3 val4");
+
+ for (int eol = 0; eol < 2; ++eol)
+ 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("<node id=' \t\r\rval1 \rval2\r\nval3\nval4\r\r'/>", flags));
+ CHECK_STRING(doc.child("node").attribute("id").value(), "val1 val2 val3 val4");
+ }
+}
+
+TEST(parse_attribute_variations)
+{
+ xml_document doc;
+
+ for (int wnorm = 0; wnorm < 2; ++wnorm)
+ for (int eol = 0; eol < 2; ++eol)
+ for (int wconv = 0; wconv < 2; ++wconv)
+ for (int escapes = 0; escapes < 2; ++escapes)
+ {
+ unsigned int flags = parse_minimal;
+
+ flags |= (wnorm ? parse_wnorm_attribute : 0);
+ flags |= (eol ? parse_eol : 0);
+ flags |= (wconv ? parse_wconv_attribute : 0);
+ flags |= (escapes ? parse_escapes : 0);
+
+ CHECK(doc.load("<node id='1'/>", flags));
+ CHECK_STRING(doc.child("node").attribute("id").value(), "1");
+ }
}
TEST(parse_attribute_error)
@@ -322,6 +366,8 @@ TEST(parse_attribute_error) CHECK(doc.load("<node id=\"'/>", parse_minimal).status == status_bad_attribute);
CHECK(doc.load("<node id='\"/>", parse_minimal).status == status_bad_attribute);
CHECK(doc.load("<node id='\"/>", parse_minimal).status == status_bad_attribute);
+ CHECK(doc.load("<node #/>", parse_minimal).status == status_bad_start_element);
+ CHECK(doc.load("<node#/>", parse_minimal).status == status_bad_start_element);
}
TEST(parse_tag_single)
diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 78516b2..81e945c 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -9,37 +9,41 @@ TEST_XML(write_simple, "<node attr='1'><child>text</child></node>") TEST_XML(write_raw, "<node attr='1'><child>text</child></node>")
{
- CHECK_NODE_EX(doc, "<node attr=\"1\"><child>text</child></node>", "", pugi::format_raw);
+ CHECK_NODE_EX(doc, "<node attr=\"1\"><child>text</child></node>", "", format_raw);
}
TEST_XML(write_indent, "<node attr='1'><child><sub>text</sub></child></node>")
{
- CHECK_NODE_EX(doc, "<node attr=\"1\">\n\t<child>\n\t\t<sub>text</sub>\n\t</child>\n</node>\n", "\t", pugi::format_indent);
+ CHECK_NODE_EX(doc, "<node attr=\"1\">\n\t<child>\n\t\t<sub>text</sub>\n\t</child>\n</node>\n", "\t", format_indent);
}
TEST_XML(write_pcdata, "<node attr='1'><child><sub/>text</child></node>")
{
- CHECK_NODE_EX(doc, "<node attr=\"1\">\n\t<child>\n\t\t<sub />\n\t\ttext\n\t</child>\n</node>\n", "\t", pugi::format_indent);
+ CHECK_NODE_EX(doc, "<node attr=\"1\">\n\t<child>\n\t\t<sub />\n\t\ttext\n\t</child>\n</node>\n", "\t", format_indent);
}
TEST_XML(write_cdata, "<![CDATA[value]]>")
{
CHECK_NODE(doc, "<![CDATA[value]]>");
+ CHECK_NODE_EX(doc, "<![CDATA[value]]>\n", "", 0);
}
-TEST_XML_FLAGS(write_comment, "<!--text-->", pugi::parse_default | pugi::parse_comments)
+TEST_XML_FLAGS(write_comment, "<!--text-->", parse_default | parse_comments)
{
CHECK_NODE(doc, "<!--text-->");
+ CHECK_NODE_EX(doc, "<!--text-->\n", "", 0);
}
-TEST_XML_FLAGS(write_pi, "<?name value?>", pugi::parse_default | pugi::parse_pi)
+TEST_XML_FLAGS(write_pi, "<?name value?>", parse_default | parse_pi)
{
CHECK_NODE(doc, "<?name value?>");
+ CHECK_NODE_EX(doc, "<?name value?>\n", "", 0);
}
-TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", pugi::parse_default | pugi::parse_declaration)
+TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", parse_default | parse_declaration)
{
CHECK_NODE(doc, "<?xml version=\"2.0\"?>");
+ CHECK_NODE_EX(doc, "<?xml version=\"2.0\"?>\n", "", 0);
}
TEST_XML(write_escape, "<node attr=''>text</node>")
@@ -75,3 +79,14 @@ TEST_XML(write_print_stream, "<node/>") CHECK(oss.str() == "<node />\n");
}
+
+TEST_XML(write_huge_chunk, "<node/>")
+{
+ std::string name(10000, 'n');
+ doc.child("node").set_name(name.c_str());
+
+ std::ostringstream oss;
+ doc.print(oss);
+
+ CHECK(oss.str() == "<" + name + " />\n");
+}
|