| 49 |
int last_aid; |
int last_aid; |
| 50 |
int current_tid; |
int current_tid; |
| 51 |
int section_first_aid; |
int section_first_aid; |
| 52 |
int group_count; |
int group_count = 100; |
| 53 |
int article_count; |
int article_count; |
| 54 |
|
int step; |
| 55 |
|
int32_t page; |
| 56 |
|
int32_t offset; |
| 57 |
|
int affected_count; |
| 58 |
|
|
| 59 |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
| 60 |
{ |
{ |
| 90 |
} |
} |
| 91 |
} |
} |
| 92 |
|
|
| 93 |
|
for (i = 0; i < section_conf_count; i++) |
| 94 |
|
{ |
| 95 |
|
if (section_list_find_by_name(sname[i]) == NULL) |
| 96 |
|
{ |
| 97 |
|
printf("section_data_find_section_by_name(%s) error\n", sname[i]); |
| 98 |
|
return -3; |
| 99 |
|
} |
| 100 |
|
} |
| 101 |
|
|
| 102 |
for (j = 0; j < BBS_article_limit_per_section; j++) |
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 103 |
{ |
{ |
| 104 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 175 |
section_list_reset_articles(p_section[i]); |
section_list_reset_articles(p_section[i]); |
| 176 |
} |
} |
| 177 |
|
|
|
group_count = 100; |
|
| 178 |
last_aid = 0; |
last_aid = 0; |
| 179 |
|
|
| 180 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 248 |
continue; |
continue; |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
|
if (p_section[i]->topic_count != group_count) |
| 252 |
|
{ |
| 253 |
|
printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count); |
| 254 |
|
} |
| 255 |
|
|
| 256 |
for (j = 0; j < group_count; j++) |
for (j = 0; j < group_count; j++) |
| 257 |
{ |
{ |
| 258 |
last_aid = p_section[i]->p_article_head->aid + j; |
last_aid = p_section[i]->p_article_head->aid + j; |
| 314 |
|
|
| 315 |
printf("Testing #3 ...\n"); |
printf("Testing #3 ...\n"); |
| 316 |
|
|
| 317 |
for (i = 0; i < section_conf_count; i++) |
for (i = 0; i < section_count; i++) |
| 318 |
{ |
{ |
| 319 |
if (section_list_find_by_name(sname[i]) == NULL) |
last_aid = 0; |
| 320 |
|
|
| 321 |
|
for (j = 0; j < p_section[i]->page_count; j++) |
| 322 |
{ |
{ |
| 323 |
printf("section_data_find_section_by_name(%s) error\n", sname[i]); |
if (p_section[i]->p_page_first_article[j]->aid <= last_aid) |
| 324 |
|
{ |
| 325 |
|
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); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
if (j > 0) |
| 329 |
|
{ |
| 330 |
|
step = 0; |
| 331 |
|
|
| 332 |
|
for (p_article = p_section[i]->p_page_first_article[j]; |
| 333 |
|
p_article != p_section[i]->p_page_first_article[j - 1]; |
| 334 |
|
p_article = p_article->p_prior) |
| 335 |
|
{ |
| 336 |
|
step++; |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
if (step != BBS_article_limit_per_page) |
| 340 |
|
{ |
| 341 |
|
printf("Incorrect page size %d at section %d page %d\n", step, i, j - 1); |
| 342 |
|
} |
| 343 |
|
} |
| 344 |
|
} |
| 345 |
|
} |
| 346 |
|
|
| 347 |
|
printf("Testing #4 ...\n"); |
| 348 |
|
|
| 349 |
|
for (i = 0; i < section_count; i++) |
| 350 |
|
{ |
| 351 |
|
step = i % 10 + 1; |
| 352 |
|
for (j = group_count; j < BBS_article_limit_per_section; j += step) |
| 353 |
|
{ |
| 354 |
|
last_aid = i * BBS_article_limit_per_section + j + 1; |
| 355 |
|
|
| 356 |
|
p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset); |
| 357 |
|
|
| 358 |
|
if (p_article == NULL) |
| 359 |
|
{ |
| 360 |
|
printf("Error find article %d in section %d offset %d\n", last_aid, i, j); |
| 361 |
|
break; |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
if (p_article->aid != last_aid) |
| 365 |
|
{ |
| 366 |
|
printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid); |
| 367 |
|
break; |
| 368 |
|
} |
| 369 |
|
|
| 370 |
|
if (section_list_set_article_visible(p_section[i], last_aid, 0) != 1) |
| 371 |
|
{ |
| 372 |
|
printf("Error set article %d invisible in section %d offset %d\n", last_aid, i, j); |
| 373 |
|
break; |
| 374 |
|
} |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
last_aid = p_section[i]->p_article_head->aid; |
| 378 |
|
if (section_list_calculate_page(p_section[i], last_aid) < 0) |
| 379 |
|
{ |
| 380 |
|
printf("section_list_calculate_page(aid = %d) error in section %d offset %d\n", last_aid, i, j); |
| 381 |
|
break; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
if (p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 385 |
|
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 386 |
|
p_section[i]->page_count) |
| 387 |
|
{ |
| 388 |
|
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
| 389 |
|
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 390 |
|
i, j, |
| 391 |
|
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 392 |
|
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0), |
| 393 |
|
p_section[i]->page_count, p_section[i]->visible_article_count, |
| 394 |
|
p_section[i]->last_page_visible_article_count); |
| 395 |
|
break; |
| 396 |
|
} |
| 397 |
|
|
| 398 |
|
affected_count = (BBS_article_limit_per_section - group_count) / step + ((BBS_article_limit_per_section - group_count) % step ? 1 : 0); |
| 399 |
|
if (p_section[i]->article_count - p_section[i]->visible_article_count != affected_count) |
| 400 |
|
{ |
| 401 |
|
printf("Inconsistent set invisible count in section %d, %d != %d\n", i, |
| 402 |
|
p_section[i]->article_count - p_section[i]->visible_article_count, |
| 403 |
|
affected_count); |
| 404 |
|
break; |
| 405 |
|
} |
| 406 |
|
|
| 407 |
|
article_count = p_section[i]->visible_article_count; |
| 408 |
|
|
| 409 |
|
for (j = 0; j < group_count; j += 1) |
| 410 |
|
{ |
| 411 |
|
last_aid = i * BBS_article_limit_per_section + j + 1; |
| 412 |
|
|
| 413 |
|
p_article = section_list_find_article_with_offset(p_section[i], last_aid, &page, &offset); |
| 414 |
|
|
| 415 |
|
if (p_article == NULL) |
| 416 |
|
{ |
| 417 |
|
printf("Error find article %d in section %d offset %d\n", last_aid, i, j); |
| 418 |
|
break; |
| 419 |
|
} |
| 420 |
|
|
| 421 |
|
if (p_article->aid != last_aid) |
| 422 |
|
{ |
| 423 |
|
printf("Inconsistent article aid in section %d page %d offset %d %d != %d\n", i, page, offset, p_article->aid, last_aid); |
| 424 |
|
break; |
| 425 |
|
} |
| 426 |
|
|
| 427 |
|
if (p_article->tid != 0) |
| 428 |
|
{ |
| 429 |
|
printf("Non-topic article aid in section %d page %d offset %d %d != 0\n", i, page, offset, p_article->tid); |
| 430 |
|
break; |
| 431 |
|
} |
| 432 |
|
|
| 433 |
|
if ((affected_count = section_list_set_article_visible(p_section[i], last_aid, 0)) <= 0) |
| 434 |
|
{ |
| 435 |
|
printf("Error set topic %d invisible in section %d offset %d\n", last_aid, i, j); |
| 436 |
|
break; |
| 437 |
|
} |
| 438 |
|
|
| 439 |
|
article_count -= affected_count; |
| 440 |
|
} |
| 441 |
|
|
| 442 |
|
if (article_count != 0) |
| 443 |
|
{ |
| 444 |
|
printf("Inconsistent total set invisible topic count in section %d, %d > 0\n", i, article_count); |
| 445 |
|
break; |
| 446 |
|
} |
| 447 |
|
|
| 448 |
|
if (p_section[i]->visible_article_count > 0) |
| 449 |
|
{ |
| 450 |
|
printf("Inconsistent invisible count in section %d, %d > 0\n", i, p_section[i]->visible_article_count); |
| 451 |
|
break; |
| 452 |
} |
} |
| 453 |
} |
} |
| 454 |
|
|