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


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

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