From d3e20391aac5f121b577cfb897c14c70d54eeee7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Dec 2010 23:12:24 +0000 Subject: Make libdom work again given lack of init/finalise in hubbub and prepare initial attempt at importing tests into the makefile svn path=/trunk/dom/; revision=10992 --- test/testutils/comparators.c | 8 +++--- test/testutils/domts.h | 4 +-- test/testutils/domtsasserts.c | 55 +++++++++++++++++++++-------------------- test/testutils/domtsasserts.h | 6 ++--- test/testutils/domtscondition.h | 27 +++++++++++++++++--- test/testutils/foreach.c | 3 +++ test/testutils/load.c | 11 +++++---- 7 files changed, 69 insertions(+), 45 deletions(-) (limited to 'test/testutils') diff --git a/test/testutils/comparators.c b/test/testutils/comparators.c index 20630c6..b7ec1b1 100644 --- a/test/testutils/comparators.c +++ b/test/testutils/comparators.c @@ -21,13 +21,13 @@ int int_comparator(const void* a, const void* b) { * one is a dom_string, return zero if equal */ int str_cmp(const void *a, const void *b) { - const char *excepted = (const char *) a; + const uint8_t *expected = (const uint8_t *) a; dom_string *actual = (dom_string *) b; dom_string *exp; dom_exception err; bool ret; - err = dom_string_create(myrealloc, NULL, excepted, strlen(excepted), + err = dom_string_create(myrealloc, NULL, expected, strlen((const char *)expected), &exp); if (err != DOM_NO_ERR) return false; @@ -52,13 +52,13 @@ int str_cmp_r(const void *a, const void *b) /* Similar with str_cmp but ignore the case of letters */ int str_icmp(const void *a, const void *b) { - const char *excepted = (const char *) a; + const uint8_t *expected = (const uint8_t *) a; dom_string *actual = (dom_string *) b; dom_string *exp; dom_exception err; bool ret; - err = dom_string_create(myrealloc, NULL, excepted, strlen(excepted), + err = dom_string_create(myrealloc, NULL, expected, strlen((const char *)expected), &exp); if (err != DOM_NO_ERR) return false; diff --git a/test/testutils/domts.h b/test/testutils/domts.h index 6aa8cc4..3c14adf 100644 --- a/test/testutils/domts.h +++ b/test/testutils/domts.h @@ -15,7 +15,7 @@ #include #include -dom_document *load_xml(char *file, bool willBeModified); -dom_document *load_html(char *file, bool willBeModified); +dom_document *load_xml(const char *file, bool willBeModified); +dom_document *load_html(const char *file, bool willBeModified); #endif diff --git a/test/testutils/domtsasserts.c b/test/testutils/domtsasserts.c index 731e19d..bd0eab1 100644 --- a/test/testutils/domtsasserts.c +++ b/test/testutils/domtsasserts.c @@ -42,57 +42,57 @@ bool is_null(void *arg) return arg == NULL; } -bool is_same(void *excepted, void *actual) +bool is_same(void *expected, void *actual) { - return excepted == actual; + return expected == actual; } -bool is_same_int(int excepted, int actual) +bool is_same_int(int expected, int actual) { - return excepted == actual; + return expected == actual; } -bool is_same_unsigned_long(unsigned long excepted, unsigned long actual) +bool is_same_unsigned_long(unsigned long expected, unsigned long actual) { - return excepted == actual; + return expected == actual; } -bool is_equals_int(int excepted, int actual, bool dummy) +bool is_equals_int(int expected, int actual, bool dummy) { UNUSED(dummy); - return excepted == actual; + return expected == actual; } -bool is_equals_bool(bool excepted, bool actual, bool dummy) +bool is_equals_bool(bool expected, bool actual, bool dummy) { UNUSED(dummy); - return excepted == actual; + return expected == actual; } -bool is_equals_unsigned_long(unsigned long excepted, unsigned long actual, bool dummy) +bool is_equals_unsigned_long(unsigned long expected, unsigned long actual, bool dummy) { UNUSED(dummy); - return excepted == actual; + return expected == actual; } /** * Test whether two string are equal * - * \param excepted The excepted string + * \param expected The expected string * \param actual The actual string * \param ignoreCase Whether to ignore letter case */ -bool is_equals_string(const char *excepted, dom_string *actual, +bool is_equals_string(const char *expected, dom_string *actual, bool ignoreCase) { dom_string *exp; dom_exception err; bool ret; - err = dom_string_create(myrealloc, NULL, excepted, strlen(excepted), + err = dom_string_create(myrealloc, NULL, (const uint8_t *)expected, strlen(expected), &exp); if (err != DOM_NO_ERR) return false; @@ -107,13 +107,13 @@ bool is_equals_string(const char *excepted, dom_string *actual, } /* Compare whether two dom_string are equal */ -bool is_equals_domstring(dom_string *excepted, dom_string *actual, +bool is_equals_domstring(dom_string *expected, dom_string *actual, bool ignoreCase) { if (ignoreCase == true) - return dom_string_icmp(excepted, actual) == 0; + return dom_string_icmp(expected, actual) == 0; else - return dom_string_cmp(excepted, actual) == 0; + return dom_string_cmp(expected, actual) == 0; } /* The param actual should always contain dom_sting and expectd should @@ -142,9 +142,7 @@ bool is_equals_list(list *expected, list *actual, bool ignoreCase) assert(cmp != NULL); - bool ret = list_contains_all(expected, actual, cmp); - if (ret) - return list_contains_all(actual, expected, rcmp); + return list_contains_all(expected, actual, cmp) && list_contains_all(actual, expected, rcmp); } @@ -152,12 +150,15 @@ bool is_equals_list(list *expected, list *actual, bool ignoreCase) bool is_instanceof(const char *type, dom_node *node) { assert("There is no instanceOf in the test-suite" == NULL); - + + (void)type; + (void)node; + return false; } -bool is_size_domnamednodemap(int size, dom_namednodemap *map) +bool is_size_domnamednodemap(unsigned long size, dom_namednodemap *map) { unsigned long len; dom_exception err; @@ -171,7 +172,7 @@ bool is_size_domnamednodemap(int size, dom_namednodemap *map) return size == len; } -bool is_size_domnodelist(int size, dom_nodelist *list) +bool is_size_domnodelist(unsigned long size, dom_nodelist *list) { unsigned long len; dom_exception err; @@ -185,7 +186,7 @@ bool is_size_domnodelist(int size, dom_nodelist *list) return size == len; } -bool is_size_list(int size, list *list) +bool is_size_list(unsigned long size, list *list) { return size == list->size; } @@ -224,12 +225,12 @@ bool has_feature(char *feature, char *version) bool ret; dom_string *df, *dv; - err = dom_string_create(myrealloc, NULL, feature, + err = dom_string_create(myrealloc, NULL, (const uint8_t *)feature, feature == NULL ? 0 : strlen(feature), &df); if (err != DOM_NO_ERR) return false; - err = dom_string_create(myrealloc, NULL, version, + err = dom_string_create(myrealloc, NULL, (const uint8_t *)version, version == NULL ? 0 : strlen(version), &dv); if (err != DOM_NO_ERR) { dom_string_unref(df); diff --git a/test/testutils/domtsasserts.h b/test/testutils/domtsasserts.h index a09603f..bb39fe5 100644 --- a/test/testutils/domtsasserts.h +++ b/test/testutils/domtsasserts.h @@ -45,9 +45,9 @@ bool is_equals_list(list *expected, list *actual, bool ignoreCase); bool is_instanceof(const char *type, dom_node *node); -bool is_size_domnamednodemap(int size, dom_namednodemap *map); -bool is_size_domnodelist(int size, dom_nodelist *list); -bool is_size_list(int size, list *list); +bool is_size_domnamednodemap(unsigned long size, dom_namednodemap *map); +bool is_size_domnodelist(unsigned long size, dom_nodelist *list); +bool is_size_list(unsigned long size, list *list); bool is_uri_equals(char *scheme, char *path, char *host, char *file, char *query, char *fragment, diff --git a/test/testutils/domtscondition.h b/test/testutils/domtscondition.h index 164977f..30da6cc 100644 --- a/test/testutils/domtscondition.h +++ b/test/testutils/domtscondition.h @@ -10,9 +10,28 @@ #include -inline bool less(int excepted, int actual); -inline bool less_or_equals(int excepted, int actual); -inline bool greater(int excepted, int actual); -inline bool greater_or_equals(int excepted, int actual); +/** + * Just simple functions which meet the needs of DOMTS conditions + */ + +static inline bool less(int excepted, int actual) +{ + return actual < excepted; +} + +static inline bool less_or_equals(int excepted, int actual) +{ + return actual <= excepted; +} + +static inline bool greater(int excepted, int actual) +{ + return actual > excepted; +} + +static inline bool greater_or_equals(int excepted, int actual) +{ + return actual >= excepted; +} #endif diff --git a/test/testutils/foreach.c b/test/testutils/foreach.c index c3868df..764920c 100644 --- a/test/testutils/foreach.c +++ b/test/testutils/foreach.c @@ -18,16 +18,19 @@ void foreach_initialise_domnodelist(dom_nodelist *list, unsigned int *iterator) { + (void)list; *iterator = 0; } void foreach_initialise_list(list *list, unsigned int *iterator) { + (void)list; *iterator = 0; } void foreach_initialise_domnamednodemap(dom_namednodemap *map, unsigned int *iterator) { + (void)map; *iterator = 0; } diff --git a/test/testutils/load.c b/test/testutils/load.c index 0028eb4..57e07ef 100644 --- a/test/testutils/load.c +++ b/test/testutils/load.c @@ -23,6 +23,7 @@ #include #include "utils.h" +#include "domts.h" /** * Load the file as it is a XML file @@ -30,14 +31,14 @@ * \param file The file path * \param willBeModified Whether this file will be modified, not used */ -dom_document *load_xml(char *file, bool willBeModified) +dom_document *load_xml(const char *file, bool willBeModified) { dom_xml_parser *parser = NULL; int handle; int readed; dom_xml_error error; dom_document *ret; - char buffer[1024]; + uint8_t buffer[1024]; UNUSED(willBeModified); @@ -92,18 +93,18 @@ dom_document *load_xml(char *file, bool willBeModified) * \param file The file path * \param willBeModified Whether this file will be modified, not used */ -dom_document *load_html(char *file, bool willBeModified) +dom_document *load_html(const char *file, bool willBeModified) { dom_hubbub_parser *parser = NULL; int handle; int readed; dom_hubbub_error error; dom_document *ret; - char buffer[1024]; + uint8_t buffer[1024]; UNUSED(willBeModified); - parser = dom_hubbub_parser_create("../data/Aliases", NULL, true, + parser = dom_hubbub_parser_create(NULL, true, myrealloc, NULL, mymsg, NULL); if (parser == NULL) { fprintf(stderr, "Can't create Hubbub Parser\n"); -- cgit v1.2.3