Removed ValidatingXMLObject interface and implementations.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / UnmarshallingTest.h
index d4f41cc..3687ea3 100644 (file)
@@ -37,21 +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
+        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
+        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
@@ -59,7 +73,7 @@ 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 XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -79,7 +93,7 @@ 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 XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -99,7 +113,7 @@ 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 XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -111,7 +125,34 @@ public:
         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
@@ -119,7 +160,7 @@ 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 XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r