2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "XMLObjectBaseTestCase.h"
20 #include <cxxtest/GlobalFixture.h>
21 #include <xmltooling/XMLToolingConfig.h>
22 #include <xmltooling/util/ParserPool.h>
24 //#define XMLTOOLINGTEST_LEAKCHECK
26 std::string data_path = "../xmltoolingtest/data/";
28 class ToolingFixture : public CxxTest::GlobalFixture
32 XMLToolingConfig::getConfig().log_config();
34 if (getenv("XMLTOOLINGTEST_DATA"))
35 data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/";
36 XMLToolingConfig::getConfig().catalog_path = data_path + "catalog.xml";
38 if (!XMLToolingConfig::getConfig().init())
43 bool tearDownWorld() {
44 XMLToolingConfig::getConfig().term();
45 #if defined(_MSC_VER ) && defined(XMLTOOLINGTEST_LEAKCHECK)
46 _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
47 _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
48 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
49 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
50 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
51 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
52 _CrtDumpMemoryLeaks();
56 //bool setUp() { printf( "</test>" ); return true; }
57 //bool tearDown() { printf( "</test>" ); return true; }
60 static ToolingFixture globalFixture;
62 class GlobalTest : public CxxTest::TestSuite
66 XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder());
70 XMLObjectBuilder::deregisterDefaultBuilder();
74 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
75 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
79 XMLHelper::serialize(doc->getDocumentElement(), buf1);
81 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());
84 auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document
85 TS_ASSERT(xmlObject.get()!=NULL);
87 auto_ptr<XMLObject> clonedObject(xmlObject->clone());
88 TS_ASSERT(clonedObject.get()!=NULL);
90 DOMElement* rootElement=clonedObject->marshall();
91 TS_ASSERT(rootElement!=NULL);
94 TS_ASSERT(rootElement==clonedObject->marshall());
97 XMLHelper::serialize(rootElement, buf2);
98 TS_ASSERT_EQUALS(buf1,buf2);
101 void testUnknownWithDocChange() {
102 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
103 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
104 TS_ASSERT(doc!=NULL);
107 XMLHelper::serialize(doc->getDocumentElement(), buf1);
109 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());
112 auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document
113 TS_ASSERT(xmlObject.get()!=NULL);
115 DOMDocument* newDoc=XMLToolingConfig::getConfig().getParser().newDocument();
116 DOMElement* rootElement=xmlObject->marshall(newDoc);
117 TS_ASSERT(rootElement!=NULL);
120 XMLHelper::serialize(rootElement, buf2);
121 TS_ASSERT_EQUALS(buf1,buf2);