[cvs-annodex] commit (/annodex): +libannodex/trunk/src/libannodex/xtag_test.c

conrad nobody at lists.annodex.net
Tue Feb 1 11:37:16 EST 2005


Update of /annodex (new revision 801)

Added files:
   libannodex/trunk/src/libannodex/xtag_test.c

Log Message:
add test program for xtag.
	+ Passes on Index.cmml attached to ticket: 1
	- unfortunately not built by default due to libtool hell not allowing
	building of the same object for both static and dynamic linking


Added: libannodex/trunk/src/libannodex/xtag_test.c
===================================================================
--- libannodex/trunk/src/libannodex/xtag_test.c	2005-02-01 00:35:16 UTC (rev 800)
+++ libannodex/trunk/src/libannodex/xtag_test.c	2005-02-01 00:37:14 UTC (rev 801)
@@ -0,0 +1,81 @@
+/*
+ * gcc -o xtag_test xtag_test.c xtag.c anx_list.c
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "xtag.h"
+
+static char * tags[] = {
+  "<tag/>",
+  "<tag></tag>",
+  "<tag></tag><tag><tag/>",
+  "<tag><subtag/></tag>",
+  "<tag><subtag>PCDATA</subtag></tag>",
+  "<tag attr=\"a\"><subtag/></tag>",
+  "<tag attr=\"a\"><subtag attr=\"b\"/></tag>",
+  "<tag><!-- comment --></tag>",
+  "<!-- comment --><tag/>",
+  "<tag/><!-- comment -->",
+  "<tag><!-- <subtag/> --></tag>"
+};
+
+int
+main (int argc, char * argv[])
+{
+  XTag * tag;
+  int i;
+  char * filename;
+  FILE * f;
+  long flen;
+  char * buf;
+
+  for (i = 0; tags[i] != NULL; i++) {
+    tag = xtag_new_parse (tags[i], strlen (tags[i]));
+    if (tag == NULL) {
+      printf ("Failed to parse:\n%s\n", tags[i]);
+      exit (1);
+    }
+    xtag_free (tag);
+  }
+
+  if (argc > 0) {
+    for (i = 1; i < argc; i++) {
+      filename = argv[i];
+      f = fopen (filename, "r");
+      if (f == NULL) {
+	printf ("Unable to open %s for reading\n", filename);
+	exit (1);
+      }
+      if (fseek (f, 0, SEEK_END) == -1) {
+	printf ("Unable to seek to end of %s\n", filename);
+	exit (1);
+      }
+      if ((flen = ftell (f)) == -1) {
+	printf ("Unable to determine length of %s\n", filename);
+	exit (1);
+      }
+      rewind (f);
+      buf = (char *)malloc ((size_t)flen) + 1;
+      memset (buf, '\0', (size_t)flen+1);
+      if (fread (buf, 1, flen, f) != (size_t)flen) {
+	printf ("Unable to read entire contents of %s\n", filename);
+	exit (1);
+      }
+      fclose (f);
+
+#ifdef DEBUG
+      printf ("Attempting to parse:\n%s\n", buf);
+#endif
+
+      tag = xtag_new_parse (buf, flen);
+      if (tag == NULL) {
+	printf ("Failed to parse %s\n", filename);
+	exit (1);
+      }
+      xtag_free (tag);
+    }
+  }
+
+  exit (0);
+}


-- 
conrad



More information about the cvs-annodex mailing list