X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltoolingtest%2Fxmltoolingtest.h;h=fe1e867e834f0b7bda2e428895a9c10ef0d8fd8f;hb=29ac236d46c15d0183af0fa084b703bd2e05d64c;hp=f3fb5af83e979f2f1954e6d836c0a04ce651a28f;hpb=e963983abe628f963602015344ad8fd65e4fe406;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltoolingtest/xmltoolingtest.h b/xmltoolingtest/xmltoolingtest.h index f3fb5af..fe1e867 100644 --- a/xmltoolingtest/xmltoolingtest.h +++ b/xmltoolingtest/xmltoolingtest.h @@ -14,31 +14,31 @@ * limitations under the License. */ -#include -#include +#include "XMLObjectBaseTestCase.h" +#include +#include #include #include -using namespace xmltooling; +//#define XMLTOOLINGTEST_LEAKCHECK -ParserPool* validatingPool=NULL; -ParserPool* nonvalidatingPool=NULL; +std::string data_path = "../xmltoolingtest/data/"; class ToolingFixture : public CxxTest::GlobalFixture { public: bool setUpWorld() { - XMLToolingConfig::getConfig().log_config("DEBUG"); + XMLToolingConfig::getConfig().log_config(); if (!XMLToolingConfig::getConfig().init()) return false; - validatingPool = new ParserPool(true,true); - nonvalidatingPool = new ParserPool(); - return true; + if (getenv("XMLTOOLINGTEST_DATA")) + data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/"; + std::string catpath=data_path + "catalog.xml"; + auto_ptr_XMLCh temp(catpath.c_str()); + return XMLToolingConfig::getConfig().getValidatingParser().loadCatalog(temp.get()); } bool tearDownWorld() { - delete validatingPool; - delete nonvalidatingPool; XMLToolingConfig::getConfig().term(); #if defined(_MSC_VER ) && defined(XMLTOOLINGTEST_LEAKCHECK) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); @@ -57,11 +57,68 @@ public: static ToolingFixture globalFixture; -class CatalogTest : public CxxTest::TestSuite +class GlobalTest : public CxxTest::TestSuite { public: - void testCatalog(void) { - auto_ptr_XMLCh temp("../xmltoolingtest/data/catalog.xml"); - TS_ASSERT(validatingPool->loadCatalog(temp.get())); + void setUp() { + XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder()); + } + + void tearDown() { + XMLObjectBuilder::deregisterDefaultBuilder(); + } + + void testUnknown() { + ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml"); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); + TS_ASSERT(doc!=NULL); + + string buf1; + XMLHelper::serialize(doc->getDocumentElement(), buf1); + + const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement()); + TS_ASSERT(b!=NULL); + + auto_ptr xmlObject(b->buildFromDocument(doc)); // bind document + TS_ASSERT(xmlObject.get()!=NULL); + + auto_ptr clonedObject(xmlObject->clone()); + TS_ASSERT(clonedObject.get()!=NULL); + + DOMElement* rootElement=clonedObject->marshall(); + TS_ASSERT(rootElement!=NULL); + + // should reuse DOM + TS_ASSERT(rootElement==clonedObject->marshall()); + + string buf2; + XMLHelper::serialize(rootElement, buf2); + TS_ASSERT_EQUALS(buf1,buf2); + } + + void testUnknownWithDocChange() { + ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml"); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); + TS_ASSERT(doc!=NULL); + + string buf1; + XMLHelper::serialize(doc->getDocumentElement(), buf1); + + const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(doc->getDocumentElement()); + TS_ASSERT(b!=NULL); + + auto_ptr xmlObject(b->buildFromDocument(doc)); // bind document + TS_ASSERT(xmlObject.get()!=NULL); + + DOMDocument* newDoc=XMLToolingConfig::getConfig().getParser().newDocument(); + DOMElement* rootElement=xmlObject->marshall(newDoc); + TS_ASSERT(rootElement!=NULL); + + string buf2; + XMLHelper::serialize(rootElement, buf2); + TS_ASSERT_EQUALS(buf1,buf2); + + newDoc->release(); } }; +