/[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.2 by sysadm, Wed May 21 05:36:04 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 i, j;          int i, j;
48          int last_aid;          int last_aid;
49            int group_count;
50    
51          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
52          {          {
# Line 63  int main(int argc, char *argv[]) Line 63  int main(int argc, char *argv[])
63                  return -2;                  return -2;
64          }          }
65    
66            printf("Testing #1 ...\n");
67    
68          last_aid = 0;          last_aid = 0;
69    
70          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
71          {          {
72                  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],
73                                                                                       stitle[i % section_conf_count],
74                                                                                       master_name[i % section_conf_count]);
75                    if (p_section[i] == NULL)
76                  {                  {
77                          log_error("section_data_create(i=%d) error\n", i);                          log_error("section_data_create(i=%d) error\n", i);
78                          return -3;                          return -3;
# Line 89  int main(int argc, char *argv[]) Line 94  int main(int argc, char *argv[])
94    
95                          section_data_append_article(p_section[i], &article);                          section_data_append_article(p_section[i], &article);
96                  }                  }
97    
98                    printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
99            }
100    
101            last_aid = 0;
102    
103            for (i = 0; i < section_count; i++)
104            {
105                    for (j = 0; j < p_section[i]->article_count; j++)
106                    {
107                            last_aid++;
108    
109                            p_article = section_data_find_article_by_index(p_section[i], j);
110                            if (p_article == NULL || p_article->aid != last_aid)
111                            {
112                                    printf("Inconsistent aid at index %d != %d\n", j, last_aid);
113                            }
114                    }
115    
116                    printf("Verify %d articles in section %d\n", p_section[i]->article_count, i);
117          }          }
118    
119            printf("Testing #2 ...\n");
120    
121            group_count = 100;
122    
123          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
124          {          {
125                  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 127  int main(int argc, char *argv[])
127                          log_error("section_data_free_block(i=%d) error\n", i);                          log_error("section_data_free_block(i=%d) error\n", i);
128                          return -4;                          return -4;
129                  }                  }
130    
131                    last_aid = 0;
132    
133                    for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)
134                    {
135                            last_aid++;
136    
137                            // Set article data
138                            article.aid = last_aid;
139                            article.cid = article.aid;
140                            article.tid = (article.aid <= group_count ? 0 : (article.aid - 1) % group_count + 1); // Group articles into group_count topics
141                            article.uid = 1;                                                                                                                                          // TODO: randomize
142                            article.visible = 1;
143                            article.excerption = 0;
144                            article.ontop = 0;
145                            article.lock = 0;
146    
147                            section_data_append_article(p_section[i], &article);
148                    }
149    
150                    printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
151            }
152    
153            for (i = 0; i < section_count; i++)
154            {
155                    for (j = 0; j < group_count; j++)
156                    {
157                            p_article = section_data_find_article_by_index(p_section[i], j);
158                            if (p_article == NULL)
159                            {
160                                    printf("NULL p_article at index %d\n", j);
161                                    break;
162                            }
163                            if (p_article->aid != j + 1)
164                            {
165                                    printf("Inconsistent aid at index %d != %d\n", j, j + 1);
166                                    break;
167                            }
168    
169                            do
170                            {
171                                    if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid)
172                                    {
173                                            printf("Non-ascending aid found %d >= %d\n", p_article->aid, p_article->next_aid);
174                                            break;
175                                    }
176    
177                                    last_aid = p_article->next_aid;
178                                    p_article = section_data_find_article_by_aid(p_section[i], last_aid);
179                                    if (p_article == NULL)
180                                    {
181                                            printf("NULL p_article at aid %d\n", last_aid);
182                                            break;
183                                    }
184                                    if (p_article->tid == 0) // loop
185                                    {
186                                            break;
187                                    }
188                                    if (p_article->tid != j + 1)
189                                    {
190                                            printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1);
191                                            break;
192                                    }
193                            } while (1);
194                    }
195    
196                    printf("Verify %d topics in section %d\n", group_count, i);
197          }          }
198    
199          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