X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-tsearch.c;h=454fef60625ca55b60d23e1a241676aea72bbd0b;hb=ba0163712435ee40583ee8eb0dc289220b31fa35;hp=b6a22fa9f08d4608f5729b70af114b3eabe627b4;hpb=b42d50108cf2147b3d80ecb6457faa96347411e9;p=gnulib.git diff --git a/tests/test-tsearch.c b/tests/test-tsearch.c index b6a22fa9f..454fef606 100644 --- a/tests/test-tsearch.c +++ b/tests/test-tsearch.c @@ -1,5 +1,5 @@ /* Test program for tsearch et al. - Copyright (C) 1997, 2000, 2001, 2007 Free Software Foundation, Inc. + Copyright (C) 1997, 2000-2001, 2007-2010 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software: you can redistribute it and/or @@ -19,6 +19,16 @@ #include +#include "signature.h" +SIGNATURE_CHECK (tdelete, void *, (void const *, void **, + int (*) (void const *, void const *))); +SIGNATURE_CHECK (tfind, void *, (void const *, void * const *, + int (*) (void const *, void const *))); +SIGNATURE_CHECK (tsearch, void *, (void const *, void **, + int (*) (void const *, void const *))); +SIGNATURE_CHECK (twalk, void, (void const *, + void (*) (void const *, VISIT, int))); + #include #include #include @@ -120,10 +130,10 @@ walk_action (const void *nodep, const VISIT which, const int depth) else { if (depths[key] != depth) - { - fputs ("Depth for one element is not constant during tree walk.\n", - stdout); - } + { + fputs ("Depth for one element is not constant during tree walk.\n", + stdout); + } } } @@ -139,8 +149,8 @@ walk_tree (void *root, int expected_count) for (i = 0; i < expected_count; ++i) if (z[i] != 1) { - fputs ("Node was not visited.\n", stdout); - error = 1; + fputs ("Node was not visited.\n", stdout); + error = 1; } #if BALANCED @@ -163,7 +173,7 @@ mangle_tree (enum order how, enum action what, void **root, int lag) if (how == randomorder) { for (i = 0; i < SIZE; ++i) - y[i] = i; + y[i] = i; memfry (y); } @@ -173,77 +183,77 @@ mangle_tree (enum order how, enum action what, void **root, int lag) int j, k; switch (how) - { - case randomorder: - if (i >= lag) - k = y[i - lag]; - else - /* Ensure that the array index is within bounds. */ - k = y[(SIZE - i - 1 + lag) % SIZE]; - j = y[i % SIZE]; - break; - - case ascending: - k = i - lag; - j = i; - break; - - case descending: - k = SIZE - i - 1 + lag; - j = SIZE - i - 1; - break; - - default: - /* This never should happen, but gcc isn't smart enough to - recognize it. */ - abort (); - } + { + case randomorder: + if (i >= lag) + k = y[i - lag]; + else + /* Ensure that the array index is within bounds. */ + k = y[(SIZE - i - 1 + lag) % SIZE]; + j = y[i % SIZE]; + break; + + case ascending: + k = i - lag; + j = i; + break; + + case descending: + k = SIZE - i - 1 + lag; + j = SIZE - i - 1; + break; + + default: + /* This never should happen, but gcc isn't smart enough to + recognize it. */ + abort (); + } switch (what) - { - case build_and_del: - case build: - if (i < SIZE) - { - if (tfind (x + j, (void *const *) root, cmp_fn) != NULL) - { - fputs ("Found element which is not in tree yet.\n", stdout); - error = 1; - } - elem = tsearch (x + j, root, cmp_fn); - if (elem == 0 - || tfind (x + j, (void *const *) root, cmp_fn) == NULL) - { - fputs ("Couldn't find element after it was added.\n", - stdout); - error = 1; - } - } - - if (what == build || i < lag) - break; - - j = k; - /* fall through */ - - case delete: - elem = tfind (x + j, (void *const *) root, cmp_fn); - if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL) - { - fputs ("Error deleting element.\n", stdout); - error = 1; - } - break; - - case find: - if (tfind (x + j, (void *const *) root, cmp_fn) == NULL) - { - fputs ("Couldn't find element after it was added.\n", stdout); - error = 1; - } - break; - - } + { + case build_and_del: + case build: + if (i < SIZE) + { + if (tfind (x + j, (void *const *) root, cmp_fn) != NULL) + { + fputs ("Found element which is not in tree yet.\n", stdout); + error = 1; + } + elem = tsearch (x + j, root, cmp_fn); + if (elem == 0 + || tfind (x + j, (void *const *) root, cmp_fn) == NULL) + { + fputs ("Couldn't find element after it was added.\n", + stdout); + error = 1; + } + } + + if (what == build || i < lag) + break; + + j = k; + /* fall through */ + + case delete: + elem = tfind (x + j, (void *const *) root, cmp_fn); + if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL) + { + fputs ("Error deleting element.\n", stdout); + error = 1; + } + break; + + case find: + if (tfind (x + j, (void *const *) root, cmp_fn) == NULL) + { + fputs ("Couldn't find element after it was added.\n", stdout); + error = 1; + } + break; + + } } } @@ -256,7 +266,9 @@ main (int argc, char **argv) void *root = NULL; int i, j; +#if HAVE_INITSTATE initstate (SEED, state, 8); +#endif for (i = 0; i < SIZE; ++i) x[i] = i; @@ -308,9 +320,9 @@ main (int argc, char **argv) mangle_tree (randomorder, delete, &root, 0); for (j = 1; j < SIZE; j *= 2) - { - mangle_tree (randomorder, build_and_del, &root, j); - } + { + mangle_tree (randomorder, build_and_del, &root, j); + } fputs (error ? " failed!\n" : " ok.\n", stdout); total_error |= error;