Removed ValidatingXMLObject interface and implementations.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / UnmarshallingTest.h
index f361266..3687ea3 100644 (file)
@@ -37,25 +37,35 @@ const XMLCh SimpleXMLObject::LOCAL_NAME[] = {
     chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull\r
 };\r
 \r
+const XMLCh SimpleXMLObject::DERIVED_NAME[] = {\r
+    chLatin_D, chLatin_e, chLatin_r, chLatin_i, chLatin_v, chLatin_e, chLatin_d,\r
+    chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull\r
+};\r
+\r
+const XMLCh SimpleXMLObject::TYPE_NAME[] = {\r
+    chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,\r
+    chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, \r
+    chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull\r
+};\r
+\r
 const XMLCh SimpleXMLObject::ID_ATTRIB_NAME[] = {\r
     chLatin_I, chLatin_d, chNull\r
 };\r
 \r
 class UnmarshallingTest : public CxxTest::TestSuite {\r
-    QName m_qname;\r
 public:\r
-    UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME) {}\r
-\r
     void setUp() {\r
-        XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());\r
-        Marshaller::registerMarshaller(m_qname, new SimpleXMLObjectMarshaller());\r
-        Unmarshaller::registerUnmarshaller(m_qname, new SimpleXMLObjectUnmarshaller());\r
+        QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);\r
+        QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);\r
+        XMLObjectBuilder::registerBuilder(qname, new SimpleXMLObjectBuilder());\r
+        XMLObjectBuilder::registerBuilder(qtype, new SimpleXMLObjectBuilder());\r
     }\r
 \r
     void tearDown() {\r
-        XMLObjectBuilder::deregisterBuilder(m_qname);\r
-        Marshaller::deregisterMarshaller(m_qname);\r
-        Unmarshaller::deregisterUnmarshaller(m_qname);\r
+        QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);\r
+        QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);\r
+        XMLObjectBuilder::deregisterBuilder(qname);\r
+        XMLObjectBuilder::deregisterBuilder(qtype);\r
     }\r
 \r
     void testUnmarshallingWithAttributes() {\r
@@ -63,13 +73,15 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithAttribute.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
-        const Unmarshaller* u = Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
-        TS_ASSERT(u!=NULL);\r
+        const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
 \r
-        auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\r
+        auto_ptr<SimpleXMLObject> sxObject(\r
+            dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
+            );\r
         TS_ASSERT(sxObject.get()!=NULL);\r
 \r
         auto_ptr_XMLCh expected("Firefly");\r
@@ -81,13 +93,15 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithContent.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
-        const Unmarshaller* u = Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
-        TS_ASSERT(u!=NULL);\r
+        const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
 \r
-        auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\r
+        auto_ptr<SimpleXMLObject> sxObject(\r
+            dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
+            );\r
         TS_ASSERT(sxObject.get()!=NULL);\r
 \r
         auto_ptr_XMLCh expected("Sample Content");\r
@@ -99,17 +113,46 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
-        const Unmarshaller* u = Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
-        TS_ASSERT(u!=NULL);\r
+        const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
 \r
-        auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\r
+        auto_ptr<SimpleXMLObject> sxObject(\r
+            dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
+            );\r
         TS_ASSERT(sxObject.get()!=NULL);\r
 \r
         VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();\r
-        TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size());\r
+        TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());\r
+        QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);\r
+        TSM_ASSERT_EQUALS("Child's schema type was not expected value", qtype, *(kids.back()->getSchemaType()));\r
+    }\r
+\r
+    void testUnmarshallingWithClone() {\r
+        TS_TRACE("testUnmarshallingWithClone");\r
+\r
+        string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
+        ifstream fs(path.c_str());\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
+        TS_ASSERT(doc!=NULL);\r
+\r
+        const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
+\r
+        auto_ptr<SimpleXMLObject> sxObject(\r
+            dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
+            );\r
+        TS_ASSERT(sxObject.get()!=NULL);\r
+\r
+        sxObject->releaseThisAndChildrenDOM();\r
+        auto_ptr<SimpleXMLObject> clonedObject(sxObject->clone());\r
+\r
+        VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects();\r
+        TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());\r
+        QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);\r
+        TSM_ASSERT_EQUALS("Child's schema type was not expected value", qtype, *(kids.back()->getSchemaType()));\r
     }\r
 \r
     void testUnmarshallingWithUnknownChild() {\r
@@ -117,13 +160,13 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
-        const Unmarshaller* u = Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
-        TS_ASSERT(u!=NULL);\r
+        const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
+        TS_ASSERT(b!=NULL);\r
 \r
-        TS_ASSERT_THROWS(u->unmarshall(doc->getDocumentElement(),true),UnmarshallingException);\r
+        TS_ASSERT_THROWS(b->buildFromDocument(doc),UnmarshallingException);\r
         doc->release();\r
     }\r
 };\r