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 <cxxtest/GlobalFixture.h>
\r
21 #include <xmltooling/XMLToolingConfig.h>
\r
22 #include <xmltooling/util/ParserPool.h>
\r
24 //#define XMLTOOLINGTEST_LEAKCHECK
\r
26 std::string data_path = "../xmltoolingtest/data/";
\r
28 class ToolingFixture : public CxxTest::GlobalFixture
\r
32 XMLToolingConfig::getConfig().log_config();
\r
34 if (getenv("XMLTOOLINGTEST_DATA"))
\r
35 data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/";
\r
36 XMLToolingConfig::getConfig().catalog_path = data_path + "catalog.xml";
\r
38 if (!XMLToolingConfig::getConfig().init())
\r
43 bool tearDownWorld() {
\r
44 XMLToolingConfig::getConfig().term();
\r
45 #if defined(_MSC_VER ) && defined(XMLTOOLINGTEST_LEAKCHECK)
\r
46 _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
\r
47 _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
\r
48 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
\r
49 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
\r
50 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
\r
51 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
\r
52 _CrtDumpMemoryLeaks();
\r
56 //bool setUp() { printf( "</test>" ); return true; }
\r
57 //bool tearDown() { printf( "</test>" ); return true; }
\r
60 static ToolingFixture globalFixture;
\r
62 class GlobalTest : public CxxTest::TestSuite
\r
66 XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder());
\r
70 XMLObjectBuilder::deregisterDefaultBuilder();
\r
73 void testUnknown() {
\r
74 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
\r
75 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
\r
76 TS_ASSERT(doc!=NULL);
\r
79 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
81 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
84 auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document
\r
85 TS_ASSERT(xmlObject.get()!=NULL);
\r
87 auto_ptr<XMLObject> clonedObject(xmlObject->clone());
\r
88 TS_ASSERT(clonedObject.get()!=NULL);
\r
90 DOMElement* rootElement=clonedObject->marshall();
\r
91 TS_ASSERT(rootElement!=NULL);
\r
94 TS_ASSERT(rootElement==clonedObject->marshall());
\r
97 XMLHelper::serialize(rootElement, buf2);
\r
98 TS_ASSERT_EQUALS(buf1,buf2);
\r
101 void testUnknownWithDocChange() {
\r
102 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
\r
103 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
\r
104 TS_ASSERT(doc!=NULL);
\r
107 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
109 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
110 TS_ASSERT(b!=NULL);
\r
112 auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document
\r
113 TS_ASSERT(xmlObject.get()!=NULL);
\r
115 DOMDocument* newDoc=XMLToolingConfig::getConfig().getParser().newDocument();
\r
116 DOMElement* rootElement=xmlObject->marshall(newDoc);
\r
117 TS_ASSERT(rootElement!=NULL);
\r
120 XMLHelper::serialize(rootElement, buf2);
\r
121 TS_ASSERT_EQUALS(buf1,buf2);
\r