/[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.2 by sysadm, Wed May 21 05:36:04 2025 UTC Revision 1.4 by sysadm, Wed May 21 06:33:19 2025 UTC
# Line 44  int main(int argc, char *argv[]) Line 44  int main(int argc, char *argv[])
44          SECTION_DATA *p_section[BBS_max_section];          SECTION_DATA *p_section[BBS_max_section];
45          ARTICLE *p_article;          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;          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; // This statement is correct
63            // - 1 to make blocks allocated is less than required
64            // Some error will be triggered while invoking section_data_append_article()
65            block_count = BBS_article_block_limit_per_section * BBS_max_section - 1;
66    
67            if (section_data_pool_init("../conf/menu.conf", block_count) < 0)
68          {          {
69                  log_error("section_data_pool_init() error\n");                  log_error("section_data_pool_init() error\n");
70                  return -2;                  return -2;
# Line 92  int main(int argc, char *argv[]) Line 99  int main(int argc, char *argv[])
99                          article.ontop = 0;                          article.ontop = 0;
100                          article.lock = 0;                          article.lock = 0;
101    
102                          section_data_append_article(p_section[i], &article);                          if (section_data_append_article(p_section[i], &article) < 0)
103                            {
104                                    printf("append article (aid = %d) error\n", article.aid);
105                                    break;
106                            }
107                  }                  }
108    
109                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
# Line 102  int main(int argc, char *argv[]) Line 113  int main(int argc, char *argv[])
113    
114          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
115          {          {
116                    if (p_section[i]->article_count == 0)
117                    {
118                            continue;
119                    }
120    
121                  for (j = 0; j < p_section[i]->article_count; j++)                  for (j = 0; j < p_section[i]->article_count; j++)
122                  {                  {
123                          last_aid++;                          last_aid++;
# Line 111  int main(int argc, char *argv[]) Line 127  int main(int argc, char *argv[])
127                          {                          {
128                                  printf("Inconsistent aid at index %d != %d\n", j, last_aid);                                  printf("Inconsistent aid at index %d != %d\n", j, last_aid);
129                          }                          }
130    
131                            if (section_data_mark_del_article(p_section[i], p_article->aid) != 1)
132                            {
133                                    printf("section_data_mark_del_article(aid = %d) error\n", p_article->aid);
134                            }
135                  }                  }
136    
137                  printf("Verify %d articles in section %d\n", p_section[i]->article_count, i);                  printf("Verify %d articles in section %d\n", p_section[i]->article_count, i);
138                    printf("Delete %d articles in section %d\n", p_section[i]->delete_count, i);
139          }          }
140    
141          printf("Testing #2 ...\n");          printf("Testing #2 ...\n");
# Line 144  int main(int argc, char *argv[]) Line 166  int main(int argc, char *argv[])
166                          article.ontop = 0;                          article.ontop = 0;
167                          article.lock = 0;                          article.lock = 0;
168    
169                          section_data_append_article(p_section[i], &article);                          if (section_data_append_article(p_section[i], &article) < 0)
170                            {
171                                    printf("append article (aid = %d) error\n", article.aid);
172                                    break;
173                            }
174                  }                  }
175    
176                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);
# Line 152  int main(int argc, char *argv[]) Line 178  int main(int argc, char *argv[])
178    
179          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
180          {          {
181                    if (p_section[i]->article_count == 0)
182                    {
183                            continue;
184                    }
185    
186                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j++)
187                  {                  {
188                          p_article = section_data_find_article_by_index(p_section[i], j);                          p_article = section_data_find_article_by_index(p_section[i], j);
# Line 166  int main(int argc, char *argv[]) Line 197  int main(int argc, char *argv[])
197                                  break;                                  break;
198                          }                          }
199    
200                            article_count = 1;
201    
202                          do                          do
203                          {                          {
204                                  if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid)                                  if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid)
# Line 190  int main(int argc, char *argv[]) Line 223  int main(int argc, char *argv[])
223                                          printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1);                                          printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1);
224                                          break;                                          break;
225                                  }                                  }
226                                    article_count++;
227                          } while (1);                          } while (1);
228    
229                            if (article_count != p_section[i]->article_count / group_count)
230                            {
231                                    printf("Count of articles in topic %d is less than expected %d < %d\n",
232                                               j + 1, article_count, p_section[i]->article_count / group_count);
233                            }
234                  }                  }
235    
236                  printf("Verify %d topics in section %d\n", group_count, i);                  printf("Verify %d topics in section %d\n", group_count, i);


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

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