| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
file_section_list.c - description |
test_section_list.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
Email : leaflet@leafok.com |
Email : leaflet@leafok.com |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#include "section_list.h" |
|
|
#include "trie_dict.h" |
|
| 17 |
#include "bbs.h" |
#include "bbs.h" |
| 18 |
#include "log.h" |
#include "log.h" |
| 19 |
|
#include "section_list.h" |
| 20 |
|
#include "trie_dict.h" |
| 21 |
|
#include "user_list.h" |
| 22 |
|
#include <errno.h> |
| 23 |
#include <stdio.h> |
#include <stdio.h> |
| 24 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <errno.h> |
|
| 25 |
|
|
| 26 |
#define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat" |
#define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat" |
| 27 |
#define SECTION_LIST_SHM_FILE "~section_list_shm.dat" |
#define SECTION_LIST_SHM_FILE "~section_list_shm.dat" |
| 28 |
#define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat" |
#define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat" |
| 29 |
|
#define USER_LIST_SHM_FILE "~user_list_shm.dat" |
| 30 |
|
|
| 31 |
const char *sname[] = { |
const char *sname[] = { |
| 32 |
"Test", |
"Test", |
| 35 |
|
|
| 36 |
const char *stitle[] = { |
const char *stitle[] = { |
| 37 |
" Test Section ", |
" Test Section ", |
| 38 |
"ĸABC", |
"字母组合ABC", |
| 39 |
"__123"}; |
"_数字_123"}; |
| 40 |
|
|
| 41 |
const char *master_name[] = { |
const char *master_name[] = { |
| 42 |
"sysadm", |
"sysadm", |
| 99 |
} |
} |
| 100 |
fclose(fp); |
fclose(fp); |
| 101 |
|
|
| 102 |
|
if ((fp = fopen(USER_LIST_SHM_FILE, "w")) == NULL) |
| 103 |
|
{ |
| 104 |
|
log_error("fopen(%s) error\n", USER_LIST_SHM_FILE); |
| 105 |
|
return -1; |
| 106 |
|
} |
| 107 |
|
fclose(fp); |
| 108 |
|
|
| 109 |
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) |
| 110 |
{ |
{ |
| 111 |
printf("trie_dict_init failed\n"); |
printf("trie_dict_init failed\n"); |
| 124 |
return -2; |
return -2; |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
|
// Load user_list and online_user_list |
| 128 |
|
if (user_list_pool_init(USER_LIST_SHM_FILE) < 0) |
| 129 |
|
{ |
| 130 |
|
log_error("user_list_pool_init() error\n"); |
| 131 |
|
return -2; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
printf("Testing #1 ...\n"); |
printf("Testing #1 ...\n"); |
| 135 |
|
|
| 136 |
last_aid = 0; |
last_aid = 0; |
| 562 |
(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) != |
| 563 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 564 |
{ |
{ |
| 565 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#1 Inconsistent page count in section %d offset %d, %d != %d, " |
| 566 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 567 |
i, j, |
i, j, |
| 568 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 645 |
(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) != |
| 646 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 647 |
{ |
{ |
| 648 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#2 Inconsistent page count in section %d offset %d, %d != %d, " |
| 649 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 650 |
i, j, |
i, j, |
| 651 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 714 |
(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) != |
| 715 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 716 |
{ |
{ |
| 717 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#3 Inconsistent page count in section %d offset %d, %d != %d, " |
| 718 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 719 |
i, j, |
i, j, |
| 720 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 988 |
printf("Press ENTER to exit..."); |
printf("Press ENTER to exit..."); |
| 989 |
getchar(); |
getchar(); |
| 990 |
|
|
| 991 |
|
user_list_pool_cleanup(); |
| 992 |
section_list_cleanup(); |
section_list_cleanup(); |
| 993 |
article_block_cleanup(); |
article_block_cleanup(); |
| 994 |
trie_dict_cleanup(); |
trie_dict_cleanup(); |
| 995 |
|
|
| 996 |
|
if (unlink(USER_LIST_SHM_FILE) < 0) |
| 997 |
|
{ |
| 998 |
|
log_error("unlink(%s) error\n", USER_LIST_SHM_FILE); |
| 999 |
|
return -1; |
| 1000 |
|
} |
| 1001 |
|
|
| 1002 |
if (unlink(TRIE_DICT_SHM_FILE) < 0) |
if (unlink(TRIE_DICT_SHM_FILE) < 0) |
| 1003 |
{ |
{ |
| 1004 |
log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); |
log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); |