diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/test-list_util.c | 29 | ||||
-rw-r--r-- | tests/test-qpath.c | 490 | ||||
-rw-r--r-- | tests/test-symtab.c | 23 | ||||
-rw-r--r-- | tests/test-vector.c | 103 |
5 files changed, 574 insertions, 77 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index d6e24db7..b4233fb8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,8 +6,8 @@ AM_LDFLAGS = $(PILDFLAGS) noinst_PROGRAMS = testsig testbuffer testmemory heavy heavywq heavythread \ aspathtest testprivs teststream testbgpcap ecommtest \ - testbgpmpattr testchecksum testvector testsymtab \ - testlistutil + testbgpmpattr testchecksum testvector testsymtab \ + testlistutil testqpath testsig_SOURCES = test-sig.c testbuffer_SOURCES = test-buffer.c @@ -25,6 +25,7 @@ testchecksum_SOURCES = test-checksum.c testvector_SOURCES = test-vector.c testsymtab_SOURCES = test-symtab.c testlistutil_SOURCES = test-list_util.c +testqpath_SOURCES = test-qpath.c testsig_LDADD = ../lib/libzebra.la @LIBCAP@ testbuffer_LDADD = ../lib/libzebra.la @LIBCAP@ @@ -42,3 +43,4 @@ testchecksum_LDADD = ../lib/libzebra.la @LIBCAP@ testvector_LDADD = ../lib/libzebra.la @LIBCAP@ testsymtab_LDADD = ../lib/libzebra.la @LIBCAP@ testlistutil_LDADD = ../lib/libzebra.la @LIBCAP@ +testqpath_LDADD = ../lib/libzebra.la @LIBCAP@ diff --git a/tests/test-list_util.c b/tests/test-list_util.c index fc81a562..c4e88502 100644 --- a/tests/test-list_util.c +++ b/tests/test-list_util.c @@ -1,4 +1,5 @@ #include <zebra.h> +#include "misc.h" #include <list_util.h> #include <string.h> @@ -20,10 +21,10 @@ static void test_ddl(void); } while (0) static void -test_assert_fail(const char* true, const char* message, const char* func, +test_assert_fail(const char* truth, const char* message, const char* func, int line) { - printf("*** %s %d: (%s) not true: %s\n", func, line, true, message) ; + printf("*** %s %d: (%s) not true: %s\n", func, line, truth, message) ; } ; @@ -253,12 +254,12 @@ test_ssl(void) this = base ; first = base->next ; ret = ssl_del(base, this, next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == true, "ssl_del did not return true") ; test_assert(first == base, "ssl_del of first item failed") ; this = other->base ; ret = ssl_del(other->base, this, other_next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == true, "ssl_del did not return true") ; test_assert(first == other->base, "ssl_del of first item failed") ; printf("\n") ; @@ -271,9 +272,9 @@ test_ssl(void) */ printf(" Deleting arbitrary items") ; ret = ssl_del(base, del, next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == true, "ssl_del did not return true") ; ret = ssl_del(ssl_parent.base, other_del, other_next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == true, "ssl_del did not return true") ; printf("\n") ; /* Deletion of items from arbitrary place in list @@ -282,9 +283,9 @@ test_ssl(void) */ printf(" Deleting non-existant items") ; ret = ssl_del(base, &dummy, next) ; - test_assert(ret == -1, "ssl_del did not return -1") ; + test_assert(ret == false, "ssl_del did not return false") ; ret = ssl_del(other->base, &dummy, other_next) ; - test_assert(ret == -1, "ssl_del did not return -1") ; + test_assert(ret == false, "ssl_del did not return false") ; printf("\n") ; /* Deletion of NULL items @@ -296,10 +297,10 @@ test_ssl(void) this = NULL ; ret = ssl_del(base, this, next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == false, "ssl_del did not return false") ; ret = ssl_del(ssl_parent.base, this, other_next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == false, "ssl_del did not return false") ; printf("\n") ; @@ -567,21 +568,21 @@ test_ssl(void) test_assert(other->base == NULL, "ssl_del of first and only item failed") ; ret = ssl_del(base, del, next) ; - test_assert(ret == -1, "ssl_del did not return -1") ; + test_assert(ret == false, "ssl_del did not return false") ; test_assert(base == NULL, "ssl_del on empty list") ; ret = ssl_del(other->base, other_del, other_next) ; - test_assert(ret == -1, "ssl_del did not return -1") ; + test_assert(ret == false, "ssl_del did not return false") ; test_assert(other->base == NULL, "ssl_del on empty list") ; this = NULL ; ret = ssl_del(base, this, next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == false, "ssl_del did not return false") ; test_assert(base == NULL, "ssl_del on empty list") ; ret = ssl_del(other->base, this, other_next) ; - test_assert(ret == 0, "ssl_del did not return 0") ; + test_assert(ret == false, "ssl_del did not return false") ; test_assert(other->base == NULL, "ssl_del on empty list") ; printf("\n") ; diff --git a/tests/test-qpath.c b/tests/test-qpath.c new file mode 100644 index 00000000..ecf1a0ae --- /dev/null +++ b/tests/test-qpath.c @@ -0,0 +1,490 @@ +#include "misc.h" +#include "qpath.h" +#include "qlib_init.h" + +#include <stdio.h> + +struct thread_master *master ; /* required by lib ! */ + +/*============================================================================== + * qpath torture tests + * + */ +static int qpath_reduce_testing(void) ; + +int +main(int argc, char **argv) +{ + int errors = 0 ; + + qlib_init_first_stage() ; + + fprintf(stdout, "qpath torture tests\n") ; + + errors += qpath_reduce_testing() ; + + + + if (errors == 0) + fprintf(stdout, "No errors\n") ; + else + fprintf(stderr, "*** %d errors\n", errors) ; +} ; + +/*============================================================================== + * Testing Path Reduction + */ +static int qpath_reduce_test(qpath qp, const char* from, const char* to) ; + +static int +qpath_reduce_testing(void) +{ + int errors = 0 ; + qpath qp ; + + fprintf(stdout, " qpath_reduce() testing") ; + + qp = qpath_init_new(NULL) ; + + /* Trivial Tests */ + + errors += qpath_reduce_test(qp, "", + "") ; + errors += qpath_reduce_test(qp, "a", + "a") ; + errors += qpath_reduce_test(qp, ".", + ".") ; + errors += qpath_reduce_test(qp, "/", + "/") ; + errors += qpath_reduce_test(qp, "/a", + "/a") ; + errors += qpath_reduce_test(qp, "/.", + "/-") ; + errors += qpath_reduce_test(qp, "//", + "//") ; + errors += qpath_reduce_test(qp, "//a", + "//a") ; + errors += qpath_reduce_test(qp, "//.", + "//-") ; + errors += qpath_reduce_test(qp, "///", + "/--") ; + errors += qpath_reduce_test(qp, "///a", + "/--a") ; + errors += qpath_reduce_test(qp, "///.", + "/---") ; + + /* Slightly longer paths */ + + errors += qpath_reduce_test(qp, "abc", + "abc") ; + errors += qpath_reduce_test(qp, "abc.", + "abc.") ; + errors += qpath_reduce_test(qp, ".abc", + ".abc") ; + errors += qpath_reduce_test(qp, "/abc", + "/abc") ; + errors += qpath_reduce_test(qp, "/.abc", + "/.abc") ; + errors += qpath_reduce_test(qp, "/..abc", + "/..abc") ; + errors += qpath_reduce_test(qp, "//abc", + "//abc") ; + errors += qpath_reduce_test(qp, "//abc.", + "//abc.") ; + errors += qpath_reduce_test(qp, "//.abc", + "//.abc") ; + errors += qpath_reduce_test(qp, "///abc", + "/--abc") ; + errors += qpath_reduce_test(qp, "///abc.", + "/--abc.") ; + errors += qpath_reduce_test(qp, "///..abc", + "/--..abc") ; + + errors += qpath_reduce_test(qp, "abc/pqr", + "abc/pqr") ; + errors += qpath_reduce_test(qp, "abc./pqr/", + "abc./pqr/") ; + errors += qpath_reduce_test(qp, ".abc/pqr//", + ".abc/pqr/-") ; + errors += qpath_reduce_test(qp, "/abc/pqr", + "/abc/pqr") ; + errors += qpath_reduce_test(qp, "/.abc/pqr/", + "/.abc/pqr/") ; + errors += qpath_reduce_test(qp, "/..abc/pqr///", + "/..abc/pqr/--") ; + errors += qpath_reduce_test(qp, "//abc/pqr", + "//abc/pqr") ; + errors += qpath_reduce_test(qp, "//abc./pqr/", + "//abc./pqr/") ; + errors += qpath_reduce_test(qp, "//.abc/pqr//", + "//.abc/pqr/-") ; + errors += qpath_reduce_test(qp, "///abc/pqr", + "/--abc/pqr") ; + errors += qpath_reduce_test(qp, "///abc./pqr/", + "/--abc./pqr/") ; + errors += qpath_reduce_test(qp, "///..abc/pqr//", + "/--..abc/pqr/-") ; + + /* Lots of / and . to get rid of -- NB: does not discard trailing '/' */ + + errors += qpath_reduce_test(qp, "/.///./././//", + "/------------") ; + errors += qpath_reduce_test(qp, "/.a.///./././//", + "/.a./----------") ; + errors += qpath_reduce_test(qp, "/.///.b/././//", + "/----.b/------") ; + errors += qpath_reduce_test(qp, "/.a.///./././//.z.", + "/.a./----------.z.") ; + errors += qpath_reduce_test(qp, "/.///.b/././//z.", + "/----.b/------z.") ; + errors += qpath_reduce_test(qp, "/a///./././//.z./", + "/a/----------.z./") ; + errors += qpath_reduce_test(qp, "/.///.b/././//.z./", + "/----.b/------.z./") ; + + errors += qpath_reduce_test(qp, "//.///./././//", + "//------------") ; + errors += qpath_reduce_test(qp, "//.a.///./././//", + "//.a./----------") ; + errors += qpath_reduce_test(qp, "//.///.b/././//", + "//----.b/------") ; + errors += qpath_reduce_test(qp, "//a///./././//z", + "//a/----------z") ; + errors += qpath_reduce_test(qp, "//.///.b/././//.z.", + "//----.b/------.z.") ; + errors += qpath_reduce_test(qp, "//a///./././//..z/", + "//a/----------..z/") ; + errors += qpath_reduce_test(qp, "//.///.b/././//z../", + "//----.b/------z../") ; + + errors += qpath_reduce_test(qp, "///.///./././//", + "/--------------") ; + errors += qpath_reduce_test(qp, "///..a///./././//", + "/--..a/----------") ; + errors += qpath_reduce_test(qp, "///.///.b/././//", + "/------.b/------") ; + errors += qpath_reduce_test(qp, "///a..///./././//z", + "/--a../----------z") ; + errors += qpath_reduce_test(qp, "///.///.b/././//z", + "/------.b/------z") ; + errors += qpath_reduce_test(qp, "///..a..///./././//z/", + "/--..a../----------z/") ; + errors += qpath_reduce_test(qp, "///.///.b/././//z/", + "/------.b/------z/") ; + + /* Assorted trailing '.' */ + + errors += qpath_reduce_test(qp, ".", + ".") ; + errors += qpath_reduce_test(qp, "./", + "./") ; + errors += qpath_reduce_test(qp, "a././", + "a./--") ; + errors += qpath_reduce_test(qp, "/.a/./", + "/.a/--") ; + errors += qpath_reduce_test(qp, "/a./.", + "/a./-") ; + errors += qpath_reduce_test(qp, "/.", + "/-") ; + errors += qpath_reduce_test(qp, "/./", + "/--") ; + errors += qpath_reduce_test(qp, "//.", + "//-") ; + errors += qpath_reduce_test(qp, "//./", + "//--") ; + errors += qpath_reduce_test(qp, "///.", + "/---") ; + errors += qpath_reduce_test(qp, "///.//", + "/-----") ; + + /* Possible .. */ + + errors += qpath_reduce_test(qp, ".a.a.a./..", + "----------") ; + errors += qpath_reduce_test(qp, "..aaa../../", + "-----------") ; + errors += qpath_reduce_test(qp, "..aaa../..", + "----------") ; + errors += qpath_reduce_test(qp, "..aaa../.././//././/.", + "---------------------") ; + errors += qpath_reduce_test(qp, "..aaa../../..z", + "-----------..z") ; + errors += qpath_reduce_test(qp, "..aaa../../..z../", + "-----------..z../") ; + + errors += qpath_reduce_test(qp, "..b.b.b../..aaa../..", + "..b.b.b../----------") ; + errors += qpath_reduce_test(qp, "..bbb../..a.a.a../../", + "..bbb../-------------") ; + errors += qpath_reduce_test(qp, "..bbb../..a.a.a../.././///./", + "..bbb../--------------------") ; + errors += qpath_reduce_test(qp, "..bbb../..aaa.././/../..z..", + "..bbb../--------------..z..") ; + errors += qpath_reduce_test(qp, "..bbb../..aaa.././/../..z../", + "..bbb../--------------..z../") ; + + errors += qpath_reduce_test(qp, "/..a.a.a../..", + "/------------") ; + errors += qpath_reduce_test(qp, "/..a.a.a/../", + "/-----------") ; + errors += qpath_reduce_test(qp, "/a.a.a../.././///./", + "/------------------") ; + errors += qpath_reduce_test(qp, "/..aaa/.//../..z", + "/------------..z") ; + errors += qpath_reduce_test(qp, "/aaa.././/../z/", + "/------------z/") ; + + errors += qpath_reduce_test(qp, "//aaa../..", + "//--------") ; + errors += qpath_reduce_test(qp, "//..aaa/../", + "//---------") ; + errors += qpath_reduce_test(qp, "//aaa../.././///./", + "//----------------") ; + errors += qpath_reduce_test(qp, "//aaa.././/../..z", + "//------------..z") ; + errors += qpath_reduce_test(qp, "//..aaa/.//../z../", + "//------------z../") ; + + errors += qpath_reduce_test(qp, "./aaa../..", + "./--------") ; + errors += qpath_reduce_test(qp, "./..aaa/../", + "./---------") ; + errors += qpath_reduce_test(qp, "./aaa../.././///./", + "./----------------") ; + errors += qpath_reduce_test(qp, "./..aaa/.//../z", + "./------------z") ; + errors += qpath_reduce_test(qp, "./aaa.././/../z/", + "./------------z/") ; + + errors += qpath_reduce_test(qp, ".///./aaa./..", + "./-----------") ; + errors += qpath_reduce_test(qp, "./././.aaa/../", + "./------------") ; + errors += qpath_reduce_test(qp, "./////.aaa/.././///./", + "./-------------------") ; + errors += qpath_reduce_test(qp, "././//./aaa././/../z", + "./-----------------z") ; + errors += qpath_reduce_test(qp, "./..aaa.././/../z/", + "./--------------z/") ; + + errors += qpath_reduce_test(qp, "///..aaa../..", + "/------------") ; + errors += qpath_reduce_test(qp, "///.aaa./../", + "/-----------") ; + errors += qpath_reduce_test(qp, "///aaa/.././///./", + "/----------------") ; + errors += qpath_reduce_test(qp, "///..aaa/.//../z", + "/--------------z") ; + errors += qpath_reduce_test(qp, "///aaa.././/../z/", + "/--------------z/") ; + + errors += qpath_reduce_test(qp, ".bbb/..aaa/../..", + "----------------") ; + errors += qpath_reduce_test(qp, "bbb./aaa../../../", + "-----------------") ; + errors += qpath_reduce_test(qp, "bbb../aaa../../.././///./", + "-------------------------") ; + errors += qpath_reduce_test(qp, "..bbb/..aaa/../../z", + "------------------z") ; + errors += qpath_reduce_test(qp, "bbb../..aaa/../../z/", + "------------------z/") ; + + errors += qpath_reduce_test(qp, "bbb./aaa/../.zzz/../qqq/../..", + "-----------------------------") ; + errors += qpath_reduce_test(qp, "bbb/.aaa/../zzz./../qqq/../../", + "------------------------------") ; + errors += qpath_reduce_test(qp, "/bbb/aaa/../zzz../../..qqq/../../", + "/--------------------------------") ; + errors += qpath_reduce_test(qp, "//bbb../aaa/../zzz/../qqq../../../", + "//--------------------------------") ; + errors += qpath_reduce_test(qp, "./..bbb/aaa/../zzz/../qqq/../../", + "./------------------------------") ; + errors += qpath_reduce_test(qp, "./bbb/aaa../../zzz/../qqq/../..", + "./-----------------------------") ; + errors += qpath_reduce_test(qp, "///bbb/aaa/../zzz../../qqq/../../", + "/--------------------------------") ; + + errors += qpath_reduce_test(qp, "bbb/aaa/../zzz/../qqq/../../.", + "-----------------------------") ; + errors += qpath_reduce_test(qp, "bbb/aaa/../zzz/../qqq/../.././", + "------------------------------") ; + errors += qpath_reduce_test(qp, "/bbb/aaa/../zzz/../qqq/../../", + "/----------------------------") ; + errors += qpath_reduce_test(qp, "//bbb/aaa/../zzz/../qqq/../../", + "//----------------------------") ; + errors += qpath_reduce_test(qp, "./bbb/aaa/../zzz/../qqq/../../", + "./----------------------------") ; + errors += qpath_reduce_test(qp, "./bbb/aaa/../zzz/../qqq/../..", + "./---------------------------") ; + errors += qpath_reduce_test(qp, "///bbb/aaa/../zzz/../qqq/../../", + "/------------------------------") ; + + errors += qpath_reduce_test(qp, "o/aaa../../zzz/../qqq/../../.", + "-----------------------------") ; + errors += qpath_reduce_test(qp, "o/aaa/../zzz../../qqq/../.././", + "------------------------------") ; + errors += qpath_reduce_test(qp, "o/bbb/aaa/../zzz/../qqq../../../", + "o/------------------------------") ; + errors += qpath_reduce_test(qp, "o/bbb/aaa/../zzz/../qqq/../../", + "o/----------------------------") ; + errors += qpath_reduce_test(qp, "o/bbb/aaa/../zzz/../qqq/../../", + "o/----------------------------") ; + errors += qpath_reduce_test(qp, "o/bbb/aaa/../zzz/../qqq/../..", + "o/---------------------------") ; + errors += qpath_reduce_test(qp, "o//bbb/aaa/../zzz/../qqq/../../", + "o/-----------------------------") ; + + errors += qpath_reduce_test(qp, "zzz../././/.././o/..", + "--------------------") ; + errors += qpath_reduce_test(qp, "zzz.././o//.././o/../", + "zzz../---------------") ; + + /* Impossible .. */ + + errors += qpath_reduce_test(qp, "..", + "..") ; + errors += qpath_reduce_test(qp, "../", + "../") ; + errors += qpath_reduce_test(qp, "/..", + "/..") ; + errors += qpath_reduce_test(qp, "/../", + "/../") ; + errors += qpath_reduce_test(qp, "//..", + "//..") ; + errors += qpath_reduce_test(qp, "//../", + "//../") ; + errors += qpath_reduce_test(qp, "///..", + "/--..") ; + errors += qpath_reduce_test(qp, "///../", + "/--../") ; + errors += qpath_reduce_test(qp, "./..", + "./..") ; + errors += qpath_reduce_test(qp, "./../", + "./../") ; + errors += qpath_reduce_test(qp, ".///..", + "./--..") ; + errors += qpath_reduce_test(qp, ".///../", + "./--../") ; + errors += qpath_reduce_test(qp, ".///..", + "./--..") ; + errors += qpath_reduce_test(qp, "././/../", + "./---../") ; + + errors += qpath_reduce_test(qp, "..///./..", + "../----..") ; + errors += qpath_reduce_test(qp, "..///./../", + "../----../") ; + errors += qpath_reduce_test(qp, "/.././///..", + "/../-----..") ; + errors += qpath_reduce_test(qp, "/..///.//../", + "/../-----../") ; + errors += qpath_reduce_test(qp, "//..///.//../.", + "//../-----../-") ; + errors += qpath_reduce_test(qp, "//..//.///.././", + "//../-----../--") ; + errors += qpath_reduce_test(qp, "///..///.//..", + "/--../-----..") ; + errors += qpath_reduce_test(qp, "///.././/./../", + "/--../-----../") ; + errors += qpath_reduce_test(qp, "./../../..", + "./../../..") ; + errors += qpath_reduce_test(qp, "./../../../", + "./../../../") ; + errors += qpath_reduce_test(qp, ".///..///.///.///..", + "./--../----------..") ; + errors += qpath_reduce_test(qp, ".///.././././../", + "./--../------../") ; + errors += qpath_reduce_test(qp, ".///..///////..", + "./--../------..") ; + errors += qpath_reduce_test(qp, "././/..//////..////", + "./---../-----../---") ; + + errors += qpath_reduce_test(qp, "../././/.", + "../------") ; + errors += qpath_reduce_test(qp, "../zzz/..", + "../------") ; + errors += qpath_reduce_test(qp, "/../zzz/.//./../", + "/../------------") ; + errors += qpath_reduce_test(qp, "/zzz../././/.././..", + "/----------------..") ; + errors += qpath_reduce_test(qp, "/zzz../././/.././../", + "/----------------../") ; + errors += qpath_reduce_test(qp, "zzz../././/.././..", + "----------------..") ; + errors += qpath_reduce_test(qp, "zzz../././/.././../", + "----------------../") ; + errors += qpath_reduce_test(qp, "/zzz../././/.././..", + "/----------------..") ; + errors += qpath_reduce_test(qp, "/zzz../././/.././../", + "/----------------../") ; + errors += qpath_reduce_test(qp, "//zzz../././/.././..", + "//----------------..") ; + errors += qpath_reduce_test(qp, "//zzz../././/.././../", + "//----------------../") ; + errors += qpath_reduce_test(qp, "///zzz../././/.././..", + "/------------------..") ; + errors += qpath_reduce_test(qp, "///zzz../././/.././../", + "/------------------../") ; + + /* Finish up */ + + qpath_reset(qp, free_it) ; + + if (errors == 0) + fprintf(stdout, " -- OK\n") ; + else + fprintf(stdout, "\n *** %d errors\n", errors) ; + + return errors ; +} ; + + +static int +qpath_reduce_test(qpath qp, const char* from, const char* to) +{ + const char* r ; + char e[100] ; + const char* p ; + char* q ; + + assert(strlen(to) < sizeof(e)) ; + if (strlen(to) != strlen(from)) + { + fprintf(stdout, + "\n" + " qpath_reduce(%s)\n" + " to: '%s' ???", from, to) ; + return 1 ; + } ; + + p = to ; + q = e ; + + while (1) + { + char ch = *p++ ; + + if ((ch == ' ') || (ch == '-')) + continue ; + + *q++ = ch ; + + if (ch == '\0') + break ; + } ; + + qpath_set(qp, from) ; /* Reduces automajically */ + + r = qpath_string(qp) ; + + if (strcmp(r, e) == 0) + return 0 ; + + fprintf(stdout, + "\n" + " qpath_reduce(%s)\n" + " returned: '%s'\n" + " expected: '%s'", from, r, e) ; + + return 1 ; +} ; diff --git a/tests/test-symtab.c b/tests/test-symtab.c index ed83e607..a4b0bcf2 100644 --- a/tests/test-symtab.c +++ b/tests/test-symtab.c @@ -56,24 +56,25 @@ test_symbol_table_init_new(void) assert_true(table != NULL, "table == NULL"); /* expect to not find */ - sym = symbol_lookup(table, name, 0); + sym = symbol_lookup(table, name, no_add); assert_true(sym == NULL, "sym != NULL"); /* add */ - sym = symbol_lookup(table, name, 1); + sym = symbol_lookup(table, name, add); symbol_set_value(sym, value); assert_true(sym != NULL, "sym == NULL"); - assert_true(strcmp(symbol_get_name(sym), name) == 0, "strcmp(symbol_get_name(sym), name) != 0"); + assert_true(strcmp(symbol_get_name(sym), name) == 0, + "strcmp(symbol_get_name(sym), name) != 0"); /* find */ - sym2 = symbol_lookup(table, name, 0); + sym2 = symbol_lookup(table, name, no_add); assert_true(sym == sym2, "sym != sym2"); assert_true(symbol_get_value(sym) == value, "symbol_get_value(sym) != value"); old_value = symbol_delete(sym); assert_true(value == old_value, "value != old_value"); - while ((old_value = symbol_table_ream(table, 1)) != NULL) + while ((old_value = symbol_table_ream(table, keep_it)) != NULL) { } @@ -98,7 +99,7 @@ test_symbol_table_lookup(void) for (i = 0; i < len; ++i) { sprintf(buf, "%d-name", i); - sym = symbol_lookup(table, buf, 1); + sym = symbol_lookup(table, buf, add); assert_true(sym != NULL, "add: sym == NULL"); assert_true(strcmp(symbol_get_name(sym), buf) == 0, "strcmp(symbol_get_name(sym), buf) != 0"); @@ -114,7 +115,7 @@ test_symbol_table_lookup(void) for (i = 0; i < len; ++i) { sprintf(buf, "%d-name", i); - sym = symbol_lookup(table, buf, 0); + sym = symbol_lookup(table, buf, no_add); assert_true(sym != NULL, "find: sym == NULL"); assert_true(strcmp(symbol_get_name(sym), buf) == 0, "strcmp(symbol_get_name(sym), buf) != 0"); @@ -162,12 +163,12 @@ test_call_back(void) /* add */ symbol_table_set_value_call_back(table, call_back_function_set); - sym = symbol_lookup(table, name, 1); + sym = symbol_lookup(table, name, add); symbol_set_value(sym, value); /* change */ symbol_table_set_value_call_back(table, call_back_function_change); - sym = symbol_lookup(table, name, 1); + sym = symbol_lookup(table, name, add); symbol_set_value(sym, new_value); /* delete */ @@ -216,7 +217,7 @@ test_ref(void) table = symbol_table_init_new(table, NULL, 0, 0, NULL, NULL); /* add */ - sym = symbol_lookup(table, name, 1); + sym = symbol_lookup(table, name, add); symbol_set_value(sym, value); /* create references, in reverse order so that walk in order */ @@ -272,7 +273,7 @@ test_ref_heavy(void) table = symbol_table_init_new(table, NULL, 0, 0, NULL, NULL); /* add */ - sym = symbol_lookup(table, name, 1); + sym = symbol_lookup(table, name, add); symbol_set_value(sym, value); /* create references, in reverse order so that walk in order */ diff --git a/tests/test-vector.c b/tests/test-vector.c index 808a7666..c528b9fd 100644 --- a/tests/test-vector.c +++ b/tests/test-vector.c @@ -25,12 +25,14 @@ void test_vector_insert_item(void); void test_vector_insert_item_here(void); void test_vector_delete_item(void); void do_test_insert(const int rider); -int sort_cmp(const void* const* a, const void* const* b); +int sort_cmp(void const* const* a, void const* const* b); void test_vector_sort(void); void test_vector_bsearch(void); void test_vector_move_item_here(void); -void do_test_move_item_here(const int rider, vector_index ins, vector_index src, - char strings[][10], const vector_index len) ; +void do_test_move_item_here(const int rider, vector_index_t ins, + vector_index_t src, + char strings[][10], + const vector_length_t len) ; void test_vector_part_reverse(void); void test_vector_copy_here(void); void test_vector_move_here(void); @@ -290,9 +292,9 @@ test_vector_set(void) "vector_active != 1000"); vector_set(v, s1000); - assert_true(vector_count(v) == len + 1, + assert_true(vector_count(v) == (unsigned)len + 1, "vector_count != 1001"); - assert_true(vector_active(v) == len + 1, + assert_true(vector_active(v) == (unsigned)len + 1, "vector_active != 1001"); assert_true(vector_slot(v,1000) == s1000, "vector_slot != 1000"); @@ -425,12 +427,12 @@ void do_test_insert(const int rider) { vector v = NULL; - const vector_index len = 100; - const vector_index ins = 50; - vector_index i; + const vector_length_t len = 100; + const vector_index_t ins = 50; + vector_index_t i; char buf[10]; - vector_index check_end = len + 1; - vector_index check_ins = ins; + vector_length_t check_end = len + 1; + vector_index_t check_ins = ins; int check_shift = 1; switch(rider) @@ -551,7 +553,7 @@ test_vector_sort(void) } int -sort_cmp(const void* const* a, const void* const* b) +sort_cmp(void const* const* a, void const* const* b) { return strcmp(*a, *b); } @@ -564,9 +566,9 @@ test_vector_bsearch(void) const int len = 2000; char buf[20]; char target[20]; - vector_index target_index = 0; + vector_index_t target_index = 0; int result; - vector_index index; + vector_index_t index; printf("test_vector_bsearch\n"); @@ -704,12 +706,14 @@ test_vector_move_item_here(void) } void -do_test_move_item_here(const int rider, vector_index ins, vector_index src, - char strings[][10], const vector_index len) +do_test_move_item_here(const int rider, vector_index_t ins, + vector_index_t src, + char strings[][10], + const vector_length_t len) { vector v = NULL; - vector_index i, e, check_end ; - vector_index hi, lo ; + vector_index_t i, e, check_end ; + vector_index_t hi, lo ; char* expect[len] ; p_vector_item dest_item = NULL; @@ -722,7 +726,6 @@ do_test_move_item_here(const int rider, vector_index ins, vector_index src, case 0: printf("test_vector_move_here at dst=%2d, src=%2d\n", src, ins); - --check_end ; break; case 1: @@ -876,17 +879,17 @@ do_test_move_item_here(const int rider, vector_index ins, vector_index src, if (rider == 0) free(dest_item); - vector_free(v); -} + vector_free(v); +} ; void test_vector_part_reverse(void) { vector v = NULL; - const vector_index len = 100; - const vector_index rstart = 50; - const vector_index rstop = 70; - vector_index i; + const vector_length_t len = 100; + const vector_index_t rstart = 50; + const vector_index_t rstop = 70; + vector_index_t i; char buf[10]; printf("test_vector_part_reverse\n"); @@ -942,8 +945,8 @@ test_vector_copy_here(void) { vector v1 = NULL; vector v2 = NULL; - vector_index i; - const vector_index len = 100; + vector_index_t i; + const vector_length_t len = 100; char buf[10]; printf("test_vector_copy_here\n"); @@ -981,8 +984,8 @@ test_vector_move_here(void) { vector v1 = NULL; vector v2 = NULL; - vector_index i; - const vector_index len = 100; + vector_index_t i; + const vector_length_t len = 100; char buf[10]; printf("test_vector_move_here\n"); @@ -1023,8 +1026,8 @@ test_vector_copy_append(void) { vector v1 = NULL; vector v2 = NULL; - vector_index i; - const vector_index len = 100; + vector_index_t i; + const vector_length_t len = 100; char buf[10]; printf("test_vector_copy_append\n"); @@ -1072,8 +1075,8 @@ test_vector_move_append(void) { vector v1 = NULL; vector v2 = NULL; - vector_index i; - const vector_index len = 100; + vector_index_t i; + const vector_length_t len = 100; char buf[10]; printf("test_vector_move_append\n"); @@ -1121,10 +1124,10 @@ void test_vector_insert(void) { vector v = NULL; - vector_index i; - const vector_index len = 100; - const vector_index istart = 50; - const vector_index istop = 70; + vector_index_t i; + const vector_length_t len = 100; + const vector_index_t istart = 50; + const vector_index_t istop = 70; char buf[10]; printf("test_vector_insert\n"); @@ -1176,10 +1179,10 @@ void test_vector_delete(void) { vector v = NULL; - vector_index i; - const vector_index len = 100; - const vector_index dstart = 50; - const vector_index dstop = 70; + vector_index_t i; + const vector_length_t len = 100; + const vector_index_t dstart = 50; + const vector_index_t dstop = 70; char buf[10]; printf("test_vector_delete\n"); @@ -1232,9 +1235,9 @@ void test_vector_discard(void) { vector v = NULL; - vector_index i; - const vector_index len = 100; - const vector_index dstart = 50; + vector_index_t i; + const vector_length_t len = 100; + const vector_index_t dstart = 50; char buf[10]; printf("test_vector_discard\n"); @@ -1282,12 +1285,12 @@ test_vector_sak(void) vector v1 = NULL; vector v2 = NULL; vector v3 = NULL; - vector_index i; - const vector_index len = 100; - const vector_index sstart = 60; - const vector_index sstop = 70; - const vector_index dstart = 40; - const vector_index dstop = 50; + vector_index_t i; + const vector_length_t len = 100; + const vector_index_t sstart = 60; + const vector_index_t sstop = 70; + const vector_index_t dstart = 40; + const vector_index_t dstop = 50; char buf[10]; printf("test_vector_sak\n"); @@ -1304,7 +1307,7 @@ test_vector_sak(void) } v1 = vector_sak(1, v1, v2, dstart, dstop - dstart, - v3, sstart, sstop - sstart, 0); + v3, sstart, sstop - sstart, 0); assert_true(v1 != NULL, "v1 == NULL"); assert_true(vector_end(v1) == (dstop - dstart), |