From c026597234aa371a106409271885f0cdb3c7bae3 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Tue, 20 Oct 2009 20:25:35 +0000 Subject: tests: Added more tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@162 99668b35-9821-0410-8761-19e4c4f06640 --- Jamfile.jam | 2 +- tests/test_document.cpp | 30 +++++++++++++++++++++++++++++ tests/test_parse.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++-- 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, ""); } + +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("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("", 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("", 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("", 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("", 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("", parse_minimal).status == status_bad_attribute); CHECK(doc.load("", parse_minimal).status == status_bad_attribute); + CHECK(doc.load("", parse_minimal).status == status_bad_start_element); + CHECK(doc.load("", 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, "text") TEST_XML(write_raw, "text") { - CHECK_NODE_EX(doc, "text", "", pugi::format_raw); + CHECK_NODE_EX(doc, "text", "", format_raw); } TEST_XML(write_indent, "text") { - CHECK_NODE_EX(doc, "\n\t\n\t\ttext\n\t\n\n", "\t", pugi::format_indent); + CHECK_NODE_EX(doc, "\n\t\n\t\ttext\n\t\n\n", "\t", format_indent); } TEST_XML(write_pcdata, "text") { - CHECK_NODE_EX(doc, "\n\t\n\t\t\n\t\ttext\n\t\n\n", "\t", pugi::format_indent); + CHECK_NODE_EX(doc, "\n\t\n\t\t\n\t\ttext\n\t\n\n", "\t", format_indent); } TEST_XML(write_cdata, "") { CHECK_NODE(doc, ""); + CHECK_NODE_EX(doc, "\n", "", 0); } -TEST_XML_FLAGS(write_comment, "", pugi::parse_default | pugi::parse_comments) +TEST_XML_FLAGS(write_comment, "", parse_default | parse_comments) { CHECK_NODE(doc, ""); + CHECK_NODE_EX(doc, "\n", "", 0); } -TEST_XML_FLAGS(write_pi, "", pugi::parse_default | pugi::parse_pi) +TEST_XML_FLAGS(write_pi, "", parse_default | parse_pi) { CHECK_NODE(doc, ""); + CHECK_NODE_EX(doc, "\n", "", 0); } -TEST_XML_FLAGS(write_declaration, "", pugi::parse_default | pugi::parse_declaration) +TEST_XML_FLAGS(write_declaration, "", parse_default | parse_declaration) { CHECK_NODE(doc, ""); + CHECK_NODE_EX(doc, "\n", "", 0); } TEST_XML(write_escape, "text") @@ -75,3 +79,14 @@ TEST_XML(write_print_stream, "") CHECK(oss.str() == "\n"); } + +TEST_XML(write_huge_chunk, "") +{ + std::string name(10000, 'n'); + doc.child("node").set_name(name.c_str()); + + std::ostringstream oss; + doc.print(oss); + + CHECK(oss.str() == "<" + name + " />\n"); +} -- cgit v1.2.3