public:\r
UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME) {}\r
\r
- void setUp() {
- XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());
- Marshaller::registerMarshaller(m_qname, new SimpleXMLObjectMarshaller());
- Unmarshaller::registerUnmarshaller(m_qname, new SimpleXMLObjectUnmarshaller());
- }
-
- void tearDown() {
- XMLObjectBuilder::deregisterBuilder(m_qname);
- Marshaller::deregisterMarshaller(m_qname);
- Unmarshaller::deregisterUnmarshaller(m_qname);
- }
+ void setUp() {\r
+ XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());\r
+ Marshaller::registerMarshaller(m_qname, new SimpleXMLObjectMarshaller());\r
+ Unmarshaller::registerUnmarshaller(m_qname, new SimpleXMLObjectUnmarshaller());\r
+ }\r
+\r
+ void tearDown() {\r
+ XMLObjectBuilder::deregisterBuilder(m_qname);\r
+ Marshaller::deregisterMarshaller(m_qname);\r
+ Unmarshaller::deregisterUnmarshaller(m_qname);\r
+ }\r
\r
void testUnmarshallingWithAttributes() {\r
- ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithAttribute.xml");\r
+ TS_TRACE("testUnmarshallingWithAttributes");\r
+\r
+ string path=data_path + "SimpleXMLObjectWithAttribute.xml";\r
+ ifstream fs(path.c_str());\r
DOMDocument* doc=nonvalidatingPool->parse(fs);\r
TS_ASSERT(doc!=NULL);\r
\r
auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\r
TS_ASSERT(sxObject.get()!=NULL);\r
\r
- auto_ptr_XMLCh expectedId("Firefly");\r
- TSM_ASSERT_SAME_DATA("ID was not expected value", expectedId.get(), sxObject->getId(), XMLString::stringLen(expectedId.get()));\r
+ auto_ptr_XMLCh expected("Firefly");\r
+ TSM_ASSERT_SAME_DATA("ID was not expected value", expected.get(), sxObject->getId(), XMLString::stringLen(expected.get()));\r
+ }\r
+\r
+ void testUnmarshallingWithElementContent() {\r
+ TS_TRACE("testUnmarshallingWithElementContent");\r
+\r
+ string path=data_path + "SimpleXMLObjectWithContent.xml";\r
+ ifstream fs(path.c_str());\r
+ 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
+\r
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\r
+ TS_ASSERT(sxObject.get()!=NULL);\r
+\r
+ auto_ptr_XMLCh expected("Sample Content");\r
+ TSM_ASSERT_SAME_DATA("Element content was not expected value", expected.get(), sxObject->getValue(), XMLString::stringLen(expected.get()));\r
+ }\r
+\r
+ void testUnmarshallingWithChildElements() {\r
+ TS_TRACE("testUnmarshallingWithChildElements");\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 Unmarshaller* u = Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
+ TS_ASSERT(u!=NULL);\r
+\r
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\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
+ }\r
+\r
+ void testUnmarshallingWithUnknownChild() {\r
+ TS_TRACE("testUnmarshallingWithUnknownChild");\r
+\r
+ string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";\r
+ ifstream fs(path.c_str());\r
+ 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
+\r
+ TS_ASSERT_THROWS(u->unmarshall(doc->getDocumentElement(),true),UnmarshallingException);\r
+ doc->release();\r
}\r
};\r