Moved DOM methods up the tree, add copy c'tors, KeyInfo sample
[shibboleth/xmltooling.git] / xmltoolingtest / UnmarshallingTest.h
index d4ba4f6..248671d 100644 (file)
@@ -37,25 +37,36 @@ 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
+    QName m_qtype;\r
 public:\r
-    UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME) {}\r
+    UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME,SimpleXMLObject::NAMESPACE_PREFIX),\r
+        m_qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME,SimpleXMLObject::NAMESPACE_PREFIX) {}\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
+        XMLObjectBuilder::registerBuilder(m_qtype, new SimpleXMLObjectBuilder());\r
     }\r
 \r
     void tearDown() {\r
         XMLObjectBuilder::deregisterBuilder(m_qname);\r
-        Marshaller::deregisterMarshaller(m_qname);\r
-        Unmarshaller::deregisterUnmarshaller(m_qname);\r
+        XMLObjectBuilder::deregisterBuilder(m_qtype);\r
     }\r
 \r
     void testUnmarshallingWithAttributes() {\r
@@ -66,10 +77,12 @@ public:
         DOMDocument* doc=nonvalidatingPool->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
@@ -84,10 +97,12 @@ public:
         DOMDocument* doc=nonvalidatingPool->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
@@ -102,13 +117,41 @@ public:
         DOMDocument* doc=nonvalidatingPool->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(\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", 3, kids.size());\r
+        TSM_ASSERT_EQUALS("Child's schema type was not expected value", m_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=nonvalidatingPool->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(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
-        TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, sxObject->getSimpleXMLObjects().size());\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
+        TSM_ASSERT_EQUALS("Child's schema type was not expected value", m_qtype, *(kids.back()->getSchemaType()));\r
     }\r
 \r
     void testUnmarshallingWithUnknownChild() {\r
@@ -119,10 +162,10 @@ public:
         DOMDocument* doc=nonvalidatingPool->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