check node number limits

This commit is contained in:
Marc Wäckerlin
2009-04-09 10:53:03 +00:00
parent f9389d1082
commit bbd3b9781d
3 changed files with 148 additions and 66 deletions

View File

@@ -265,32 +265,49 @@ class ComplexTest: public CppUnit::TestFixture {
} {
std::stringstream file("<base one two three></base>");
CPPUNIT_ASSERT_THROW(factory.read(file), xml::illegal_attribute);
} {
std::stringstream file("<base one/>");
CPPUNIT_ASSERT_NO_THROW(factory.read(file));
} {
std::stringstream file("<base one=\"abc def ghi\"/>");
CPPUNIT_ASSERT_EQUAL(std::string("abc"),
(*factory.read(file)).attribute("one").front());
} {
std::stringstream file("<base one=\"abc def ghi\"/>");
CPPUNIT_ASSERT_EQUAL((size_t)3,
(*factory.read(file)).attribute("one").toList()
.size());
} {
std::stringstream file("<base one=\"abc\"/>");
CPPUNIT_ASSERT_EQUAL(std::string("abc"),
(*factory.read(file)).attribute("one").front());
} {
std::stringstream file("<base one/>");
CPPUNIT_ASSERT_EQUAL(std::string(""),
(*factory.read(file)).attribute("one").front());
}
}
void ranges() {
xml::Factory factory(xml::Node("base", 2, 2)
<<xml::Node("mandatory", 1)
xml::Factory factory(xml::Node("base")
<<xml::Node("mandatory", 1, 1)
<<xml::Node("optional", 0, 1));
{
std::stringstream file("<base><mandatory></mandatory></base>"
"<base><mandatory/><optional/></base>");
std::stringstream file("<base><mandatory/><optional/></base>");
CPPUNIT_ASSERT_NO_THROW(factory.read(file));
} /*{
std::stringstream file("<base><mandatory></mandatory></base>"
"<base><mandatory/><optional/></base>");
} {
std::stringstream file("<base><optional/></base>");
CPPUNIT_ASSERT_THROW(factory.read(file),
xml::wrong_node_number);
} {
std::stringstream file("<base><mandatory></mandatory></base>"
"<base><mandatory/><optional/></base>");
std::stringstream file("<base><mandatory/><optional/>"
"<optional/></base>");
CPPUNIT_ASSERT_THROW(factory.read(file),
xml::wrong_node_number);
} {
std::stringstream file("<base><mandatory></mandatory></base>"
"<base><mandatory/><optional/></base>");
std::stringstream file("<base><mandatory/><mandatory/></base>");
CPPUNIT_ASSERT_THROW(factory.read(file),
xml::wrong_node_number);
}*/
}
}
CPPUNIT_TEST_SUITE(ComplexTest);
CPPUNIT_TEST(nodes);