summaryrefslogtreecommitdiff
path: root/examples/cppunittest/XmlElementTest.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-05-23 17:38:39 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-05-23 17:38:39 +0000
commit5ad4640702a80078748b38ebaeda37e69dce1189 (patch)
tree9d1ecf8d28f0e9397c2f90565d96ccda6d08b98e /examples/cppunittest/XmlElementTest.cpp
parent7edd0684368ed3c43fe2707d1d34d6b7590d9fd6 (diff)
downloadcppunit-5ad4640702a80078748b38ebaeda37e69dce1189.tar.gz
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.
Diffstat (limited to 'examples/cppunittest/XmlElementTest.cpp')
-rw-r--r--examples/cppunittest/XmlElementTest.cpp115
1 files changed, 115 insertions, 0 deletions
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 <cppunit/tools/XmlElement.h>
+#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 = "<element></element>";
+ 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 = "<element id=\"17\" "
+ "date-format=\"iso-8901\">"
+ "</element>";
+ CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
+}
+
+
+void
+XmlElementTest::testEscapedAttributeValueToString()
+{
+ CppUnit::XmlElement node( "element" );
+ node.addAttribute( "escaped", "&<>\"'" );
+ std::string expectedXml = "<element escaped=\""
+ "&amp;&lt;&gt;&quot;&apos;"
+ "\"></element>";
+ CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
+}
+
+
+void
+XmlElementTest::testNodeToStringEscapeContent()
+{
+ CppUnit::XmlElement node( "element", "ChessTest<class Chess>" );
+ std::string expectedXml = "<element>"
+ "ChessTest&lt;class Chess&gt;"
+ "</element>";
+ 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 = "<element><child1></child1>"
+ "<child2></child2></element>";
+ CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
+}
+
+
+void
+XmlElementTest::testNodeWithContentToString()
+{
+ CppUnit::XmlElement node( "element", "content\nline2" );
+ std::string expectedXml = "<element>content\nline2</element>";
+ CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
+}
+
+
+void
+XmlElementTest::testNodeWithNumericContentToString()
+{
+ CppUnit::XmlElement node( "element", 123456789 );
+ std::string expectedXml = "<element>123456789</element>";
+ CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
+}
+
+
+void
+XmlElementTest::testNodeWithContentAndChildToString()
+{
+ CppUnit::XmlElement node( "element", "content" );
+ node.addNode( new CppUnit::XmlElement( "child1" ) );
+ std::string expectedXml = "<element><child1></child1>content</element>";
+ CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
+}