X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-tsearch.c;h=ae4de66ca0ccb854e1e1ae0fbf66148ac3347805;hb=09001dfb3ec39d237f8e248ff347cf1be3e6f0c1;hp=1d55824b69cc64f5c07ee58759d6df8fd499ab3d;hpb=192bd848d1106fc68d24e24e61534d6d9d49a335;p=gnulib.git diff --git a/tests/test-tsearch.c b/tests/test-tsearch.c index 1d55824b6..ae4de66ca 100644 --- a/tests/test-tsearch.c +++ b/tests/test-tsearch.c @@ -1,26 +1,34 @@ /* Test program for tsearch et al. - Copyright (C) 1997, 2000, 2001, 2007 Free Software Foundation, Inc. + Copyright (C) 1997, 2000-2001, 2007-2011 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 - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + The GNU C Library is free software: you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ #include #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 @@ -122,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); + } } } @@ -141,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 @@ -165,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); } @@ -175,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; + + } } } @@ -258,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; @@ -310,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;