This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
FYI: I've added a number of tests to tst-bsearch that should fail. The patch has been committed already. Andreas 2000-09-07 Andreas Jaeger <aj@suse.de> * stdlib/tst-bsearch.c (main): Add more test cases. ============================================================ Index: stdlib/tst-bsearch.c --- stdlib/tst-bsearch.c 2000/09/06 21:02:33 1.1 +++ stdlib/tst-bsearch.c 2000/09/07 09:56:33 @@ -56,11 +56,11 @@ { int cnt; int result = 0; + struct entry key; + struct entry *res; for (cnt = 0; cnt < narr; ++cnt) { - struct entry key; - struct entry *res; key.val = arr[cnt].val; @@ -73,6 +73,57 @@ else if (res != &arr[cnt]) { puts ("wrong entry returned"); + result = 1; + } + } + + /* And some special tests that shouldn't find any entry. */ + key.val = -1; + res = (struct entry *) bsearch (&key, arr, narr, sizeof (arr[0]), comp); + if (res != NULL) + { + puts ("found an entry that's not there"); + result = 1; + } + + key.val = 11; + res = (struct entry *) bsearch (&key, arr, narr, sizeof (arr[0]), comp); + if (res != NULL) + { + puts ("found an entry that's not there"); + result = 1; + } + + key.val = 11; + res = (struct entry *) bsearch (&key, arr, 0, sizeof (arr[0]), comp); + if (res != NULL) + { + puts ("found an entry that's not there"); + result = 1; + } + + /* Now the array contains only one element - no entry should be found. */ + for (cnt = 0; cnt < narr; ++cnt) + { + key.val = arr[cnt].val; + + res = (struct entry *) bsearch (&key, &arr[5], 1, sizeof (arr[0]), comp); + if (cnt == 5) + { + if (res == NULL) + { + printf ("entry %d not found\n", cnt); + result = 1; + } + else if (res != &arr[cnt]) + { + puts ("wrong entry returned"); + result = 1; + } + } + else if (res != NULL) + { + puts ("found an entry that's not there"); result = 1; } } -- Andreas Jaeger SuSE Labs aj@suse.de private aj@arthur.inka.de http://www.suse.de/~aj
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |