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
31 XMLObjectBuilder::deregisterBuilder(m_qname);
\r
34 void testMarshallingWithAttributes() {
\r
35 TS_TRACE("testMarshallingWithAttributes");
\r
37 auto_ptr_XMLCh expected("Firefly");
\r
38 auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(XMLObjectBuilder::getBuilder(m_qname)->buildObject()));
\r
39 TS_ASSERT(sxObject.get()!=NULL);
\r
40 sxObject->setId(expected.get());
\r
42 DOMElement* rootElement = sxObject->marshall();
\r
44 string path=data_path + "SimpleXMLObjectWithAttribute.xml";
\r
45 ifstream fs(path.c_str());
\r
46 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
47 TS_ASSERT(doc!=NULL);
\r
49 TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));
\r
53 void testMarshallingWithElementContent() {
\r
54 TS_TRACE("testMarshallingWithElementContent");
\r
56 auto_ptr_XMLCh expected("Sample Content");
\r
57 auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(XMLObjectBuilder::getBuilder(m_qname)->buildObject()));
\r
58 TS_ASSERT(sxObject.get()!=NULL);
\r
59 sxObject->setValue(expected.get());
\r
61 DOMElement* rootElement = sxObject->marshall();
\r
63 string path=data_path + "SimpleXMLObjectWithContent.xml";
\r
64 ifstream fs(path.c_str());
\r
65 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
66 TS_ASSERT(doc!=NULL);
\r
68 TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));
\r
72 void testMarshallingWithChildElements() {
\r
73 TS_TRACE("testMarshallingWithChildElements");
\r
75 const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(m_qname));
\r
78 auto_ptr<SimpleXMLObject> sxObject(b->buildObject());
\r
79 TS_ASSERT(sxObject.get()!=NULL);
\r
80 VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
\r
81 kids.push_back(b->buildObject());
\r
82 kids.push_back(b->buildObject());
\r
83 kids.push_back(b->buildObject());
\r
85 // Test some collection stuff
\r
86 auto_ptr_XMLCh foo("Foo");
\r
87 auto_ptr_XMLCh bar("Bar");
\r
88 kids.begin()->setId(foo.get());
\r
89 kids.at(2)->setValue(bar.get());
\r
90 kids.erase(kids.begin()+1);
\r
91 TS_ASSERT_SAME_DATA(kids.back()->getValue(), bar.get(), XMLString::stringLen(bar.get()));
\r
93 DOMElement* rootElement = sxObject->marshall();
\r
95 string path=data_path + "SimpleXMLObjectWithChildren.xml";
\r
96 ifstream fs(path.c_str());
\r
97 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
98 TS_ASSERT(doc!=NULL);
\r
100 TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));
\r