int m_lineNo; // line number in original file, or -1
bool m_noConversion; // don't do encoding conversion - node is plain text
+ void DoFree();
void DoCopy(const wxXmlNode& node);
};
}
wxXmlNode::~wxXmlNode()
+{
+ DoFree();
+}
+
+wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node)
+{
+ DoFree();
+ DoCopy(node);
+ return *this;
+}
+
+void wxXmlNode::DoFree()
{
wxXmlNode *c, *c2;
for (c = m_children; c; c = c2)
}
}
-wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node)
-{
- wxDELETE(m_attrs);
- wxDELETE(m_children);
- DoCopy(node);
- return *this;
-}
-
void wxXmlNode::DoCopy(const wxXmlNode& node)
{
m_type = node.m_type;
CPPUNIT_TEST( DetachRoot );
CPPUNIT_TEST( AppendToProlog );
CPPUNIT_TEST( SetRoot );
+ CPPUNIT_TEST( CopyNode );
CPPUNIT_TEST_SUITE_END();
void InsertChild();
void DetachRoot();
void AppendToProlog();
void SetRoot();
+ void CopyNode();
DECLARE_NO_COPY_CLASS(XmlTestCase)
};
doc.SetRoot(root);
CPPUNIT_ASSERT( doc.IsOk() );
}
+
+void XmlTestCase::CopyNode()
+{
+ const char *xmlText =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<root>\n"
+" <first><sub1/><sub2/><sub3/></first>\n"
+" <second/>\n"
+"</root>\n"
+ ;
+ wxXmlDocument doc;
+ wxStringInputStream sis(xmlText);
+ CPPUNIT_ASSERT( doc.Load(sis) );
+
+ wxXmlNode* const root = doc.GetRoot();
+ CPPUNIT_ASSERT( root );
+
+ wxXmlNode* const first = root->GetChildren();
+ CPPUNIT_ASSERT( first );
+
+ wxXmlNode* const second = first->GetNext();
+ CPPUNIT_ASSERT( second );
+
+ *first = *second;
+
+ wxStringOutputStream sos;
+ CPPUNIT_ASSERT( doc.Save(sos) );
+
+ const char *xmlTextResult =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<root>\n"
+" <second/>\n"
+" <second/>\n"
+"</root>\n"
+ ;
+ CPPUNIT_ASSERT_EQUAL( xmlTextResult, sos.GetString() );
+}