summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile18
-rw-r--r--test/binding.c2
-rw-r--r--test/lib/Makefile69
-rw-r--r--test/lib/exceptions.h34
-rw-r--r--test/lib/list.c (renamed from test/list.c)2
-rw-r--r--test/lib/list.h (renamed from test/list.h)0
-rw-r--r--test/lib/testassert.c25
-rw-r--r--test/lib/testassert.h22
-rw-r--r--test/lib/testobject.c116
-rw-r--r--test/lib/testobject.h22
-rw-r--r--test/lib/utils.c34
-rw-r--r--test/lib/utils.h35
-rw-r--r--test/testutils.h187
13 files changed, 379 insertions, 187 deletions
diff --git a/test/Makefile b/test/Makefile
index fd17232..d298648 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -22,6 +22,9 @@
CFLAGS += -I${TOP}/src/ -I${TOP}/bindings/xml/ -I$(CURDIR)
LDFLAGS += `${PKGCONFIG} ${PKGCONFIGFLAGS} --libs libxml-2.0`
+# Libraries we link against
+LIBS = -L./lib -ldebug -ldom-libxml-debug -ldom-debug
+
# Release output
RELEASE =
@@ -39,14 +42,17 @@ XMLOBJS = $(addprefix xml/bin/, $(notdir $(XMLFILES:.xml=)))
OTHEROBJS = binding
OBJS = $(OTHEROBJS) $(XMLOBJS)
-.PHONY: clean debug export release setup test
+.PHONY: clean debug export release setup test transform
# Targets
release:
+ @${MAKE} -C lib release
debug:
+ @${MAKE} -C lib debug
clean:
+ @${MAKE} -C lib clean
ifneq (${OBJS}, )
-@${RM} ${RMFLAGS} $(addsuffix ${EXEEXT}, $(OTHEROBJS))
-@${RM} ${RMFLAGS} -r xml/c/
@@ -54,15 +60,18 @@ ifneq (${OBJS}, )
endif
distclean:
+ @${MAKE} -C lib distclean
-@${RM} ${RMFLAGS} log
setup:
+ @${MAKE} -C lib setup
@${MKDIR} ${MKDIRFLAGS} $(CURDIR)/xml/c
@${MKDIR} ${MKDIRFLAGS} $(CURDIR)/xml/bin
export:
+ @${MAKE} -C lib export
-test: $(OBJS)
+test: release debug $(OBJS)
@${PERL} testrunner.pl ${EXEEXT}
transform: $(CFILES)
@@ -71,7 +80,7 @@ transform: $(CFILES)
xml/bin/%: xml/c/%.c
@${ECHO} ${ECHOFLAGS} "==> $<"
@${CC} -c -g ${CFLAGS} -o $@.o $<
- @${LD} -g -o $@ $@.o ${LDFLAGS} -ldom-libxml-debug -ldom-debug
+ @${LD} -g -o $@ $@.o ${LDFLAGS} $(LIBS)
@${RM} ${RMFLAGS} $@.o
xml/c/%.c: xml/tests/%.xml
@@ -80,5 +89,6 @@ xml/c/%.c: xml/tests/%.xml
%: %.c
@${ECHO} ${ECHOFLAGS} "==> $<"
@${CC} -c -g ${CFLAGS} -o $@.o $<
- @${LD} -g -o $@ $@.o ${LDFLAGS} -ldom-libxml-debug -ldom-debug
+ @${LD} -g -o $@ $@.o ${LDFLAGS} $(LIBS)
@${RM} ${RMFLAGS} $@.o
+
diff --git a/test/binding.c b/test/binding.c
index a06763c..ac76733 100644
--- a/test/binding.c
+++ b/test/binding.c
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
#include <dom/dom.h>
#include "testutils.h"
diff --git a/test/lib/Makefile b/test/lib/Makefile
new file mode 100644
index 0000000..22a06e9
--- /dev/null
+++ b/test/lib/Makefile
@@ -0,0 +1,69 @@
+# Makefile for DOM testcase utility library
+#
+# Toolchain is exported by top-level makefile
+#
+# Top-level makefile also exports the following variables:
+#
+# COMPONENT Name of component
+# EXPORT Absolute path of export directory
+# TOP Absolute path of source tree root
+#
+# The top-level makefile requires the following targets to exist:
+#
+# clean Clean source tree
+# debug Create a debug binary
+# distclean Fully clean source tree, back to pristine condition
+# export Export distributable components to ${EXPORT}
+# release Create a release binary
+# setup Perform any setup required prior to compilation
+# test Execute any test cases
+
+# Manipulate include paths
+CFLAGS += -I$(TOP) -I$(CURDIR)
+
+# Release output
+RELEASE = libdebug.a
+
+# Debug output
+DEBUG = libdebug-debug.a
+
+# Objects
+OBJS = list testassert testobject utils
+
+.PHONY: clean debug export release setup test
+
+# Targets
+release: $(addprefix Release/, $(addsuffix .o, $(OBJS)))
+ @${AR} ${ARFLAGS} $(RELEASE) Release/*
+
+debug: $(addprefix Debug/, $(addsuffix .o, $(OBJS)))
+ @${AR} ${ARFLAGS} $(DEBUG) Debug/*
+
+clean:
+ifneq (${OBJS}, )
+ -@${RM} ${RMFLAGS} $(addprefix Release/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(addprefix Debug/, $(addsuffix .o, ${OBJS}))
+endif
+ -@${RM} ${RMFLAGS} $(RELEASE) $(DEBUG)
+
+distclean:
+ -@${RM} ${RMFLAGS} -r Release
+ -@${RM} ${RMFLAGS} -r Debug
+
+setup:
+ @${MKDIR} ${MKDIRFLAGS} Release
+ @${MKDIR} ${MKDIRFLAGS} Debug
+
+export:
+
+test:
+
+# Pattern rules
+Release/%.o: %.c
+ @${ECHO} ${ECHOFLAGS} "==> $<"
+ @${CC} -c ${CFLAGS} -DNDEBUG -o $@ $<
+
+Debug/%.o: %.c
+ @${ECHO} ${ECHOFLAGS} "==> $<"
+ @${CC} -c -g ${CFLAGS} -o $@ $<
+
diff --git a/test/lib/exceptions.h b/test/lib/exceptions.h
new file mode 100644
index 0000000..1c6b8e2
--- /dev/null
+++ b/test/lib/exceptions.h
@@ -0,0 +1,34 @@
+#ifndef exceptions_h_
+#define exceptions_h_
+
+#include <setjmp.h>
+
+#include <dom/core/exceptions.h>
+
+/* Usage:
+ TRY
+ THROW(DOM_NOT_FOUND_ERR);
+ THROW_IF_ERR(dom_document_get_doctype(...));
+ CATCH(ex)
+ printf("exception: %d\n", ex);
+ ENDTRY
+*/
+#define TRY __exvalue=setjmp(__exbuf); \
+ if (__exvalue==0) {
+#define CATCH(x) } else { \
+ int x = __exvalue;
+#define ENDTRY }
+#define THROW(x) longjmp(__exbuf, x)
+
+#define THROW_IF_ERR(x) \
+ do { \
+ int err = x; \
+ if (err != DOM_NO_ERR) \
+ THROW(err); \
+ } while (0)
+
+jmp_buf __exbuf;
+int __exvalue;
+
+#endif
+
diff --git a/test/list.c b/test/lib/list.c
index 2c742fa..0b2965f 100644
--- a/test/list.c
+++ b/test/lib/list.c
@@ -5,13 +5,13 @@
* Copyright 2007 James Shaw <jshaw@netsurf-browser.org>
*/
-#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
+#include "testassert.h"
struct list* list_new(void)
{
diff --git a/test/list.h b/test/lib/list.h
index a0a6c6a..a0a6c6a 100644
--- a/test/list.h
+++ b/test/lib/list.h
diff --git a/test/lib/testassert.c b/test/lib/testassert.c
new file mode 100644
index 0000000..2a31ff3
--- /dev/null
+++ b/test/lib/testassert.c
@@ -0,0 +1,25 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "testassert.h"
+#include "utils.h"
+
+void __assert2(const char *expr, const char *function,
+ const char *file, int line)
+{
+ UNUSED(function);
+ UNUSED(file);
+
+ printf("FAIL - %s at line %d\n", expr, line);
+
+ exit(EXIT_FAILURE);
+}
+
+
diff --git a/test/lib/testassert.h b/test/lib/testassert.h
new file mode 100644
index 0000000..329feff
--- /dev/null
+++ b/test/lib/testassert.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef testassert_h_
+#define testassert_h_
+
+/* Redefine assert, so we can simply use the standard assert mechanism
+ * within testcases and exit with the right output for the testrunner
+ * to do the right thing. */
+void __assert2(const char *expr, const char *function,
+ const char *file, int line);
+
+#define assert(expr) \
+ ((void) ((expr) || (__assert2 (#expr, __func__, __FILE__, __LINE__), 0)))
+
+
+#endif
+
diff --git a/test/lib/testobject.c b/test/lib/testobject.c
new file mode 100644
index 0000000..e9d3d06
--- /dev/null
+++ b/test/lib/testobject.c
@@ -0,0 +1,116 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "bindings/xml/xmlbinding.h"
+#include "bindings/xml/xmlparser.h"
+
+#include "testassert.h"
+#include "testobject.h"
+#include "utils.h"
+
+struct TestObject {
+ xml_parser *parser;
+ struct dom_document *doc;
+};
+
+TestObject *test_object_create(int argc, char **argv,
+ const char *uri, bool will_be_modified)
+{
+ static bool xml_parser_initialised;
+
+ char fnbuf[1024];
+#define CHUNK_SIZE 4096
+ uint8_t buf[CHUNK_SIZE];
+ FILE *fp;
+ size_t len;
+ TestObject *ret;
+
+ UNUSED(will_be_modified);
+
+ if (argc != 2) {
+ printf("Usage: %s <datapath>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ if (xml_parser_initialised == false) {
+ assert(xml_dom_binding_initialise(myrealloc, NULL) == XML_OK);
+
+ xml_parser_initialised = true;
+ }
+
+ snprintf(fnbuf, sizeof fnbuf, "%s/%s", argv[1], uri);
+
+ ret = malloc(sizeof(TestObject));
+ if (ret == NULL)
+ return NULL;
+
+ ret->parser = xml_parser_create(NULL, "UTF-8", myrealloc, NULL,
+ mymsg, NULL);
+ if (ret->parser == NULL) {
+ free(ret);
+ return NULL;
+ }
+
+ fp = fopen(fnbuf, "r");
+ if (fp == NULL) {
+ xml_parser_destroy(ret->parser);
+ free(ret);
+ return NULL;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ len = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ while (len > CHUNK_SIZE) {
+ fread(buf, 1, CHUNK_SIZE, fp);
+
+ assert(xml_parser_parse_chunk(ret->parser, buf,
+ CHUNK_SIZE) == XML_OK);
+
+ len -= CHUNK_SIZE;
+ }
+
+ if (len > 0) {
+ fread(buf, 1, len, fp);
+
+ assert(xml_parser_parse_chunk(ret->parser, buf,
+ len) == XML_OK);
+
+ len = 0;
+ }
+
+ assert(xml_parser_completed(ret->parser) == XML_OK);
+
+ fclose(fp);
+
+ ret->doc = xml_parser_get_document(ret->parser);
+
+ xml_parser_destroy(ret->parser);
+ ret->parser = NULL;
+
+ return ret;
+
+#undef CHUNK_SIZE
+}
+
+struct dom_document *test_object_get_doc(TestObject *obj)
+{
+ return obj->doc;
+}
+
+const char *test_object_get_mimetype(TestObject *obj)
+{
+ UNUSED(obj);
+
+ return "text/xml";
+}
+
+
diff --git a/test/lib/testobject.h b/test/lib/testobject.h
new file mode 100644
index 0000000..c72b39f
--- /dev/null
+++ b/test/lib/testobject.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef testobject_h_
+#define testobject_h_
+
+#include <stdbool.h>
+
+struct TestObject;
+typedef struct TestObject TestObject;
+
+TestObject *test_object_create(int argc, char **argv,
+ const char *uri, bool will_be_modified);
+struct dom_document *test_object_get_doc(TestObject *obj);
+const char *test_object_get_mimetype(TestObject *obj);
+
+#endif
+
diff --git a/test/lib/utils.c b/test/lib/utils.c
new file mode 100644
index 0000000..739933f
--- /dev/null
+++ b/test/lib/utils.c
@@ -0,0 +1,34 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "utils.h"
+
+void *myrealloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ return realloc(ptr, len);
+}
+
+void mymsg(uint32_t severity, void *ctx, const char *msg, ...)
+{
+ va_list l;
+
+ UNUSED(ctx);
+
+ va_start(l, msg);
+
+ fprintf(stderr, "%d: ", severity);
+ vfprintf(stderr, msg, l);
+ fprintf(stderr, "\n");
+}
+
+
diff --git a/test/lib/utils.h b/test/lib/utils.h
new file mode 100644
index 0000000..b57db36
--- /dev/null
+++ b/test/lib/utils.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef utils_h_
+#define utils_h_
+
+#include <stddef.h>
+#include <inttypes.h>
+
+#ifndef max
+#define max(a,b) ((a)>(b)?(a):(b))
+#endif
+
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#ifndef SLEN
+/* Calculate length of a string constant */
+#define SLEN(s) (sizeof((s)) - 1) /* -1 for '\0' */
+#endif
+
+#ifndef UNUSED
+#define UNUSED(x) ((x) = (x))
+#endif
+
+void *myrealloc(void *ptr, size_t len, void *pw);
+void mymsg(uint32_t severity, void *ctx, const char *msg, ...);
+
+#endif
+
diff --git a/test/testutils.h b/test/testutils.h
index 6e07660..9fa8241 100644
--- a/test/testutils.h
+++ b/test/testutils.h
@@ -1,188 +1,11 @@
#ifndef dom_test_testutils_h_
#define dom_test_testutils_h_
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-#include <setjmp.h>
+#include "lib/exceptions.h"
+#include "lib/list.h"
+#include "lib/testassert.h"
+#include "lib/testobject.h"
+#include "lib/utils.h"
-#include "exceptions.h"
-#include "utils.h"
-#include "xmlbinding.h"
-#include "xmlparser.h"
-
-#ifndef UNUSED
-#define UNUSED(x) ((x) = (x))
#endif
-/* Usage:
- TRY
- THROW(DOM_NOT_FOUND_ERR);
- THROW_IF_ERR(dom_document_get_doctype(...));
- CATCH(ex)
- printf("exception: %d\n", ex);
- ENDTRY
-*/
-#define TRY __exvalue=setjmp(__exbuf); \
- if (__exvalue==0) {
-#define CATCH(x) } else { \
- int x = __exvalue;
-#define ENDTRY }
-#define THROW(x) longjmp(__exbuf, x)
-
-#define THROW_IF_ERR(x) \
- do { \
- int err = x; \
- if (err != DOM_NO_ERR) \
- THROW(err); \
- } while (0)
-
-jmp_buf __exbuf;
-int __exvalue;
-
-/* Redefine assert, so we can simply use the standard assert mechanism
- * within testcases and exit with the right output for the testrunner
- * to do the right thing. */
-void __assert2(const char *expr, const char *function,
- const char *file, int line);
-
-void __assert2(const char *expr, const char *function,
- const char *file, int line)
-{
- UNUSED(function);
- UNUSED(file);
-
- printf("FAIL - %s at line %d\n", expr, line);
-
- exit(EXIT_FAILURE);
-}
-
-#define assert(expr) \
- ((void) ((expr) || (__assert2 (#expr, __func__, __FILE__, __LINE__), 0)))
-
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
-
-static void mymsg(uint32_t severity, void *ctx, const char *msg, ...)
-{
- va_list l;
-
- UNUSED(ctx);
-
- va_start(l, msg);
-
- fprintf(stderr, "%d: ", severity);
- vfprintf(stderr, msg, l);
- fprintf(stderr, "\n");
-}
-
-typedef struct TestObject {
- xml_parser *parser;
- struct dom_document *doc;
-} TestObject;
-
-TestObject *test_object_create(int argc, char **argv,
- const char *uri, bool will_be_modified);
-struct dom_document *test_object_get_doc(TestObject *obj);
-const char *test_object_get_mimetype(TestObject *obj);
-
-TestObject *test_object_create(int argc, char **argv,
- const char *uri, bool will_be_modified)
-{
- static bool xml_parser_initialised;
-
- char fnbuf[1024];
-#define CHUNK_SIZE 4096
- uint8_t buf[CHUNK_SIZE];
- FILE *fp;
- size_t len;
- TestObject *ret;
-
- UNUSED(will_be_modified);
-
- if (argc != 2) {
- printf("Usage: %s <datapath>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
-
- if (xml_parser_initialised == false) {
- assert(xml_dom_binding_initialise(myrealloc, NULL) == XML_OK);
-
- xml_parser_initialised = true;
- }
-
- snprintf(fnbuf, sizeof fnbuf, "%s/%s", argv[1], uri);
-
- ret = malloc(sizeof(TestObject));
- if (ret == NULL)
- return NULL;
-
- ret->parser = xml_parser_create(NULL, "UTF-8", myrealloc, NULL,
- mymsg, NULL);
- if (ret->parser == NULL) {
- free(ret);
- return NULL;
- }
-
- fp = fopen(fnbuf, "r");
- if (fp == NULL) {
- xml_parser_destroy(ret->parser);
- free(ret);
- return NULL;
- }
-
- fseek(fp, 0, SEEK_END);
- len = ftell(fp);
- fseek(fp, 0, SEEK_SET);
-
- while (len > CHUNK_SIZE) {
- fread(buf, 1, CHUNK_SIZE, fp);
-
- assert(xml_parser_parse_chunk(ret->parser, buf,
- CHUNK_SIZE) == XML_OK);
-
- len -= CHUNK_SIZE;
- }
-
- if (len > 0) {
- fread(buf, 1, len, fp);
-
- assert(xml_parser_parse_chunk(ret->parser, buf,
- len) == XML_OK);
-
- len = 0;
- }
-
- assert(xml_parser_completed(ret->parser) == XML_OK);
-
- fclose(fp);
-
- ret->doc = xml_parser_get_document(ret->parser);
-
- xml_parser_destroy(ret->parser);
- ret->parser = NULL;
-
- return ret;
-
-#undef CHUNK_SIZE
-}
-
-struct dom_document *test_object_get_doc(TestObject *obj)
-{
- return obj->doc;
-}
-
-const char *test_object_get_mimetype(TestObject *obj)
-{
- UNUSED(obj);
-
- return "text/xml";
-}
-
-#endif