/[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.2 by sysadm, Wed May 21 05:36:04 2025 UTC Revision 1.7 by sysadm, Wed May 21 12:43:04 2025 UTC
# Line 44  int main(int argc, char *argv[]) Line 44  int main(int argc, char *argv[])
44          SECTION_DATA *p_section[BBS_max_section];          SECTION_DATA *p_section[BBS_max_section];
45          ARTICLE *p_article;          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;          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;
# Line 77  int main(int argc, char *argv[]) Line 84  int main(int argc, char *argv[])
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 92  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++)
114            {
115                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
116          }          }
117    
         last_aid = 0;  
   
118          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
119          {          {
120                  for (j = 0; j < p_section[i]->article_count; j++)                  if (p_section[i]->article_count == 0)
121                  {                  {
122                          last_aid++;                          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);                          p_article = section_data_find_article_by_index(p_section[i], j);
130                          if (p_article == NULL || p_article->aid != last_aid)                          if (p_article == NULL || p_article->aid != last_aid)
131                          {                          {
132                                  printf("Inconsistent aid at index %d != %d\n", j, last_aid);                                  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);                  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");          printf("Testing #2 ...\n");
# Line 144  int main(int argc, char *argv[]) Line 173  int main(int argc, char *argv[])
173                          article.ontop = 0;                          article.ontop = 0;
174                          article.lock = 0;                          article.lock = 0;
175    
176                          section_data_append_article(p_section[i], &article);                          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);                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
# Line 152  int main(int argc, char *argv[]) Line 185  int main(int argc, char *argv[])
185    
186          for (i = 0; i < section_count; i++)          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    
195                    p_article = p_section[i]->p_article_head;
196    
197                    do
198                    {
199                            article_count++;
200                            p_article = p_article->p_next;
201                    } while (p_article != p_section[i]->p_article_head);
202    
203                    if (article_count != p_section[i]->article_count)
204                    {
205                            printf("Count of articles in section %d is different from expected %d != %d\n",
206                                       i, article_count, p_section[i]->article_count);
207                    }
208    
209                    printf("Verify %d articles in section %d\n", group_count, i);
210            }
211    
212            for (i = 0; i < section_count; i++)
213            {
214                    if (p_section[i]->article_count == 0)
215                    {
216                            continue;
217                    }
218    
219                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j++)
220                  {                  {
221                          p_article = section_data_find_article_by_index(p_section[i], j);                          p_article = section_data_find_article_by_index(p_section[i], j);
# Line 166  int main(int argc, char *argv[]) Line 230  int main(int argc, char *argv[])
230                                  break;                                  break;
231                          }                          }
232    
233                            article_count = 1;
234    
235                          do                          do
236                          {                          {
237                                  if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid)                                  p_article = p_article->p_topic_next;
                                 {  
                                         printf("Non-ascending aid found %d >= %d\n", p_article->aid, p_article->next_aid);  
                                         break;  
                                 }  
   
                                 last_aid = p_article->next_aid;  
                                 p_article = section_data_find_article_by_aid(p_section[i], last_aid);  
238                                  if (p_article == NULL)                                  if (p_article == NULL)
239                                  {                                  {
240                                          printf("NULL p_article at aid %d\n", last_aid);                                          printf("NULL p_article found\n");
241                                          break;                                          break;
242                                  }                                  }
243                                  if (p_article->tid == 0) // loop                                  if (p_article->tid == 0) // loop
# Line 187  int main(int argc, char *argv[]) Line 246  int main(int argc, char *argv[])
246                                  }                                  }
247                                  if (p_article->tid != j + 1)                                  if (p_article->tid != j + 1)
248                                  {                                  {
249                                          printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1);                                          printf("Inconsistent tid  %d != %d\n", last_aid, j + 1);
250                                          break;                                          break;
251                                  }                                  }
252                                    article_count++;
253                          } while (1);                          } while (1);
254    
255                            if (article_count != p_section[i]->article_count / group_count)
256                            {
257                                    printf("Count of articles in topic %d is less than expected %d < %d\n",
258                                               j + 1, article_count, p_section[i]->article_count / group_count);
259                            }
260                  }                  }
261    
262                  printf("Verify %d topics in section %d\n", group_count, i);                  printf("Verify %d topics in section %d\n", group_count, i);
263          }          }
264    
265            printf("Testing #3 ...\n");
266    
267            for (i = 0; i < section_conf_count; i++)
268            {
269                    if (section_data_find_section_by_name(sname[i]) == NULL)
270                    {
271                            printf("section_data_find_section_by_name(%s) error\n", sname[i]);
272                    }
273            }
274    
275            printf("Press ENTER to exit...");
276            getchar();
277    
278          section_data_pool_cleanup();          section_data_pool_cleanup();
279    
280          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