diff options
author | Bo Yang <struggleyb.nku@gmail.com> | 2009-08-11 11:17:23 +0000 |
---|---|---|
committer | Bo Yang <struggleyb.nku@gmail.com> | 2009-08-11 11:17:23 +0000 |
commit | 399da01ae4eb5c5e3e9349bacc2063c946c3d4a1 (patch) | |
tree | 433c8bcde94fc7a6e6f2e5cbf23842a84db98146 /test/testutils/comparators.c | |
parent | eec057c7437e19b59ca1e698ce548cb56ce37240 (diff) | |
download | libdom-399da01ae4eb5c5e3e9349bacc2063c946c3d4a1.tar.gz libdom-399da01ae4eb5c5e3e9349bacc2063c946c3d4a1.tar.bz2 |
Merge the branches/struggleyb/libdom-remain back to trunk.
svn path=/trunk/dom/; revision=9191
Diffstat (limited to 'test/testutils/comparators.c')
-rw-r--r-- | test/testutils/comparators.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/testutils/comparators.c b/test/testutils/comparators.c new file mode 100644 index 0000000..20630c6 --- /dev/null +++ b/test/testutils/comparators.c @@ -0,0 +1,80 @@ +/* + * This file is part of libdom test suite. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com> + */ + +#include "comparators.h" +#include "domts.h" + +#include <string.h> + +#include <dom/dom.h> + +/* Compare to integer, return zero if equal */ +int int_comparator(const void* a, const void* b) { + return *((const int *)a) - *((const int *)b); +} + +/* Compare two string. The first one is a char * and the second + * one is a dom_string, return zero if equal */ +int str_cmp(const void *a, const void *b) +{ + const char *excepted = (const char *) a; + dom_string *actual = (dom_string *) b; + dom_string *exp; + dom_exception err; + bool ret; + + err = dom_string_create(myrealloc, NULL, excepted, strlen(excepted), + &exp); + if (err != DOM_NO_ERR) + return false; + + ret = dom_string_cmp(exp, actual) == 0; + + dom_string_unref(exp); + + if (ret == true) + return 0; + else + return 1; +} + +/* Similar with str_cmp but the first param is a dom_string the second + * param is a char * */ +int str_cmp_r(const void *a, const void *b) +{ + return str_cmp(b, a); +} + +/* 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; + dom_string *actual = (dom_string *) b; + dom_string *exp; + dom_exception err; + bool ret; + + err = dom_string_create(myrealloc, NULL, excepted, strlen(excepted), + &exp); + if (err != DOM_NO_ERR) + return false; + + ret = dom_string_icmp(exp, actual) == 0; + + dom_string_unref(exp); + + if (ret == true) + return 0; + else + return 1; +} + +/* Similar with str_icmp, but the param order are reverse */ +int str_icmp_r(const void *a, const void *b) +{ + return str_icmp(b, a); +} |