X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltoolingtest%2Fxmltoolingtest.h;h=fe1e867e834f0b7bda2e428895a9c10ef0d8fd8f;hb=38003505e53ef5b8c2590af38cfbb0d405ad245f;hp=42c21c9ce633070828e93ae8a13d4fb19fe9f3c7;hpb=df9a324e78e2fbb16d458dc4b30e7ebe27a0c934;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltoolingtest/xmltoolingtest.h b/xmltoolingtest/xmltoolingtest.h index 42c21c9..fe1e867 100644 --- a/xmltoolingtest/xmltoolingtest.h +++ b/xmltoolingtest/xmltoolingtest.h @@ -14,16 +14,15 @@ * 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 @@ -33,15 +32,13 @@ public: XMLToolingConfig::getConfig().log_config(); if (!XMLToolingConfig::getConfig().init()) return false; - validatingPool = new ParserPool(true,true); - nonvalidatingPool = new ParserPool(); if (getenv("XMLTOOLINGTEST_DATA")) data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/"; - return true; + 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 ); @@ -60,12 +57,68 @@ public: static ToolingFixture globalFixture; -class CatalogTest : public CxxTest::TestSuite +class GlobalTest : public CxxTest::TestSuite { public: - void testCatalog(void) { - std::string path=data_path + "catalog.xml"; - auto_ptr_XMLCh temp(path.c_str()); - 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(); } }; +