aboutsummaryrefslogtreecommitdiff
path: root/tests/libutil/str_table.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 11:30:46 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 18:04:25 +0100
commit72c8155d9fc0eaeac72c053f46ebb7b231d4596a (patch)
tree5758865289c52fa93f56e3fe743bb40c283c5233 /tests/libutil/str_table.c
parentcdccc69c62579b0c13b35fad0728079652b8f3c9 (diff)
Reintegrate test code with library code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libutil/str_table.c')
-rw-r--r--tests/libutil/str_table.c85
1 files changed, 0 insertions, 85 deletions
diff --git a/tests/libutil/str_table.c b/tests/libutil/str_table.c
deleted file mode 100644
index d4160eb..0000000
--- a/tests/libutil/str_table.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * str_table.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "util/str_table.h"
-#include "io/file.h"
-#include "compat.h"
-#include "util/test.h"
-
-static char *strings[1000];
-
-static int read_strings(void)
-{
- istream_t *fp;
- ssize_t ret;
- char *line;
- int i;
-
- fp = istream_open_file("words.txt");
- TEST_NOT_NULL(fp);
-
- for (i = 0; i < 1000; ++i) {
- ret = istream_get_line(fp, &line, NULL, 0);
- TEST_EQUAL_I(ret, 0);
-
- strings[i] = line;
- }
-
- sqfs_drop(fp);
- return 0;
-}
-
-int main(int argc, char **argv)
-{
- str_table_t table;
- size_t i, j, idx;
- const char *str;
- (void)argc; (void)argv;
-
- TEST_ASSERT(chdir(TEST_PATH) == 0);
-
- if (read_strings())
- return EXIT_FAILURE;
-
- TEST_ASSERT(str_table_init(&table) == 0);
-
- for (i = 0; i < 1000; ++i) {
- TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0);
-
- TEST_EQUAL_UI(idx, i);
-
- for (j = 0; j <= i; ++j) {
- str = str_table_get_string(&table, j);
-
- TEST_NOT_NULL(str);
- TEST_ASSERT(str != strings[i]);
- TEST_STR_EQUAL(str, strings[j]);
- }
-
- for (; j < 1000; ++j)
- TEST_NULL(str_table_get_string(&table, j));
- }
-
- for (i = 0; i < 1000; ++i) {
- TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0);
- TEST_EQUAL_UI(idx, i);
-
- str = str_table_get_string(&table, i);
-
- TEST_NOT_NULL(str);
- TEST_ASSERT(str != strings[i]);
- TEST_STR_EQUAL(str, strings[i]);
- }
-
- str_table_cleanup(&table);
-
- for (i = 0; i < 1000; ++i)
- free(strings[i]);
-
- return EXIT_SUCCESS;
-}