/[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.19 by sysadm, Sat May 24 07:32:46 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 47  int main(int argc, char *argv[]) Line 50  int main(int argc, char *argv[])
50          ARTICLE article;          ARTICLE article;
51          int block_count;          int block_count;
52          int i, j;          int i, j;
53            int sid;
54          int last_aid;          int last_aid;
55          int current_tid;          int current_tid;
56          int section_first_aid;          int section_first_aid;
# Line 56  int main(int argc, char *argv[]) Line 60  int main(int argc, char *argv[])
60          int32_t page;          int32_t page;
61          int32_t offset;          int32_t offset;
62          int affected_count;          int affected_count;
63            FILE *fp;
64    
65          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
66          {          {
# Line 69  int main(int argc, char *argv[]) Line 74  int main(int argc, char *argv[])
74          // - 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
75          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;
76    
77          if (article_block_init("../conf/menu.conf", block_count) < 0)          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
78            {
79                    log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
80                    return -1;
81            }
82            fclose(fp);
83    
84            if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL)
85            {
86                    log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE);
87                    return -1;
88            }
89            fclose(fp);
90    
91            if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)
92          {          {
93                  log_error("section_data_pool_init() error\n");                  log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);
94                    return -2;
95            }
96    
97            if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0)
98            {
99                    log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);
100                  return -2;                  return -2;
101          }          }
102    
# Line 81  int main(int argc, char *argv[]) Line 106  int main(int argc, char *argv[])
106    
107          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
108          {          {
109                  p_section[i] = section_list_create(i + 1,                  sid = i * 3 + 1;
110                    p_section[i] = section_list_create(sid,
111                                                                                     sname[i % section_conf_count],                                                                                     sname[i % section_conf_count],
112                                                                                     stitle[i % section_conf_count],                                                                                     stitle[i % section_conf_count],
113                                                                                     master_name[i % section_conf_count]);                                                                                     master_name[i % section_conf_count]);
114                  if (p_section[i] == NULL)                  if (p_section[i] == NULL)
115                  {                  {
116                          log_error("section_data_create(i=%d) error\n", i);                          printf("section_list_create(i = %d) error\n", i);
117                            return -3;
118                    }
119            }
120    
121            for (i = 0; i < section_count; i++)
122            {
123                    if (get_section_index(p_section[i]) != i)
124                    {
125                            printf("get_section_index(i = %d) error\n", i);
126                          return -3;                          return -3;
127                  }                  }
128          }          }
# Line 96  int main(int argc, char *argv[]) Line 131  int main(int argc, char *argv[])
131          {          {
132                  if (section_list_find_by_name(sname[i]) == NULL)                  if (section_list_find_by_name(sname[i]) == NULL)
133                  {                  {
134                          printf("section_data_find_section_by_name(%s) error\n", sname[i]);                          printf("section_list_find_by_name(%s) error\n", sname[i]);
135                            return -3;
136                    }
137            }
138    
139            for (i = 0; i < section_count; i++)
140            {
141                    sid = i * 3 + 1;
142                    if (section_list_find_by_sid(sid) == NULL || section_list_find_by_sid(sid)->sid != sid)
143                    {
144                            printf("section_list_find_by_sid(%d) error\n", sid);
145                          return -3;                          return -3;
146                  }                  }
147          }          }
# Line 109  int main(int argc, char *argv[]) Line 154  int main(int argc, char *argv[])
154    
155                          // Set article data                          // Set article data
156                          article.aid = last_aid;                          article.aid = last_aid;
                         article.cid = article.aid;  
157                          article.tid = 0;                          article.tid = 0;
158                            article.sid = i * 3 + 1;
159                            article.cid = article.aid;
160                          article.uid = 1; // TODO: randomize                          article.uid = 1; // TODO: randomize
161                          article.visible = 1;                          article.visible = 1;
162                          article.excerption = 0;                          article.excerption = 0;
# Line 132  int main(int argc, char *argv[]) Line 178  int main(int argc, char *argv[])
178    
179          last_aid = 0;          last_aid = 0;
180    
181          for (i = 0; i < section_count; i++)          for (j = 0; j < BBS_article_limit_per_section; j++)
182          {          {
183                  if (p_section[i]->article_count == 0)                  for (i = 0; i < section_count; i++)
                 {  
                         continue;  
                 }  
   
                 for (j = 0; j < p_section[i]->article_count; j++)  
184                  {                  {
185                          last_aid++;                          last_aid++;
186    
# Line 149  int main(int argc, char *argv[]) Line 190  int main(int argc, char *argv[])
190                                  printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);                                  printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);
191                          }                          }
192    
                         p_article = article_block_find_by_index(last_aid - 1);  
                         if (p_article == NULL || p_article->aid != last_aid)  
                         {  
                                 printf("article_block_find_by_index() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);  
                         }  
   
193                          if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1)                          if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1)
194                          {                          {
195                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
# Line 168  int main(int argc, char *argv[]) Line 203  int main(int argc, char *argv[])
203    
204          if (article_block_reset() != 0)          if (article_block_reset() != 0)
205          {          {
206                  log_error("section_data_free_block(i=%d) error\n", i);                  log_error("article_block_reset() error\n");
207                  return -4;                  return -4;
208          }          }
209    
# Line 189  int main(int argc, char *argv[]) Line 224  int main(int argc, char *argv[])
224    
225                          // Set article data                          // Set article data
226                          article.aid = last_aid;                          article.aid = last_aid;
                         article.cid = article.aid;  
227                          // Group articles into group_count topics                          // Group articles into group_count topics
228                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
229                            article.sid = i * 3 + 1;
230                            article.cid = article.aid;
231                          article.uid = 1; // TODO: randomize                          article.uid = 1; // TODO: randomize
232                          article.visible = 1;                          article.visible = 1;
233                          article.excerption = 0;                          article.excerption = 0;
# Line 307  int main(int argc, char *argv[]) Line 343  int main(int argc, char *argv[])
343                          {                          {
344                                  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",
345                                             j + 1, article_count, p_section[i]->article_count / group_count);                                             j + 1, article_count, p_section[i]->article_count / group_count);
346                                  break;                                  // break;
347                          }                          }
348                  }                  }
349    
# Line 542  int main(int argc, char *argv[]) Line 578  int main(int argc, char *argv[])
578    
579          if (article_block_reset() != 0)          if (article_block_reset() != 0)
580          {          {
581                  log_error("section_data_free_block(i=%d) error\n", i);                  log_error("article_block_reset() error\n");
582                  return -4;                  return -4;
583          }          }
584    
# Line 563  int main(int argc, char *argv[]) Line 599  int main(int argc, char *argv[])
599    
600                          // Set article data                          // Set article data
601                          article.aid = last_aid;                          article.aid = last_aid;
                         article.cid = article.aid;  
602                          // Group articles into group_count topics                          // Group articles into group_count topics
603                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
604                            article.sid = i * 3 + 1;
605                            article.cid = article.aid;
606                          article.uid = 1; // TODO: randomize                          article.uid = 1; // TODO: randomize
607                          article.visible = 1;                          article.visible = 1;
608                          article.excerption = 0;                          article.excerption = 0;
# Line 586  int main(int argc, char *argv[]) Line 623  int main(int argc, char *argv[])
623          {          {
624                  section_first_aid = p_section[i]->p_article_head->aid;                  section_first_aid = p_section[i]->p_article_head->aid;
625    
626                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j += 2)
627                  {                  {
628                          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);
629                          if (p_article == NULL)                          if (p_article == NULL)
# Line 595  int main(int argc, char *argv[]) Line 632  int main(int argc, char *argv[])
632                                             section_first_aid + j, i);                                             section_first_aid + j, i);
633                                  break;                                  break;
634                          }                          }
635    
636                            if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != BBS_article_limit_per_section / group_count)
637                            {
638                                    printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
639                            }
640                  }                  }
641          }          }
642    
# Line 617  int main(int argc, char *argv[]) Line 659  int main(int argc, char *argv[])
659                                  printf("move topic (aid = %d) affected article count %d != %d\n",                                  printf("move topic (aid = %d) affected article count %d != %d\n",
660                                             section_first_aid + j, affected_count,                                             section_first_aid + j, affected_count,
661                                             BBS_article_limit_per_section / group_count);                                             BBS_article_limit_per_section / group_count);
662                                  break;                                  // break;
663                          }                          }
664                  }                  }
665          }          }
# Line 631  int main(int argc, char *argv[]) Line 673  int main(int argc, char *argv[])
673                          break;                          break;
674                  }                  }
675    
676                    if (p_section[i]->visible_topic_count != (i < section_count / 2 ? 0 : group_count / 2))
677                    {
678                            printf("Visible topic count error in section %d, %d != %d\n", i,
679                                       p_section[i]->visible_topic_count, (i < section_count / 2 ? 0 : group_count / 2));
680                            break;
681                    }
682    
683                  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))
684                  {                  {
685                          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 687  int main(int argc, char *argv[])
687                          break;                          break;
688                  }                  }
689    
690                  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))
691                    {
692                            printf("Visible article count error in section %d, %d != %d\n", i,
693                                       p_section[i]->visible_article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2));
694                            break;
695                    }
696    
697                    if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page))
698                  {                  {
699                          printf("Page count error in section %d, %d != %d\n", i,                          printf("Page count error in section %d, %d != %d\n", i,
700                                     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));
701                          break;                          break;
702                  }                  }
703          }          }
# Line 650  int main(int argc, char *argv[]) Line 706  int main(int argc, char *argv[])
706          getchar();          getchar();
707    
708          article_block_cleanup();          article_block_cleanup();
709            section_list_pool_cleanup();
710    
711            if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
712            {
713                    log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
714                    return -1;
715            }
716    
717            if (unlink(SECTION_LIST_SHM_FILE) < 0)
718            {
719                    log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE);
720                    return -1;
721            }
722    
723          log_end();          log_end();
724    


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

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