/[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.36 by sysadm, Mon Nov 3 15:05:02 2025 UTC Revision 1.45 by sysadm, Fri Dec 19 06:16:27 2025 UTC
# Line 1  Line 1 
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  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "log.h"  #include "log.h"
# Line 23  Line 19 
19  #include <stdio.h>  #include <stdio.h>
20  #include <unistd.h>  #include <unistd.h>
21    
22  #define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat"  static const char ARTICLE_BLOCK_SHM_FILE[] = "~article_block_shm.dat";
23  #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"  static const char SECTION_LIST_SHM_FILE[] = "~section_list_shm.dat";
24  #define TRIE_DICT_SHM_FILE "~trie_dict_shm.dat"  static const char TRIE_DICT_SHM_FILE[] = "~trie_dict_shm.dat";
25  #define USER_LIST_SHM_FILE "~user_list_shm.dat"  static const char USER_LIST_SHM_FILE[] = "~user_list_shm.dat";
26    
27  const char *sname[] = {  const char *sname[] = {
28          "Test",          "Test",
# Line 76  int main(int argc, char *argv[]) Line 72  int main(int argc, char *argv[])
72          log_error_redir(STDERR_FILENO);          log_error_redir(STDERR_FILENO);
73    
74          // - 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
75          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;
76    
77          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
78          {          {
79                  log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE);                  log_error("fopen(%s) error", ARTICLE_BLOCK_SHM_FILE);
80                  return -1;                  return -1;
81          }          }
82          fclose(fp);          fclose(fp);
83    
84          if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL)          if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL)
85          {          {
86                  log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE);                  log_error("fopen(%s) error", SECTION_LIST_SHM_FILE);
87                  return -1;                  return -1;
88          }          }
89          fclose(fp);          fclose(fp);
90    
91          if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL)          if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL)
92          {          {
93                  log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE);                  log_error("fopen(%s) error", TRIE_DICT_SHM_FILE);
94                  return -1;                  return -1;
95          }          }
96          fclose(fp);          fclose(fp);
97    
98          if ((fp = fopen(USER_LIST_SHM_FILE, "w")) == NULL)          if ((fp = fopen(USER_LIST_SHM_FILE, "w")) == NULL)
99          {          {
100                  log_error("fopen(%s) error\n", USER_LIST_SHM_FILE);                  log_error("fopen(%s) error", USER_LIST_SHM_FILE);
101                  return -1;                  return -1;
102          }          }
103          fclose(fp);          fclose(fp);
# Line 114  int main(int argc, char *argv[]) Line 110  int main(int argc, char *argv[])
110    
111          if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)          if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)
112          {          {
113                  log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);                  log_error("article_block_init(%s, %d) error", ARTICLE_BLOCK_SHM_FILE, block_count);
114                  return -2;                  return -2;
115          }          }
116    
117          if (section_list_init(SECTION_LIST_SHM_FILE) < 0)          if (section_list_init(SECTION_LIST_SHM_FILE) < 0)
118          {          {
119                  log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);                  log_error("section_list_pool_init(%s) error", SECTION_LIST_SHM_FILE);
120                  return -2;                  return -2;
121          }          }
122    
123          // Load user_list and online_user_list          // Load user_list and online_user_list
124          if (user_list_pool_init(USER_LIST_SHM_FILE) < 0)          if (user_list_pool_init(USER_LIST_SHM_FILE) < 0)
125          {          {
126                  log_error("user_list_pool_init() error\n");                  log_error("user_list_pool_init() error");
127                  return -2;                  return -2;
128          }          }
129    
# Line 282  int main(int argc, char *argv[]) Line 278  int main(int argc, char *argv[])
278    
279          if (article_block_reset() != 0)          if (article_block_reset() != 0)
280          {          {
281                  log_error("article_block_reset() error\n");                  log_error("article_block_reset() error");
282                  return -4;                  return -4;
283          }          }
284    
# Line 740  int main(int argc, char *argv[]) Line 736  int main(int argc, char *argv[])
736    
737          if (article_block_reset() != 0)          if (article_block_reset() != 0)
738          {          {
739                  log_error("article_block_reset() error\n");                  log_error("article_block_reset() error");
740                  return -4;                  return -4;
741          }          }
742    
# Line 995  int main(int argc, char *argv[]) Line 991  int main(int argc, char *argv[])
991    
992          if (unlink(USER_LIST_SHM_FILE) < 0)          if (unlink(USER_LIST_SHM_FILE) < 0)
993          {          {
994                  log_error("unlink(%s) error\n", USER_LIST_SHM_FILE);                  log_error("unlink(%s) error", USER_LIST_SHM_FILE);
995                  return -1;                  return -1;
996          }          }
997    
998          if (unlink(TRIE_DICT_SHM_FILE) < 0)          if (unlink(TRIE_DICT_SHM_FILE) < 0)
999          {          {
1000                  log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE);                  log_error("unlink(%s) error", TRIE_DICT_SHM_FILE);
1001                  return -1;                  return -1;
1002          }          }
1003    
1004          if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)          if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
1005          {          {
1006                  log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE);                  log_error("unlink(%s) error", ARTICLE_BLOCK_SHM_FILE);
1007                  return -1;                  return -1;
1008          }          }
1009    
1010          if (unlink(SECTION_LIST_SHM_FILE) < 0)          if (unlink(SECTION_LIST_SHM_FILE) < 0)
1011          {          {
1012                  log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE);                  log_error("unlink(%s) error", SECTION_LIST_SHM_FILE);
1013                  return -1;                  return -1;
1014          }          }
1015    


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

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