Added copy operations for node/tree/documents, Daniel.
diff --git a/tester.c b/tester.c
index 56d74be..6830917 100644
--- a/tester.c
+++ b/tester.c
@@ -31,6 +31,7 @@
#include "debugXML.h"
static int debug = 0;
+static int copy = 0;
/*
* Note: there is a couple of errors introduced on purpose.
@@ -63,12 +64,12 @@
************************************************************************/
int treeTest(void) {
+ xmlDocPtr doc, tmp;
+ xmlNodePtr tree, subtree;
+
/*
* build a fake XML document
*/
- xmlDocPtr doc;
- xmlNodePtr tree, subtree;
-
doc = xmlNewDoc("1.0");
doc->root = xmlNewDocNode(doc, NULL, "EXAMPLE", NULL);
xmlSetProp(doc->root, "prop1", "gnome is great");
@@ -82,6 +83,15 @@
xmlSetProp(subtree, "href", "linus.gif");
/*
+ * test intermediate copy if needed.
+ */
+ if (copy) {
+ tmp = doc;
+ doc = xmlCopyDoc(doc, 1);
+ xmlFreeDoc(tmp);
+ }
+
+ /*
* print it.
*/
xmlDocDump(stdout, doc);
@@ -94,7 +104,7 @@
}
void parseAndPrintFile(char *filename) {
- xmlDocPtr doc;
+ xmlDocPtr doc, tmp;
/*
* build an XML tree from a string;
@@ -102,6 +112,15 @@
doc = xmlParseFile(filename);
/*
+ * test intermediate copy if needed.
+ */
+ if (copy) {
+ tmp = doc;
+ doc = xmlCopyDoc(doc, 1);
+ xmlFreeDoc(tmp);
+ }
+
+ /*
* print it.
*/
if (!debug)
@@ -116,7 +135,7 @@
}
void parseAndPrintBuffer(CHAR *buf) {
- xmlDocPtr doc;
+ xmlDocPtr doc, tmp;
/*
* build an XML tree from a string;
@@ -124,6 +143,15 @@
doc = xmlParseDoc(buf);
/*
+ * test intermediate copy if needed.
+ */
+ if (copy) {
+ tmp = doc;
+ doc = xmlCopyDoc(doc, 1);
+ xmlFreeDoc(tmp);
+ }
+
+ /*
* print it.
*/
if (!debug)
@@ -139,15 +167,21 @@
int main(int argc, char **argv) {
int i;
+ int files = 0;
- if (argc > 1) {
- for (i = 1; i < argc ; i++) {
- if ((strcmp(argv[i], "-debug")) && (strcmp(argv[i], "--debug")))
- parseAndPrintFile(argv[i]);
- else
- debug++;
+ for (i = 1; i < argc ; i++) {
+ if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
+ debug++;
+ else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
+ copy++;
+ }
+ for (i = 1; i < argc ; i++) {
+ if (argv[i][0] != '-') {
+ parseAndPrintFile(argv[i]);
+ files ++;
}
- } else {
+ }
+ if (files == 0) {
printf("\nFirst test for the parser, with errors\n");
parseAndPrintBuffer(buffer);
printf("\nBuilding a tree from scratch and printing it\n");