r3574 jshaw - in /trunk/dom/test: test-list test-list.c
by netsurf@semichrome.net
Author: jshaw
Date: Sun Sep 23 00:10:33 2007
New Revision: 3574
URL: http://source.netsurf-browser.org?rev=3574&view=rev
Log:
Extend list implementation, add test-list.c to test some of it.
Added:
trunk/dom/test/test-list (with props)
trunk/dom/test/test-list.c
Added: trunk/dom/test/test-list
URL: http://source.netsurf-browser.org/trunk/dom/test/test-list?rev=3574&view=...
==============================================================================
Binary file - no diff available.
Propchange: trunk/dom/test/test-list
------------------------------------------------------------------------------
svn:executable = *
Propchange: trunk/dom/test/test-list
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: trunk/dom/test/test-list.c
URL: http://source.netsurf-browser.org/trunk/dom/test/test-list.c?rev=3574&vie...
==============================================================================
--- trunk/dom/test/test-list.c (added)
+++ trunk/dom/test/test-list.c Sun Sep 23 00:10:33 2007
@@ -1,0 +1,56 @@
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "testutils.h"
+
+void test_add_remove(void);
+void test_contains_all_true(void);
+
+void test_add_remove(void)
+{
+ struct list* list = list_new();
+
+ char s[] = "hello";
+
+ /* add element */
+ list_add(list, s);
+ assert(strcmp(list->head->data, "hello") == 0);
+ assert(list->size == 1);
+
+ /* remove element */
+ bool found = list_remove(list, s);
+ assert(found == true);
+ assert(list->size == 0);
+ assert(list->head == NULL);
+
+ list_destroy(list);
+}
+
+void test_contains_all_true(void)
+{
+ struct list* superList = list_new();
+ struct list* subList = list_new();
+
+ list_add(superList, (void*) "hello");
+ list_add(superList, (void*) "world");
+
+ list_add(subList, (void*) "hello");
+
+ bool b = list_contains_all(superList, subList, (comparator) strcmp);
+ assert(b == true);
+ assert(superList->size == 2);
+ assert(superList->head->next->next == NULL);
+
+ list_destroy(superList);
+ list_destroy(subList);
+}
+
+int main(void)
+{
+ test_add_remove();
+ test_contains_all_true();
+ //test_different_size_lists();
+
+ printf("PASS\n");
+}
16 years, 2 months
r3573 jshaw - in /trunk/dom/test: Makefile lib/Makefile lib/comparators.c lib/comparators.h lib/exceptions.h lib/list.c lib/list.h lib/testassert.c lib/testassert.h
by netsurf@semichrome.net
Author: jshaw
Date: Sun Sep 23 00:08:54 2007
New Revision: 3573
URL: http://source.netsurf-browser.org?rev=3573&view=rev
Log:
Extend list implementation, add test-list.c to test some of it.
Added:
trunk/dom/test/lib/comparators.c
trunk/dom/test/lib/comparators.h
Modified:
trunk/dom/test/Makefile
trunk/dom/test/lib/Makefile
trunk/dom/test/lib/exceptions.h
trunk/dom/test/lib/list.c
trunk/dom/test/lib/list.h
trunk/dom/test/lib/testassert.c
trunk/dom/test/lib/testassert.h
Modified: trunk/dom/test/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/Makefile?rev=3573&r1=357...
==============================================================================
--- trunk/dom/test/Makefile (original)
+++ trunk/dom/test/Makefile Sun Sep 23 00:08:54 2007
@@ -39,7 +39,7 @@
# Objects
XMLOBJS = $(addprefix xml/bin/, $(notdir $(XMLFILES:.xml=)))
-OTHEROBJS = binding
+OTHEROBJS = binding test-list
OBJS = $(OTHEROBJS) $(XMLOBJS)
.PHONY: clean debug export release setup test transform
Modified: trunk/dom/test/lib/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/Makefile?rev=3573&r1...
==============================================================================
--- trunk/dom/test/lib/Makefile (original)
+++ trunk/dom/test/lib/Makefile Sun Sep 23 00:08:54 2007
@@ -28,7 +28,7 @@
DEBUG = libdomtest-debug.a
# Objects
-OBJS = list testassert testobject utils
+OBJS = comparators list testassert testobject utils
.PHONY: clean debug export release setup test
Added: trunk/dom/test/lib/comparators.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/comparators.c?rev=35...
==============================================================================
--- trunk/dom/test/lib/comparators.c (added)
+++ trunk/dom/test/lib/comparators.c Sun Sep 23 00:08:54 2007
@@ -1,0 +1,5 @@
+#include "comparators.h"
+
+int int_comparator(const int* a, const int* b) {
+ return (*a) - (*b);
+}
Added: trunk/dom/test/lib/comparators.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/comparators.h?rev=35...
==============================================================================
--- trunk/dom/test/lib/comparators.h (added)
+++ trunk/dom/test/lib/comparators.h Sun Sep 23 00:08:54 2007
@@ -1,0 +1,18 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 James Shaw <jshaw(a)netsurf-browser.org>
+ */
+
+#ifndef comparators_h_
+#define comparators_h_
+
+/**
+ * A function pointer type for a comparator.
+ */
+typedef int (*comparator)(const void* a, const void* b);
+
+int int_comparator(const int* a, const int* b);
+
+#endif
Modified: trunk/dom/test/lib/exceptions.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/exceptions.h?rev=357...
==============================================================================
--- trunk/dom/test/lib/exceptions.h (original)
+++ trunk/dom/test/lib/exceptions.h Sun Sep 23 00:08:54 2007
@@ -1,3 +1,10 @@
+/*
+ * This file is part of libdom test suite.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 James Shaw <jshaw(a)netsurf-browser.org>
+ */
+
#ifndef exceptions_h_
#define exceptions_h_
@@ -5,7 +12,8 @@
#include <dom/core/exceptions.h>
-/* Usage:
+/* Adapted from http://www.math.princeton.edu/~asnowden/c-except.html
+ Usage:
TRY
THROW(DOM_NOT_FOUND_ERR);
THROW_IF_ERR(dom_document_get_doctype(...));
Modified: trunk/dom/test/lib/list.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/list.c?rev=3573&r1=3...
==============================================================================
--- trunk/dom/test/lib/list.c (original)
+++ trunk/dom/test/lib/list.c Sun Sep 23 00:08:54 2007
@@ -10,8 +10,23 @@
#include <stdio.h>
#include <stdlib.h>
+#include "comparators.h"
#include "list.h"
#include "testassert.h"
+
+/**
+ * Private helper function.
+ * Create a new list_elt and initialise it.
+ */
+struct list_elt* list_new_elt(void* data);
+
+struct list_elt* list_new_elt(void* data) {
+ struct list_elt* elt = malloc(sizeof(struct list_elt));
+ assert(elt != NULL);
+ elt->data = data;
+ elt->next = NULL;
+ return elt;
+}
struct list* list_new(void)
{
@@ -36,10 +51,7 @@
void list_add(struct list* list, void* data)
{
- struct list_elt* elt = malloc(sizeof(struct list_elt));
- assert(elt != NULL);
- elt->data = data;
- elt->next = NULL;
+ struct list_elt* elt = list_new_elt(data);
struct list_elt* tail = list->tail;
/* if tail was set, make its 'next' ptr point to elt */
@@ -58,7 +70,50 @@
list->size++;
}
-bool list_contains(struct list* list, void* data, list_compare_func comparator)
+bool list_remove(struct list* list, void* data)
+{
+ struct list_elt* prevElt = NULL;
+ struct list_elt* elt = list->head;
+
+ bool found = false;
+
+ while (elt != NULL) {
+ struct list_elt* nextElt = elt->next;
+
+ /* if data is identical, fix up pointers, and free the element */
+ if (data == elt->data) {
+ if (prevElt == NULL) {
+ list->head = nextElt;
+ } else {
+ prevElt->next = nextElt;
+ }
+ free(elt);
+ list->size--;
+ found = true;
+ break;
+ }
+
+ prevElt = elt;
+ elt = nextElt;
+ }
+
+ return found;
+}
+
+struct list* list_clone(struct list* list)
+{
+ struct list* newList = list_new();
+ struct list_elt* elt = list->head;
+
+ while (elt != NULL) {
+ list_add(newList, elt->data);
+ elt = elt->next;
+ }
+
+ return newList;
+}
+
+bool list_contains(struct list* list, void* data, comparator comparator)
{
struct list_elt* elt = list->head;
while (elt != NULL) {
@@ -71,15 +126,29 @@
}
bool list_contains_all(struct list* superList, struct list* subList,
- list_compare_func comparator)
+ comparator comparator)
{
- struct list_elt* elt = subList->head;
- while (elt != NULL) {
- if (!list_contains(superList, elt->data, comparator)) {
- return false;
+ struct list_elt* subElt = subList->head;
+ struct list* superListClone = list_clone(superList);
+
+ bool found = true;
+
+ while (subElt != NULL) {
+ struct list_elt* superElt = superListClone->head;
+
+ found = false;
+ while (superElt != NULL && found == false) {
+ if (comparator(subElt->data, superElt->data) == 0) {
+ found = true;
+ list_remove(superListClone, superElt->data);
+ }
+ superElt = superElt->next;
}
- elt = elt->next;
+
+ subElt = subElt->next;
}
- return true;
+ free(superListClone);
+
+ return found;
}
Modified: trunk/dom/test/lib/list.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/list.h?rev=3573&r1=3...
==============================================================================
--- trunk/dom/test/lib/list.h (original)
+++ trunk/dom/test/lib/list.h Sun Sep 23 00:08:54 2007
@@ -7,6 +7,10 @@
#ifndef list_h_
#define list_h_
+
+#include <stdbool.h>
+
+#include "comparators.h"
struct list_elt {
void* data;
@@ -22,23 +26,32 @@
struct list* list_new(void);
void list_destroy(struct list* list);
-typedef int (*list_compare_func)(const void* a, const void* b);
-
/**
* Add data to the tail of the list.
*/
void list_add(struct list* list, void* data);
/**
+ * Remove element containing data from list.
+ * The list element is freed, but the caller must free the data itself
+ * if necessary.
+ *
+ * Returns true if data was found in the list.
+ */
+bool list_remove(struct list* list, void* data);
+
+struct list* list_clone(struct list* list);
+
+/**
* Tests if data is equal to any element in the list.
*/
-bool list_contains(struct list* list, void* data,
- int (*comparator)(const void* a, const void* b));
+bool list_contains(struct list* list, void* data,
+ comparator comparator);
/**
* Tests if superlist contains all elements in sublist. Order is not important.
*/
bool list_contains_all(struct list* superList, struct list* subList,
- list_compare_func comparator);
+ comparator comparator);
#endif
Modified: trunk/dom/test/lib/testassert.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testassert.c?rev=357...
==============================================================================
--- trunk/dom/test/lib/testassert.c (original)
+++ trunk/dom/test/lib/testassert.c Sun Sep 23 00:08:54 2007
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include "testassert.h"
+#include "comparators.h"
#include "utils.h"
void __assert2(const char *expr, const char *function,
@@ -22,4 +23,22 @@
exit(EXIT_FAILURE);
}
+void assert_equals_collection(struct list* expected, struct list* actual,
+ comparator comparator)
+{
+ assert_not_null(expected);
+ assert_not_null(actual);
+ assert_equals(expected->size, actual->size, (int (*)(const void* a, const void* b)) int_comparator);
+ list_contains_all(actual, expected, comparator);
+}
+void assert_equals(int expected, int actual, comparator comparator)
+{
+ assert(comparator(&expected, &actual) == 0);
+}
+
+void assert_not_null(void* x)
+{
+ assert(x != NULL);
+}
+
Modified: trunk/dom/test/lib/testassert.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testassert.h?rev=357...
==============================================================================
--- trunk/dom/test/lib/testassert.h (original)
+++ trunk/dom/test/lib/testassert.h Sun Sep 23 00:08:54 2007
@@ -8,6 +8,9 @@
#ifndef testassert_h_
#define testassert_h_
+#include "comparators.h"
+#include "list.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. */
@@ -17,6 +20,11 @@
#define assert(expr) \
((void) ((expr) || (__assert2 (#expr, __func__, __FILE__, __LINE__), 0)))
+void assert_equals_collection(struct list* expected, struct list* actual,
+ comparator comparator);
+void assert_equals(int expected, int actual, comparator comparator);
+void assert_not_null(void* x);
+
#endif
16 years, 2 months
r3572 jmb - /trunk/dom/src/core/document.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 22 23:45:35 2007
New Revision: 3572
URL: http://source.netsurf-browser.org?rev=3572&view=rev
Log:
Implement dom_document_get_implementation()
Implement dom_document_get_elements_by_tag_name()
Implement dom_document_get_elements_by_tag_name_ns()
Modified:
trunk/dom/src/core/document.c
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3572&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Sat Sep 22 23:45:35 2007
@@ -266,14 +266,20 @@
* \param doc The document to retrieve the implementation from
* \param result Pointer to location to receive result
* \return DOM_NO_ERR.
+ *
+ * The returned implementation will have its reference count increased.
+ * It is the responsibility of the caller to unref the implementation once
+ * it has finished with it.
*/
dom_exception dom_document_get_implementation(struct dom_document *doc,
struct dom_implementation **result)
{
- UNUSED(doc);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ if (doc->impl != NULL)
+ dom_implementation_ref(doc->impl);
+
+ *result = doc->impl;
+
+ return DOM_NO_ERR;
}
/**
@@ -483,11 +489,8 @@
dom_exception dom_document_get_elements_by_tag_name(struct dom_document *doc,
struct dom_string *tagname, struct dom_nodelist **result)
{
- UNUSED(doc);
- UNUSED(tagname);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_document_get_nodelist(doc, (struct dom_node *) doc,
+ tagname, NULL, NULL, result);
}
/**
@@ -613,12 +616,8 @@
struct dom_document *doc, struct dom_string *namespace,
struct dom_string *localname, struct dom_nodelist **result)
{
- UNUSED(doc);
- UNUSED(namespace);
- UNUSED(localname);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ return dom_document_get_nodelist(doc, (struct dom_node *) doc,
+ NULL, namespace, localname, result);
}
/**
16 years, 2 months
r3571 jmb - in /trunk/dom/test: Makefile lib/Makefile
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 22 18:45:37 2007
New Revision: 3571
URL: http://source.netsurf-browser.org?rev=3571&view=rev
Log:
Rename testcase utility library to libdomtest -- libdebug made no sense
Modified:
trunk/dom/test/Makefile
trunk/dom/test/lib/Makefile
Modified: trunk/dom/test/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/Makefile?rev=3571&r1=357...
==============================================================================
--- trunk/dom/test/Makefile (original)
+++ trunk/dom/test/Makefile Sat Sep 22 18:45:37 2007
@@ -23,7 +23,7 @@
LDFLAGS += `${PKGCONFIG} ${PKGCONFIGFLAGS} --libs libxml-2.0`
# Libraries we link against
-LIBS = -L./lib -ldebug -ldom-libxml-debug -ldom-debug
+LIBS = -L./lib -ldomtest-debug -ldom-libxml-debug -ldom-debug
# Release output
RELEASE =
Modified: trunk/dom/test/lib/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/Makefile?rev=3571&r1...
==============================================================================
--- trunk/dom/test/lib/Makefile (original)
+++ trunk/dom/test/lib/Makefile Sat Sep 22 18:45:37 2007
@@ -22,10 +22,10 @@
CFLAGS += -I$(TOP) -I$(CURDIR)
# Release output
-RELEASE = libdebug.a
+RELEASE = libdomtest.a
# Debug output
-DEBUG = libdebug-debug.a
+DEBUG = libdomtest-debug.a
# Objects
OBJS = list testassert testobject utils
16 years, 2 months
r3570 jmb - /trunk/dom/src/core/node.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 22 18:38:47 2007
New Revision: 3570
URL: http://source.netsurf-browser.org?rev=3570&view=rev
Log:
Implement dom_node_get_child_nodes()
Implement dom_node_get_attributes()
Modified:
trunk/dom/src/core/node.c
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3570&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Sat Sep 22 18:38:47 2007
@@ -408,15 +408,21 @@
* \param result Pointer to location to receive child list
* \return DOM_NO_ERR.
*
- * \todo Work out reference counting semantics of dom_nodelist
+ * The returned NodeList will be referenced. It is the responsibility
+ * of the caller to unref the list once it has finished with it.
*/
dom_exception dom_node_get_child_nodes(struct dom_node *node,
struct dom_nodelist **result)
{
- UNUSED(node);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ /* Can't do anything without an owning document.
+ * This is only a problem for DocumentType nodes
+ * which are not yet attached to a document.
+ * DocumentType nodes have no children, anyway. */
+ if (node->owner == NULL)
+ return DOM_NOT_SUPPORTED_ERR;
+
+ return dom_document_get_nodelist(node->owner, node,
+ NULL, NULL, NULL, result);
}
/**
@@ -518,15 +524,22 @@
* \param result Pointer to location to receive attribute map
* \return DOM_NO_ERR.
*
- * \todo Work out reference counting semantics of dom_namednodemap
+ * The returned NamedNodeMap will be referenced. It is the responsibility
+ * of the caller to unref the map once it has finished with it.
+ *
+ * If ::node is not an Element, then NULL will be returned.
*/
dom_exception dom_node_get_attributes(struct dom_node *node,
struct dom_namednodemap **result)
{
- UNUSED(node);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ if (node->type != DOM_ELEMENT_NODE) {
+ *result = NULL;
+
+ return DOM_NO_ERR;
+ }
+
+ return dom_document_get_namednodemap(node->owner, node,
+ DOM_ATTRIBUTE_NODE, result);
}
/**
16 years, 2 months
r3569 jmb - in /trunk/dom/src/core: namednodemap.c nodelist.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 22 18:38:07 2007
New Revision: 3569
URL: http://source.netsurf-browser.org?rev=3569&view=rev
Log:
Whitespace changes
Modified:
trunk/dom/src/core/namednodemap.c
trunk/dom/src/core/nodelist.c
Modified: trunk/dom/src/core/namednodemap.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/namednodemap.c?rev=3...
==============================================================================
--- trunk/dom/src/core/namednodemap.c (original)
+++ trunk/dom/src/core/namednodemap.c Sat Sep 22 18:38:07 2007
@@ -28,7 +28,7 @@
/**
* Create a namednodemap
*
- * \param doc The owning document
+ * \param doc The owning document
* \param head Start of list containing items in map
* \param type The type of items in the map
* \param map Pointer to location to receive created map
Modified: trunk/dom/src/core/nodelist.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/nodelist.c?rev=3569&...
==============================================================================
--- trunk/dom/src/core/nodelist.c (original)
+++ trunk/dom/src/core/nodelist.c Sat Sep 22 18:38:07 2007
@@ -55,9 +55,11 @@
*
* If ::tagname is non-NULL, ::namespace and ::localname must be NULL and
* the created list will match nodes by name
+ *
* If ::namespace is non-NULL, ::localname must be non-NULL and
* ::tagname must be NULL and the created list will match nodes by namespace
* and localname
+ *
* If ::tagname, ::namespace and ::localname are NULL, the created list
* will match the children of ::root.
*
16 years, 2 months
r3568 jmb - in /trunk/dom/test: Makefile binding.c lib/ lib/Makefile lib/exceptions.h lib/list.c lib/list.h lib/testassert.c lib/testassert.h lib/testobject.c lib/testobject.h lib/utils.c lib/utils.h list.c list.h testutils.h
by netsurf@semichrome.net
Author: jmb
Date: Sat Sep 22 14:32:42 2007
New Revision: 3568
URL: http://source.netsurf-browser.org?rev=3568&view=rev
Log:
Create a library of utility functions for the testsuite to use
Make test/binding.c include stdio.h itself rather than relying on other things to include it.
Added:
trunk/dom/test/lib/
trunk/dom/test/lib/Makefile
trunk/dom/test/lib/exceptions.h
trunk/dom/test/lib/list.c
- copied, changed from r3565, trunk/dom/test/list.c
trunk/dom/test/lib/list.h
- copied unchanged from r3565, trunk/dom/test/list.h
trunk/dom/test/lib/testassert.c
trunk/dom/test/lib/testassert.h
trunk/dom/test/lib/testobject.c
trunk/dom/test/lib/testobject.h
trunk/dom/test/lib/utils.c
trunk/dom/test/lib/utils.h
Removed:
trunk/dom/test/list.c
trunk/dom/test/list.h
Modified:
trunk/dom/test/Makefile
trunk/dom/test/binding.c
trunk/dom/test/testutils.h
Modified: trunk/dom/test/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/Makefile?rev=3568&r1=356...
==============================================================================
--- trunk/dom/test/Makefile (original)
+++ trunk/dom/test/Makefile Sat Sep 22 14:32:42 2007
@@ -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 @@
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 @@
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 @@
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 @@
%: %.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
+
Modified: trunk/dom/test/binding.c
URL: http://source.netsurf-browser.org/trunk/dom/test/binding.c?rev=3568&r1=35...
==============================================================================
--- trunk/dom/test/binding.c (original)
+++ trunk/dom/test/binding.c Sat Sep 22 14:32:42 2007
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
#include <dom/dom.h>
#include "testutils.h"
Added: trunk/dom/test/lib/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/Makefile?rev=3568&vi...
==============================================================================
--- trunk/dom/test/lib/Makefile (added)
+++ trunk/dom/test/lib/Makefile Sat Sep 22 14:32:42 2007
@@ -1,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 $@ $<
+
Added: trunk/dom/test/lib/exceptions.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/exceptions.h?rev=356...
==============================================================================
--- trunk/dom/test/lib/exceptions.h (added)
+++ trunk/dom/test/lib/exceptions.h Sat Sep 22 14:32:42 2007
@@ -1,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
+
Copied: trunk/dom/test/lib/list.c (from r3565, trunk/dom/test/list.c)
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/list.c?p2=trunk/dom/...
==============================================================================
--- trunk/dom/test/list.c (original)
+++ trunk/dom/test/lib/list.c Sat Sep 22 14:32:42 2007
@@ -5,13 +5,13 @@
* Copyright 2007 James Shaw <jshaw(a)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)
{
Added: trunk/dom/test/lib/testassert.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testassert.c?rev=356...
==============================================================================
--- trunk/dom/test/lib/testassert.c (added)
+++ trunk/dom/test/lib/testassert.c Sat Sep 22 14:32:42 2007
@@ -1,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(a)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);
+}
+
+
Added: trunk/dom/test/lib/testassert.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testassert.h?rev=356...
==============================================================================
--- trunk/dom/test/lib/testassert.h (added)
+++ trunk/dom/test/lib/testassert.h Sat Sep 22 14:32:42 2007
@@ -1,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(a)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
+
Added: trunk/dom/test/lib/testobject.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=356...
==============================================================================
--- trunk/dom/test/lib/testobject.c (added)
+++ trunk/dom/test/lib/testobject.c Sat Sep 22 14:32:42 2007
@@ -1,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(a)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";
+}
+
+
Added: trunk/dom/test/lib/testobject.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.h?rev=356...
==============================================================================
--- trunk/dom/test/lib/testobject.h (added)
+++ trunk/dom/test/lib/testobject.h Sat Sep 22 14:32:42 2007
@@ -1,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(a)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
+
Added: trunk/dom/test/lib/utils.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/utils.c?rev=3568&vie...
==============================================================================
--- trunk/dom/test/lib/utils.c (added)
+++ trunk/dom/test/lib/utils.c Sat Sep 22 14:32:42 2007
@@ -1,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(a)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");
+}
+
+
Added: trunk/dom/test/lib/utils.h
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/utils.h?rev=3568&vie...
==============================================================================
--- trunk/dom/test/lib/utils.h (added)
+++ trunk/dom/test/lib/utils.h Sat Sep 22 14:32:42 2007
@@ -1,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(a)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
+
Removed: trunk/dom/test/list.c
URL: http://source.netsurf-browser.org/trunk/dom/test/list.c?rev=3567&view=auto
==============================================================================
--- trunk/dom/test/list.c (original)
+++ trunk/dom/test/list.c (removed)
@@ -1,85 +1,0 @@
-/*
- * This file is part of libdom test suite.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2007 James Shaw <jshaw(a)netsurf-browser.org>
- */
-
-#include <assert.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "list.h"
-
-struct list* list_new(void)
-{
- struct list* list = malloc(sizeof(struct list));
- assert(list != NULL);
- list->size = 0;
- list->head = NULL;
- list->tail = NULL;
- return list;
-}
-
-void list_destroy(struct list* list)
-{
- struct list_elt* elt = list->head;
- while (elt != NULL) {
- struct list_elt* nextElt = elt->next;
- free(elt);
- elt = nextElt;
- }
- free(list);
-}
-
-void list_add(struct list* list, void* data)
-{
- struct list_elt* elt = malloc(sizeof(struct list_elt));
- assert(elt != NULL);
- elt->data = data;
- elt->next = NULL;
- struct list_elt* tail = list->tail;
-
- /* if tail was set, make its 'next' ptr point to elt */
- if (tail != NULL) {
- tail->next = elt;
- }
-
- /* make elt the new tail */
- list->tail = elt;
-
- if (list->head == NULL) {
- list->head = elt;
- }
-
- /* inc the size of the list */
- list->size++;
-}
-
-bool list_contains(struct list* list, void* data, list_compare_func comparator)
-{
- struct list_elt* elt = list->head;
- while (elt != NULL) {
- if (comparator(elt->data, data) == 0) {
- return true;
- }
- elt = elt->next;
- }
- return false;
-}
-
-bool list_contains_all(struct list* superList, struct list* subList,
- list_compare_func comparator)
-{
- struct list_elt* elt = subList->head;
- while (elt != NULL) {
- if (!list_contains(superList, elt->data, comparator)) {
- return false;
- }
- elt = elt->next;
- }
- return true;
-}
-
Removed: trunk/dom/test/list.h
URL: http://source.netsurf-browser.org/trunk/dom/test/list.h?rev=3567&view=auto
==============================================================================
--- trunk/dom/test/list.h (original)
+++ trunk/dom/test/list.h (removed)
@@ -1,44 +1,0 @@
-/*
- * This file is part of libdom test suite.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2007 James Shaw <jshaw(a)netsurf-browser.org>
- */
-
-#ifndef list_h_
-#define list_h_
-
-struct list_elt {
- void* data;
- struct list_elt* next;
-};
-
-struct list {
- unsigned int size;
- struct list_elt* head;
- struct list_elt* tail;
-};
-
-struct list* list_new(void);
-void list_destroy(struct list* list);
-
-typedef int (*list_compare_func)(const void* a, const void* b);
-
-/**
- * Add data to the tail of the list.
- */
-void list_add(struct list* list, void* data);
-
-/**
- * Tests if data is equal to any element in the list.
- */
-bool list_contains(struct list* list, void* data,
- int (*comparator)(const void* a, const void* b));
-
-/**
- * Tests if superlist contains all elements in sublist. Order is not important.
- */
-bool list_contains_all(struct list* superList, struct list* subList,
- list_compare_func comparator);
-
-#endif
Modified: trunk/dom/test/testutils.h
URL: http://source.netsurf-browser.org/trunk/dom/test/testutils.h?rev=3568&r1=...
==============================================================================
--- trunk/dom/test/testutils.h (original)
+++ trunk/dom/test/testutils.h Sat Sep 22 14:32:42 2007
@@ -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
16 years, 2 months
r3566 jshaw - /trunk/dom/docs/TestSuite
by netsurf@semichrome.net
Author: jshaw
Date: Sat Sep 22 13:52:02 2007
New Revision: 3566
URL: http://source.netsurf-browser.org?rev=3566&view=rev
Log:
More notes
Modified:
trunk/dom/docs/TestSuite
Modified: trunk/dom/docs/TestSuite
URL: http://source.netsurf-browser.org/trunk/dom/docs/TestSuite?rev=3566&r1=35...
==============================================================================
--- trunk/dom/docs/TestSuite (original)
+++ trunk/dom/docs/TestSuite Sat Sep 22 13:52:02 2007
@@ -6,6 +6,19 @@
assertNull
assertNotNull
assertEquals
+ Test actual is equal to expected.
+
+ <assertEquals actual="result" expected="expectedResult" ignoreCase="true/false/auto" context="attribute/element" bitmask="..."/>
+
+ For Collections (or Lists), need to check neither list is null, then that both lists have the same size, then that all their elements are equal.
+
+ ignoreCase="auto"
+ if contentType == "text/html":
+ if context == "attribute", do case insensitive test
+ if context == "element", do case sensitive test against expected.toUpperCase()
+ context attribute used in combination with ignoreCase="auto"
+ bitmask attribute used in DOM Level 3 only. Tests: (actual & bitmask) equals (expectedResult & bitmask) where bitmask is an int
+
assertNotEquals
assertSame
@@ -17,12 +30,33 @@
Can use Node.getNodeType() to get runtime type
assertSize
+ Tests a Java Collection has the specified size.
+
+ <assertSize size="2" collection="notifications"/>
+
assertEventCount
assertURIEquals
assertImplementationException
assertDOMException
-
+ Tests that a DOMException is thrown with a specified code. Try/catching not nested.
+
+ <assertDOMException id="setValue_throws_NO_MODIFICATION_ERR">
+ <NO_MODIFICATION_ALLOWED_ERR>
+ <removeChild obj="attrNode" oldChild="textNode" var="removedNode"/>
+ </NO_MODIFICATION_ALLOWED_ERR>
+ </assertDOMException>
+
+ boolean success = false;
+ try {
+ removedNode = attrNode.removeChild(textNode);
+ } catch (DOMException ex) {
+ success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
+ }
+ assertTrue(success);
+
+assertLowerSeverity
+ DOM Level 3 Core only
Conditions
-------------------------------------------------------------------------------
@@ -86,12 +120,17 @@
while
try
- <try>
+Fail if reach the end of the try without throwing an exception specified in <catch>
+<try>
+ ...
+ <catch>
+ <DOMException code="..."/>
+ <DOMException code="..."/>
...
- <catch>
- <DOMException code="..."/>
- </catch>
- </try>
+ </catch>
+</try>
+
+No nesting in test cases, but sometimes more than one instance in a single test.
for-each
<for-each collection="..." member="...">
@@ -103,12 +142,13 @@
Only used in DOM Level 2/3. Returns immediately from method call with optional @value
userObj
+ (not used)
atEvents
capturedEvents
bubbledEvents
allEvents
- DOM Level 2 Evemts only
+ DOM Level 2 Events only
createXPathEvaluator
DOM Level 3 XPath only
@@ -127,7 +167,6 @@
Only used in DOM Level 3
Calls org.w3c.domts.DOMErrorMonitor.getAllErrors(), which is an instance of DOMErrorHandler
-assertLowerSeverity
allNotifications
operation
key
@@ -148,6 +187,10 @@
Collection
In Java, an ArrayList instance typed as a Collection
+
+ <var name="expectedResult" type="Collection">
+ <member>"ent1"</member>
+ <member>"ent2"</member>
EventMonitor
DOM Level 2 Events only
16 years, 2 months
r3565 jshaw - /trunk/dom/test/testutils.h
by netsurf@semichrome.net
Author: jshaw
Date: Sat Sep 22 13:46:12 2007
New Revision: 3565
URL: http://source.netsurf-browser.org?rev=3565&view=rev
Log:
Implement #defines for try/catch
Modified:
trunk/dom/test/testutils.h
Modified: trunk/dom/test/testutils.h
URL: http://source.netsurf-browser.org/trunk/dom/test/testutils.h?rev=3565&r1=...
==============================================================================
--- trunk/dom/test/testutils.h (original)
+++ trunk/dom/test/testutils.h Sat Sep 22 13:46:12 2007
@@ -6,7 +6,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
+#include <setjmp.h>
+#include "exceptions.h"
#include "utils.h"
#include "xmlbinding.h"
#include "xmlparser.h"
@@ -14,6 +16,31 @@
#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
16 years, 2 months