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


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

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