/[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.9 by sysadm, Thu May 22 06:20:47 2025 UTC Revision 1.10 by sysadm, Thu May 22 11:10:19 2025 UTC
# Line 49  int main(int argc, char *argv[]) Line 49  int main(int argc, char *argv[])
49          int last_aid;          int last_aid;
50          int current_tid;          int current_tid;
51          int section_first_aid;          int section_first_aid;
52          int group_count;          int group_count = 100;
53          int article_count;          int article_count;
54            int step;
55            int32_t page;
56            int32_t offset;
57            int affected_count;
58    
59          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
60          {          {
# Line 86  int main(int argc, char *argv[]) Line 90  int main(int argc, char *argv[])
90                  }                  }
91          }          }
92    
93            for (i = 0; i < section_conf_count; i++)
94            {
95                    if (section_list_find_by_name(sname[i]) == NULL)
96                    {
97                            printf("section_data_find_section_by_name(%s) error\n", sname[i]);
98                            return -3;
99                    }
100            }
101    
102          for (j = 0; j < BBS_article_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_section; j++)
103          {          {
104                  for (i = 0; i < section_count; i++)                  for (i = 0; i < section_count; i++)
# Line 162  int main(int argc, char *argv[]) Line 175  int main(int argc, char *argv[])
175                  section_list_reset_articles(p_section[i]);                  section_list_reset_articles(p_section[i]);
176          }          }
177    
         group_count = 100;  
178          last_aid = 0;          last_aid = 0;
179    
180          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
# Line 236  int main(int argc, char *argv[]) Line 248  int main(int argc, char *argv[])
248                          continue;                          continue;
249                  }                  }
250    
251                    if (p_section[i]->topic_count != group_count)
252                    {
253                            printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count);
254                    }
255    
256                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j++)
257                  {                  {
258                          last_aid = p_section[i]->p_article_head->aid + j;                          last_aid = p_section[i]->p_article_head->aid + j;
# Line 297  int main(int argc, char *argv[]) Line 314  int main(int argc, char *argv[])
314    
315          printf("Testing #3 ...\n");          printf("Testing #3 ...\n");
316    
317          for (i = 0; i < section_conf_count; i++)          for (i = 0; i < section_count; i++)
318          {          {
319                  if (section_list_find_by_name(sname[i]) == NULL)                  last_aid = 0;
320    
321                    for (j = 0; j < p_section[i]->page_count; j++)
322                  {                  {
323                          printf("section_data_find_section_by_name(%s) error\n", sname[i]);                          if (p_section[i]->p_page_first_article[j]->aid <= last_aid)
324                            {
325                                    printf("Non-ascending aid found at section %d page %d, %d <= %d\n", i, j, p_section[i]->p_page_first_article[j]->aid, last_aid);
326                            }
327    
328                            if (j > 0)
329                            {
330                                    step = 0;
331    
332                                    for (p_article = p_section[i]->p_page_first_article[j];
333                                             p_article != p_section[i]->p_page_first_article[j - 1];
334                                             p_article = p_article->p_prior)
335                                    {
336                                            step++;
337                                    }
338    
339                                    if (step != BBS_article_limit_per_page)
340                                    {
341                                            printf("Incorrect page size %d at section %d page %d\n", step, i, j - 1);
342                                    }
343                            }
344                    }
345            }
346    
347            printf("Testing #4 ...\n");
348    
349            for (i = 0; i < BBS_max_section; i++)
350            {
351                    step = i % 10 + 1;
352                    for (j = group_count; j < BBS_article_limit_per_section; j += step)
353                    {
354                            last_aid = i * BBS_article_limit_per_section + j + 1;
355    
356                            p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset);
357    
358                            if (p_article == NULL)
359                            {
360                                    printf("Error find article %d in section %d offset %d\n", last_aid, i, j);
361                                    break;
362                            }
363    
364                            if (p_article->aid != last_aid)
365                            {
366                                    printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid);
367                                    break;
368                            }
369    
370                            if (page * BBS_article_limit_per_page + offset != j)
371                            {
372                                    printf("Inconsistent article offset %d in section %d page %d offset %d\n", j, i, page, offset);
373                                    break;
374                            }
375    
376                            if (section_list_set_article_visible(p_section[i], last_aid, 0) != 1)
377                            {
378                                    printf("Error set article %d invisible in section %d offset %d\n", last_aid, i, j);
379                                    break;
380                            }
381                    }
382    
383                    affected_count = (BBS_article_limit_per_section - group_count) / step + ((BBS_article_limit_per_section - group_count) % step ? 1 : 0);
384                    if (p_section[i]->article_count - p_section[i]->visible_article_count != affected_count)
385                    {
386                            printf("Inconsistent set invisible count in section %d, %d != %d\n", i,
387                                       p_section[i]->article_count - p_section[i]->visible_article_count,
388                                       affected_count);
389                            break;
390                    }
391    
392                    article_count = p_section[i]->visible_article_count;
393    
394                    for (j = 0; j < group_count; j += 1)
395                    {
396                            last_aid = i * BBS_article_limit_per_section + j + 1;
397    
398                            p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset);
399    
400                            if (p_article == NULL)
401                            {
402                                    printf("Error find article %d in section %d offset %d\n", last_aid, i, j);
403                                    break;
404                            }
405    
406                            if (p_article->aid != last_aid)
407                            {
408                                    printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid);
409                                    break;
410                            }
411    
412                            if (p_article->tid != 0)
413                            {
414                                    printf("Non-topic article aid in section %d page %d offset %d %d != 0\n", i, page, offset, p_article->tid);
415                                    break;
416                            }
417    
418                            if ((affected_count = section_list_set_article_visible(p_section[i], last_aid, 0)) <= 0)
419                            {
420                                    printf("Error set topic %d invisible in section %d offset %d\n", last_aid, i, j);
421                                    break;
422                            }
423    
424                            article_count -= affected_count;
425                    }
426    
427                    if (article_count != 0)
428                    {
429                            printf("Inconsistent total set invisible topic count in section %d, %d > 0\n", i, article_count);
430                            break;
431                    }
432    
433                    if (p_section[i]->visible_article_count > 0)
434                    {
435                            printf("Inconsistent invisible count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);
436                            break;
437                  }                  }
438          }          }
439    


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

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