/[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.13 by sysadm, Fri May 23 00:12:59 2025 UTC Revision 1.16 by sysadm, Fri May 23 11:05:44 2025 UTC
# Line 43  int main(int argc, char *argv[]) Line 43  int main(int argc, char *argv[])
43  {  {
44          SECTION_LIST *p_section[BBS_max_section];          SECTION_LIST *p_section[BBS_max_section];
45          ARTICLE *p_article;          ARTICLE *p_article;
46            ARTICLE *p_next;
47          ARTICLE article;          ARTICLE article;
48          int block_count;          int block_count;
49          int i, j;          int i, j;
# Line 80  int main(int argc, char *argv[]) Line 81  int main(int argc, char *argv[])
81    
82          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
83          {          {
84                  p_section[i] = section_list_create(sname[i % section_conf_count],                  p_section[i] = section_list_create(i + 1,
85                                                                                       sname[i % section_conf_count],
86                                                                                     stitle[i % section_conf_count],                                                                                     stitle[i % section_conf_count],
87                                                                                     master_name[i % section_conf_count]);                                                                                     master_name[i % section_conf_count]);
88                  if (p_section[i] == NULL)                  if (p_section[i] == NULL)
# Line 305  int main(int argc, char *argv[]) Line 307  int main(int argc, char *argv[])
307                          {                          {
308                                  printf("Count of articles in topic %d is different from expected %d != %d\n",                                  printf("Count of articles in topic %d is different from expected %d != %d\n",
309                                             j + 1, article_count, p_section[i]->article_count / group_count);                                             j + 1, article_count, p_section[i]->article_count / group_count);
310                                  break;                                  // break;
311                          }                          }
312                  }                  }
313    
# Line 353  int main(int argc, char *argv[]) Line 355  int main(int argc, char *argv[])
355                  {                  {
356                          last_aid = i * BBS_article_limit_per_section + j + 1;                          last_aid = i * BBS_article_limit_per_section + j + 1;
357    
358                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset);                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
359    
360                          if (p_article == NULL)                          if (p_article == NULL)
361                          {                          {
# Line 410  int main(int argc, char *argv[]) Line 412  int main(int argc, char *argv[])
412                  {                  {
413                          last_aid = i * BBS_article_limit_per_section + j + 1;                          last_aid = i * BBS_article_limit_per_section + j + 1;
414    
415                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset);                          p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
416    
417                          if (p_article == NULL)                          if (p_article == NULL)
418                          {                          {
# Line 535  int main(int argc, char *argv[]) Line 537  int main(int argc, char *argv[])
537                          break;                          break;
538                  }                  }
539          }          }
540    
541            printf("Testing #5 ...\n");
542    
543            if (article_block_reset() != 0)
544            {
545                    log_error("section_data_free_block(i=%d) error\n", i);
546                    return -4;
547            }
548    
549            for (i = 0; i < section_count; i++)
550            {
551                    section_list_reset_articles(p_section[i]);
552            }
553    
554            last_aid = 0;
555    
556            for (i = 0; i < section_count / 2; i++)
557            {
558                    section_first_aid = last_aid + 1;
559    
560                    for (j = 0; j < BBS_article_limit_per_section; j++)
561                    {
562                            last_aid++;
563    
564                            // Set article data
565                            article.aid = last_aid;
566                            article.cid = article.aid;
567                            // Group articles into group_count topics
568                            article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
569                            article.uid = 1; // TODO: randomize
570                            article.visible = 1;
571                            article.excerption = 0;
572                            article.ontop = 0;
573                            article.lock = 0;
574    
575                            if (section_list_append_article(p_section[i], &article) < 0)
576                            {
577                                    printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
578                                    break;
579                            }
580                    }
581    
582                    // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
583            }
584    
585            for (i = 0; i < section_count / 2; i++)
586            {
587                    section_first_aid = p_section[i]->p_article_head->aid;
588    
589                    for (j = 0; j < group_count; j += 2)
590                    {
591                            p_article = section_list_find_article_with_offset(p_section[i], section_first_aid + j, &page, &offset, &p_next);
592                            if (p_article == NULL)
593                            {
594                                    printf("section_list_find_article_with_offset(aid = %d) not found in section %d\n",
595                                               section_first_aid + j, i);
596                                    break;
597                            }
598    
599                            if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != BBS_article_limit_per_section / group_count)
600                            {
601                                    printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
602                            }
603                    }
604            }
605    
606            for (i = 0; i < section_count / 2; i++)
607            {
608                    section_first_aid = p_section[i]->p_article_head->aid;
609    
610                    for (j = 0; j < group_count; j++)
611                    {
612                            affected_count = section_list_move_topic(p_section[i], p_section[section_count / 2 + i], section_first_aid + j);
613    
614                            if (affected_count < 0)
615                            {
616                                    printf("move topic (aid = %d) error from section %d to section %d\n", section_first_aid + j, i, section_count / 2 + i);
617                                    break;
618                            }
619    
620                            if (affected_count != BBS_article_limit_per_section / group_count)
621                            {
622                                    printf("move topic (aid = %d) affected article count %d != %d\n",
623                                               section_first_aid + j, affected_count,
624                                               BBS_article_limit_per_section / group_count);
625                                    // break;
626                            }
627                    }
628            }
629    
630            for (i = 0; i < section_count; i++)
631            {
632                    if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))
633                    {
634                            printf("Topic count error in section %d, %d != %d\n", i,
635                                       p_section[i]->topic_count, (i < section_count / 2 ? 0 : group_count));
636                            break;
637                    }
638    
639                    if (p_section[i]->visible_topic_count != (i < section_count / 2 ? 0 : group_count / 2))
640                    {
641                            printf("Visible topic count error in section %d, %d != %d\n", i,
642                                       p_section[i]->visible_topic_count, (i < section_count / 2 ? 0 : group_count / 2));
643                            break;
644                    }
645    
646                    if (p_section[i]->article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section))
647                    {
648                            printf("Article count error in section %d, %d != %d\n", i,
649                                       p_section[i]->article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section));
650                            break;
651                    }
652    
653                    if (p_section[i]->visible_article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2))
654                    {
655                            printf("Visible article count error in section %d, %d != %d\n", i,
656                                       p_section[i]->visible_article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2));
657                            break;
658                    }
659    
660                    if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page))
661                    {
662                            printf("Page count error in section %d, %d != %d\n", i,
663                                       p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page));
664                            break;
665                    }
666            }
667    
668          printf("Press ENTER to exit...");          printf("Press ENTER to exit...");
669          getchar();          getchar();


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

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