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
20 #include <xmltooling/io/Marshaller.h>
\r
21 #include <xmltooling/io/Unmarshaller.h>
\r
24 class UnknownTest : public CxxTest::TestSuite {
\r
27 void testUnknown() {
\r
28 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
\r
29 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
30 TS_ASSERT(doc!=NULL);
\r
33 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
35 const Unmarshaller* u=Unmarshaller::getUnmarshaller(doc->getDocumentElement());
\r
38 auto_ptr<XMLObject> xmlObject(u->unmarshall(doc->getDocumentElement(),true)); // bind document
\r
39 TS_ASSERT(xmlObject.get()!=NULL);
\r
41 auto_ptr<XMLObject> clonedObject(xmlObject->clone());
\r
42 TS_ASSERT(clonedObject.get()!=NULL);
\r
44 const Marshaller* m=Marshaller::getMarshaller(clonedObject.get());
\r
47 DOMElement* rootElement=m->marshall(clonedObject.get());
\r
48 TS_ASSERT(rootElement!=NULL);
\r
50 rootElement=m->marshall(clonedObject.get()); // should reuse DOM
\r
51 TS_ASSERT(rootElement!=NULL);
\r
54 XMLHelper::serialize(rootElement, buf2);
\r
55 TS_ASSERT_EQUALS(buf1,buf2);
\r
58 void testUnknownWithDocChange() {
\r
59 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
\r
60 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
61 TS_ASSERT(doc!=NULL);
\r
64 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
66 const Unmarshaller* u=Unmarshaller::getUnmarshaller(doc->getDocumentElement());
\r
69 auto_ptr<XMLObject> xmlObject(u->unmarshall(doc->getDocumentElement(),true)); // bind document
\r
70 TS_ASSERT(xmlObject.get()!=NULL);
\r
72 const Marshaller* m=Marshaller::getMarshaller(xmlObject.get());
\r
75 DOMDocument* newDoc=nonvalidatingPool->newDocument();
\r
76 DOMElement* rootElement=m->marshall(xmlObject.get(), newDoc);
\r
77 TS_ASSERT(rootElement!=NULL);
\r
80 XMLHelper::serialize(rootElement, buf2);
\r
81 TS_ASSERT_EQUALS(buf1,buf2);
\r