You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/09/23 20:27:48 UTC
cvs commit: xml-xerces/c/tests/DOM/DOMTest DTest.cpp DTest.h
tng 2002/09/23 11:27:48
Modified: c/tests/DOM/DOMTest DTest.cpp DTest.h
Log:
DOM L3: Test baseURI. Added by Gareth Reakes and Thomas Ford.
Revision Changes Path
1.31 +253 -0 xml-xerces/c/tests/DOM/DOMTest/DTest.cpp
Index: DTest.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/tests/DOM/DOMTest/DTest.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- DTest.cpp 21 Aug 2002 20:59:11 -0000 1.30
+++ DTest.cpp 23 Sep 2002 18:27:48 -0000 1.31
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.31 2002/09/23 18:27:48 tng
+ * DOM L3: Test baseURI. Added by Gareth Reakes and Thomas Ford.
+ *
* Revision 1.30 2002/08/21 20:59:11 tng
* release the cloned document.
*
@@ -125,6 +128,7 @@
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLException.hpp>
#include <xercesc/util/XMLString.hpp>
+#include <xercesc/parsers/XercesDOMParser.hpp>
#define EXCEPTIONSTEST(operation, expectedException, resultFlag, testNum) \
@@ -1009,6 +1013,10 @@
d->setUserData(tempStr, (void*) tempStr, &userhandler);
d->release();
+ // Test baseURI. BaseURI is set on nodes at parse time so we
+ // cannot use the docBuilder document above
+
+ OK = test.testBaseURI();
};
@@ -4356,6 +4364,251 @@
};
+/**
+ * This method tests setting the DOM Level 3 baseURI attribute at
+ * parse time on nodes from the document personal-schema.xml.xml
+ *
+ */
+
+bool DOMTest::testBaseURI(void) {
+
+ bool OK;
+
+ //Run tests using both setDoNamespaces(true) and (false)
+
+ const char *namespaceResolver;
+ bool namespaceRes = true;
+ bool doSchemaRes = true;
+
+ do {
+
+ //Setup parser
+
+ XercesDOMParser *parser = new XercesDOMParser;
+ parser->setValidationScheme(XercesDOMParser::Val_Auto);
+ parser->setDoNamespaces(namespaceRes);
+ parser->setDoSchema(doSchemaRes);
+ parser->setCreateEntityReferenceNodes(true);
+
+ if(namespaceRes) {
+ namespaceResolver = "setDoNamespaces(true)";
+ }
+ else {
+ namespaceResolver = "setDoNamespaces(false)";
+ }
+
+ try {
+ // this one assumes executing in samples/data where personal-schema.xml resides
+ // please modify if this is not correct
+ parser->parse("personal-schema.xml");
+ }
+
+ catch (...) {
+ fprintf(stderr, "parsing personal-schema.xml failed at line %i\n", __LINE__);
+ return false;
+ }
+
+ // test only if there is no error
+ if (!parser->getErrorCount()) {
+
+ //Setup testing strings
+ XMLCh *fileSchema = XMLString::transcode("file://");
+ XMLCh *filePath = XMLString::transcode("samples/data/personal-schema.xml");
+
+ //Test document baseURI
+ DOMDocument *document = parser->getDocument();
+
+ //The baseURI should contain `file://' and `samples/data/personal-schema.xml'
+ const XMLCh *docBaseURI = document->getBaseURI();
+
+ if(XMLString::patternMatch(docBaseURI, fileSchema) == -1) {
+ OK = false;
+ fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__);
+ }
+
+ if(XMLString::patternMatch(docBaseURI, filePath) == -1) {
+ OK = false;
+ fprintf(stderr, "checking baseURI failed at line %i\n", __LINE__);
+ }
+
+ //Create relative paths from document baseURI
+
+ XMLCh *docBaseURIRoot = new XMLCh [ XMLString::stringLen(docBaseURI) ];
+ XMLString::copyNString(docBaseURIRoot, docBaseURI, XMLString::lastIndexOf(docBaseURI, chForwardSlash) + 1);
+
+ XMLCh *base_foobar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 8];
+ XMLString::copyString(base_foobar, docBaseURIRoot);
+ XMLCh *foobar = XMLString::transcode("foo/bar");
+ XMLString::catString(base_foobar, foobar);
+
+ XMLCh *base_foobarbar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 12];
+ XMLString::copyString(base_foobarbar, docBaseURIRoot);
+ XMLCh *foobarbar = XMLString::transcode("foo/bar/bar");
+ XMLString::catString(base_foobarbar, foobarbar);
+
+ XMLCh *base_foocarbar = new XMLCh [ XMLString::stringLen(docBaseURIRoot) + 12];
+ XMLString::copyString(base_foocarbar, docBaseURIRoot);
+ XMLCh *foocarbar = XMLString::transcode("foo/car/bar");
+ XMLString::catString(base_foocarbar, foocarbar);
+
+ XMLCh *file_autobar = XMLString::transcode("file:///auto/bar");
+ XMLCh *file_carfoo = XMLString::transcode("file:///car/foo/");
+ XMLCh *file_carfoobarbar = XMLString::transcode("file:///car/foo/bar/bar");
+
+ XMLCh *http_carcar = XMLString::transcode("http://www.example.com/car/car");
+ XMLCh *http_barfoo = XMLString::transcode("http://www.example.com/bar/foo/");
+ XMLCh *http_barfoofoobar = XMLString::transcode("http://www.example.com/bar/foo/foo/bar");
+
+ //Processing instruction before Document Element (has document baseURI)
+
+ DOMNode *node = document->getFirstChild();
+ while(node->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), docBaseURI) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ //Document Element baseURI (same as document)
+
+ node = document->getDocumentElement();
+
+ if(XMLString::compareString(node->getBaseURI(), docBaseURI) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s), failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <level 1>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ DOMNode *level1 = node;
+
+ // <one>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), base_foobar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <inner1>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), base_foobarbar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <inner2>
+
+ node = node->getNextSibling();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), base_foocarbar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <?proc-inst-2?>
+
+ node = node->getNextSibling();
+ while(node->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), base_foobar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <level2>
+
+ node = level1->getNextSibling();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ DOMNode *level2 = node;
+
+ if(XMLString::compareString(node->getBaseURI(), file_autobar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <two>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), file_carfoo) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <inner1>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), file_carfoobarbar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <level3>
+
+ node = level2->getNextSibling();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), http_carcar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <three>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), http_barfoo) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ // <inner1>
+
+ node = node->getFirstChild();
+ while(node->getNodeType() != DOMNode::ELEMENT_NODE)
+ node = node->getNextSibling();
+
+ if(XMLString::compareString(node->getBaseURI(), http_barfoofoobar) != 0) {
+ OK = false;
+ fprintf(stderr, "checking baseURI (%s) failed at line %i\n", namespaceResolver, __LINE__);
+ }
+
+ namespaceRes = !namespaceRes;
+
+ }
+ else {
+ printf("baseURI test was not carried out\n");
+ }
+ } while(namespaceRes == false);
+
+ return OK;
+}
/**
1.8 +5 -0 xml-xerces/c/tests/DOM/DOMTest/DTest.h
Index: DTest.h
===================================================================
RCS file: /home/cvs/xml-xerces/c/tests/DOM/DOMTest/DTest.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DTest.h 12 Jun 2002 18:31:17 -0000 1.7
+++ DTest.h 23 Sep 2002 18:27:48 -0000 1.8
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.8 2002/09/23 18:27:48 tng
+ * DOM L3: Test baseURI. Added by Gareth Reakes and Thomas Ford.
+ *
* Revision 1.7 2002/06/12 18:31:17 tng
* DOM L3: test the DOMUserDataHandler and set/getUserData
*
@@ -150,6 +153,8 @@
bool testPI(DOMDocument* document);
bool testText(DOMDocument* document);
bool treeCompare(DOMNode* node, DOMNode* node2);
+
+bool testBaseURI(void);
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org