blob: 07a41174d74046a5f54da8e79ad0f2ca1ac50606 [file] [log] [blame]
Daniel Veillard01791d51998-07-24 19:24:09 +00001/*
2 * tester.c : a small tester program for XML input.
3 *
4 * See Copyright for the status of this software.
5 *
6 * $Id$
7 */
8
Daniel Veillard260a68f1998-08-13 03:39:55 +00009#ifdef WIN32
10#define HAVE_FCNTL_H
11#include <io.h>
12#else
13#include <config.h>
14#endif
Daniel Veillard01791d51998-07-24 19:24:09 +000015#include <sys/types.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000016#ifdef HAVE_SYS_STAT_H
Daniel Veillard01791d51998-07-24 19:24:09 +000017#include <sys/stat.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000018#endif
19#ifdef HAVE_FCNTL_H
Daniel Veillard01791d51998-07-24 19:24:09 +000020#include <fcntl.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000021#endif
22#ifdef HAVE_UNISTD_H
Daniel Veillard01791d51998-07-24 19:24:09 +000023#include <unistd.h>
Daniel Veillard260a68f1998-08-13 03:39:55 +000024#endif
Daniel Veillard01791d51998-07-24 19:24:09 +000025#include <stdio.h>
26#include <string.h>
Seth Alvese7f12e61998-10-01 20:51:15 +000027#include <stdlib.h>
Daniel Veillard01791d51998-07-24 19:24:09 +000028
Daniel Veillard260a68f1998-08-13 03:39:55 +000029#include "parser.h"
30#include "tree.h"
Daniel Veillardbaf4cd51998-10-27 22:56:57 +000031#include "debugXML.h"
32
33static int debug = 0;
Daniel Veillard01791d51998-07-24 19:24:09 +000034
Daniel Veillard260a68f1998-08-13 03:39:55 +000035/*
36 * Note: there is a couple of errors introduced on purpose.
37 */
38static CHAR buffer[] =
Daniel Veillard01791d51998-07-24 19:24:09 +000039"\n\
40<?xml version=\"1.0\">\n\
41<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
42<?xml:namespace ns = \"http://www.w3.com/standards/z39.50/\" prefix = \"Z\"?>\n\
43<D:propertyupdate>\n\
44<D:set a=\"'toto'\" b>\n\
45 <D:prop>\n\
46 <Z:authors>\n\
47 <Z:Author>Jim Whitehead</Z:Author>\n\
48 <Z:Author>Roy Fielding</Z:Author>\n\
49 </Z:authors>\n\
50 </D:prop>\n\
51 </D:set>\n\
52 <D:remove>\n\
53 <D:prop><Z:Copyright-Owner/></D:prop>\n\
54 </D:remove>\n\
55</D:propertyupdate>\n\
56\n\
57";
58
Daniel Veillard01791d51998-07-24 19:24:09 +000059
Daniel Veillard260a68f1998-08-13 03:39:55 +000060void parseAndPrintFile(char *filename) {
Daniel Veillard01791d51998-07-24 19:24:09 +000061 xmlDocPtr doc;
62
63 /*
Daniel Veillard260a68f1998-08-13 03:39:55 +000064 * build an XML tree from a string;
65 */
66 doc = xmlParseFile(filename);
67
68 /*
69 * print it.
70 */
Daniel Veillardbaf4cd51998-10-27 22:56:57 +000071 if (!debug)
72 xmlDocDump(stdout, doc);
73 else
74 xmlDebugDumpDocument(stdout, doc);
Daniel Veillard260a68f1998-08-13 03:39:55 +000075
76 /*
77 * free it.
78 */
79 xmlFreeDoc(doc);
80}
81
82void parseAndPrintBuffer(CHAR *buf) {
83 xmlDocPtr doc;
84
85 /*
86 * build an XML tree from a string;
Daniel Veillard01791d51998-07-24 19:24:09 +000087 */
88 doc = xmlParseDoc(buf);
89
90 /*
91 * print it.
92 */
Daniel Veillardbaf4cd51998-10-27 22:56:57 +000093 if (!debug)
94 xmlDocDump(stdout, doc);
95 else
96 xmlDebugDumpDocument(stdout, doc);
Daniel Veillard01791d51998-07-24 19:24:09 +000097
98 /*
99 * free it.
100 */
101 xmlFreeDoc(doc);
102}
103
104int main(int argc, char **argv) {
105 int i;
106
107 if (argc > 1) {
108 for (i = 1; i < argc ; i++) {
Daniel Veillardbaf4cd51998-10-27 22:56:57 +0000109 if ((strcmp(argv[i], "-debug")) && (strcmp(argv[i], "--debug")))
110 parseAndPrintFile(argv[i]);
111 else
112 debug++;
Daniel Veillard01791d51998-07-24 19:24:09 +0000113 }
114 } else
Daniel Veillard260a68f1998-08-13 03:39:55 +0000115 parseAndPrintBuffer(buffer);
Daniel Veillard01791d51998-07-24 19:24:09 +0000116
117 return(0);
118}