--- /dev/null
+/*\r
+ * Copyright 2001-2005 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include "XMLObjectBaseTestCase.h"\r
+\r
+#include <fstream>\r
+\r
+class MarshallingTest : public CxxTest::TestSuite {\r
+ QName m_qname;\r
+public:\r
+ MarshallingTest() : 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
+ }\r
+\r
+ void tearDown() {\r
+ XMLObjectBuilder::deregisterBuilder(m_qname);\r
+ Marshaller::deregisterMarshaller(m_qname);\r
+ Unmarshaller::deregisterUnmarshaller(m_qname);\r
+ }\r
+\r
+ void testMarshallingWithAttributes() {\r
+ TS_TRACE("testMarshallingWithAttributes");\r
+\r
+ auto_ptr_XMLCh expected("Firefly");\r
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(XMLObjectBuilder::getBuilder(m_qname)->buildObject()));\r
+ TS_ASSERT(sxObject.get()!=NULL);\r
+ sxObject->setId(expected.get());\r
+ \r
+ DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get());\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
+ TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));\r
+ doc->release();\r
+ }\r
+\r
+ void testMarshallingWithElementContent() {\r
+ TS_TRACE("testMarshallingWithElementContent");\r
+\r
+ auto_ptr_XMLCh expected("Sample Content");\r
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(XMLObjectBuilder::getBuilder(m_qname)->buildObject()));\r
+ TS_ASSERT(sxObject.get()!=NULL);\r
+ sxObject->setValue(expected.get());\r
+ \r
+ DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get());\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
+ TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));\r
+ doc->release();\r
+ }\r
+\r
+ void testMarshallingWithChildElements() {\r
+ TS_TRACE("testMarshallingWithChildElements");\r
+\r
+ const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(m_qname);\r
+ TS_ASSERT(b!=NULL);\r
+ \r
+ auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(b->buildObject()));\r
+ TS_ASSERT(sxObject.get()!=NULL);\r
+ sxObject->getSimpleXMLObjects().push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));\r
+ sxObject->getSimpleXMLObjects().push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));\r
+ \r
+ DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get());\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
+ TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));\r
+ doc->release();\r
+ }\r
+\r
+};\r