/[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.1 by sysadm, Wed May 21 04:07:42 2025 UTC Revision 1.3 by sysadm, Wed May 21 06:17:52 2025 UTC
# Line 24  Line 24 
24  const char *sname[] = {  const char *sname[] = {
25          "Test",          "Test",
26          "ABCDEFG",          "ABCDEFG",
27          "_1234_"          "_1234_"};
 };  
28    
29  const char *stitle[] = {  const char *stitle[] = {
30          " Test Section ",          " Test Section ",
31          "字母组合ABC",          "字母组合ABC",
32          "_数字_123"          "_数字_123"};
 };  
33    
34  const char *master_name[] = {  const char *master_name[] = {
35          "sysadm",          "sysadm",
36          "SYSOP",          "SYSOP",
37          ""          ""};
 };  
38    
39  int section_count = 3;  int section_conf_count = 3;
40    int section_count = BBS_max_section;
41    
42  int main(int argc, char *argv[])  int main(int argc, char *argv[])
43  {  {
44          SECTION_DATA *p_section[BBS_max_section];          SECTION_DATA *p_section[BBS_max_section];
45            ARTICLE *p_article;
46          ARTICLE article;          ARTICLE article;
47            int block_count;
48          int i, j;          int i, j;
49          int last_aid;          int last_aid;
50            int group_count;
51            int article_count;
52    
53          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
54          {          {
# Line 57  int main(int argc, char *argv[]) Line 59  int main(int argc, char *argv[])
59          log_std_redirect(STDOUT_FILENO);          log_std_redirect(STDOUT_FILENO);
60          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
61    
62          if (section_data_pool_init("../conf/menu.conf", BBS_article_block_limit_per_section * BBS_max_section) < 0)          block_count = BBS_article_block_limit_per_section * BBS_max_section - 1;
63    
64            if (section_data_pool_init("../conf/menu.conf", block_count) < 0)
65          {          {
66                  log_error("section_data_pool_init() error\n");                  log_error("section_data_pool_init() error\n");
67                  return -2;                  return -2;
68          }          }
69    
70            printf("Testing #1 ...\n");
71    
72          last_aid = 0;          last_aid = 0;
73    
74          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
75          {          {
76                  if ((p_section[i] = section_data_create(sname[i], stitle[i], master_name[i])) == NULL)                  p_section[i] = section_data_create(sname[i % section_conf_count],
77                                                                                       stitle[i % section_conf_count],
78                                                                                       master_name[i % section_conf_count]);
79                    if (p_section[i] == NULL)
80                  {                  {
81                          log_error("section_data_create(i=%d) error\n", i);                          log_error("section_data_create(i=%d) error\n", i);
82                          return -3;                          return -3;
# Line 87  int main(int argc, char *argv[]) Line 96  int main(int argc, char *argv[])
96                          article.ontop = 0;                          article.ontop = 0;
97                          article.lock = 0;                          article.lock = 0;
98    
99                          section_data_append_article(p_section[i], &article);                          if (section_data_append_article(p_section[i], &article) < 0)
100                            {
101                                    printf("append article (aid = %d) error\n", article.aid);
102                                    break;
103                            }
104                  }                  }
105    
106                    printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
107          }          }
108    
109            last_aid = 0;
110    
111            for (i = 0; i < section_count; i++)
112            {
113                    if (p_section[i]->article_count == 0)
114                    {
115                            continue;
116                    }
117    
118                    for (j = 0; j < p_section[i]->article_count; j++)
119                    {
120                            last_aid++;
121    
122                            p_article = section_data_find_article_by_index(p_section[i], j);
123                            if (p_article == NULL || p_article->aid != last_aid)
124                            {
125                                    printf("Inconsistent aid at index %d != %d\n", j, last_aid);
126                            }
127                    }
128    
129                    printf("Verify %d articles in section %d\n", p_section[i]->article_count, i);
130            }
131    
132            printf("Testing #2 ...\n");
133    
134            group_count = 100;
135    
136          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
137          {          {
138                  if (section_data_free_block(p_section[i]) != 0)                  if (section_data_free_block(p_section[i]) != 0)
# Line 98  int main(int argc, char *argv[]) Line 140  int main(int argc, char *argv[])
140                          log_error("section_data_free_block(i=%d) error\n", i);                          log_error("section_data_free_block(i=%d) error\n", i);
141                          return -4;                          return -4;
142                  }                  }
143    
144                    last_aid = 0;
145    
146                    for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)
147                    {
148                            last_aid++;
149    
150                            // Set article data
151                            article.aid = last_aid;
152                            article.cid = article.aid;
153                            article.tid = (article.aid <= group_count ? 0 : (article.aid - 1) % group_count + 1); // Group articles into group_count topics
154                            article.uid = 1;                                                                                                                                          // TODO: randomize
155                            article.visible = 1;
156                            article.excerption = 0;
157                            article.ontop = 0;
158                            article.lock = 0;
159    
160                            if (section_data_append_article(p_section[i], &article) < 0)
161                            {
162                                    printf("append article (aid = %d) error\n", article.aid);
163                                    break;
164                            }
165                    }
166    
167                    printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
168            }
169    
170            for (i = 0; i < section_count; i++)
171            {
172                    if (p_section[i]->article_count == 0)
173                    {
174                            continue;
175                    }
176    
177                    for (j = 0; j < group_count; j++)
178                    {
179                            p_article = section_data_find_article_by_index(p_section[i], j);
180                            if (p_article == NULL)
181                            {
182                                    printf("NULL p_article at index %d\n", j);
183                                    break;
184                            }
185                            if (p_article->aid != j + 1)
186                            {
187                                    printf("Inconsistent aid at index %d != %d\n", j, j + 1);
188                                    break;
189                            }
190    
191                            article_count = 1;
192    
193                            do
194                            {
195                                    if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid)
196                                    {
197                                            printf("Non-ascending aid found %d >= %d\n", p_article->aid, p_article->next_aid);
198                                            break;
199                                    }
200    
201                                    last_aid = p_article->next_aid;
202                                    p_article = section_data_find_article_by_aid(p_section[i], last_aid);
203                                    if (p_article == NULL)
204                                    {
205                                            printf("NULL p_article at aid %d\n", last_aid);
206                                            break;
207                                    }
208                                    if (p_article->tid == 0) // loop
209                                    {
210                                            break;
211                                    }
212                                    if (p_article->tid != j + 1)
213                                    {
214                                            printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1);
215                                            break;
216                                    }
217                                    article_count++;
218                            } while (1);
219    
220                            if (article_count != p_section[i]->article_count / group_count)
221                            {
222                                    printf("Count of articles in topic %d is less than expected %d < %d\n",
223                                               j + 1, article_count, p_section[i]->article_count / group_count);
224                            }
225                    }
226    
227                    printf("Verify %d topics in section %d\n", group_count, i);
228          }          }
229    
230          section_data_pool_cleanup();          section_data_pool_cleanup();


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

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