/[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.11 by sysadm, Thu May 22 14:12:33 2025 UTC Revision 1.15 by sysadm, Fri May 23 10:45:54 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 66  int main(int argc, char *argv[]) Line 67  int main(int argc, char *argv[])
67          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
68    
69          // - 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
70          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK - 1;          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;
71    
72          if (article_block_init("../conf/menu.conf", block_count) < 0)          if (article_block_init("../conf/menu.conf", block_count) < 0)
73          {          {
# 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 447  int main(int argc, char *argv[]) Line 449  int main(int argc, char *argv[])
449    
450                  if (p_section[i]->visible_article_count > 0)                  if (p_section[i]->visible_article_count > 0)
451                  {                  {
452                          printf("Inconsistent invisible count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);                          printf("Inconsistent invisible article count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);
453                            break;
454                    }
455    
456                    if (p_section[i]->visible_topic_count > 0)
457                    {
458                            printf("Inconsistent invisible topic count in section %d, %d > 0\n", i, p_section[i]->visible_topic_count);
459                            break;
460                    }
461    
462                    last_aid = p_section[i]->p_article_head->aid;
463                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
464                    {
465                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
466                            break;
467                    }
468    
469                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
470                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
471                            p_section[i]->page_count)
472                    {
473                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
474                                       "visible_article_count = %d, last_page_visible_count = %d\n",
475                                       i, j,
476                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
477                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
478                                       p_section[i]->page_count, p_section[i]->visible_article_count,
479                                       p_section[i]->last_page_visible_article_count);
480                            break;
481                    }
482            }
483    
484            for (i = 0; i < BBS_max_section; i++)
485            {
486                    affected_count = 0;
487    
488                    for (j = 0; j < BBS_article_limit_per_section; j += 1)
489                    {
490                            last_aid = i * BBS_article_limit_per_section + j + 1;
491    
492                            if (section_list_set_article_visible(p_section[i], last_aid, 1) <= 0)
493                            {
494                                    printf("Error set article %d visible in section %d offset %d\n", last_aid, i, j);
495                                    break;
496                            }
497    
498                            affected_count++;
499                    }
500    
501                    if (affected_count != p_section[i]->article_count)
502                    {
503                            printf("Inconsistent total set visible article count in section %d, %d != %d\n", i, affected_count, p_section[i]->article_count);
504                            break;
505                    }
506    
507                    if (p_section[i]->visible_article_count != p_section[i]->article_count)
508                    {
509                            printf("Inconsistent visible article count in section %d, %d != %d\n", i, p_section[i]->visible_article_count, p_section[i]->article_count);
510                            break;
511                    }
512    
513                    if (p_section[i]->visible_topic_count != group_count)
514                    {
515                            printf("Inconsistent visible topic count in section %d, %d != %d\n", i, p_section[i]->visible_topic_count, group_count);
516                            break;
517                    }
518    
519                    last_aid = p_section[i]->p_article_head->aid;
520                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
521                    {
522                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
523                            break;
524                    }
525    
526                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
527                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
528                            p_section[i]->page_count)
529                    {
530                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
531                                       "visible_article_count = %d, last_page_visible_count = %d\n",
532                                       i, j,
533                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
534                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
535                                       p_section[i]->page_count, p_section[i]->visible_article_count,
536                                       p_section[i]->last_page_visible_article_count);
537                            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++)
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            }
600    
601            for (i = 0; i < section_count / 2; i++)
602            {
603                    section_first_aid = p_section[i]->p_article_head->aid;
604    
605                    for (j = 0; j < group_count; j++)
606                    {
607                            affected_count = section_list_move_topic(p_section[i], p_section[section_count / 2 + i], section_first_aid + j);
608    
609                            if (affected_count < 0)
610                            {
611                                    printf("move topic (aid = %d) error from section %d to section %d\n", section_first_aid + j, i, section_count / 2 + i);
612                                    break;
613                            }
614    
615                            if (affected_count != BBS_article_limit_per_section / group_count)
616                            {
617                                    printf("move topic (aid = %d) affected article count %d != %d\n",
618                                               section_first_aid + j, affected_count,
619                                               BBS_article_limit_per_section / group_count);
620                                    // break;
621                            }
622                    }
623            }
624    
625            for (i = 0; i < section_count; i++)
626            {
627                    if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))
628                    {
629                            printf("Topic count error in section %d, %d != %d\n", i,
630                                       p_section[i]->topic_count, (i < section_count / 2 ? 0 : group_count));
631                            break;
632                    }
633    
634                    if (p_section[i]->article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section))
635                    {
636                            printf("Article count error in section %d, %d != %d\n", i,
637                                       p_section[i]->article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section));
638                            break;
639                    }
640    
641                    if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / BBS_article_limit_per_page))
642                    {
643                            printf("Page count error in section %d, %d != %d\n", i,
644                                       p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / BBS_article_limit_per_page));
645                          break;                          break;
646                  }                  }
647          }          }


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

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