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
22 class UnknownTest : public CxxTest::TestSuite {
\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
31 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
33 const Unmarshaller* u=Unmarshaller::getUnmarshaller(doc->getDocumentElement());
\r
36 auto_ptr<XMLObject> xmlObject(u->unmarshall(doc->getDocumentElement(),true)); // bind document
\r
37 TS_ASSERT(xmlObject.get()!=NULL);
\r
39 auto_ptr<XMLObject> clonedObject(xmlObject->clone());
\r
40 TS_ASSERT(clonedObject.get()!=NULL);
\r
42 const Marshaller* m=Marshaller::getMarshaller(clonedObject.get());
\r
45 DOMElement* rootElement=m->marshall(clonedObject.get());
\r
46 TS_ASSERT(rootElement!=NULL);
\r
48 rootElement=m->marshall(clonedObject.get()); // should reuse DOM
\r
49 TS_ASSERT(rootElement!=NULL);
\r
52 XMLHelper::serialize(rootElement, buf2);
\r
53 TS_ASSERT_EQUALS(buf1,buf2);
\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
62 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
64 const Unmarshaller* u=Unmarshaller::getUnmarshaller(doc->getDocumentElement());
\r
67 auto_ptr<XMLObject> xmlObject(u->unmarshall(doc->getDocumentElement(),true)); // bind document
\r
68 TS_ASSERT(xmlObject.get()!=NULL);
\r
70 const Marshaller* m=Marshaller::getMarshaller(xmlObject.get());
\r
73 DOMDocument* newDoc=nonvalidatingPool->newDocument();
\r
74 DOMElement* rootElement=m->marshall(xmlObject.get(), newDoc);
\r
75 TS_ASSERT(rootElement!=NULL);
\r
78 XMLHelper::serialize(rootElement, buf2);
\r
79 TS_ASSERT_EQUALS(buf1,buf2);
\r