/[LeafOK_CVS]/lbbs/src/test_section_list.c
ViewVC logotype

Diff of /lbbs/src/test_section_list.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.25 by sysadm, Mon May 26 23:38:11 2025 UTC Revision 1.40 by sysadm, Wed Nov 5 06:14:01 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          file_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  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"  static const char ARTICLE_BLOCK_SHM_FILE[] = "~article_block_shm.dat";
19  #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"  static const char SECTION_LIST_SHM_FILE[] = "~section_list_shm.dat";
20  #define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat"  static const char TRIE_DICT_SHM_FILE[] = "~trie_dict_shm.dat";
21    static const char USER_LIST_SHM_FILE[] = "~user_list_shm.dat";
22    
23  const char *sname[] = {  const char *sname[] = {
24          "Test",          "Test",
# Line 33  const char *sname[] = { Line 27  const char *sname[] = {
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",
# Line 70  int main(int argc, char *argv[]) Line 64  int main(int argc, char *argv[])
64                  return -1;                  return -1;
65          }          }
66    
67          log_std_redirect(STDOUT_FILENO);          log_common_redir(STDOUT_FILENO);
68          log_err_redirect(STDERR_FILENO);          log_error_redir(STDERR_FILENO);
69    
70          // - 1 to make blocks allocated is less than required, to trigger error handling          // - 1 to make blocks allocated is less than required, to trigger error handling
71          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;          block_count = BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block;
72    
73          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
74          {          {
# Line 97  int main(int argc, char *argv[]) Line 91  int main(int argc, char *argv[])
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");
# Line 115  int main(int argc, char *argv[]) Line 116  int main(int argc, char *argv[])
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;
# Line 179  int main(int argc, char *argv[]) Line 187  int main(int argc, char *argv[])
187                          article.tid = 0;                          article.tid = 0;
188                          article.sid = i * 3 + 1;                          article.sid = i * 3 + 1;
189                          article.cid = article.aid;                          article.cid = article.aid;
190                          article.uid = 1; // TODO: randomize                          article.uid = 1;
191                          article.visible = 1;                          article.visible = 1;
192                          article.excerption = 0;                          article.excerption = 0;
193                          article.ontop = 0;                          article.ontop = 0;
194                          article.lock = 0;                          article.lock = 0;
195                            article.transship = 0;
196    
197                          if (section_list_rw_lock(p_section[i]) < 0)                          if (section_list_rw_lock(p_section[i]) < 0)
198                          {                          {
# Line 215  int main(int argc, char *argv[]) Line 224  int main(int argc, char *argv[])
224                  printf("last_aid != %d\n", article_block_last_aid());                  printf("last_aid != %d\n", article_block_last_aid());
225          }          }
226    
227            if (article_block_article_count() != section_count * BBS_article_limit_per_section)
228            {
229                    printf("article_block_article_count() error %d != %d * %d\n",
230                               article_block_article_count(), section_count, BBS_article_limit_per_section);
231            }
232    
233          last_aid = 0;          last_aid = 0;
234    
235          for (j = 0; j < BBS_article_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_section; j++)
# Line 295  int main(int argc, char *argv[]) Line 310  int main(int argc, char *argv[])
310                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
311                          article.sid = i * 3 + 1;                          article.sid = i * 3 + 1;
312                          article.cid = article.aid;                          article.cid = article.aid;
313                          article.uid = 1; // TODO: randomize                          article.uid = 1;
314                          article.visible = 1;                          article.visible = 1;
315                          article.excerption = 0;                          article.excerption = 0;
316                          article.ontop = 0;                          article.ontop = 0;
317                          article.lock = 0;                          article.lock = 0;
318                            article.transship = 0;
319    
320                          if (section_list_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
321                          {                          {
# Line 538  int main(int argc, char *argv[]) Line 554  int main(int argc, char *argv[])
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 +
# Line 621  int main(int argc, char *argv[]) Line 637  int main(int argc, char *argv[])
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 +
# Line 690  int main(int argc, char *argv[]) Line 706  int main(int argc, char *argv[])
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 +
# Line 752  int main(int argc, char *argv[]) Line 768  int main(int argc, char *argv[])
768                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
769                          article.sid = i * 3 + 1;                          article.sid = i * 3 + 1;
770                          article.cid = article.aid;                          article.cid = article.aid;
771                          article.uid = 1; // TODO: randomize                          article.uid = 1;
772                          article.visible = 1;                          article.visible = 1;
773                          article.excerption = 0;                          article.excerption = 0;
774                          article.ontop = 0;                          article.ontop = 0;
775                          article.lock = 0;                          article.lock = 0;
776                            article.transship = 0;
777    
778                          if (section_list_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
779                          {                          {
# Line 963  int main(int argc, char *argv[]) Line 980  int main(int argc, char *argv[])
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);


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1