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