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 ParserPool* validatingPool=NULL;
\r
25 ParserPool* nonvalidatingPool=NULL;
\r
26 std::string data_path = "../xmltoolingtest/data/";
\r
28 class ToolingFixture : public CxxTest::GlobalFixture
\r
32 XMLToolingConfig::getConfig().log_config();
\r
33 if (!XMLToolingConfig::getConfig().init())
\r
35 validatingPool = new ParserPool(true,true);
\r
36 nonvalidatingPool = new ParserPool();
\r
37 if (getenv("XMLTOOLINGTEST_DATA"))
\r
38 data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/";
\r
41 bool tearDownWorld() {
\r
42 delete validatingPool;
\r
43 delete nonvalidatingPool;
\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 testCatalog(void) {
\r
74 std::string path=data_path + "catalog.xml";
\r
75 auto_ptr_XMLCh temp(path.c_str());
\r
76 TS_ASSERT(validatingPool->loadCatalog(temp.get()));
\r
79 void testUnknown() {
\r
80 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
\r
81 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
82 TS_ASSERT(doc!=NULL);
\r
85 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
87 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
90 auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document
\r
91 TS_ASSERT(xmlObject.get()!=NULL);
\r
93 auto_ptr<XMLObject> clonedObject(xmlObject->clone());
\r
94 TS_ASSERT(clonedObject.get()!=NULL);
\r
96 DOMElement* rootElement=clonedObject->marshall();
\r
97 TS_ASSERT(rootElement!=NULL);
\r
100 TS_ASSERT(rootElement==clonedObject->marshall());
\r
103 XMLHelper::serialize(rootElement, buf2);
\r
104 TS_ASSERT_EQUALS(buf1,buf2);
\r
107 void testUnknownWithDocChange() {
\r
108 ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
\r
109 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
110 TS_ASSERT(doc!=NULL);
\r
113 XMLHelper::serialize(doc->getDocumentElement(), buf1);
\r
115 const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
116 TS_ASSERT(b!=NULL);
\r
118 auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document
\r
119 TS_ASSERT(xmlObject.get()!=NULL);
\r
121 DOMDocument* newDoc=nonvalidatingPool->newDocument();
\r
122 DOMElement* rootElement=xmlObject->marshall(newDoc);
\r
123 TS_ASSERT(rootElement!=NULL);
\r
126 XMLHelper::serialize(rootElement, buf2);
\r
127 TS_ASSERT_EQUALS(buf1,buf2);
\r