diff --git a/samples/CreateDOMDocument/CreateDOMDocument.cpp b/samples/CreateDOMDocument/CreateDOMDocument.cpp index ab234409dbd36669f814ab8462b9148adf1099fa..b8c0fc95efde4aa783a762524d54b5bc58d2e99c 100644 --- a/samples/CreateDOMDocument/CreateDOMDocument.cpp +++ b/samples/CreateDOMDocument/CreateDOMDocument.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.7 2001/10/26 11:55:46 tng + * Nest entire test in an inner block for reference counting to recover all document storage when this block exits before XMLPlatformUtils::Terminate is called. + * * Revision 1.6 2001/10/19 19:02:42 tng * [Bug 3909] return non-zero an exit code when error was encounted. * And other modification for consistent help display and return code across samples. @@ -131,55 +134,60 @@ int main(int argC, char* argV[]) return 1; } - // The tree we create below is the same that the DOMParser would - // have created, except that no whitespace text nodes would be created. + { + // Nest entire test in an inner block. + // Reference counting should recover all document + // storage when this block exits. + // The tree we create below is the same that the DOMParser would + // have created, except that no whitespace text nodes would be created. - // <company> - // <product>Xerces-C</product> - // <category idea='great'>XML Parsing Tools</category> - // <developedBy>Apache Software Foundation</developedBy> - // </company> + // <company> + // <product>Xerces-C</product> + // <category idea='great'>XML Parsing Tools</category> + // <developedBy>Apache Software Foundation</developedBy> + // </company> - DOM_DOMImplementation impl; + DOM_DOMImplementation impl; - DOM_Document doc = impl.createDocument( - 0, // root element namespace URI. - "company", // root element name - DOM_DocumentType()); // document type object (DTD). + DOM_Document doc = impl.createDocument( + 0, // root element namespace URI. + "company", // root element name + DOM_DocumentType()); // document type object (DTD). - DOM_Element rootElem = doc.getDocumentElement(); + DOM_Element rootElem = doc.getDocumentElement(); - DOM_Element prodElem = doc.createElement("product"); - rootElem.appendChild(prodElem); + DOM_Element prodElem = doc.createElement("product"); + rootElem.appendChild(prodElem); - DOM_Text prodDataVal = doc.createTextNode("Xerces-C"); - prodElem.appendChild(prodDataVal); + DOM_Text prodDataVal = doc.createTextNode("Xerces-C"); + prodElem.appendChild(prodDataVal); - DOM_Element catElem = doc.createElement("category"); - rootElem.appendChild(catElem); - catElem.setAttribute("idea", "great"); + DOM_Element catElem = doc.createElement("category"); + rootElem.appendChild(catElem); + catElem.setAttribute("idea", "great"); - DOM_Text catDataVal = doc.createTextNode("XML Parsing Tools"); - catElem.appendChild(catDataVal); + DOM_Text catDataVal = doc.createTextNode("XML Parsing Tools"); + catElem.appendChild(catDataVal); - DOM_Element devByElem = doc.createElement("developedBy"); - rootElem.appendChild(devByElem); + DOM_Element devByElem = doc.createElement("developedBy"); + rootElem.appendChild(devByElem); - DOM_Text devByDataVal = doc.createTextNode("Apache Software Foundation"); - devByElem.appendChild(devByDataVal); + DOM_Text devByDataVal = doc.createTextNode("Apache Software Foundation"); + devByElem.appendChild(devByDataVal); - // - // Now count the number of elements in the above DOM tree. - // + // + // Now count the number of elements in the above DOM tree. + // - unsigned int elementCount = doc.getElementsByTagName("*").getLength(); - cout << "The tree just created contains: " << elementCount - << " elements." << endl; + unsigned int elementCount = doc.getElementsByTagName("*").getLength(); + cout << "The tree just created contains: " << elementCount + << " elements." << endl; - // - // The DOM document and its contents are reference counted, and need - // no explicit deletion. - // + // + // The DOM document and its contents are reference counted, and need + // no explicit deletion. + // + } XMLPlatformUtils::Terminate(); return 0; } diff --git a/tests/DOM/DOMIDTest/DOMIDTest.cpp b/tests/DOM/DOMIDTest/DOMIDTest.cpp index f3275ca264c63cc8586ae42b987c3c19aaab014c..966a0fb9be8f68354593ea770f3c1d709abfcb85 100644 --- a/tests/DOM/DOMIDTest/DOMIDTest.cpp +++ b/tests/DOM/DOMIDTest/DOMIDTest.cpp @@ -196,95 +196,100 @@ int main() return 1; } - bool doValidation = true; - bool doNamespaces = false; + { + // Nest entire test in an inner block. + // Reference counting should recover all document + // storage when this block exits. + bool doValidation = true; + bool doNamespaces = false; - DOMParser *parser = new DOMParser; - parser->setDoValidation(doValidation); - parser->setDoNamespaces(doNamespaces); + DOMParser *parser = new DOMParser; + parser->setDoValidation(doValidation); + parser->setDoNamespaces(doNamespaces); - ErrorHandler *ehandler = new SimpleErrorHandler(); - parser->setErrorHandler(ehandler); + ErrorHandler *ehandler = new SimpleErrorHandler(); + parser->setErrorHandler(ehandler); - MemBufInputSource* memBufIS = new MemBufInputSource ( - (const XMLByte*)TestDoc1, - strlen(TestDoc1), - "TestDoc1", - false - ); - parser->parse(*memBufIS); + MemBufInputSource* memBufIS = new MemBufInputSource ( + (const XMLByte*)TestDoc1, + strlen(TestDoc1), + "TestDoc1", + false + ); + parser->parse(*memBufIS); - DOM_Document doc = parser->getDocument(); + DOM_Document doc = parser->getDocument(); - DomMemDebug entryMemState, exitMemState; + DomMemDebug entryMemState, exitMemState; - TESTPROLOG; - { - DOM_Element elA = doc.getElementById("a001"); - TASSERT(elA != 0); + TESTPROLOG; + { + DOM_Element elA = doc.getElementById("a001"); + TASSERT(elA != 0); - DOM_Element elB = doc.getElementById("a002"); - TASSERT(elB == 0); + DOM_Element elB = doc.getElementById("a002"); + TASSERT(elB == 0); - DOM_Element elC = doc.getElementById("a003"); - TASSERT(elC != 0); - TASSERT(elC != elA); + DOM_Element elC = doc.getElementById("a003"); + TASSERT(elC != 0); + TASSERT(elC != elA); - DOMString s = elA.getAttribute("id"); - TASSERT(s.equals("a001")); + DOMString s = elA.getAttribute("id"); + TASSERT(s.equals("a001")); - s = elC.getAttribute("id"); - TASSERT(s.equals("a003")); + s = elC.getAttribute("id"); + TASSERT(s.equals("a003")); - } - TESTEPILOG; + } + TESTEPILOG; - parser->parse(*memBufIS); - doc = parser->getDocument(); - TESTPROLOG; - { - // This one should get an element - DOM_Element elA = doc.getElementById("a001"); - TASSERT(!elA.isNull()); + parser->parse(*memBufIS); + doc = parser->getDocument(); + TESTPROLOG; + { + // This one should get an element + DOM_Element elA = doc.getElementById("a001"); + TASSERT(!elA.isNull()); - elA.setAttribute("id", "a004"); + elA.setAttribute("id", "a004"); - // This one should NOT get an element - elA = doc.getElementById("a001"); - TASSERT(elA.isNull()); - }; + // This one should NOT get an element + elA = doc.getElementById("a001"); + TASSERT(elA.isNull()); + }; - parser->parse(*memBufIS); - doc = parser->getDocument(); - TESTPROLOG; - { - // This one should get an element - DOM_Element elA = doc.getElementById("a001"); - TASSERT(!elA.isNull()); - - DOM_Node parent = elA.getParentNode(); - DOM_Node removed = parent.removeChild(elA); - removed = 0; - elA = 0; - - // This one should NOT get an element - elA = doc.getElementById("a001"); - TASSERT(elA.isNull()); - } + parser->parse(*memBufIS); + doc = parser->getDocument(); + TESTPROLOG; + { + // This one should get an element + DOM_Element elA = doc.getElementById("a001"); + TASSERT(!elA.isNull()); - doc = 0; - delete parser; - delete memBufIS; - delete ehandler; + DOM_Node parent = elA.getParentNode(); + DOM_Node removed = parent.removeChild(elA); + removed = 0; + elA = 0; + + // This one should NOT get an element + elA = doc.getElementById("a001"); + TASSERT(elA.isNull()); + } + + doc = 0; + delete parser; + delete memBufIS; + delete ehandler; + } // // Print Final allocation stats for full set of tests // - XMLPlatformUtils::Terminate(); DomMemDebug().print(); + XMLPlatformUtils::Terminate(); return 0;