]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/xml/xmltest.cpp
support wxFD_MULTIPLE
[wxWidgets.git] / tests / xml / xmltest.cpp
index 6d7faeb3c84ef8b2b2d9d91100bac8c504b6548e..7b1d8ebd5363e6a414753e291ab5efb2accfa75b 100644 (file)
@@ -75,11 +75,15 @@ private:
         CPPUNIT_TEST( InsertChild );
         CPPUNIT_TEST( InsertChildAfter );
         CPPUNIT_TEST( LoadSave );
+        CPPUNIT_TEST( CDATA );
+        CPPUNIT_TEST( Escaping );
     CPPUNIT_TEST_SUITE_END();
 
     void InsertChild();
     void InsertChildAfter();
     void LoadSave();
+    void CDATA();
+    void Escaping();
 
     DECLARE_NO_COPY_CLASS(XmlTestCase)
 };
@@ -165,6 +169,7 @@ void XmlTestCase::LoadSave()
     CPPUNIT_ASSERT_EQUAL( xmlText, sos.GetString() );
 
 
+#if wxUSE_UNICODE
     const char *utf8xmlText =
 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 "<word>\n"
@@ -187,5 +192,53 @@ void XmlTestCase::LoadSave()
     CPPUNIT_ASSERT( doc.Save(sos8) );
     CPPUNIT_ASSERT_EQUAL( wxString(utf8xmlText),
                           wxString(sos8.GetString().ToUTF8()) );
+#endif // wxUSE_UNICODE
 }
 
+void XmlTestCase::CDATA()
+{
+    const char *xmlText =
+        "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n"
+        "<name>\n"
+        "  <![CDATA[Giovanni Mittone]]>\n"
+        "</name>\n"
+    ;
+
+    wxStringInputStream sis(xmlText);
+    wxXmlDocument doc;
+    CPPUNIT_ASSERT( doc.Load(sis) );
+
+    wxXmlNode *n = doc.GetRoot();
+    CPPUNIT_ASSERT( n );
+
+    n = n->GetChildren();
+    CPPUNIT_ASSERT( n );
+
+    // check that both leading ("  ") and trailing white space is not part of
+    // the node contents when CDATA is used and wxXMLDOC_KEEP_WHITESPACE_NODES
+    // is not
+    CPPUNIT_ASSERT_EQUAL( "Giovanni Mittone", n->GetContent() );
+}
+
+void XmlTestCase::Escaping()
+{
+    // Verify that attribute values are escaped correctly, see
+    // http://trac.wxwidgets.org/ticket/12275
+
+    const char *xmlText =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<root text=\"hello&#xD;&#xA;this is a new line\">\n"
+"  <x/>\n"
+"</root>\n"
+    ;
+
+    wxStringInputStream sis(xmlText);
+
+    wxXmlDocument doc;
+    CPPUNIT_ASSERT( doc.Load(sis) );
+
+    wxStringOutputStream sos;
+    CPPUNIT_ASSERT( doc.Save(sos) );
+
+    CPPUNIT_ASSERT_EQUAL( xmlText, sos.GetString() );
+}