/[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.1 by sysadm, Wed May 21 04:07:42 2025 UTC Revision 1.8 by sysadm, Wed May 21 12:54:06 2025 UTC
# Line 24  Line 24 
24  const char *sname[] = {  const char *sname[] = {
25          "Test",          "Test",
26          "ABCDEFG",          "ABCDEFG",
27          "_1234_"          "_1234_"};
 };  
28    
29  const char *stitle[] = {  const char *stitle[] = {
30          " Test Section ",          " Test Section ",
31          "字母组合ABC",          "字母组合ABC",
32          "_数字_123"          "_数字_123"};
 };  
33    
34  const char *master_name[] = {  const char *master_name[] = {
35          "sysadm",          "sysadm",
36          "SYSOP",          "SYSOP",
37          ""          ""};
 };  
38    
39  int section_count = 3;  int section_conf_count = 3;
40    int section_count = BBS_max_section;
41    
42  int main(int argc, char *argv[])  int main(int argc, char *argv[])
43  {  {
44          SECTION_DATA *p_section[BBS_max_section];          SECTION_DATA *p_section[BBS_max_section];
45            ARTICLE *p_article;
46          ARTICLE article;          ARTICLE article;
47            int block_count;
48          int i, j;          int i, j;
49          int last_aid;          int last_aid;
50            int group_count;
51            int article_count;
52    
53          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
54          {          {
# Line 57  int main(int argc, char *argv[]) Line 59  int main(int argc, char *argv[])
59          log_std_redirect(STDOUT_FILENO);          log_std_redirect(STDOUT_FILENO);
60          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
61    
62          if (section_data_pool_init("../conf/menu.conf", BBS_article_block_limit_per_section * BBS_max_section) < 0)          // block_count = BBS_article_block_limit_per_section * BBS_max_section; // This statement is correct
63            // - 1 to make blocks allocated is less than required
64            // Some error will be triggered while invoking section_data_append_article()
65            block_count = BBS_article_block_limit_per_section * BBS_max_section - 1;
66    
67            if (section_data_pool_init("../conf/menu.conf", block_count) < 0)
68          {          {
69                  log_error("section_data_pool_init() error\n");                  log_error("section_data_pool_init() error\n");
70                  return -2;                  return -2;
71          }          }
72    
73            printf("Testing #1 ...\n");
74    
75          last_aid = 0;          last_aid = 0;
76    
77          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
78          {          {
79                  if ((p_section[i] = section_data_create(sname[i], stitle[i], master_name[i])) == NULL)                  p_section[i] = section_data_create(sname[i % section_conf_count],
80                                                                                       stitle[i % section_conf_count],
81                                                                                       master_name[i % section_conf_count]);
82                    if (p_section[i] == NULL)
83                  {                  {
84                          log_error("section_data_create(i=%d) error\n", i);                          log_error("section_data_create(i=%d) error\n", i);
85                          return -3;                          return -3;
86                  }                  }
87            }
88    
89                  for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)
90            {
91                    for (i = 0; i < section_count; i++)
92                  {                  {
93                          last_aid++;                          last_aid++;
94    
# Line 87  int main(int argc, char *argv[]) Line 102  int main(int argc, char *argv[])
102                          article.ontop = 0;                          article.ontop = 0;
103                          article.lock = 0;                          article.lock = 0;
104    
105                          section_data_append_article(p_section[i], &article);                          if (section_data_append_article(p_section[i], &article) < 0)
106                            {
107                                    printf("append article (aid = %d) error\n", article.aid);
108                                    break;
109                            }
110                  }                  }
111          }          }
112    
113          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
114          {          {
115                    printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
116            }
117    
118            for (i = 0; i < section_count; i++)
119            {
120                    if (p_section[i]->article_count == 0)
121                    {
122                            continue;
123                    }
124    
125                    last_aid = i + 1;
126    
127                    for (j = 0; j < p_section[i]->article_count; j++)
128                    {
129                            p_article = section_data_find_article_by_index(p_section[i], j);
130                            if (p_article == NULL || p_article->aid != last_aid)
131                            {
132                                    printf("Inconsistent aid at section %d index %d != %d\n", i, j, last_aid);
133                            }
134    
135                            if (section_data_mark_del_article(p_section[i], p_article->aid) != 1)
136                            {
137                                    printf("section_data_mark_del_article(aid = %d) error\n", p_article->aid);
138                            }
139    
140                            last_aid += section_count;
141                    }
142    
143                    printf("Verify %d articles in section %d\n", p_section[i]->article_count, i);
144    
145                    printf("Delete %d articles in section %d\n", p_section[i]->delete_count, i);
146            }
147    
148            printf("Testing #2 ...\n");
149    
150            group_count = 100;
151    
152            for (i = 0; i < section_count; i++)
153            {
154                  if (section_data_free_block(p_section[i]) != 0)                  if (section_data_free_block(p_section[i]) != 0)
155                  {                  {
156                          log_error("section_data_free_block(i=%d) error\n", i);                          log_error("section_data_free_block(i=%d) error\n", i);
157                          return -4;                          return -4;
158                  }                  }
159    
160                    last_aid = 0;
161    
162                    for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)
163                    {
164                            last_aid++;
165    
166                            // Set article data
167                            article.aid = last_aid;
168                            article.cid = article.aid;
169                            article.tid = (article.aid <= group_count ? 0 : (article.aid - 1) % group_count + 1); // Group articles into group_count topics
170                            article.uid = 1;                                                                                                                                          // TODO: randomize
171                            article.visible = 1;
172                            article.excerption = 0;
173                            article.ontop = 0;
174                            article.lock = 0;
175    
176                            if (section_data_append_article(p_section[i], &article) < 0)
177                            {
178                                    printf("append article (aid = %d) error\n", article.aid);
179                                    break;
180                            }
181                    }
182    
183                    printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
184            }
185    
186            for (i = 0; i < section_count; i++)
187            {
188                    if (p_section[i]->article_count == 0)
189                    {
190                            continue;
191                    }
192    
193                    article_count = 0;
194                    last_aid = 0;
195    
196                    p_article = p_section[i]->p_article_head;
197    
198                    do
199                    {
200                            article_count++;
201    
202                            if (p_article->aid <= last_aid)
203                            {
204                                    printf("Non-ascending aid found %d <= %d\n", p_article->aid, last_aid);
205                            }
206                            last_aid = p_article->aid;
207    
208                            p_article = p_article->p_next;
209                    } while (p_article != p_section[i]->p_article_head);
210    
211                    if (article_count != p_section[i]->article_count)
212                    {
213                            printf("Count of articles in section %d is different from expected %d != %d\n",
214                                       i, article_count, p_section[i]->article_count);
215                    }
216    
217                    printf("Verify %d articles in section %d\n", group_count, i);
218            }
219    
220            for (i = 0; i < section_count; i++)
221            {
222                    if (p_section[i]->article_count == 0)
223                    {
224                            continue;
225                    }
226    
227                    for (j = 0; j < group_count; j++)
228                    {
229                            p_article = section_data_find_article_by_index(p_section[i], j);
230                            if (p_article == NULL)
231                            {
232                                    printf("NULL p_article at index %d\n", j);
233                                    break;
234                            }
235                            if (p_article->aid != j + 1)
236                            {
237                                    printf("Inconsistent aid at index %d != %d\n", j, j + 1);
238                                    break;
239                            }
240    
241                            article_count = 1;
242                            last_aid = 0;
243    
244                            do
245                            {
246                                    if (p_article->aid <= last_aid)
247                                    {
248                                            printf("Non-ascending aid found %d <= %d\n", p_article->aid, last_aid);
249                                    }
250                                    last_aid = p_article->aid;
251    
252                                    p_article = p_article->p_topic_next;
253    
254                                    if (p_article == NULL)
255                                    {
256                                            printf("NULL p_article found\n");
257                                            break;
258                                    }
259                                    if (p_article->tid == 0) // loop
260                                    {
261                                            break;
262                                    }
263                                    if (p_article->tid != j + 1)
264                                    {
265                                            printf("Inconsistent tid  %d != %d\n", last_aid, j + 1);
266                                            break;
267                                    }
268    
269                                    article_count++;
270                            } while (1);
271    
272                            if (article_count != p_section[i]->article_count / group_count)
273                            {
274                                    printf("Count of articles in topic %d is less than expected %d < %d\n",
275                                               j + 1, article_count, p_section[i]->article_count / group_count);
276                            }
277                    }
278    
279                    printf("Verify %d topics in section %d\n", group_count, i);
280          }          }
281    
282            printf("Testing #3 ...\n");
283    
284            for (i = 0; i < section_conf_count; i++)
285            {
286                    if (section_data_find_section_by_name(sname[i]) == NULL)
287                    {
288                            printf("section_data_find_section_by_name(%s) error\n", sname[i]);
289                    }
290            }
291    
292            printf("Press ENTER to exit...");
293            getchar();
294    
295          section_data_pool_cleanup();          section_data_pool_cleanup();
296    
297          log_end();          log_end();


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

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