]> git.saurik.com Git - wxWidgets.git/blob - tests/xml/xmltest.cpp
Add OS/2 to buildbot (patch #1929212).
[wxWidgets.git] / tests / xml / xmltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/xml/xmltest.cpp
3 // Purpose: XML classes unit test
4 // Author: Vaclav Slavik
5 // Created: 2008-03-29
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/xml/xml.h"
25
26 #include <stdarg.h>
27
28 // ----------------------------------------------------------------------------
29 // helpers for testing XML tree
30 // ----------------------------------------------------------------------------
31
32 namespace
33 {
34
35 void CheckXml(wxXmlNode *n, ...)
36 {
37 va_list args;
38 va_start(args, n);
39
40 wxXmlNode *child = n->GetChildren();
41
42 for (;;)
43 {
44 const char *childName = va_arg(args, char*);
45 if ( childName == NULL )
46 break;
47
48 CPPUNIT_ASSERT( child );
49 WX_ASSERT_STR_EQUAL( childName, child->GetName() );
50 CPPUNIT_ASSERT( child->GetChildren() == NULL );
51 CPPUNIT_ASSERT( child->GetParent() == n );
52
53 child = child->GetNext();
54 }
55
56 va_end(args);
57
58 CPPUNIT_ASSERT( child == NULL ); // no more children
59 }
60
61 } // anon namespace
62
63 // ----------------------------------------------------------------------------
64 // test class
65 // ----------------------------------------------------------------------------
66
67 class XmlTestCase : public CppUnit::TestCase
68 {
69 public:
70 XmlTestCase() {}
71
72 private:
73 CPPUNIT_TEST_SUITE( XmlTestCase );
74 CPPUNIT_TEST( InsertChild );
75 CPPUNIT_TEST_SUITE_END();
76
77 void InsertChild();
78
79 DECLARE_NO_COPY_CLASS(XmlTestCase)
80 };
81
82 // register in the unnamed registry so that these tests are run by default
83 CPPUNIT_TEST_SUITE_REGISTRATION( XmlTestCase );
84
85 // also include in it's own registry so that these tests can be run alone
86 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlTestCase, "XmlTestCase" );
87
88 void XmlTestCase::InsertChild()
89 {
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");
93 root->AddChild(two);
94 root->AddChild(new wxXmlNode(wxXML_ELEMENT_NODE, "3"));
95 CheckXml(root, "1", "2", "3", NULL);
96
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);
102
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);
106 }