--- lbbs/src/test_file_loader.c 2025/06/07 07:35:06 1.8 +++ lbbs/src/test_file_loader.c 2026/01/03 10:27:14 1.18 @@ -1,28 +1,22 @@ -/*************************************************************************** - test_file_loader.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * test_file_loader + * - tester for shared memory based file loader + * + * Copyright (C) 2004-2026 Leaflet + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "file_loader.h" -#include "trie_dict.h" #include "log.h" +#include +#include #include +#include #include -#include -#include - -#define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat" const char *files[] = { "../data/welcome.txt", @@ -36,14 +30,12 @@ int files_cnt = 6; int main(int argc, char *argv[]) { - int ret; int i; - const void *p_shm; + void *p_shm; size_t data_len; long line_total; const void *p_data; const long *p_line_offsets; - FILE *fp; if (log_begin("../log/bbsd.log", "../log/error.log") < 0) { @@ -54,32 +46,6 @@ int main(int argc, char *argv[]) log_common_redir(STDOUT_FILENO); log_error_redir(STDERR_FILENO); - if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL) - { - log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE); - return -1; - } - fclose(fp); - - if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0) - { - printf("trie_dict_init failed\n"); - return -1; - } - - ret = file_loader_init(); - if (ret < 0) - { - printf("file_loader_init() error (%d)\n", ret); - return ret; - } - - ret = file_loader_init(); - if (ret == 0) - { - printf("Rerun file_loader_init() error\n"); - } - printf("Testing #1\n"); for (i = 0; i < files_cnt; i++) @@ -107,7 +73,7 @@ int main(int argc, char *argv[]) if (detach_file_shm(p_shm) < 0) { - log_error("detach_file_shm(%s) error\n", files[i]); + log_error("detach_file_shm(%s) error", files[i]); } } } @@ -157,23 +123,12 @@ int main(int argc, char *argv[]) if (detach_file_shm(p_shm) < 0) { - log_error("detach_file_shm(%s) error\n", files[i]); + log_error("detach_file_shm(%s) error", files[i]); } } } } - file_loader_cleanup(); - file_loader_cleanup(); - - trie_dict_cleanup(); - - if (unlink(TRIE_DICT_SHM_FILE) < 0) - { - log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); - return -1; - } - log_end(); return 0;