| 44 |
SECTION_DATA *p_section[BBS_max_section]; |
SECTION_DATA *p_section[BBS_max_section]; |
| 45 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 46 |
ARTICLE article; |
ARTICLE article; |
| 47 |
|
int block_count; |
| 48 |
int i, j; |
int i, j; |
| 49 |
int last_aid; |
int last_aid; |
| 50 |
int group_count; |
int group_count; |
| 51 |
|
int article_count; |
| 52 |
|
|
| 53 |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
| 54 |
{ |
{ |
| 59 |
log_std_redirect(STDOUT_FILENO); |
log_std_redirect(STDOUT_FILENO); |
| 60 |
log_err_redirect(STDERR_FILENO); |
log_err_redirect(STDERR_FILENO); |
| 61 |
|
|
| 62 |
if (section_data_pool_init("../conf/menu.conf", BBS_article_block_limit_per_section * BBS_max_section) < 0) |
// block_count = BBS_article_block_limit_per_section * BBS_max_section; // This statement is correct |
| 63 |
|
// - 1 to make blocks allocated is less than required |
| 64 |
|
// Some error will be triggered while invoking section_data_append_article() |
| 65 |
|
block_count = BBS_article_block_limit_per_section * BBS_max_section - 1; |
| 66 |
|
|
| 67 |
|
if (section_data_pool_init("../conf/menu.conf", block_count) < 0) |
| 68 |
{ |
{ |
| 69 |
log_error("section_data_pool_init() error\n"); |
log_error("section_data_pool_init() error\n"); |
| 70 |
return -2; |
return -2; |
| 99 |
article.ontop = 0; |
article.ontop = 0; |
| 100 |
article.lock = 0; |
article.lock = 0; |
| 101 |
|
|
| 102 |
section_data_append_article(p_section[i], &article); |
if (section_data_append_article(p_section[i], &article) < 0) |
| 103 |
|
{ |
| 104 |
|
printf("append article (aid = %d) error\n", article.aid); |
| 105 |
|
break; |
| 106 |
|
} |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
printf("Load %d articles into section %d\n", p_section[i]->article_count, i); |
printf("Load %d articles into section %d\n", p_section[i]->article_count, i); |
| 113 |
|
|
| 114 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 115 |
{ |
{ |
| 116 |
|
if (p_section[i]->article_count == 0) |
| 117 |
|
{ |
| 118 |
|
continue; |
| 119 |
|
} |
| 120 |
|
|
| 121 |
for (j = 0; j < p_section[i]->article_count; j++) |
for (j = 0; j < p_section[i]->article_count; j++) |
| 122 |
{ |
{ |
| 123 |
last_aid++; |
last_aid++; |
| 127 |
{ |
{ |
| 128 |
printf("Inconsistent aid at index %d != %d\n", j, last_aid); |
printf("Inconsistent aid at index %d != %d\n", j, last_aid); |
| 129 |
} |
} |
| 130 |
|
|
| 131 |
|
if (section_data_mark_del_article(p_section[i], p_article->aid) != 1) |
| 132 |
|
{ |
| 133 |
|
printf("section_data_mark_del_article(aid = %d) error\n", p_article->aid); |
| 134 |
|
} |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
printf("Verify %d articles in section %d\n", p_section[i]->article_count, i); |
printf("Verify %d articles in section %d\n", p_section[i]->article_count, i); |
| 138 |
|
printf("Delete %d articles in section %d\n", p_section[i]->delete_count, i); |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
printf("Testing #2 ...\n"); |
printf("Testing #2 ...\n"); |
| 166 |
article.ontop = 0; |
article.ontop = 0; |
| 167 |
article.lock = 0; |
article.lock = 0; |
| 168 |
|
|
| 169 |
section_data_append_article(p_section[i], &article); |
if (section_data_append_article(p_section[i], &article) < 0) |
| 170 |
|
{ |
| 171 |
|
printf("append article (aid = %d) error\n", article.aid); |
| 172 |
|
break; |
| 173 |
|
} |
| 174 |
} |
} |
| 175 |
|
|
| 176 |
printf("Load %d articles into section %d\n", p_section[i]->article_count, i); |
printf("Load %d articles into section %d\n", p_section[i]->article_count, i); |
| 178 |
|
|
| 179 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 180 |
{ |
{ |
| 181 |
|
if (p_section[i]->article_count == 0) |
| 182 |
|
{ |
| 183 |
|
continue; |
| 184 |
|
} |
| 185 |
|
|
| 186 |
for (j = 0; j < group_count; j++) |
for (j = 0; j < group_count; j++) |
| 187 |
{ |
{ |
| 188 |
p_article = section_data_find_article_by_index(p_section[i], j); |
p_article = section_data_find_article_by_index(p_section[i], j); |
| 197 |
break; |
break; |
| 198 |
} |
} |
| 199 |
|
|
| 200 |
|
article_count = 1; |
| 201 |
|
|
| 202 |
do |
do |
| 203 |
{ |
{ |
| 204 |
if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid) |
if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid) |
| 223 |
printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1); |
printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1); |
| 224 |
break; |
break; |
| 225 |
} |
} |
| 226 |
|
article_count++; |
| 227 |
} while (1); |
} while (1); |
| 228 |
|
|
| 229 |
|
if (article_count != p_section[i]->article_count / group_count) |
| 230 |
|
{ |
| 231 |
|
printf("Count of articles in topic %d is less than expected %d < %d\n", |
| 232 |
|
j + 1, article_count, p_section[i]->article_count / group_count); |
| 233 |
|
} |
| 234 |
} |
} |
| 235 |
|
|
| 236 |
printf("Verify %d topics in section %d\n", group_count, i); |
printf("Verify %d topics in section %d\n", group_count, i); |