| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
test_section_list.c - description |
/* |
| 3 |
------------------- |
* test_section_list |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - tester for data models and basic operations of section and article |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 by Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
|
/*************************************************************************** |
|
|
* * |
|
|
* 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. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
|
#include "section_list.h" |
|
|
#include "trie_dict.h" |
|
| 9 |
#include "bbs.h" |
#include "bbs.h" |
| 10 |
#include "log.h" |
#include "log.h" |
| 11 |
|
#include "section_list.h" |
| 12 |
|
#include "trie_dict.h" |
| 13 |
|
#include "user_list.h" |
| 14 |
|
#include <errno.h> |
| 15 |
#include <stdio.h> |
#include <stdio.h> |
| 16 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <errno.h> |
|
| 17 |
|
|
| 18 |
#define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat" |
#define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat" |
| 19 |
#define SECTION_LIST_SHM_FILE "~section_list_shm.dat" |
#define SECTION_LIST_SHM_FILE "~section_list_shm.dat" |
| 20 |
#define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat" |
#define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat" |
| 21 |
|
#define USER_LIST_SHM_FILE "~user_list_shm.dat" |
| 22 |
|
|
| 23 |
const char *sname[] = { |
const char *sname[] = { |
| 24 |
"Test", |
"Test", |
| 27 |
|
|
| 28 |
const char *stitle[] = { |
const char *stitle[] = { |
| 29 |
" Test Section ", |
" Test Section ", |
| 30 |
"ĸABC", |
"字母组合ABC", |
| 31 |
"__123"}; |
"_数字_123"}; |
| 32 |
|
|
| 33 |
const char *master_name[] = { |
const char *master_name[] = { |
| 34 |
"sysadm", |
"sysadm", |
| 91 |
} |
} |
| 92 |
fclose(fp); |
fclose(fp); |
| 93 |
|
|
| 94 |
|
if ((fp = fopen(USER_LIST_SHM_FILE, "w")) == NULL) |
| 95 |
|
{ |
| 96 |
|
log_error("fopen(%s) error\n", USER_LIST_SHM_FILE); |
| 97 |
|
return -1; |
| 98 |
|
} |
| 99 |
|
fclose(fp); |
| 100 |
|
|
| 101 |
if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0) |
if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0) |
| 102 |
{ |
{ |
| 103 |
printf("trie_dict_init failed\n"); |
printf("trie_dict_init failed\n"); |
| 116 |
return -2; |
return -2; |
| 117 |
} |
} |
| 118 |
|
|
| 119 |
|
// Load user_list and online_user_list |
| 120 |
|
if (user_list_pool_init(USER_LIST_SHM_FILE) < 0) |
| 121 |
|
{ |
| 122 |
|
log_error("user_list_pool_init() error\n"); |
| 123 |
|
return -2; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
printf("Testing #1 ...\n"); |
printf("Testing #1 ...\n"); |
| 127 |
|
|
| 128 |
last_aid = 0; |
last_aid = 0; |
| 554 |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 555 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 556 |
{ |
{ |
| 557 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#1 Inconsistent page count in section %d offset %d, %d != %d, " |
| 558 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 559 |
i, j, |
i, j, |
| 560 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 637 |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 638 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 639 |
{ |
{ |
| 640 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#2 Inconsistent page count in section %d offset %d, %d != %d, " |
| 641 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 642 |
i, j, |
i, j, |
| 643 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 706 |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 707 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 708 |
{ |
{ |
| 709 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#3 Inconsistent page count in section %d offset %d, %d != %d, " |
| 710 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 711 |
i, j, |
i, j, |
| 712 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 980 |
printf("Press ENTER to exit..."); |
printf("Press ENTER to exit..."); |
| 981 |
getchar(); |
getchar(); |
| 982 |
|
|
| 983 |
|
user_list_pool_cleanup(); |
| 984 |
section_list_cleanup(); |
section_list_cleanup(); |
| 985 |
article_block_cleanup(); |
article_block_cleanup(); |
| 986 |
trie_dict_cleanup(); |
trie_dict_cleanup(); |
| 987 |
|
|
| 988 |
|
if (unlink(USER_LIST_SHM_FILE) < 0) |
| 989 |
|
{ |
| 990 |
|
log_error("unlink(%s) error\n", USER_LIST_SHM_FILE); |
| 991 |
|
return -1; |
| 992 |
|
} |
| 993 |
|
|
| 994 |
if (unlink(TRIE_DICT_SHM_FILE) < 0) |
if (unlink(TRIE_DICT_SHM_FILE) < 0) |
| 995 |
{ |
{ |
| 996 |
log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); |
log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); |