• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂445 (tree)
時間2012-04-18 01:50:51
作者ornse01

Log Message

add test and fix bug.
- number count mistake.
- delete condition mistake.

Change Summary

差異

--- bchanl/trunk/src/test_extbbslist.c (revision 444)
+++ bchanl/trunk/src/test_extbbslist.c (revision 445)
@@ -168,7 +168,102 @@
168168 return result;
169169 }
170170
171+LOCAL UNITTEST_RESULT test_extbbslist_2()
172+{
173+ extbbslist_t *list;
174+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
175+ TC *title;
176+ UB *url;
177+ W err, title_len, url_len, num;
178+
179+ list = extbbslist_new(NULL, 0, 0);
180+
181+ num = extbbslist_number(list);
182+ if (num != 0) {
183+ printf("extbbslist_number 000\n");
184+ result = UNITTEST_RESULT_FAIL;
185+ }
186+
187+ title = test_extbbslist_testtitle001;
188+ title_len = tc_strlen(title);
189+ url = test_extbbslist_testurl001;
190+ url_len = strlen(url);
191+ err = extbbslist_appenditem(list, title, title_len, url, url_len);
192+ if (err < 0) {
193+ printf("extbbslist_appenditem 001\n");
194+ result = UNITTEST_RESULT_FAIL;
195+ }
196+ num = extbbslist_number(list);
197+ if (num != 1) {
198+ printf("extbbslist_number 001\n");
199+ result = UNITTEST_RESULT_FAIL;
200+ }
201+
202+ title = test_extbbslist_testtitle002;
203+ title_len = tc_strlen(title);
204+ url = test_extbbslist_testurl002;
205+ url_len = strlen(url);
206+ err = extbbslist_appenditem(list, title, title_len, url, url_len);
207+ if (err < 0) {
208+ printf("extbbslist_appenditem 002\n");
209+ result = UNITTEST_RESULT_FAIL;
210+ }
211+ num = extbbslist_number(list);
212+ if (num != 2) {
213+ printf("extbbslist_number 002\n");
214+ result = UNITTEST_RESULT_FAIL;
215+ }
216+
217+ title = test_extbbslist_testtitle003;
218+ title_len = tc_strlen(title);
219+ url = test_extbbslist_testurl003;
220+ url_len = strlen(url);
221+ err = extbbslist_appenditem(list, title, title_len, url, url_len);
222+ if (err < 0) {
223+ printf("extbbslist_appenditem 003\n");
224+ result = UNITTEST_RESULT_FAIL;
225+ }
226+ num = extbbslist_number(list);
227+ if (num != 3) {
228+ printf("extbbslist_number 003\n");
229+ result = UNITTEST_RESULT_FAIL;
230+ }
231+
232+ title = test_extbbslist_testtitle004;
233+ title_len = tc_strlen(title);
234+ url = test_extbbslist_testurl004;
235+ url_len = strlen(url);
236+ err = extbbslist_appenditem(list, title, title_len, url, url_len);
237+ if (err < 0) {
238+ printf("extbbslist_appenditem 004\n");
239+ result = UNITTEST_RESULT_FAIL;
240+ }
241+ num = extbbslist_number(list);
242+ if (num != 4) {
243+ printf("extbbslist_number 004\n");
244+ result = UNITTEST_RESULT_FAIL;
245+ }
246+
247+ title = test_extbbslist_testtitle002;
248+ title_len = tc_strlen(title);
249+ err = extbbslist_deleteitem(list, title, title_len);
250+ if (err < 0) {
251+ printf("extbbslist_deleteitem 002\n");
252+ result = UNITTEST_RESULT_FAIL;
253+ }
254+ num = extbbslist_number(list);
255+ if (num != 3) {
256+ printf("extbbslist_number 002\n");
257+ result = UNITTEST_RESULT_FAIL;
258+ }
259+
260+ extbbslist_delete(list);
261+
262+ return result;
263+}
264+
171265 EXPORT VOID test_extbbslist_main(unittest_driver_t *driver)
172266 {
173267 UNITTEST_DRIVER_REGIST(driver, test_extbbslist_1);
268+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_2);
174269 }
--- bchanl/trunk/src/extbbslist.c (revision 444)
+++ bchanl/trunk/src/extbbslist.c (revision 445)
@@ -243,6 +243,7 @@
243243
244244 senti = extbbslist_sentinelnode(list);
245245 extbbslist_item_QueInsert(item, senti);
246+ list->num++;
246247
247248 return 0;
248249 }
@@ -256,11 +257,12 @@
256257 }
257258
258259 item = extbbslist_searchitem(list, title, title_len);
259- if (item != NULL) {
260+ if (item == NULL) {
260261 return -1; /* TODO */
261262 }
262263
263264 extbbslist_item_delete(item);
265+ list->num--;
264266
265267 return 0; /* TODO */
266268 }
Show on old repository browser