From 5ad4640702a80078748b38ebaeda37e69dce1189 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Thu, 23 May 2002 17:38:39 +0000 Subject: Include/cppunit/XmlOutputter. include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: extracted class XmlOutputter::Node to XmlElement. Extracted xml 'prolog' generation to XmlDocument. * include/cppunit/tools/XmlElement.h: * src/cppunit/tools/XmlElement.cpp: added, extracted from XmlOutputter::Node. * include/cppunit/tools/XmlDocument.h: * src/cppunit/tools/XmlDocument.cpp: added, extracted from XmlOutputter. Handle XML document prolog (encoding & style-sheet) and manage the root element. * src/DllPlugInTester/DllPlugInTester.cpp: bug fix, flag --xsl was ignored. * examples/cppunittest/XmlOutputterTest.h: * examples/cppunittest/XmlOutputterTest.cpp: updated for XmlOuputter changes. extracted tests for XmlOutputter::Node to XmlElementTest * examples/cppunittest/XmlElementTest.h: * examples/cppunittest/XmlElementTest.cpp: added, tests extracted from XmlOutputterTest. --- examples/cppunittest/XmlElementTest.cpp | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 examples/cppunittest/XmlElementTest.cpp (limited to 'examples/cppunittest/XmlElementTest.cpp') diff --git a/examples/cppunittest/XmlElementTest.cpp b/examples/cppunittest/XmlElementTest.cpp new file mode 100644 index 0000000..e460458 --- /dev/null +++ b/examples/cppunittest/XmlElementTest.cpp @@ -0,0 +1,115 @@ +#include +#include "ToolsSuite.h" +#include "XmlElementTest.h" +#include "XmlUniformiser.h" + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlElementTest, + CppUnitTest::toolsSuiteName() ); + + +XmlElementTest::XmlElementTest() +{ +} + + +XmlElementTest::~XmlElementTest() +{ +} + + +void +XmlElementTest::setUp() +{ +} + + +void +XmlElementTest::tearDown() +{ +} + + +void +XmlElementTest::testEmptyNodeToString() +{ + CppUnit::XmlElement node( "element" ); + std::string expectedXml = ""; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testNodeWithAttributesToString() +{ + CppUnit::XmlElement node( "element" ); + node.addAttribute( "id", 17 ); + node.addAttribute( "date-format", "iso-8901" ); + std::string expectedXml = "" + ""; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testEscapedAttributeValueToString() +{ + CppUnit::XmlElement node( "element" ); + node.addAttribute( "escaped", "&<>\"'" ); + std::string expectedXml = ""; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testNodeToStringEscapeContent() +{ + CppUnit::XmlElement node( "element", "ChessTest" ); + std::string expectedXml = "" + "ChessTest<class Chess>" + ""; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testNodeWithChildrenToString() +{ + CppUnit::XmlElement node( "element" ); + node.addNode( new CppUnit::XmlElement( "child1" ) ); + node.addNode( new CppUnit::XmlElement( "child2" ) ); + std::string expectedXml = "" + ""; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testNodeWithContentToString() +{ + CppUnit::XmlElement node( "element", "content\nline2" ); + std::string expectedXml = "content\nline2"; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testNodeWithNumericContentToString() +{ + CppUnit::XmlElement node( "element", 123456789 ); + std::string expectedXml = "123456789"; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} + + +void +XmlElementTest::testNodeWithContentAndChildToString() +{ + CppUnit::XmlElement node( "element", "content" ); + node.addNode( new CppUnit::XmlElement( "child1" ) ); + std::string expectedXml = "content"; + CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); +} -- cgit v1.2.1