Merged marshalling/unmarshalling methods into core interface.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / xmltoolingtest.h
index 42c21c9..50a66d3 100644 (file)
  * limitations under the License.\r
  */\r
 \r
-#include <cxxtest/TestSuite.h>\r
-#include <cxxtest/GlobalFixture.h>\r
+#include "XMLObjectBaseTestCase.h"\r
 \r
+#include <fstream>\r
+#include <cxxtest/GlobalFixture.h>\r
 #include <xmltooling/XMLToolingConfig.h>\r
 #include <xmltooling/util/ParserPool.h>\r
 \r
-using namespace xmltooling;\r
-\r
 ParserPool* validatingPool=NULL;\r
 ParserPool* nonvalidatingPool=NULL;\r
 std::string data_path = "../xmltoolingtest/data/";\r
@@ -60,7 +59,7 @@ public:
 \r
 static ToolingFixture globalFixture;\r
 \r
-class CatalogTest : public CxxTest::TestSuite\r
+class GlobalTest : public CxxTest::TestSuite\r
 {\r
 public:\r
     void testCatalog(void) {\r
@@ -68,4 +67,58 @@ public:
         auto_ptr_XMLCh temp(path.c_str());\r
         TS_ASSERT(validatingPool->loadCatalog(temp.get()));\r
     }\r
+\r
+    void testUnknown() {\r
+        ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");\r
+        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        TS_ASSERT(doc!=NULL);\r
+\r
+        string buf1;\r
+        XMLHelper::serialize(doc->getDocumentElement(), buf1);\r
+\r
+        const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
+\r
+        auto_ptr<XMLObject> xmlObject(b->buildObject(doc->getDocumentElement())->unmarshall(doc->getDocumentElement(),true)); // bind document\r
+        TS_ASSERT(xmlObject.get()!=NULL);\r
+\r
+        auto_ptr<XMLObject> clonedObject(xmlObject->clone());\r
+        TS_ASSERT(clonedObject.get()!=NULL);\r
+\r
+        DOMElement* rootElement=clonedObject->marshall();\r
+        TS_ASSERT(rootElement!=NULL);\r
+\r
+        // should reuse DOM\r
+        TS_ASSERT(rootElement==clonedObject->marshall());\r
+\r
+        string buf2;\r
+        XMLHelper::serialize(rootElement, buf2);\r
+        TS_ASSERT_EQUALS(buf1,buf2);\r
+    }\r
+\r
+    void testUnknownWithDocChange() {\r
+        ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");\r
+        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        TS_ASSERT(doc!=NULL);\r
+\r
+        string buf1;\r
+        XMLHelper::serialize(doc->getDocumentElement(), buf1);\r
+\r
+        const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
+\r
+        auto_ptr<XMLObject> xmlObject(b->buildObject(doc->getDocumentElement())->unmarshall(doc->getDocumentElement(),true)); // bind document\r
+        TS_ASSERT(xmlObject.get()!=NULL);\r
+\r
+        DOMDocument* newDoc=nonvalidatingPool->newDocument();\r
+        DOMElement* rootElement=xmlObject->marshall(newDoc);\r
+        TS_ASSERT(rootElement!=NULL);\r
+\r
+        string buf2;\r
+        XMLHelper::serialize(rootElement, buf2);\r
+        TS_ASSERT_EQUALS(buf1,buf2);\r
+\r
+        newDoc->release();\r
+    }\r
 };\r
+\r