]>
git.saurik.com Git - wxWidgets.git/blob - tests/xml/xmltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/xml/xmltest.cpp
3 // Purpose: XML classes unit test
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2008 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/xml/xml.h"
28 // ----------------------------------------------------------------------------
29 // helpers for testing XML tree
30 // ----------------------------------------------------------------------------
35 void CheckXml(wxXmlNode
*n
, ...)
40 wxXmlNode
*child
= n
->GetChildren();
44 const char *childName
= va_arg(args
, char*);
45 if ( childName
== NULL
)
48 CPPUNIT_ASSERT( child
);
49 WX_ASSERT_STR_EQUAL( childName
, child
->GetName() );
50 CPPUNIT_ASSERT( child
->GetChildren() == NULL
);
51 CPPUNIT_ASSERT( child
->GetParent() == n
);
53 child
= child
->GetNext();
58 CPPUNIT_ASSERT( child
== NULL
); // no more children
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 class XmlTestCase
: public CppUnit::TestCase
73 CPPUNIT_TEST_SUITE( XmlTestCase
);
74 CPPUNIT_TEST( InsertChild
);
75 CPPUNIT_TEST_SUITE_END();
79 DECLARE_NO_COPY_CLASS(XmlTestCase
)
82 // register in the unnamed registry so that these tests are run by default
83 CPPUNIT_TEST_SUITE_REGISTRATION( XmlTestCase
);
85 // also include in it's own registry so that these tests can be run alone
86 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlTestCase
, "XmlTestCase" );
88 void XmlTestCase::InsertChild()
90 wxXmlNode
*root
= new wxXmlNode(wxXML_ELEMENT_NODE
, "root");
91 root
->AddChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "1"));
92 wxXmlNode
*two
= new wxXmlNode(wxXML_ELEMENT_NODE
, "2");
94 root
->AddChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "3"));
95 CheckXml(root
, "1", "2", "3", NULL
);
97 // check inserting in front:
98 root
->InsertChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "A"), NULL
);
99 CheckXml(root
, "A", "1", "2", "3", NULL
);
100 root
->InsertChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "B"), root
->GetChildren());
101 CheckXml(root
, "B", "A", "1", "2", "3", NULL
);
103 // and in the middle:
104 root
->InsertChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "C"), two
);
105 CheckXml(root
, "B", "A", "1", "C", "2", "3", NULL
);