much more tests; all exceptions in readin tested
This commit is contained in:
		| @@ -161,6 +161,106 @@ class StringTest: public CppUnit::TestFixture { | ||||
| }; | ||||
| CPPUNIT_TEST_SUITE_REGISTRATION(StringTest); | ||||
|  | ||||
| class ComplexTest: public CppUnit::TestFixture {  | ||||
|   public: | ||||
|     void nodes() { | ||||
|       xml::Factory factory(xml::Node("base") | ||||
|                            <<(xml::Node("child").attr("a", xml::optional) | ||||
|                               <<xml::String("childofchild") | ||||
|                               <<xml::UnsignedInteger("number")) | ||||
|                            <<xml::Node("otherchild")); | ||||
|       std::stringstream file1; | ||||
|       file1<<"<!DOCTYPE xyz>"<<std::endl | ||||
|            <<"<?xml 1.0 encoding=\"utf8\"?>"<<std::endl | ||||
|            <<"<base>"<<std::endl | ||||
|            <<"<child a=\"b\"><childofchild/><childofchild/><childofchild>" | ||||
|            <<"xxx</childofchild><number>13</number><number/><number>" | ||||
|            <<" 42  </number><number>   </number></child>" | ||||
|            <<"<child a=\"b\"/>" | ||||
|            <<"< otherchild ><  / otherchild  >< otherchild / >"<<std::endl | ||||
|            <<"</base>"; | ||||
|       std::auto_ptr<xml::Node> node(factory.read(file1)); // should work | ||||
|       CPPUNIT_ASSERT_EQUAL((size_t)2, node->list("child").size()); | ||||
|       CPPUNIT_ASSERT_EQUAL((size_t)3, (*node)[0].list("childofchild").size()); | ||||
|       CPPUNIT_ASSERT_EQUAL((size_t)4, (*node)[0].list("number").size()); | ||||
|       CPPUNIT_ASSERT_EQUAL((size_t)0, (*node)[1].list("childofchild").size()); | ||||
|       CPPUNIT_ASSERT_EQUAL((size_t)2, node->list("otherchild").size()); | ||||
|       CPPUNIT_ASSERT_EQUAL(std::string("xxx"), *(*node)["child"][2]); | ||||
|       CPPUNIT_ASSERT_EQUAL(std::string("13"), *(*node)["child"][3]); | ||||
|       CPPUNIT_ASSERT_EQUAL(std::string("0"), *(*node)["child"][4]); | ||||
|       CPPUNIT_ASSERT_EQUAL(std::string("42"), *(*node)["child"][5]); | ||||
|       CPPUNIT_ASSERT_EQUAL(std::string("0"), *(*node)["child"][6]); | ||||
|       std::stringstream file2; | ||||
|       file2<<"<!DOCTYPE xyz>"<<std::endl | ||||
|            <<"<?xml 1.0 encoding=\"utf8\"?>"<<std::endl | ||||
|            <<"<base>"<<std::endl | ||||
|            <<"<child><childofchild/><exception><childofchild/><childofchild>" | ||||
|            <<"xxx</childofchild></child>" | ||||
|            <<"<child/>" | ||||
|            <<"< otherchild ><  / otherchild  >< otherchild / >"<<std::endl | ||||
|            <<"</base>"; | ||||
|       CPPUNIT_ASSERT_THROW(factory.read(file2), xml::access_error); | ||||
|       { | ||||
|         std::stringstream file("<base></xyz>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::wrong_end_tag); | ||||
|       } { | ||||
|         std::stringstream file("<xyz></xyz>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::wrong_start_tag); | ||||
|       } { | ||||
|         std::stringstream file("base"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::tag_expected); | ||||
|       } { | ||||
|         std::stringstream file("<base>hallo</base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::tag_expected); | ||||
|       } { | ||||
|         std::stringstream file | ||||
|           ("<base><child><number>x</number></child></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::type_mismatch); | ||||
|       } { | ||||
|         std::stringstream file | ||||
|           ("<base><child><number>xyz</number></child></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::type_mismatch); | ||||
|       } { | ||||
|         std::stringstream file("<base><child></child/></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::second_slash_in_tag); | ||||
|       } { | ||||
|         std::stringstream file("<base><child><child/a></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::character_after_slash); | ||||
|       } { | ||||
|         std::stringstream file("<base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::missing_end_tag); | ||||
|       } { | ||||
|         std::stringstream file("<base><child>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::missing_end_tag); | ||||
|       } { | ||||
|         std::stringstream file; | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::missing_end_tag); | ||||
|       } { | ||||
|         std::stringstream file("<base><child a=b></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), | ||||
|                              xml::attribute_value_not_quoted); | ||||
|       } { | ||||
|         std::stringstream file("<base><child a=\"b\" a=\"b\"></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::duplicate_attribute); | ||||
|       } { | ||||
|         std::stringstream file("<base><child></child a=\"b\"></base>"); | ||||
|         CPPUNIT_ASSERT_THROW(factory.read(file), xml::attributes_in_end_tag); | ||||
|       } | ||||
|     } | ||||
|     void attributes() { | ||||
|       xml::Factory factory(xml::Node("base") | ||||
|                            <<(xml::Node("child") | ||||
|                               <<xml::String("childofchild") | ||||
|                               <<xml::UnsignedInteger("number")) | ||||
|                            <<xml::Node("otherchild")); | ||||
|     } | ||||
|     CPPUNIT_TEST_SUITE(ComplexTest); | ||||
|     CPPUNIT_TEST(nodes); | ||||
|     CPPUNIT_TEST(attributes); | ||||
|     CPPUNIT_TEST_SUITE_END(); | ||||
| }; | ||||
| CPPUNIT_TEST_SUITE_REGISTRATION(ComplexTest); | ||||
|  | ||||
| class FunTest: public CppUnit::TestFixture {  | ||||
|   public: | ||||
|     void playing() { | ||||
| @@ -276,9 +376,9 @@ class FunTest: public CppUnit::TestFixture { | ||||
|                               <<(xml::String("application") | ||||
|                                  .attr("id", xml::mandatory) | ||||
|                                  .attr("os", xml::optional)))); | ||||
|       std::cout<<std::endl | ||||
|                <<*applications<<std::endl | ||||
|                <<*edition<<std::endl; | ||||
|       /*std::cout<<std::endl | ||||
|           <<*applications<<std::endl | ||||
|           <<*edition<<std::endl;*/ | ||||
|     } | ||||
|     CPPUNIT_TEST_SUITE(FunTest); | ||||
|     CPPUNIT_TEST(playing); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user