summaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/posix/search.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:52 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 18:24:51 -0500
commitf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch)
tree93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/posix/search.c
parentbd5969fc876a10b18613302db7087ef3c40f18e1 (diff)
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/posix/search.c')
-rw-r--r--lib/mlibc/tests/posix/search.c51
1 files changed, 0 insertions, 51 deletions
diff --git a/lib/mlibc/tests/posix/search.c b/lib/mlibc/tests/posix/search.c
deleted file mode 100644
index 6b68ef9..0000000
--- a/lib/mlibc/tests/posix/search.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include <search.h>
-#include <assert.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-static int compare(const void *pa, const void *pb) {
- if (*(int*)pa < *(int*) pb)
- return -1;
- if (*(int*)pa > *(int*) pb)
- return 1;
- return 0;
-}
-
-static void check_key(int key, void *root) {
- int keyp = key;
- void *ret = tfind((void*) &keyp, &root, compare);
- assert(ret);
- assert(**((int **) ret) == key);
-}
-
-static void free_key(void *key) {
- free(key);
-}
-
-int main() {
- void *root = NULL;
- for (int i = 0; i < 12; i++) {
- int *ptr = malloc(sizeof(int));
- assert(ptr);
- *ptr = i;
-
- void *ret = tsearch((void*) ptr, &root, compare);
- assert(ret);
- assert(**((int **) ret) == i);
- }
-
- // Test a couple of keys
- check_key(1, root);
- check_key(5, root);
- check_key(10, root);
-
- // Verify NULL on non-existent key
- int key = -1;
- void *ret = tfind((void*) &key, &root, compare);
- assert(ret == NULL);
-
- // tdelete is not implemented yet (#351)
- (void)free_key;
- // tdestroy(root, free_key);
- return 0;
-}