/[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.8 by sysadm, Wed May 21 12:54:06 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 41  int section_count = BBS_max_section; Line 44  int section_count = BBS_max_section;
44    
45  int main(int argc, char *argv[])  int main(int argc, char *argv[])
46  {  {
47          SECTION_DATA *p_section[BBS_max_section];          SECTION_LIST *p_section[BBS_max_section];
48          ARTICLE *p_article;          ARTICLE *p_article;
49            ARTICLE *p_next;
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 group_count;          int current_tid;
56            int section_first_aid;
57            int group_count = 100;
58          int article_count;          int article_count;
59            int step;
60            int32_t page;
61            int32_t offset;
62            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 59  int main(int argc, char *argv[]) Line 71  int main(int argc, char *argv[])
71          log_std_redirect(STDOUT_FILENO);          log_std_redirect(STDOUT_FILENO);
72          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
73    
74          // block_count = BBS_article_block_limit_per_section * BBS_max_section; // This statement is correct          // - 1 to make blocks allocated is less than required, to trigger error handling
75          // - 1 to make blocks allocated is less than required          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;
76          // Some error will be triggered while invoking section_data_append_article()  
77          block_count = BBS_article_block_limit_per_section * BBS_max_section - 1;          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("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);
94                    return -2;
95            }
96    
97          if (section_data_pool_init("../conf/menu.conf", block_count) < 0)          if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0)
98          {          {
99                  log_error("section_data_pool_init() error\n");                  log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);
100                  return -2;                  return -2;
101          }          }
102    
# Line 76  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_data_create(sname[i % section_conf_count],                  sid = i * 3 + 1;
110                    p_section[i] = section_list_create(sid,
111                                                                                       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;
127                    }
128            }
129    
130            for (i = 0; i < section_conf_count; i++)
131            {
132                    if (section_list_find_by_name(sname[i]) == NULL)
133                    {
134                            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          }          }
148    
149          for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)          for (j = 0; j < BBS_article_limit_per_section; j++)
150          {          {
151                  for (i = 0; i < section_count; i++)                  for (i = 0; i < section_count; i++)
152                  {                  {
# Line 94  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;
163                          article.ontop = 0;                          article.ontop = 0;
164                          article.lock = 0;                          article.lock = 0;
165    
166                          if (section_data_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
167                          {                          {
168                                  printf("append article (aid = %d) error\n", article.aid);                                  printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
169                                  break;                                  break;
170                          }                          }
171                  }                  }
# Line 112  int main(int argc, char *argv[]) Line 173  int main(int argc, char *argv[])
173    
174          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
175          {          {
176                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);                  // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
177          }          }
178    
179          for (i = 0; i < section_count; i++)          last_aid = 0;
180    
181            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++)
184                  {                  {
185                          continue;                          last_aid++;
                 }  
   
                 last_aid = i + 1;  
186    
187                  for (j = 0; j < p_section[i]->article_count; j++)                          p_article = article_block_find_by_aid(last_aid);
                 {  
                         p_article = section_data_find_article_by_index(p_section[i], j);  
188                          if (p_article == NULL || p_article->aid != last_aid)                          if (p_article == NULL || p_article->aid != last_aid)
189                          {                          {
190                                  printf("Inconsistent aid at section %d index %d != %d\n", i, j, 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    
193                          if (section_data_mark_del_article(p_section[i], p_article->aid) != 1)                          if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1)
194                          {                          {
195                                  printf("section_data_mark_del_article(aid = %d) error\n", p_article->aid);                                  printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
196                          }                          }
   
                         last_aid += section_count;  
197                  }                  }
198    
199                  printf("Verify %d articles in section %d\n", p_section[i]->article_count, i);                  // printf("Verified %d articles in section %d\n", p_section[i]->article_count, i);
   
                 printf("Delete %d articles in section %d\n", p_section[i]->delete_count, i);  
200          }          }
201    
202          printf("Testing #2 ...\n");          printf("Testing #2 ...\n");
203    
204          group_count = 100;          if (article_block_reset() != 0)
205            {
206                    log_error("article_block_reset() error\n");
207                    return -4;
208            }
209    
210          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
211          {          {
212                  if (section_data_free_block(p_section[i]) != 0)                  section_list_reset_articles(p_section[i]);
213                  {          }
                         log_error("section_data_free_block(i=%d) error\n", i);  
                         return -4;  
                 }  
214    
215                  last_aid = 0;          last_aid = 0;
216    
217            for (i = 0; i < section_count; i++)
218            {
219                    section_first_aid = last_aid + 1;
220    
221                  for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)                  for (j = 0; j < BBS_article_limit_per_section; j++)
222                  {                  {
223                          last_aid++;                          last_aid++;
224    
225                          // Set article data                          // Set article data
226                          article.aid = last_aid;                          article.aid = last_aid;
227                            // Group articles into group_count topics
228                            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;                          article.cid = article.aid;
231                          article.tid = (article.aid <= group_count ? 0 : (article.aid - 1) % group_count + 1); // Group articles into group_count topics                          article.uid = 1; // TODO: randomize
                         article.uid = 1;                                                                                                                                          // TODO: randomize  
232                          article.visible = 1;                          article.visible = 1;
233                          article.excerption = 0;                          article.excerption = 0;
234                          article.ontop = 0;                          article.ontop = 0;
235                          article.lock = 0;                          article.lock = 0;
236    
237                          if (section_data_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
238                          {                          {
239                                  printf("append article (aid = %d) error\n", article.aid);                                  printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
240                                  break;                                  break;
241                          }                          }
242                  }                  }
243    
244                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);                  // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
245          }          }
246    
247          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
# Line 201  int main(int argc, char *argv[]) Line 262  int main(int argc, char *argv[])
262    
263                          if (p_article->aid <= last_aid)                          if (p_article->aid <= last_aid)
264                          {                          {
265                                  printf("Non-ascending aid found %d <= %d\n", p_article->aid, last_aid);                                  printf("Non-ascending aid found %d <= %d at article\n", p_article->aid, last_aid);
266                          }                          }
267                          last_aid = p_article->aid;                          last_aid = p_article->aid;
268    
# Line 212  int main(int argc, char *argv[]) Line 273  int main(int argc, char *argv[])
273                  {                  {
274                          printf("Count of articles in section %d is different from expected %d != %d\n",                          printf("Count of articles in section %d is different from expected %d != %d\n",
275                                     i, article_count, p_section[i]->article_count);                                     i, article_count, p_section[i]->article_count);
276                            break;
277                  }                  }
278    
279                  printf("Verify %d articles in section %d\n", group_count, i);                  // printf("Verified %d articles in section %d\n", group_count, i);
280          }          }
281    
282          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
# Line 224  int main(int argc, char *argv[]) Line 286  int main(int argc, char *argv[])
286                          continue;                          continue;
287                  }                  }
288    
289                    if (p_section[i]->topic_count != group_count)
290                    {
291                            printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count);
292                    }
293    
294                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j++)
295                  {                  {
296                          p_article = section_data_find_article_by_index(p_section[i], j);                          last_aid = p_section[i]->p_article_head->aid + j;
297    
298                            p_article = article_block_find_by_aid(last_aid);
299                          if (p_article == NULL)                          if (p_article == NULL)
300                          {                          {
301                                  printf("NULL p_article at index %d\n", j);                                  printf("NULL p_article at section %d index %d\n", i, j);
302                                  break;                                  break;
303                          }                          }
304                          if (p_article->aid != j + 1)                          if (p_article->aid != last_aid)
305                          {                          {
306                                  printf("Inconsistent aid at index %d != %d\n", j, j + 1);                                  printf("Inconsistent aid at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);
307                                  break;                                  break;
308                          }                          }
309    
310                          article_count = 1;                          article_count = 1;
311                          last_aid = 0;                          last_aid = 0;
312                            current_tid = p_article->aid;
313    
314                          do                          do
315                          {                          {
# Line 260  int main(int argc, char *argv[]) Line 330  int main(int argc, char *argv[])
330                                  {                                  {
331                                          break;                                          break;
332                                  }                                  }
333                                  if (p_article->tid != j + 1)                                  if (p_article->tid != current_tid)
334                                  {                                  {
335                                          printf("Inconsistent tid  %d != %d\n", last_aid, j + 1);                                          printf("Inconsistent tid %d != %d\n", p_article->tid, current_tid);
336                                          break;                                          break;
337                                  }                                  }
338    
# Line 271  int main(int argc, char *argv[]) Line 341  int main(int argc, char *argv[])
341    
342                          if (article_count != p_section[i]->article_count / group_count)                          if (article_count != p_section[i]->article_count / group_count)
343                          {                          {
344                                  printf("Count of articles in topic %d is less than 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;
347                          }                          }
348                  }                  }
349    
350                  printf("Verify %d topics in section %d\n", group_count, i);                  // printf("Verified %d topics in section %d\n", group_count, i);
351          }          }
352    
353          printf("Testing #3 ...\n");          printf("Testing #3 ...\n");
354    
355          for (i = 0; i < section_conf_count; i++)          for (i = 0; i < section_count; i++)
356            {
357                    last_aid = 0;
358    
359                    for (j = 0; j < p_section[i]->page_count; j++)
360                    {
361                            if (p_section[i]->p_page_first_article[j]->aid <= last_aid)
362                            {
363                                    printf("Non-ascending aid found at section %d page %d, %d <= %d\n", i, j, p_section[i]->p_page_first_article[j]->aid, last_aid);
364                            }
365    
366                            if (j > 0)
367                            {
368                                    step = 0;
369    
370                                    for (p_article = p_section[i]->p_page_first_article[j];
371                                             p_article != p_section[i]->p_page_first_article[j - 1];
372                                             p_article = p_article->p_prior)
373                                    {
374                                            step++;
375                                    }
376    
377                                    if (step != BBS_article_limit_per_page)
378                                    {
379                                            printf("Incorrect page size %d at section %d page %d\n", step, i, j - 1);
380                                    }
381                            }
382                    }
383            }
384    
385            printf("Testing #4 ...\n");
386    
387            for (i = 0; i < section_count; i++)
388            {
389                    step = i % 10 + 1;
390                    for (j = group_count; j < BBS_article_limit_per_section; j += step)
391                    {
392                            last_aid = i * BBS_article_limit_per_section + j + 1;
393    
394                            p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
395    
396                            if (p_article == NULL)
397                            {
398                                    printf("Error find article %d in section %d offset %d\n", last_aid, i, j);
399                                    break;
400                            }
401    
402                            if (p_article->aid != last_aid)
403                            {
404                                    printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid);
405                                    break;
406                            }
407    
408                            if (section_list_set_article_visible(p_section[i], last_aid, 0) != 1)
409                            {
410                                    printf("Error set article %d invisible in section %d offset %d\n", last_aid, i, j);
411                                    break;
412                            }
413                    }
414    
415                    last_aid = p_section[i]->p_article_head->aid;
416                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
417                    {
418                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
419                            break;
420                    }
421    
422                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
423                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
424                            p_section[i]->page_count)
425                    {
426                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
427                                       "visible_article_count = %d, last_page_visible_count = %d\n",
428                                       i, j,
429                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
430                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
431                                       p_section[i]->page_count, p_section[i]->visible_article_count,
432                                       p_section[i]->last_page_visible_article_count);
433                            break;
434                    }
435    
436                    affected_count = (BBS_article_limit_per_section - group_count) / step + ((BBS_article_limit_per_section - group_count) % step ? 1 : 0);
437                    if (p_section[i]->article_count - p_section[i]->visible_article_count != affected_count)
438                    {
439                            printf("Inconsistent set invisible count in section %d, %d != %d\n", i,
440                                       p_section[i]->article_count - p_section[i]->visible_article_count,
441                                       affected_count);
442                            break;
443                    }
444    
445                    article_count = p_section[i]->visible_article_count;
446    
447                    for (j = 0; j < group_count; j += 1)
448                    {
449                            last_aid = i * BBS_article_limit_per_section + j + 1;
450    
451                            p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
452    
453                            if (p_article == NULL)
454                            {
455                                    printf("Error find article %d in section %d offset %d\n", last_aid, i, j);
456                                    break;
457                            }
458    
459                            if (p_article->aid != last_aid)
460                            {
461                                    printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid);
462                                    break;
463                            }
464    
465                            if (p_article->tid != 0)
466                            {
467                                    printf("Non-topic article aid in section %d page %d offset %d %d != 0\n", i, page, offset, p_article->tid);
468                                    break;
469                            }
470    
471                            if ((affected_count = section_list_set_article_visible(p_section[i], last_aid, 0)) <= 0)
472                            {
473                                    printf("Error set topic %d invisible in section %d offset %d\n", last_aid, i, j);
474                                    break;
475                            }
476    
477                            article_count -= affected_count;
478                    }
479    
480                    if (article_count != 0)
481                    {
482                            printf("Inconsistent total set invisible topic count in section %d, %d > 0\n", i, article_count);
483                            break;
484                    }
485    
486                    if (p_section[i]->visible_article_count > 0)
487                    {
488                            printf("Inconsistent invisible article count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);
489                            break;
490                    }
491    
492                    if (p_section[i]->visible_topic_count > 0)
493                    {
494                            printf("Inconsistent invisible topic count in section %d, %d > 0\n", i, p_section[i]->visible_topic_count);
495                            break;
496                    }
497    
498                    last_aid = p_section[i]->p_article_head->aid;
499                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
500                    {
501                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
502                            break;
503                    }
504    
505                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
506                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
507                            p_section[i]->page_count)
508                    {
509                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
510                                       "visible_article_count = %d, last_page_visible_count = %d\n",
511                                       i, j,
512                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
513                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
514                                       p_section[i]->page_count, p_section[i]->visible_article_count,
515                                       p_section[i]->last_page_visible_article_count);
516                            break;
517                    }
518            }
519    
520            for (i = 0; i < BBS_max_section; i++)
521            {
522                    affected_count = 0;
523    
524                    for (j = 0; j < BBS_article_limit_per_section; j += 1)
525                    {
526                            last_aid = i * BBS_article_limit_per_section + j + 1;
527    
528                            if (section_list_set_article_visible(p_section[i], last_aid, 1) <= 0)
529                            {
530                                    printf("Error set article %d visible in section %d offset %d\n", last_aid, i, j);
531                                    break;
532                            }
533    
534                            affected_count++;
535                    }
536    
537                    if (affected_count != p_section[i]->article_count)
538                    {
539                            printf("Inconsistent total set visible article count in section %d, %d != %d\n", i, affected_count, p_section[i]->article_count);
540                            break;
541                    }
542    
543                    if (p_section[i]->visible_article_count != p_section[i]->article_count)
544                    {
545                            printf("Inconsistent visible article count in section %d, %d != %d\n", i, p_section[i]->visible_article_count, p_section[i]->article_count);
546                            break;
547                    }
548    
549                    if (p_section[i]->visible_topic_count != group_count)
550                    {
551                            printf("Inconsistent visible topic count in section %d, %d != %d\n", i, p_section[i]->visible_topic_count, group_count);
552                            break;
553                    }
554    
555                    last_aid = p_section[i]->p_article_head->aid;
556                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
557                    {
558                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
559                            break;
560                    }
561    
562                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
563                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
564                            p_section[i]->page_count)
565                    {
566                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
567                                       "visible_article_count = %d, last_page_visible_count = %d\n",
568                                       i, j,
569                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
570                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
571                                       p_section[i]->page_count, p_section[i]->visible_article_count,
572                                       p_section[i]->last_page_visible_article_count);
573                            break;
574                    }
575            }
576    
577            printf("Testing #5 ...\n");
578    
579            if (article_block_reset() != 0)
580            {
581                    log_error("article_block_reset() error\n");
582                    return -4;
583            }
584    
585            for (i = 0; i < section_count; i++)
586            {
587                    section_list_reset_articles(p_section[i]);
588            }
589    
590            last_aid = 0;
591    
592            for (i = 0; i < section_count / 2; i++)
593            {
594                    section_first_aid = last_aid + 1;
595    
596                    for (j = 0; j < BBS_article_limit_per_section; j++)
597                    {
598                            last_aid++;
599    
600                            // Set article data
601                            article.aid = last_aid;
602                            // Group articles into group_count topics
603                            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
607                            article.visible = 1;
608                            article.excerption = 0;
609                            article.ontop = 0;
610                            article.lock = 0;
611    
612                            if (section_list_append_article(p_section[i], &article) < 0)
613                            {
614                                    printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
615                                    break;
616                            }
617                    }
618    
619                    // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
620            }
621    
622            for (i = 0; i < section_count / 2; i++)
623            {
624                    section_first_aid = p_section[i]->p_article_head->aid;
625    
626                    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);
629                            if (p_article == NULL)
630                            {
631                                    printf("section_list_find_article_with_offset(aid = %d) not found in section %d\n",
632                                               section_first_aid + j, i);
633                                    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    
643            for (i = 0; i < section_count / 2; i++)
644            {
645                    section_first_aid = p_section[i]->p_article_head->aid;
646    
647                    for (j = 0; j < group_count; j++)
648                    {
649                            affected_count = section_list_move_topic(p_section[i], p_section[section_count / 2 + i], section_first_aid + j);
650    
651                            if (affected_count < 0)
652                            {
653                                    printf("move topic (aid = %d) error from section %d to section %d\n", section_first_aid + j, i, section_count / 2 + i);
654                                    break;
655                            }
656    
657                            if (affected_count != BBS_article_limit_per_section / group_count)
658                            {
659                                    printf("move topic (aid = %d) affected article count %d != %d\n",
660                                               section_first_aid + j, affected_count,
661                                               BBS_article_limit_per_section / group_count);
662                                    // break;
663                            }
664                    }
665            }
666    
667            for (i = 0; i < section_count; i++)
668          {          {
669                  if (section_data_find_section_by_name(sname[i]) == NULL)                  if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))
670                    {
671                            printf("Topic count error in section %d, %d != %d\n", i,
672                                       p_section[i]->topic_count, (i < section_count / 2 ? 0 : group_count));
673                            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))
684                    {
685                            printf("Article count error in section %d, %d != %d\n", i,
686                                       p_section[i]->article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section));
687                            break;
688                    }
689    
690                    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("section_data_find_section_by_name(%s) error\n", sname[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 / 2 / BBS_article_limit_per_page));
701                            break;
702                  }                  }
703          }          }
704    
705          printf("Press ENTER to exit...");          printf("Press ENTER to exit...");
706          getchar();          getchar();
707    
708          section_data_pool_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