2 * Copyright 2001-2005 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "XMLObjectBaseTestCase.h"
\r
21 class MarshallingTest : public CxxTest::TestSuite {
\r
24 MarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME) {}
\r
27 XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());
\r
28 Marshaller::registerMarshaller(m_qname, new SimpleXMLObjectMarshaller());
\r
29 Unmarshaller::registerUnmarshaller(m_qname, new SimpleXMLObjectUnmarshaller());
\r
33 XMLObjectBuilder::deregisterBuilder(m_qname);
\r
34 Marshaller::deregisterMarshaller(m_qname);
\r
35 Unmarshaller::deregisterUnmarshaller(m_qname);
\r
38 void testMarshallingWithAttributes() {
\r
39 TS_TRACE("testMarshallingWithAttributes");
\r
41 auto_ptr_XMLCh expected("Firefly");
\r
42 auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(XMLObjectBuilder::getBuilder(m_qname)->buildObject()));
\r
43 TS_ASSERT(sxObject.get()!=NULL);
\r
44 sxObject->setId(expected.get());
\r
46 DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get());
\r
48 string path=data_path + "SimpleXMLObjectWithAttribute.xml";
\r
49 ifstream fs(path.c_str());
\r
50 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
51 TS_ASSERT(doc!=NULL);
\r
53 TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));
\r
57 void testMarshallingWithElementContent() {
\r
58 TS_TRACE("testMarshallingWithElementContent");
\r
60 auto_ptr_XMLCh expected("Sample Content");
\r
61 auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(XMLObjectBuilder::getBuilder(m_qname)->buildObject()));
\r
62 TS_ASSERT(sxObject.get()!=NULL);
\r
63 sxObject->setValue(expected.get());
\r
65 DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get());
\r
67 string path=data_path + "SimpleXMLObjectWithContent.xml";
\r
68 ifstream fs(path.c_str());
\r
69 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
70 TS_ASSERT(doc!=NULL);
\r
72 TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));
\r
76 void testMarshallingWithChildElements() {
\r
77 TS_TRACE("testMarshallingWithChildElements");
\r
79 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(m_qname);
\r
82 auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
\r
83 TS_ASSERT(sxObject.get()!=NULL);
\r
84 VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
\r
85 kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
\r
86 kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
\r
87 kids.push_back(dynamic_cast<SimpleXMLObject*>(b->buildObject()));
\r
89 // Test some collection stuff
\r
90 auto_ptr_XMLCh foo("Foo");
\r
91 auto_ptr_XMLCh bar("Bar");
\r
92 kids.begin()->setId(foo.get());
\r
93 kids.at(2)->setValue(bar.get());
\r
94 kids.erase(kids.begin()+1);
\r
95 TS_ASSERT_SAME_DATA(kids.back()->getValue(), bar.get(), XMLString::stringLen(bar.get()));
\r
97 DOMElement* rootElement = Marshaller::getMarshaller(sxObject.get())->marshall(sxObject.get());
\r
99 string path=data_path + "SimpleXMLObjectWithChildren.xml";
\r
100 ifstream fs(path.c_str());
\r
101 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
102 TS_ASSERT(doc!=NULL);
\r
104 TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));
\r