| 41 |
|
|
| 42 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
| 43 |
{ |
{ |
| 44 |
SECTION_DATA *p_section[BBS_max_section]; |
SECTION_LIST *p_section[BBS_max_section]; |
| 45 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 46 |
ARTICLE article; |
ARTICLE article; |
| 47 |
int block_count; |
int block_count; |
| 48 |
int i, j; |
int i, j; |
| 49 |
int last_aid; |
int last_aid; |
| 50 |
|
int current_tid; |
| 51 |
|
int section_first_aid; |
| 52 |
int group_count; |
int group_count; |
| 53 |
int article_count; |
int article_count; |
| 54 |
|
|
| 61 |
log_std_redirect(STDOUT_FILENO); |
log_std_redirect(STDOUT_FILENO); |
| 62 |
log_err_redirect(STDERR_FILENO); |
log_err_redirect(STDERR_FILENO); |
| 63 |
|
|
| 64 |
// 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 |
| 65 |
// - 1 to make blocks allocated is less than required |
block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK - 1; |
|
// Some error will be triggered while invoking section_data_append_article() |
|
|
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) |
if (article_block_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; |
| 76 |
|
|
| 77 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 78 |
{ |
{ |
| 79 |
p_section[i] = section_data_create(sname[i % section_conf_count], |
p_section[i] = section_list_create(sname[i % section_conf_count], |
| 80 |
stitle[i % section_conf_count], |
stitle[i % section_conf_count], |
| 81 |
master_name[i % section_conf_count]); |
master_name[i % section_conf_count]); |
| 82 |
if (p_section[i] == NULL) |
if (p_section[i] == NULL) |
| 86 |
} |
} |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
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++) |
| 90 |
{ |
{ |
| 91 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 92 |
{ |
{ |
| 102 |
article.ontop = 0; |
article.ontop = 0; |
| 103 |
article.lock = 0; |
article.lock = 0; |
| 104 |
|
|
| 105 |
if (section_data_append_article(p_section[i], &article) < 0) |
if (section_list_append_article(p_section[i], &article) < 0) |
| 106 |
{ |
{ |
| 107 |
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); |
| 108 |
break; |
break; |
| 109 |
} |
} |
| 110 |
} |
} |
| 112 |
|
|
| 113 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 114 |
{ |
{ |
| 115 |
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); |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
|
last_aid = 0; |
| 119 |
|
|
| 120 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 121 |
{ |
{ |
| 122 |
if (p_section[i]->article_count == 0) |
if (p_section[i]->article_count == 0) |
| 124 |
continue; |
continue; |
| 125 |
} |
} |
| 126 |
|
|
|
last_aid = i + 1; |
|
|
|
|
| 127 |
for (j = 0; j < p_section[i]->article_count; j++) |
for (j = 0; j < p_section[i]->article_count; j++) |
| 128 |
{ |
{ |
| 129 |
p_article = section_data_find_article_by_index(p_section[i], j); |
last_aid++; |
| 130 |
|
|
| 131 |
|
p_article = article_block_find_by_aid(last_aid); |
| 132 |
if (p_article == NULL || p_article->aid != last_aid) |
if (p_article == NULL || p_article->aid != last_aid) |
| 133 |
{ |
{ |
| 134 |
printf("Inconsistent aid at section %d index %d != %d\n", i, j, last_aid); |
printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid); |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
if (section_data_mark_del_article(p_section[i], p_article->aid) != 1) |
p_article = article_block_find_by_index(last_aid - 1); |
| 138 |
|
if (p_article == NULL || p_article->aid != last_aid) |
| 139 |
{ |
{ |
| 140 |
printf("section_data_mark_del_article(aid = %d) error\n", p_article->aid); |
printf("article_block_find_by_index() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid); |
| 141 |
} |
} |
| 142 |
|
|
| 143 |
last_aid += section_count; |
if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1) |
| 144 |
|
{ |
| 145 |
|
printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid); |
| 146 |
|
} |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
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); |
|
| 150 |
} |
} |
| 151 |
|
|
| 152 |
printf("Testing #2 ...\n"); |
printf("Testing #2 ...\n"); |
| 153 |
|
|
| 154 |
group_count = 100; |
if (article_block_reset() != 0) |
| 155 |
|
{ |
| 156 |
|
log_error("section_data_free_block(i=%d) error\n", i); |
| 157 |
|
return -4; |
| 158 |
|
} |
| 159 |
|
|
| 160 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 161 |
{ |
{ |
| 162 |
if (section_data_free_block(p_section[i]) != 0) |
section_list_reset_articles(p_section[i]); |
| 163 |
{ |
} |
|
log_error("section_data_free_block(i=%d) error\n", i); |
|
|
return -4; |
|
|
} |
|
| 164 |
|
|
| 165 |
last_aid = 0; |
group_count = 100; |
| 166 |
|
last_aid = 0; |
| 167 |
|
|
| 168 |
for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++) |
for (i = 0; i < section_count; i++) |
| 169 |
|
{ |
| 170 |
|
section_first_aid = last_aid + 1; |
| 171 |
|
|
| 172 |
|
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 173 |
{ |
{ |
| 174 |
last_aid++; |
last_aid++; |
| 175 |
|
|
| 176 |
// Set article data |
// Set article data |
| 177 |
article.aid = last_aid; |
article.aid = last_aid; |
| 178 |
article.cid = article.aid; |
article.cid = article.aid; |
| 179 |
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 |
| 180 |
article.uid = 1; // TODO: randomize |
article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count)); |
| 181 |
|
article.uid = 1; // TODO: randomize |
| 182 |
article.visible = 1; |
article.visible = 1; |
| 183 |
article.excerption = 0; |
article.excerption = 0; |
| 184 |
article.ontop = 0; |
article.ontop = 0; |
| 185 |
article.lock = 0; |
article.lock = 0; |
| 186 |
|
|
| 187 |
if (section_data_append_article(p_section[i], &article) < 0) |
if (section_list_append_article(p_section[i], &article) < 0) |
| 188 |
{ |
{ |
| 189 |
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); |
| 190 |
break; |
break; |
| 191 |
} |
} |
| 192 |
} |
} |
| 193 |
|
|
| 194 |
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); |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 212 |
|
|
| 213 |
if (p_article->aid <= last_aid) |
if (p_article->aid <= last_aid) |
| 214 |
{ |
{ |
| 215 |
printf("Non-ascending aid found %d <= %d\n", p_article->aid, last_aid); |
printf("Non-ascending aid found %d <= %d at article\n", p_article->aid, last_aid); |
| 216 |
} |
} |
| 217 |
last_aid = p_article->aid; |
last_aid = p_article->aid; |
| 218 |
|
|
| 223 |
{ |
{ |
| 224 |
printf("Count of articles in section %d is different from expected %d != %d\n", |
printf("Count of articles in section %d is different from expected %d != %d\n", |
| 225 |
i, article_count, p_section[i]->article_count); |
i, article_count, p_section[i]->article_count); |
| 226 |
|
break; |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
printf("Verify %d articles in section %d\n", group_count, i); |
// printf("Verified %d articles in section %d\n", group_count, i); |
| 230 |
} |
} |
| 231 |
|
|
| 232 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 238 |
|
|
| 239 |
for (j = 0; j < group_count; j++) |
for (j = 0; j < group_count; j++) |
| 240 |
{ |
{ |
| 241 |
p_article = section_data_find_article_by_index(p_section[i], j); |
last_aid = p_section[i]->p_article_head->aid + j; |
| 242 |
|
|
| 243 |
|
p_article = article_block_find_by_aid(last_aid); |
| 244 |
if (p_article == NULL) |
if (p_article == NULL) |
| 245 |
{ |
{ |
| 246 |
printf("NULL p_article at index %d\n", j); |
printf("NULL p_article at section %d index %d\n", i, j); |
| 247 |
break; |
break; |
| 248 |
} |
} |
| 249 |
if (p_article->aid != j + 1) |
if (p_article->aid != last_aid) |
| 250 |
{ |
{ |
| 251 |
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); |
| 252 |
break; |
break; |
| 253 |
} |
} |
| 254 |
|
|
| 255 |
article_count = 1; |
article_count = 1; |
| 256 |
last_aid = 0; |
last_aid = 0; |
| 257 |
|
current_tid = p_article->aid; |
| 258 |
|
|
| 259 |
do |
do |
| 260 |
{ |
{ |
| 275 |
{ |
{ |
| 276 |
break; |
break; |
| 277 |
} |
} |
| 278 |
if (p_article->tid != j + 1) |
if (p_article->tid != current_tid) |
| 279 |
{ |
{ |
| 280 |
printf("Inconsistent tid %d != %d\n", last_aid, j + 1); |
printf("Inconsistent tid %d != %d\n", p_article->tid, current_tid); |
| 281 |
break; |
break; |
| 282 |
} |
} |
| 283 |
|
|
| 286 |
|
|
| 287 |
if (article_count != p_section[i]->article_count / group_count) |
if (article_count != p_section[i]->article_count / group_count) |
| 288 |
{ |
{ |
| 289 |
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", |
| 290 |
j + 1, article_count, p_section[i]->article_count / group_count); |
j + 1, article_count, p_section[i]->article_count / group_count); |
| 291 |
|
break; |
| 292 |
} |
} |
| 293 |
} |
} |
| 294 |
|
|
| 295 |
printf("Verify %d topics in section %d\n", group_count, i); |
// printf("Verified %d topics in section %d\n", group_count, i); |
| 296 |
} |
} |
| 297 |
|
|
| 298 |
printf("Testing #3 ...\n"); |
printf("Testing #3 ...\n"); |
| 299 |
|
|
| 300 |
for (i = 0; i < section_conf_count; i++) |
for (i = 0; i < section_conf_count; i++) |
| 301 |
{ |
{ |
| 302 |
if (section_data_find_section_by_name(sname[i]) == NULL) |
if (section_list_find_by_name(sname[i]) == NULL) |
| 303 |
{ |
{ |
| 304 |
printf("section_data_find_section_by_name(%s) error\n", sname[i]); |
printf("section_data_find_section_by_name(%s) error\n", sname[i]); |
| 305 |
} |
} |
| 308 |
printf("Press ENTER to exit..."); |
printf("Press ENTER to exit..."); |
| 309 |
getchar(); |
getchar(); |
| 310 |
|
|
| 311 |
section_data_pool_cleanup(); |
article_block_cleanup(); |
| 312 |
|
|
| 313 |
log_end(); |
log_end(); |
| 314 |
|
|