| 24 |
const char *sname[] = { |
const char *sname[] = { |
| 25 |
"Test", |
"Test", |
| 26 |
"ABCDEFG", |
"ABCDEFG", |
| 27 |
"_1234_" |
"_1234_"}; |
|
}; |
|
| 28 |
|
|
| 29 |
const char *stitle[] = { |
const char *stitle[] = { |
| 30 |
" Test Section ", |
" Test Section ", |
| 31 |
"字母组合ABC", |
"字母组合ABC", |
| 32 |
"_数字_123" |
"_数字_123"}; |
|
}; |
|
| 33 |
|
|
| 34 |
const char *master_name[] = { |
const char *master_name[] = { |
| 35 |
"sysadm", |
"sysadm", |
| 36 |
"SYSOP", |
"SYSOP", |
| 37 |
"" |
""}; |
|
}; |
|
| 38 |
|
|
| 39 |
int section_count = 3; |
int section_conf_count = 3; |
| 40 |
|
int section_count = BBS_max_section; |
| 41 |
|
|
| 42 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
| 43 |
{ |
{ |
| 44 |
SECTION_DATA *p_section[BBS_max_section]; |
SECTION_DATA *p_section[BBS_max_section]; |
| 45 |
|
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; |
| 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; |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
|
printf("Testing #1 ...\n"); |
| 74 |
|
|
| 75 |
last_aid = 0; |
last_aid = 0; |
| 76 |
|
|
| 77 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 78 |
{ |
{ |
| 79 |
if ((p_section[i] = section_data_create(sname[i], stitle[i], master_name[i])) == NULL) |
p_section[i] = section_data_create(sname[i % section_conf_count], |
| 80 |
|
stitle[i % section_conf_count], |
| 81 |
|
master_name[i % section_conf_count]); |
| 82 |
|
if (p_section[i] == NULL) |
| 83 |
{ |
{ |
| 84 |
log_error("section_data_create(i=%d) error\n", i); |
log_error("section_data_create(i=%d) error\n", i); |
| 85 |
return -3; |
return -3; |
| 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); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
last_aid = 0; |
| 113 |
|
|
| 114 |
|
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++) |
| 122 |
|
{ |
| 123 |
|
last_aid++; |
| 124 |
|
|
| 125 |
|
p_article = section_data_find_article_by_index(p_section[i], j); |
| 126 |
|
if (p_article == NULL || p_article->aid != last_aid) |
| 127 |
|
{ |
| 128 |
|
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); |
| 138 |
|
printf("Delete %d articles in section %d\n", p_section[i]->delete_count, i); |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
|
printf("Testing #2 ...\n"); |
| 142 |
|
|
| 143 |
|
group_count = 100; |
| 144 |
|
|
| 145 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 146 |
{ |
{ |
| 147 |
if (section_data_free_block(p_section[i]) != 0) |
if (section_data_free_block(p_section[i]) != 0) |
| 149 |
log_error("section_data_free_block(i=%d) error\n", i); |
log_error("section_data_free_block(i=%d) error\n", i); |
| 150 |
return -4; |
return -4; |
| 151 |
} |
} |
| 152 |
|
|
| 153 |
|
last_aid = 0; |
| 154 |
|
|
| 155 |
|
for (j = 0; j < BBS_article_limit_per_block * BBS_article_block_limit_per_section; j++) |
| 156 |
|
{ |
| 157 |
|
last_aid++; |
| 158 |
|
|
| 159 |
|
// Set article data |
| 160 |
|
article.aid = last_aid; |
| 161 |
|
article.cid = article.aid; |
| 162 |
|
article.tid = (article.aid <= group_count ? 0 : (article.aid - 1) % group_count + 1); // Group articles into group_count topics |
| 163 |
|
article.uid = 1; // TODO: randomize |
| 164 |
|
article.visible = 1; |
| 165 |
|
article.excerption = 0; |
| 166 |
|
article.ontop = 0; |
| 167 |
|
article.lock = 0; |
| 168 |
|
|
| 169 |
|
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); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
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++) |
| 187 |
|
{ |
| 188 |
|
p_article = section_data_find_article_by_index(p_section[i], j); |
| 189 |
|
if (p_article == NULL) |
| 190 |
|
{ |
| 191 |
|
printf("NULL p_article at index %d\n", j); |
| 192 |
|
break; |
| 193 |
|
} |
| 194 |
|
if (p_article->aid != j + 1) |
| 195 |
|
{ |
| 196 |
|
printf("Inconsistent aid at index %d != %d\n", j, j + 1); |
| 197 |
|
break; |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
article_count = 1; |
| 201 |
|
|
| 202 |
|
do |
| 203 |
|
{ |
| 204 |
|
if (p_article->next_aid <= p_article->aid && p_article->next_aid != p_article->tid) |
| 205 |
|
{ |
| 206 |
|
printf("Non-ascending aid found %d >= %d\n", p_article->aid, p_article->next_aid); |
| 207 |
|
break; |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
last_aid = p_article->next_aid; |
| 211 |
|
p_article = section_data_find_article_by_aid(p_section[i], last_aid); |
| 212 |
|
if (p_article == NULL) |
| 213 |
|
{ |
| 214 |
|
printf("NULL p_article at aid %d\n", last_aid); |
| 215 |
|
break; |
| 216 |
|
} |
| 217 |
|
if (p_article->tid == 0) // loop |
| 218 |
|
{ |
| 219 |
|
break; |
| 220 |
|
} |
| 221 |
|
if (p_article->tid != j + 1) |
| 222 |
|
{ |
| 223 |
|
printf("Inconsistent tid at aid %d != %d\n", last_aid, j + 1); |
| 224 |
|
break; |
| 225 |
|
} |
| 226 |
|
article_count++; |
| 227 |
|
} 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); |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
printf("Testing #3 ...\n"); |
| 240 |
|
|
| 241 |
|
for (i = 0; i < section_conf_count; i++) |
| 242 |
|
{ |
| 243 |
|
if (section_data_find_section_by_name(sname[i]) == NULL) |
| 244 |
|
{ |
| 245 |
|
printf("section_data_find_section_by_name(%s) error\n", sname[i]); |
| 246 |
|
} |
| 247 |
} |
} |
| 248 |
|
|
| 249 |
|
printf("Press ENTER to exit..."); |
| 250 |
|
getchar(); |
| 251 |
|
|
| 252 |
section_data_pool_cleanup(); |
section_data_pool_cleanup(); |
| 253 |
|
|
| 254 |
log_end(); |
log_end(); |