Merged marshalling/unmarshalling methods into core interface.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / ComplexXMLObjectTest.h
1 /*\r
2  *  Copyright 2001-2005 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 #include "XMLObjectBaseTestCase.h"\r
18 \r
19 #include <fstream>\r
20 #include <xercesc/util/XMLUniDefs.hpp>\r
21 \r
22 class ComplexXMLObjectTest : public CxxTest::TestSuite {\r
23 public:\r
24     ComplexXMLObjectTest() {}\r
25 \r
26     void setUp() {\r
27         XMLObjectBuilder::registerDefaultBuilder(new WildcardXMLObjectBuilder());\r
28     }\r
29 \r
30     void tearDown() {\r
31         //XMLObjectBuilder::deregisterDefaultBuilder();\r
32     }\r
33 \r
34     void testComplexUnmarshalling() {\r
35         TS_TRACE("testComplexUnmarshalling");\r
36 \r
37         string path=data_path + "ComplexXMLObject.xml";\r
38         ifstream fs(path.c_str());\r
39         DOMDocument* doc=nonvalidatingPool->parse(fs);\r
40         TS_ASSERT(doc!=NULL);\r
41 \r
42         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
43         TS_ASSERT(b!=NULL);\r
44 \r
45         auto_ptr<WildcardXMLObject> wcObject(\r
46             dynamic_cast<WildcardXMLObject*>(b->buildObject(doc->getDocumentElement())->unmarshall(doc->getDocumentElement(),true))\r
47             );\r
48         TS_ASSERT(wcObject.get()!=NULL);\r
49 \r
50         ListOf(XMLObject) kids=wcObject->getXMLObjects();\r
51         TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size());\r
52         \r
53         WildcardXMLObject* wc1=dynamic_cast<WildcardXMLObject*>(*(++kids.begin()));\r
54         WildcardXMLObject* wc2=dynamic_cast<WildcardXMLObject*>(*(++(wc1->getXMLObjects().begin())));\r
55         TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, wc2->getXMLObjects().size());\r
56 \r
57         static const XMLCh html[] = {chLatin_h, chLatin_t, chLatin_m, chLatin_l, chNull};\r
58         static const XMLCh div[] = {chLatin_d, chLatin_i, chLatin_v, chNull};\r
59         auto_ptr_XMLCh htmlns("http://www.w3.org/1999/xhtml");\r
60         QName q(htmlns.get(),div,html);\r
61         ListOf(XMLObject)::const_iterator it=wc2->getXMLObjects().begin();\r
62         ++it; ++it;\r
63         TSM_ASSERT_EQUALS("Element QName unexpected", it->getElementQName(),q);\r
64     }\r
65 \r
66 };\r