/[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.14 by sysadm, Fri May 23 07:06:57 2025 UTC Revision 1.17 by sysadm, Fri May 23 14:04:05 2025 UTC
# Line 21  Line 21 
21  #include <unistd.h>  #include <unistd.h>
22  #include <errno.h>  #include <errno.h>
23    
24    #define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat"
25    #define SECTION_LIST_SHM_FILE "~section_list_shm.dat"
26    
27  const char *sname[] = {  const char *sname[] = {
28          "Test",          "Test",
29          "ABCDEFG",          "ABCDEFG",
# Line 56  int main(int argc, char *argv[]) Line 59  int main(int argc, char *argv[])
59          int32_t page;          int32_t page;
60          int32_t offset;          int32_t offset;
61          int affected_count;          int affected_count;
62            FILE *fp;
63    
64          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
65          {          {
# Line 69  int main(int argc, char *argv[]) Line 73  int main(int argc, char *argv[])
73          // - 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
74          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;
75    
76          if (article_block_init("../conf/menu.conf", block_count) < 0)          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
77            {
78                    log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
79                    return -1;
80            }
81            fclose(fp);
82    
83            if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL)
84            {
85                    log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE);
86                    return -1;
87            }
88            fclose(fp);
89    
90            if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)
91          {          {
92                  log_error("section_data_pool_init() error\n");                  log_error("section_data_pool_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);
93                    return -2;
94            }
95    
96            if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0)
97            {
98                    log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);
99                  return -2;                  return -2;
100          }          }
101    
# Line 307  int main(int argc, char *argv[]) Line 331  int main(int argc, char *argv[])
331                          {                          {
332                                  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",
333                                             j + 1, article_count, p_section[i]->article_count / group_count);                                             j + 1, article_count, p_section[i]->article_count / group_count);
334                                  break;                                  // break;
335                          }                          }
336                  }                  }
337    
# Line 586  int main(int argc, char *argv[]) Line 610  int main(int argc, char *argv[])
610          {          {
611                  section_first_aid = p_section[i]->p_article_head->aid;                  section_first_aid = p_section[i]->p_article_head->aid;
612    
613                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j += 2)
614                  {                  {
615                          p_article = section_list_find_article_with_offset(p_section[i], section_first_aid + j, &page, &offset, &p_next);                          p_article = section_list_find_article_with_offset(p_section[i], section_first_aid + j, &page, &offset, &p_next);
616                          if (p_article == NULL)                          if (p_article == NULL)
# Line 595  int main(int argc, char *argv[]) Line 619  int main(int argc, char *argv[])
619                                             section_first_aid + j, i);                                             section_first_aid + j, i);
620                                  break;                                  break;
621                          }                          }
622    
623                            if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != BBS_article_limit_per_section / group_count)
624                            {
625                                    printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
626                            }
627                  }                  }
628          }          }
629    
# Line 617  int main(int argc, char *argv[]) Line 646  int main(int argc, char *argv[])
646                                  printf("move topic (aid = %d) affected article count %d != %d\n",                                  printf("move topic (aid = %d) affected article count %d != %d\n",
647                                             section_first_aid + j, affected_count,                                             section_first_aid + j, affected_count,
648                                             BBS_article_limit_per_section / group_count);                                             BBS_article_limit_per_section / group_count);
649                                  break;                                  // break;
650                          }                          }
651                  }                  }
652          }          }
# Line 631  int main(int argc, char *argv[]) Line 660  int main(int argc, char *argv[])
660                          break;                          break;
661                  }                  }
662    
663                    if (p_section[i]->visible_topic_count != (i < section_count / 2 ? 0 : group_count / 2))
664                    {
665                            printf("Visible topic count error in section %d, %d != %d\n", i,
666                                       p_section[i]->visible_topic_count, (i < section_count / 2 ? 0 : group_count / 2));
667                            break;
668                    }
669    
670                  if (p_section[i]->article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section))                  if (p_section[i]->article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section))
671                  {                  {
672                          printf("Article count error in section %d, %d != %d\n", i,                          printf("Article count error in section %d, %d != %d\n", i,
# Line 638  int main(int argc, char *argv[]) Line 674  int main(int argc, char *argv[])
674                          break;                          break;
675                  }                  }
676    
677                  if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / BBS_article_limit_per_page))                  if (p_section[i]->visible_article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2))
678                    {
679                            printf("Visible article count error in section %d, %d != %d\n", i,
680                                       p_section[i]->visible_article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2));
681                            break;
682                    }
683    
684                    if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page))
685                  {                  {
686                          printf("Page count error in section %d, %d != %d\n", i,                          printf("Page count error in section %d, %d != %d\n", i,
687                                     p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / BBS_article_limit_per_page));                                     p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page));
688                          break;                          break;
689                  }                  }
690          }          }
# Line 650  int main(int argc, char *argv[]) Line 693  int main(int argc, char *argv[])
693          getchar();          getchar();
694    
695          article_block_cleanup();          article_block_cleanup();
696            section_list_pool_cleanup();
697    
698            if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
699            {
700                    log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
701                    return -1;
702            }
703    
704            if (unlink(SECTION_LIST_SHM_FILE) < 0)
705            {
706                    log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE);
707                    return -1;
708            }
709    
710          log_end();          log_end();
711    


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

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