]>
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 CPPUNIT_ASSERT_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( InsertChildAfter
);
76 CPPUNIT_TEST_SUITE_END();
79 void InsertChildAfter();
81 DECLARE_NO_COPY_CLASS(XmlTestCase
)
84 // register in the unnamed registry so that these tests are run by default
85 CPPUNIT_TEST_SUITE_REGISTRATION( XmlTestCase
);
87 // also include in it's own registry so that these tests can be run alone
88 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlTestCase
, "XmlTestCase" );
90 void XmlTestCase::InsertChild()
92 wxXmlNode
*root
= new wxXmlNode(wxXML_ELEMENT_NODE
, "root");
93 root
->AddChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "1"));
94 wxXmlNode
*two
= new wxXmlNode(wxXML_ELEMENT_NODE
, "2");
96 root
->AddChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "3"));
97 CheckXml(root
, "1", "2", "3", NULL
);
99 // check inserting in front:
100 root
->InsertChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "A"), NULL
);
101 CheckXml(root
, "A", "1", "2", "3", NULL
);
102 root
->InsertChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "B"), root
->GetChildren());
103 CheckXml(root
, "B", "A", "1", "2", "3", NULL
);
105 // and in the middle:
106 root
->InsertChild(new wxXmlNode(wxXML_ELEMENT_NODE
, "C"), two
);
107 CheckXml(root
, "B", "A", "1", "C", "2", "3", NULL
);
110 void XmlTestCase::InsertChildAfter()
112 wxXmlNode
*root
= new wxXmlNode(wxXML_ELEMENT_NODE
, "root");
114 root
->InsertChildAfter(new wxXmlNode(wxXML_ELEMENT_NODE
, "1"), NULL
);
115 CheckXml(root
, "1", NULL
);
117 wxXmlNode
*two
= new wxXmlNode(wxXML_ELEMENT_NODE
, "2");
119 wxXmlNode
*three
= new wxXmlNode(wxXML_ELEMENT_NODE
, "3");
120 root
->AddChild(three
);
121 CheckXml(root
, "1", "2", "3", NULL
);
123 // check inserting in the middle:
124 root
->InsertChildAfter(new wxXmlNode(wxXML_ELEMENT_NODE
, "A"), root
->GetChildren());
125 CheckXml(root
, "1", "A", "2", "3", NULL
);
126 root
->InsertChildAfter(new wxXmlNode(wxXML_ELEMENT_NODE
, "B"), two
);
127 CheckXml(root
, "1", "A", "2", "B", "3", NULL
);
130 root
->InsertChildAfter(new wxXmlNode(wxXML_ELEMENT_NODE
, "C"), three
);
131 CheckXml(root
, "1", "A", "2", "B", "3", "C", NULL
);