/[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.6 by sysadm, Wed May 21 09:18:17 2025 UTC Revision 1.17 by sysadm, Fri May 23 14:04:05 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 last_aid;          int last_aid;
54          int group_count;          int current_tid;
55            int section_first_aid;
56            int group_count = 100;
57          int article_count;          int article_count;
58            int step;
59            int32_t page;
60            int32_t offset;
61            int affected_count;
62            FILE *fp;
63    
64          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)          if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
65          {          {
# Line 59  int main(int argc, char *argv[]) Line 70  int main(int argc, char *argv[])
70          log_std_redirect(STDOUT_FILENO);          log_std_redirect(STDOUT_FILENO);
71          log_err_redirect(STDERR_FILENO);          log_err_redirect(STDERR_FILENO);
72    
73          // 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
74          // - 1 to make blocks allocated is less than required          block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK;
75          // Some error will be triggered while invoking section_data_append_article()  
76          block_count = BBS_article_block_limit_per_section * BBS_max_section - 1;          if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL)
77            {
78                    log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
79                    return -1;
80            }
81            fclose(fp);
82    
83            if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL)
84            {
85                    log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE);
86                    return -1;
87            }
88            fclose(fp);
89    
90          if (section_data_pool_init("../conf/menu.conf", block_count) < 0)          if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0)
91          {          {
92                  log_error("section_data_pool_init() error\n");                  log_error("section_data_pool_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count);
93                    return -2;
94            }
95    
96            if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0)
97            {
98                    log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE);
99                  return -2;                  return -2;
100          }          }
101    
# Line 76  int main(int argc, char *argv[]) Line 105  int main(int argc, char *argv[])
105    
106          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
107          {          {
108                  p_section[i] = section_data_create(sname[i % section_conf_count],                  p_section[i] = section_list_create(i + 1,
109                                                                                       sname[i % section_conf_count],
110                                                                                     stitle[i % section_conf_count],                                                                                     stitle[i % section_conf_count],
111                                                                                     master_name[i % section_conf_count]);                                                                                     master_name[i % section_conf_count]);
112                  if (p_section[i] == NULL)                  if (p_section[i] == NULL)
# Line 84  int main(int argc, char *argv[]) Line 114  int main(int argc, char *argv[])
114                          log_error("section_data_create(i=%d) error\n", i);                          log_error("section_data_create(i=%d) error\n", i);
115                          return -3;                          return -3;
116                  }                  }
117            }
118    
119                  for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)          for (i = 0; i < section_conf_count; i++)
120            {
121                    if (section_list_find_by_name(sname[i]) == NULL)
122                    {
123                            printf("section_data_find_section_by_name(%s) error\n", sname[i]);
124                            return -3;
125                    }
126            }
127    
128            for (j = 0; j < BBS_article_limit_per_section; j++)
129            {
130                    for (i = 0; i < section_count; i++)
131                  {                  {
132                          last_aid++;                          last_aid++;
133    
# Line 99  int main(int argc, char *argv[]) Line 141  int main(int argc, char *argv[])
141                          article.ontop = 0;                          article.ontop = 0;
142                          article.lock = 0;                          article.lock = 0;
143    
144                          if (section_data_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
145                          {                          {
146                                  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);
147                                  break;                                  break;
148                          }                          }
149                  }                  }
150            }
151    
152                  printf("Load %d articles into section %d\n", p_section[i]->article_count, i);          for (i = 0; i < section_count; i++)
153            {
154                    // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
155          }          }
156    
157          last_aid = 0;          last_aid = 0;
# Line 122  int main(int argc, char *argv[]) Line 167  int main(int argc, char *argv[])
167                  {                  {
168                          last_aid++;                          last_aid++;
169    
170                          p_article = section_data_find_article_by_index(p_section[i], j);                          p_article = article_block_find_by_aid(last_aid);
171                            if (p_article == NULL || p_article->aid != last_aid)
172                            {
173                                    printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);
174                            }
175    
176                            p_article = article_block_find_by_index(last_aid - 1);
177                          if (p_article == NULL || p_article->aid != last_aid)                          if (p_article == NULL || p_article->aid != last_aid)
178                          {                          {
179                                  printf("Inconsistent aid at index %d != %d\n", j, last_aid);                                  printf("article_block_find_by_index() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid);
180                          }                          }
181    
182                          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)
183                          {                          {
184                                  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);
185                          }                          }
186                  }                  }
187    
188                  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);  
189          }          }
190    
191          printf("Testing #2 ...\n");          printf("Testing #2 ...\n");
192    
193          group_count = 100;          if (article_block_reset() != 0)
194            {
195                    log_error("section_data_free_block(i=%d) error\n", i);
196                    return -4;
197            }
198    
199          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
200          {          {
201                  if (section_data_free_block(p_section[i]) != 0)                  section_list_reset_articles(p_section[i]);
202                  {          }
                         log_error("section_data_free_block(i=%d) error\n", i);  
                         return -4;  
                 }  
203    
204                  last_aid = 0;          last_aid = 0;
205    
206                  for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++)          for (i = 0; i < section_count; i++)
207            {
208                    section_first_aid = last_aid + 1;
209    
210                    for (j = 0; j < BBS_article_limit_per_section; j++)
211                  {                  {
212                          last_aid++;                          last_aid++;
213    
214                          // Set article data                          // Set article data
215                          article.aid = last_aid;                          article.aid = last_aid;
216                          article.cid = article.aid;                          article.cid = article.aid;
217                          article.tid = (article.aid <= group_count ? 0 : (article.aid - 1) % group_count + 1); // Group articles into group_count topics                          // Group articles into group_count topics
218                          article.uid = 1;                                                                                                                                          // TODO: randomize                          article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
219                            article.uid = 1; // TODO: randomize
220                          article.visible = 1;                          article.visible = 1;
221                          article.excerption = 0;                          article.excerption = 0;
222                          article.ontop = 0;                          article.ontop = 0;
223                          article.lock = 0;                          article.lock = 0;
224    
225                          if (section_data_append_article(p_section[i], &article) < 0)                          if (section_list_append_article(p_section[i], &article) < 0)
226                          {                          {
227                                  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);
228                                  break;                                  break;
229                          }                          }
230                  }                  }
231    
232                  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);
233          }          }
234    
235          for (i = 0; i < section_count; i++)          for (i = 0; i < section_count; i++)
# Line 183  int main(int argc, char *argv[]) Line 239  int main(int argc, char *argv[])
239                          continue;                          continue;
240                  }                  }
241    
242                    article_count = 0;
243                    last_aid = 0;
244    
245                    p_article = p_section[i]->p_article_head;
246    
247                    do
248                    {
249                            article_count++;
250    
251                            if (p_article->aid <= last_aid)
252                            {
253                                    printf("Non-ascending aid found %d <= %d at article\n", p_article->aid, last_aid);
254                            }
255                            last_aid = p_article->aid;
256    
257                            p_article = p_article->p_next;
258                    } while (p_article != p_section[i]->p_article_head);
259    
260                    if (article_count != p_section[i]->article_count)
261                    {
262                            printf("Count of articles in section %d is different from expected %d != %d\n",
263                                       i, article_count, p_section[i]->article_count);
264                            break;
265                    }
266    
267                    // printf("Verified %d articles in section %d\n", group_count, i);
268            }
269    
270            for (i = 0; i < section_count; i++)
271            {
272                    if (p_section[i]->article_count == 0)
273                    {
274                            continue;
275                    }
276    
277                    if (p_section[i]->topic_count != group_count)
278                    {
279                            printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count);
280                    }
281    
282                  for (j = 0; j < group_count; j++)                  for (j = 0; j < group_count; j++)
283                  {                  {
284                          p_article = section_data_find_article_by_index(p_section[i], j);                          last_aid = p_section[i]->p_article_head->aid + j;
285    
286                            p_article = article_block_find_by_aid(last_aid);
287                          if (p_article == NULL)                          if (p_article == NULL)
288                          {                          {
289                                  printf("NULL p_article at index %d\n", j);                                  printf("NULL p_article at section %d index %d\n", i, j);
290                                  break;                                  break;
291                          }                          }
292                          if (p_article->aid != j + 1)                          if (p_article->aid != last_aid)
293                          {                          {
294                                  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);
295                                  break;                                  break;
296                          }                          }
297    
298                          article_count = 1;                          article_count = 1;
299                            last_aid = 0;
300                            current_tid = p_article->aid;
301    
302                          do                          do
303                          {                          {
304                                  if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid)                                  if (p_article->aid <= last_aid)
305                                  {                                  {
306                                          printf("Non-ascending aid found %d >= %d\n", p_article->aid, p_article->next_aid);                                          printf("Non-ascending aid found %d <= %d\n", p_article->aid, last_aid);
                                         break;  
307                                  }                                  }
308                                    last_aid = p_article->aid;
309    
310                                    p_article = p_article->p_topic_next;
311    
                                 last_aid = p_article->next_aid;  
                                 p_article = section_data_find_article_by_aid(p_section[i], last_aid);  
312                                  if (p_article == NULL)                                  if (p_article == NULL)
313                                  {                                  {
314                                          printf("NULL p_article at aid %d\n", last_aid);                                          printf("NULL p_article found\n");
315                                          break;                                          break;
316                                  }                                  }
317                                  if (p_article->tid == 0) // loop                                  if (p_article->tid == 0) // loop
318                                  {                                  {
319                                          break;                                          break;
320                                  }                                  }
321                                  if (p_article->tid != j + 1)                                  if (p_article->tid != current_tid)
322                                  {                                  {
323                                          printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1);                                          printf("Inconsistent tid %d != %d\n", p_article->tid, current_tid);
324                                          break;                                          break;
325                                  }                                  }
326    
327                                  article_count++;                                  article_count++;
328                          } while (1);                          } while (1);
329    
330                          if (article_count != p_section[i]->article_count / group_count)                          if (article_count != p_section[i]->article_count / group_count)
331                          {                          {
332                                  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",
333                                             j + 1, article_count, p_section[i]->article_count / group_count);                                             j + 1, article_count, p_section[i]->article_count / group_count);
334                                    // break;
335                          }                          }
336                  }                  }
337    
338                  printf("Verify %d topics in section %d\n", group_count, i);                  // printf("Verified %d topics in section %d\n", group_count, i);
339          }          }
340    
341          printf("Testing #3 ...\n");          printf("Testing #3 ...\n");
342    
343          for (i = 0; i < section_conf_count; i++)          for (i = 0; i < section_count; i++)
344          {          {
345                  if (section_data_find_section_by_name(sname[i]) == NULL)                  last_aid = 0;
346    
347                    for (j = 0; j < p_section[i]->page_count; j++)
348                  {                  {
349                          printf("section_data_find_section_by_name(%s) error\n", sname[i]);                          if (p_section[i]->p_page_first_article[j]->aid <= last_aid)
350                            {
351                                    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);
352                            }
353    
354                            if (j > 0)
355                            {
356                                    step = 0;
357    
358                                    for (p_article = p_section[i]->p_page_first_article[j];
359                                             p_article != p_section[i]->p_page_first_article[j - 1];
360                                             p_article = p_article->p_prior)
361                                    {
362                                            step++;
363                                    }
364    
365                                    if (step != BBS_article_limit_per_page)
366                                    {
367                                            printf("Incorrect page size %d at section %d page %d\n", step, i, j - 1);
368                                    }
369                            }
370                    }
371            }
372    
373            printf("Testing #4 ...\n");
374    
375            for (i = 0; i < section_count; i++)
376            {
377                    step = i % 10 + 1;
378                    for (j = group_count; j < BBS_article_limit_per_section; j += step)
379                    {
380                            last_aid = i * BBS_article_limit_per_section + j + 1;
381    
382                            p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
383    
384                            if (p_article == NULL)
385                            {
386                                    printf("Error find article %d in section %d offset %d\n", last_aid, i, j);
387                                    break;
388                            }
389    
390                            if (p_article->aid != last_aid)
391                            {
392                                    printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid);
393                                    break;
394                            }
395    
396                            if (section_list_set_article_visible(p_section[i], last_aid, 0) != 1)
397                            {
398                                    printf("Error set article %d invisible in section %d offset %d\n", last_aid, i, j);
399                                    break;
400                            }
401                    }
402    
403                    last_aid = p_section[i]->p_article_head->aid;
404                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
405                    {
406                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
407                            break;
408                    }
409    
410                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
411                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
412                            p_section[i]->page_count)
413                    {
414                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
415                                       "visible_article_count = %d, last_page_visible_count = %d\n",
416                                       i, j,
417                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
418                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
419                                       p_section[i]->page_count, p_section[i]->visible_article_count,
420                                       p_section[i]->last_page_visible_article_count);
421                            break;
422                    }
423    
424                    affected_count = (BBS_article_limit_per_section - group_count) / step + ((BBS_article_limit_per_section - group_count) % step ? 1 : 0);
425                    if (p_section[i]->article_count - p_section[i]->visible_article_count != affected_count)
426                    {
427                            printf("Inconsistent set invisible count in section %d, %d != %d\n", i,
428                                       p_section[i]->article_count - p_section[i]->visible_article_count,
429                                       affected_count);
430                            break;
431                    }
432    
433                    article_count = p_section[i]->visible_article_count;
434    
435                    for (j = 0; j < group_count; j += 1)
436                    {
437                            last_aid = i * BBS_article_limit_per_section + j + 1;
438    
439                            p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset, &p_next);
440    
441                            if (p_article == NULL)
442                            {
443                                    printf("Error find article %d in section %d offset %d\n", last_aid, i, j);
444                                    break;
445                            }
446    
447                            if (p_article->aid != last_aid)
448                            {
449                                    printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid);
450                                    break;
451                            }
452    
453                            if (p_article->tid != 0)
454                            {
455                                    printf("Non-topic article aid in section %d page %d offset %d %d != 0\n", i, page, offset, p_article->tid);
456                                    break;
457                            }
458    
459                            if ((affected_count = section_list_set_article_visible(p_section[i], last_aid, 0)) <= 0)
460                            {
461                                    printf("Error set topic %d invisible in section %d offset %d\n", last_aid, i, j);
462                                    break;
463                            }
464    
465                            article_count -= affected_count;
466                    }
467    
468                    if (article_count != 0)
469                    {
470                            printf("Inconsistent total set invisible topic count in section %d, %d > 0\n", i, article_count);
471                            break;
472                    }
473    
474                    if (p_section[i]->visible_article_count > 0)
475                    {
476                            printf("Inconsistent invisible article count in section %d, %d > 0\n", i, p_section[i]->visible_article_count);
477                            break;
478                    }
479    
480                    if (p_section[i]->visible_topic_count > 0)
481                    {
482                            printf("Inconsistent invisible topic count in section %d, %d > 0\n", i, p_section[i]->visible_topic_count);
483                            break;
484                    }
485    
486                    last_aid = p_section[i]->p_article_head->aid;
487                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
488                    {
489                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
490                            break;
491                    }
492    
493                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
494                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
495                            p_section[i]->page_count)
496                    {
497                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
498                                       "visible_article_count = %d, last_page_visible_count = %d\n",
499                                       i, j,
500                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
501                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
502                                       p_section[i]->page_count, p_section[i]->visible_article_count,
503                                       p_section[i]->last_page_visible_article_count);
504                            break;
505                    }
506            }
507    
508            for (i = 0; i < BBS_max_section; i++)
509            {
510                    affected_count = 0;
511    
512                    for (j = 0; j < BBS_article_limit_per_section; j += 1)
513                    {
514                            last_aid = i * BBS_article_limit_per_section + j + 1;
515    
516                            if (section_list_set_article_visible(p_section[i], last_aid, 1) <= 0)
517                            {
518                                    printf("Error set article %d visible in section %d offset %d\n", last_aid, i, j);
519                                    break;
520                            }
521    
522                            affected_count++;
523                    }
524    
525                    if (affected_count != p_section[i]->article_count)
526                    {
527                            printf("Inconsistent total set visible article count in section %d, %d != %d\n", i, affected_count, p_section[i]->article_count);
528                            break;
529                    }
530    
531                    if (p_section[i]->visible_article_count != p_section[i]->article_count)
532                    {
533                            printf("Inconsistent visible article count in section %d, %d != %d\n", i, p_section[i]->visible_article_count, p_section[i]->article_count);
534                            break;
535                    }
536    
537                    if (p_section[i]->visible_topic_count != group_count)
538                    {
539                            printf("Inconsistent visible topic count in section %d, %d != %d\n", i, p_section[i]->visible_topic_count, group_count);
540                            break;
541                    }
542    
543                    last_aid = p_section[i]->p_article_head->aid;
544                    if (section_list_calculate_page(p_section[i], last_aid) < 0)
545                    {
546                            printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j);
547                            break;
548                    }
549    
550                    if (p_section[i]->visible_article_count / BBS_article_limit_per_page +
551                                    (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) !=
552                            p_section[i]->page_count)
553                    {
554                            printf("Inconsistent page count in section %d offset %d, %d != %d, "
555                                       "visible_article_count = %d, last_page_visible_count = %d\n",
556                                       i, j,
557                                       p_section[i]->visible_article_count / BBS_article_limit_per_page +
558                                               (p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0),
559                                       p_section[i]->page_count, p_section[i]->visible_article_count,
560                                       p_section[i]->last_page_visible_article_count);
561                            break;
562                    }
563            }
564    
565            printf("Testing #5 ...\n");
566    
567            if (article_block_reset() != 0)
568            {
569                    log_error("section_data_free_block(i=%d) error\n", i);
570                    return -4;
571            }
572    
573            for (i = 0; i < section_count; i++)
574            {
575                    section_list_reset_articles(p_section[i]);
576            }
577    
578            last_aid = 0;
579    
580            for (i = 0; i < section_count / 2; i++)
581            {
582                    section_first_aid = last_aid + 1;
583    
584                    for (j = 0; j < BBS_article_limit_per_section; j++)
585                    {
586                            last_aid++;
587    
588                            // Set article data
589                            article.aid = last_aid;
590                            article.cid = article.aid;
591                            // Group articles into group_count topics
592                            article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count));
593                            article.uid = 1; // TODO: randomize
594                            article.visible = 1;
595                            article.excerption = 0;
596                            article.ontop = 0;
597                            article.lock = 0;
598    
599                            if (section_list_append_article(p_section[i], &article) < 0)
600                            {
601                                    printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j);
602                                    break;
603                            }
604                    }
605    
606                    // printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i);
607            }
608    
609            for (i = 0; i < section_count / 2; i++)
610            {
611                    section_first_aid = p_section[i]->p_article_head->aid;
612    
613                    for (j = 0; j < group_count; j += 2)
614                    {
615                            p_article = section_list_find_article_with_offset(p_section[i], section_first_aid + j, &page, &offset, &p_next);
616                            if (p_article == NULL)
617                            {
618                                    printf("section_list_find_article_with_offset(aid = %d) not found in section %d\n",
619                                               section_first_aid + j, i);
620                                    break;
621                            }
622    
623                            if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != BBS_article_limit_per_section / group_count)
624                            {
625                                    printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid);
626                            }
627                    }
628            }
629    
630            for (i = 0; i < section_count / 2; i++)
631            {
632                    section_first_aid = p_section[i]->p_article_head->aid;
633    
634                    for (j = 0; j < group_count; j++)
635                    {
636                            affected_count = section_list_move_topic(p_section[i], p_section[section_count / 2 + i], section_first_aid + j);
637    
638                            if (affected_count < 0)
639                            {
640                                    printf("move topic (aid = %d) error from section %d to section %d\n", section_first_aid + j, i, section_count / 2 + i);
641                                    break;
642                            }
643    
644                            if (affected_count != BBS_article_limit_per_section / group_count)
645                            {
646                                    printf("move topic (aid = %d) affected article count %d != %d\n",
647                                               section_first_aid + j, affected_count,
648                                               BBS_article_limit_per_section / group_count);
649                                    // break;
650                            }
651                    }
652            }
653    
654            for (i = 0; i < section_count; i++)
655            {
656                    if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count))
657                    {
658                            printf("Topic count error in section %d, %d != %d\n", i,
659                                       p_section[i]->topic_count, (i < section_count / 2 ? 0 : group_count));
660                            break;
661                    }
662    
663                    if (p_section[i]->visible_topic_count != (i < section_count / 2 ? 0 : group_count / 2))
664                    {
665                            printf("Visible topic count error in section %d, %d != %d\n", i,
666                                       p_section[i]->visible_topic_count, (i < section_count / 2 ? 0 : group_count / 2));
667                            break;
668                    }
669    
670                    if (p_section[i]->article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section))
671                    {
672                            printf("Article count error in section %d, %d != %d\n", i,
673                                       p_section[i]->article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section));
674                            break;
675                    }
676    
677                    if (p_section[i]->visible_article_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2))
678                    {
679                            printf("Visible article count error in section %d, %d != %d\n", i,
680                                       p_section[i]->visible_article_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2));
681                            break;
682                    }
683    
684                    if (p_section[i]->page_count != (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page))
685                    {
686                            printf("Page count error in section %d, %d != %d\n", i,
687                                       p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page));
688                            break;
689                  }                  }
690          }          }
691    
692          printf("Press ENTER to exit...");          printf("Press ENTER to exit...");
693          getchar();          getchar();
694            
695          section_data_pool_cleanup();          article_block_cleanup();
696            section_list_pool_cleanup();
697    
698            if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0)
699            {
700                    log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE);
701                    return -1;
702            }
703    
704            if (unlink(SECTION_LIST_SHM_FILE) < 0)
705            {
706                    log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE);
707                    return -1;
708            }
709    
710          log_end();          log_end();
711    


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

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