Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / ComplexXMLObjectTest.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "XMLObjectBaseTestCase.h"
22
23 #include <fstream>
24 #include <xercesc/util/XMLUniDefs.hpp>
25
26 class ComplexXMLObjectTest : public CxxTest::TestSuite {
27 public:
28     ComplexXMLObjectTest() {}
29
30     void setUp() {
31         XMLObjectBuilder::registerDefaultBuilder(new AnyElementBuilder());
32     }
33
34     void tearDown() {
35         XMLObjectBuilder::deregisterDefaultBuilder();
36     }
37
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);
44
45         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
46         TS_ASSERT(b!=nullptr);
47
48         auto_ptr<ElementProxy> wcObject(
49             dynamic_cast<ElementProxy*>(b->buildFromDocument(doc, false))
50             );
51         TS_ASSERT(wcObject.get()!=nullptr);
52         
53         VectorOf(XMLObject) kids=wcObject->getUnknownXMLObjects();
54         TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size());
55         
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());
59
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);
65
66         DOMElement* rebuilt = wcObject->marshall(XMLToolingConfig::getConfig().getParser().newDocument());
67         wcObject->setDocument(rebuilt->getOwnerDocument());
68         TS_ASSERT(rebuilt->isEqualNode(doc->getDocumentElement()));
69     }
70
71 };