2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
21 #include "XMLObjectBaseTestCase.h"
24 #include <xercesc/util/XMLUniDefs.hpp>
26 class ComplexXMLObjectTest : public CxxTest::TestSuite {
28 ComplexXMLObjectTest() {}
31 XMLObjectBuilder::registerDefaultBuilder(new AnyElementBuilder());
35 XMLObjectBuilder::deregisterDefaultBuilder();
38 void testComplexUnmarshalling() {
39 string path=data_path + "ComplexXMLObject.xml";
40 ifstream fs(path.c_str());
41 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
42 TS_ASSERT(doc!=nullptr);
43 XercesJanitor<DOMDocument> janitor(doc);
45 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
46 TS_ASSERT(b!=nullptr);
48 auto_ptr<ElementProxy> wcObject(
49 dynamic_cast<ElementProxy*>(b->buildFromDocument(doc, false))
51 TS_ASSERT(wcObject.get()!=nullptr);
53 VectorOf(XMLObject) kids=wcObject->getUnknownXMLObjects();
54 TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size());
56 ElementProxy* wc1=dynamic_cast<ElementProxy*>(*(++kids.begin()));
57 ElementProxy* wc2=dynamic_cast<ElementProxy*>(*(++(wc1->getUnknownXMLObjects().begin())));
58 TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, wc2->getUnknownXMLObjects().size());
60 static const XMLCh html[] = {chLatin_h, chLatin_t, chLatin_m, chLatin_l, chNull};
61 static const XMLCh div[] = {chLatin_d, chLatin_i, chLatin_v, chNull};
62 auto_ptr_XMLCh htmlns("http://www.w3.org/1999/xhtml");
63 xmltooling::QName q(htmlns.get(),div,html);
64 TSM_ASSERT_EQUALS("Element QName unexpected", wc2->getUnknownXMLObjects()[2]->getElementQName(),q);
66 DOMElement* rebuilt = wcObject->marshall(XMLToolingConfig::getConfig().getParser().newDocument());
67 wcObject->setDocument(rebuilt->getOwnerDocument());
68 TS_ASSERT(rebuilt->isEqualNode(doc->getDocumentElement()));