Fixes for disabling xmlsec
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / UnknownTest.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 \r
21 \r
22 class UnknownTest : public CxxTest::TestSuite {\r
23 public:\r
24 \r
25     void testUnknown() {\r
26         ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");\r
27         DOMDocument* doc=nonvalidatingPool->parse(fs);\r
28         TS_ASSERT(doc!=NULL);\r
29 \r
30         string buf1;\r
31         XMLHelper::serialize(doc->getDocumentElement(), buf1);\r
32 \r
33         const Unmarshaller* u=Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
34         TS_ASSERT(u!=NULL);\r
35 \r
36         auto_ptr<XMLObject> xmlObject(u->unmarshall(doc->getDocumentElement(),true)); // bind document\r
37         TS_ASSERT(xmlObject.get()!=NULL);\r
38 \r
39         auto_ptr<XMLObject> clonedObject(xmlObject->clone());\r
40         TS_ASSERT(clonedObject.get()!=NULL);\r
41 \r
42         const Marshaller* m=Marshaller::getMarshaller(clonedObject.get());\r
43         TS_ASSERT(m!=NULL);\r
44 \r
45         DOMElement* rootElement=m->marshall(clonedObject.get());\r
46         TS_ASSERT(rootElement!=NULL);\r
47 \r
48         rootElement=m->marshall(clonedObject.get());    // should reuse DOM\r
49         TS_ASSERT(rootElement!=NULL);\r
50 \r
51         string buf2;\r
52         XMLHelper::serialize(rootElement, buf2);\r
53         TS_ASSERT_EQUALS(buf1,buf2);\r
54     }\r
55 \r
56     void testUnknownWithDocChange() {\r
57         ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");\r
58         DOMDocument* doc=nonvalidatingPool->parse(fs);\r
59         TS_ASSERT(doc!=NULL);\r
60 \r
61         string buf1;\r
62         XMLHelper::serialize(doc->getDocumentElement(), buf1);\r
63 \r
64         const Unmarshaller* u=Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
65         TS_ASSERT(u!=NULL);\r
66 \r
67         auto_ptr<XMLObject> xmlObject(u->unmarshall(doc->getDocumentElement(),true)); // bind document\r
68         TS_ASSERT(xmlObject.get()!=NULL);\r
69 \r
70         const Marshaller* m=Marshaller::getMarshaller(xmlObject.get());\r
71         TS_ASSERT(m!=NULL);\r
72 \r
73         DOMDocument* newDoc=nonvalidatingPool->newDocument();\r
74         DOMElement* rootElement=m->marshall(xmlObject.get(), newDoc);\r
75         TS_ASSERT(rootElement!=NULL);\r
76 \r
77         string buf2;\r
78         XMLHelper::serialize(rootElement, buf2);\r
79         TS_ASSERT_EQUALS(buf1,buf2);\r
80 \r
81         newDoc->release();\r
82     }\r
83 };\r