• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂455 (tree)
時間2012-05-01 02:28:21
作者ornse01

Log Message

add tests and fix bugs
- fix index handling in swap
- fix selected index in editing
- fix counting number in editing

Change Summary

差異

--- bchanl/trunk/src/test_extbbslist.c (revision 454)
+++ bchanl/trunk/src/test_extbbslist.c (revision 455)
@@ -44,16 +44,127 @@
4444 LOCAL UB test_extbbslist_testurl002[] = "http://ddd.eee.fff/abcdef/";
4545 LOCAL UB test_extbbslist_testurl003[] = "http://aaa.bbb.ccc/ghijkl/";
4646 LOCAL UB test_extbbslist_testurl004[] = "http://aaa.bbb.ccc/mnopqr/";
47+LOCAL UB test_extbbslist_testurl005[] = "http://a/a/";
48+LOCAL UB test_extbbslist_testurl006[] = "http://b/a/";
49+LOCAL UB test_extbbslist_testurl007[] = "http://c/a/";
50+LOCAL UB test_extbbslist_testurl008[] = "http://d/a/";
51+LOCAL TC test_extbbslist_testTCurl005[] = {TK_h, TK_t, TK_t, TK_p, TK_COLN, TK_SLSH, TK_SLSH, TK_a, TK_SLSH, TK_a, TK_SLSH, TNULL};
52+LOCAL TC test_extbbslist_testTCurl006[] = {TK_h, TK_t, TK_t, TK_p, TK_COLN, TK_SLSH, TK_SLSH, TK_b, TK_SLSH, TK_a, TK_SLSH, TNULL};
53+LOCAL TC test_extbbslist_testTCurl007[] = {TK_h, TK_t, TK_t, TK_p, TK_COLN, TK_SLSH, TK_SLSH, TK_c, TK_SLSH, TK_a, TK_SLSH, TNULL};
54+LOCAL TC test_extbbslist_testTCurl008[] = {TK_h, TK_t, TK_t, TK_p, TK_COLN, TK_SLSH, TK_SLSH, TK_d, TK_SLSH, TK_a, TK_SLSH, TNULL};
4755
56+struct testextbbslist_input_t_ {
57+ TC *title;
58+ W title_len;
59+ TC *url;
60+ W url_len;
61+};
62+typedef struct testextbbslist_input_t_ testextbbslist_input_t;
63+
64+struct testextbbslist_expected_t_ {
65+ TC *title;
66+ W title_len;
67+ UB *url;
68+ W url_len;
69+};
70+typedef struct testextbbslist_expected_t_ testextbbslist_expected_t;
71+
72+LOCAL W test_extbbslist_appenditem(extbbslist_editcontext_t *ctx, testextbbslist_input_t *input, W input_len)
73+{
74+ W i, err, title_len, url_len;
75+ TC *title, *url;
76+
77+ for (i = 0; i < input_len; i++) {
78+ title = input[i].title;
79+ title_len = input[i].title_len;
80+ url = input[i].url;
81+ url_len = input[i].url_len;
82+ err = extbbslist_editcontext_append(ctx, title, title_len, url, url_len);
83+ if (err < 0) {
84+ printf("extbbslist_editcontext_appenditem %d\n", i);
85+ return err;
86+ }
87+ }
88+
89+ return 0;
90+}
91+
92+LOCAL W test_extbbslist_checkexpected(extbbslist_t *list, testextbbslist_expected_t *expected, W expected_len)
93+{
94+ W ret = 0, i, title_len, url_len;
95+ TC *title;
96+ UB *url;
97+ Bool cont;
98+ extbbslist_readcontext_t *ctx;
99+
100+ ctx = extbbslist_startread(list);
101+ if (ctx == NULL) {
102+ printf("extbbslist_startread\n");
103+ return -1;
104+ }
105+
106+ for (i = 0; i < expected_len; i++) {
107+ cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
108+ if (cont == False) {
109+ printf("extbbslist_readcontext_getnext return value %d\n", i);
110+ ret = -1;
111+ }
112+ if (tc_strncmp(title, expected[i].title, title_len) != 0) {
113+ printf("extbbslist_readcontext_getnext title %d\n", i);
114+ ret = -1;
115+ }
116+ if (strncmp(url, expected[i].url, url_len) != 0) {
117+ printf("extbbslist_readcontext_getnext url %d\n", i);
118+ printf(" expected = %s\n", expected[i].url);
119+ printf(" result = %s\n", url);
120+ ret = -1;
121+ }
122+ }
123+ cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
124+ if (cont != False) {
125+ printf("extbbslist_readcontext_getnext return value last\n");
126+ ret = -1;
127+ }
128+
129+ extbbslist_endread(list, ctx);
130+
131+ return ret;
132+}
133+
48134 LOCAL UNITTEST_RESULT test_extbbslist_1()
49135 {
50136 extbbslist_t *list;
51- extbbslist_readcontext_t *ctx;
52137 UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
53138 TC *title;
54139 UB *url;
55140 W err, title_len, url_len;
56- Bool cont;
141+ testextbbslist_expected_t expected[] = {
142+ {
143+ test_extbbslist_testtitle001,
144+ tc_strlen(test_extbbslist_testtitle001),
145+ test_extbbslist_testurl001,
146+ strlen(test_extbbslist_testurl001)
147+ },
148+ {
149+ test_extbbslist_testtitle002,
150+ tc_strlen(test_extbbslist_testtitle002),
151+ test_extbbslist_testurl002,
152+ strlen(test_extbbslist_testurl002)
153+ },
154+ {
155+ test_extbbslist_testtitle003,
156+ tc_strlen(test_extbbslist_testtitle003),
157+ test_extbbslist_testurl003,
158+ strlen(test_extbbslist_testurl003)
159+ },
160+ {
161+ test_extbbslist_testtitle004,
162+ tc_strlen(test_extbbslist_testtitle004),
163+ test_extbbslist_testurl004,
164+ strlen(test_extbbslist_testurl004)
165+ },
166+ };
167+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
57168
58169 list = extbbslist_new(NULL, 0, 0);
59170
@@ -94,75 +205,11 @@
94205 result = UNITTEST_RESULT_FAIL;
95206 }
96207
97- ctx = extbbslist_startread(list);
98- if (ctx == NULL) {
99- printf("extbbslist_startread\n");
100- extbbslist_delete(list);
101- return UNITTEST_RESULT_FAIL;
102- }
103-
104- cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
105- if (cont == False) {
106- printf("extbbslist_readcontext_getnext return value 001\n");
208+ err = test_extbbslist_checkexpected(list, expected, expected_len);
209+ if (err < 0) {
107210 result = UNITTEST_RESULT_FAIL;
108211 }
109- if (tc_strncmp(title, test_extbbslist_testtitle001, title_len) != 0) {
110- printf("extbbslist_readcontext_getnext title 001\n");
111- result = UNITTEST_RESULT_FAIL;
112- }
113- if (strncmp(url, test_extbbslist_testurl001, url_len) != 0) {
114- printf("extbbslist_readcontext_getnext url 001\n");
115- printf(" expected = %s\n", test_extbbslist_testurl001);
116- printf(" result = %s\n", url);
117- result = UNITTEST_RESULT_FAIL;
118- }
119- cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
120- if (cont == False) {
121- printf("extbbslist_readcontext_getnext return value 002\n");
122- result = UNITTEST_RESULT_FAIL;
123- }
124- if (tc_strncmp(title, test_extbbslist_testtitle002, title_len) != 0) {
125- printf("extbbslist_readcontext_getnext title 002\n");
126- result = UNITTEST_RESULT_FAIL;
127- }
128- if (strncmp(url, test_extbbslist_testurl002, url_len) != 0) {
129- printf("extbbslist_readcontext_getnext url 002\n");
130- result = UNITTEST_RESULT_FAIL;
131- }
132- cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
133- if (cont == False) {
134- printf("extbbslist_readcontext_getnext return value 003\n");
135- result = UNITTEST_RESULT_FAIL;
136- }
137- if (tc_strncmp(title, test_extbbslist_testtitle003, title_len) != 0) {
138- printf("extbbslist_readcontext_getnext title 003\n");
139- result = UNITTEST_RESULT_FAIL;
140- }
141- if (strncmp(url, test_extbbslist_testurl003, url_len) != 0) {
142- printf("extbbslist_readcontext_getnext url 003\n");
143- result = UNITTEST_RESULT_FAIL;
144- }
145- cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
146- if (cont == False) {
147- printf("extbbslist_readcontext_getnext return value 004\n");
148- result = UNITTEST_RESULT_FAIL;
149- }
150- if (tc_strncmp(title, test_extbbslist_testtitle004, title_len) != 0) {
151- printf("extbbslist_readcontext_getnext title 004\n");
152- result = UNITTEST_RESULT_FAIL;
153- }
154- if (strncmp(url, test_extbbslist_testurl004, url_len) != 0) {
155- printf("extbbslist_readcontext_getnext url 004\n");
156- result = UNITTEST_RESULT_FAIL;
157- }
158- cont = extbbslist_readcontext_getnext(ctx, &title, &title_len, &url, &url_len);
159- if (cont != False) {
160- printf("extbbslist_readcontext_getnext return value 005\n");
161- result = UNITTEST_RESULT_FAIL;
162- }
163212
164- extbbslist_endread(list, ctx);
165-
166213 extbbslist_delete(list);
167214
168215 return result;
@@ -262,8 +309,1108 @@
262309 return result;
263310 }
264311
312+LOCAL UNITTEST_RESULT test_extbbslist_3()
313+{
314+ extbbslist_t *list;
315+ extbbslist_editcontext_t *editctx;
316+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
317+ W err;
318+ testextbbslist_input_t input[] = {
319+ {
320+ test_extbbslist_testtitle001,
321+ tc_strlen(test_extbbslist_testtitle001),
322+ test_extbbslist_testTCurl005,
323+ tc_strlen(test_extbbslist_testTCurl005),
324+ },
325+ {
326+ test_extbbslist_testtitle002,
327+ tc_strlen(test_extbbslist_testtitle002),
328+ test_extbbslist_testTCurl006,
329+ tc_strlen(test_extbbslist_testTCurl006),
330+ },
331+ {
332+ test_extbbslist_testtitle003,
333+ tc_strlen(test_extbbslist_testtitle003),
334+ test_extbbslist_testTCurl007,
335+ tc_strlen(test_extbbslist_testTCurl007),
336+ },
337+ {
338+ test_extbbslist_testtitle004,
339+ tc_strlen(test_extbbslist_testtitle004),
340+ test_extbbslist_testTCurl008,
341+ tc_strlen(test_extbbslist_testTCurl008),
342+ },
343+ };
344+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
345+ testextbbslist_expected_t expected[] = {
346+ {
347+ test_extbbslist_testtitle001,
348+ tc_strlen(test_extbbslist_testtitle001),
349+ test_extbbslist_testurl005,
350+ strlen(test_extbbslist_testurl005)
351+ },
352+ {
353+ test_extbbslist_testtitle002,
354+ tc_strlen(test_extbbslist_testtitle002),
355+ test_extbbslist_testurl006,
356+ strlen(test_extbbslist_testurl006)
357+ },
358+ {
359+ test_extbbslist_testtitle003,
360+ tc_strlen(test_extbbslist_testtitle003),
361+ test_extbbslist_testurl007,
362+ strlen(test_extbbslist_testurl007)
363+ },
364+ {
365+ test_extbbslist_testtitle004,
366+ tc_strlen(test_extbbslist_testtitle004),
367+ test_extbbslist_testurl008,
368+ strlen(test_extbbslist_testurl008)
369+ },
370+ };
371+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
372+
373+ list = extbbslist_new(NULL, 0, 0);
374+
375+ editctx = extbbslist_startedit(list);
376+ if (editctx == NULL) {
377+ printf("extbbslist_startedit\n");
378+ extbbslist_delete(list);
379+ return UNITTEST_RESULT_FAIL;
380+ }
381+ err = test_extbbslist_appenditem(editctx, input, input_len);
382+ if (err < 0) {
383+ result = UNITTEST_RESULT_FAIL;
384+ }
385+ extbbslist_endedit(list, editctx, True);
386+
387+ err = test_extbbslist_checkexpected(list, expected, expected_len);
388+ if (err < 0) {
389+ result = UNITTEST_RESULT_FAIL;
390+ }
391+
392+ extbbslist_delete(list);
393+
394+ return result;
395+}
396+
397+LOCAL UNITTEST_RESULT test_extbbslist_4()
398+{
399+ extbbslist_t *list;
400+ extbbslist_editcontext_t *editctx;
401+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
402+ W err;
403+ testextbbslist_input_t input[] = {
404+ {
405+ test_extbbslist_testtitle001,
406+ tc_strlen(test_extbbslist_testtitle001),
407+ test_extbbslist_testTCurl005,
408+ tc_strlen(test_extbbslist_testTCurl005),
409+ },
410+ {
411+ test_extbbslist_testtitle002,
412+ tc_strlen(test_extbbslist_testtitle002),
413+ test_extbbslist_testTCurl006,
414+ tc_strlen(test_extbbslist_testTCurl006),
415+ },
416+ {
417+ test_extbbslist_testtitle003,
418+ tc_strlen(test_extbbslist_testtitle003),
419+ test_extbbslist_testTCurl007,
420+ tc_strlen(test_extbbslist_testTCurl007),
421+ },
422+ {
423+ test_extbbslist_testtitle004,
424+ tc_strlen(test_extbbslist_testtitle004),
425+ test_extbbslist_testTCurl008,
426+ tc_strlen(test_extbbslist_testTCurl008),
427+ },
428+ };
429+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
430+
431+ list = extbbslist_new(NULL, 0, 0);
432+
433+ editctx = extbbslist_startedit(list);
434+ if (editctx == NULL) {
435+ printf("extbbslist_startedit\n");
436+ extbbslist_delete(list);
437+ return UNITTEST_RESULT_FAIL;
438+ }
439+ err = test_extbbslist_appenditem(editctx, input, input_len);
440+ if (err < 0) {
441+ result = UNITTEST_RESULT_FAIL;
442+ }
443+ extbbslist_endedit(list, editctx, False);
444+
445+ err = test_extbbslist_checkexpected(list, NULL, 0);
446+ if (err < 0) {
447+ result = UNITTEST_RESULT_FAIL;
448+ }
449+
450+ extbbslist_delete(list);
451+
452+ return result;
453+}
454+
455+LOCAL UNITTEST_RESULT test_extbbslist_5()
456+{
457+ extbbslist_t *list;
458+ extbbslist_editcontext_t *editctx;
459+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
460+ W err, num;
461+ testextbbslist_input_t input[] = {
462+ {
463+ test_extbbslist_testtitle001,
464+ tc_strlen(test_extbbslist_testtitle001),
465+ test_extbbslist_testTCurl005,
466+ tc_strlen(test_extbbslist_testTCurl005),
467+ },
468+ {
469+ test_extbbslist_testtitle002,
470+ tc_strlen(test_extbbslist_testtitle002),
471+ test_extbbslist_testTCurl006,
472+ tc_strlen(test_extbbslist_testTCurl006),
473+ },
474+ {
475+ test_extbbslist_testtitle003,
476+ tc_strlen(test_extbbslist_testtitle003),
477+ test_extbbslist_testTCurl007,
478+ tc_strlen(test_extbbslist_testTCurl007),
479+ },
480+ {
481+ test_extbbslist_testtitle004,
482+ tc_strlen(test_extbbslist_testtitle004),
483+ test_extbbslist_testTCurl008,
484+ tc_strlen(test_extbbslist_testTCurl008),
485+ },
486+ };
487+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
488+
489+ list = extbbslist_new(NULL, 0, 0);
490+
491+ editctx = extbbslist_startedit(list);
492+ if (editctx == NULL) {
493+ printf("extbbslist_startedit\n");
494+ extbbslist_delete(list);
495+ return UNITTEST_RESULT_FAIL;
496+ }
497+ err = test_extbbslist_appenditem(editctx, input, input_len);
498+ if (err < 0) {
499+ result = UNITTEST_RESULT_FAIL;
500+ }
501+ extbbslist_endedit(list, editctx, True);
502+
503+ num = extbbslist_number(list);
504+ if (num != 4) {
505+ printf("extbbslist_number 002\n");
506+ result = UNITTEST_RESULT_FAIL;
507+ }
508+
509+ extbbslist_delete(list);
510+
511+ return result;
512+}
513+
514+LOCAL UNITTEST_RESULT test_extbbslist_6()
515+{
516+ extbbslist_t *list;
517+ extbbslist_editcontext_t *editctx;
518+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
519+ W err, num;
520+ testextbbslist_input_t input[] = {
521+ {
522+ test_extbbslist_testtitle001,
523+ tc_strlen(test_extbbslist_testtitle001),
524+ test_extbbslist_testTCurl005,
525+ tc_strlen(test_extbbslist_testTCurl005),
526+ },
527+ {
528+ test_extbbslist_testtitle002,
529+ tc_strlen(test_extbbslist_testtitle002),
530+ test_extbbslist_testTCurl006,
531+ tc_strlen(test_extbbslist_testTCurl006),
532+ },
533+ {
534+ test_extbbslist_testtitle003,
535+ tc_strlen(test_extbbslist_testtitle003),
536+ test_extbbslist_testTCurl007,
537+ tc_strlen(test_extbbslist_testTCurl007),
538+ },
539+ {
540+ test_extbbslist_testtitle004,
541+ tc_strlen(test_extbbslist_testtitle004),
542+ test_extbbslist_testTCurl008,
543+ tc_strlen(test_extbbslist_testTCurl008),
544+ },
545+ };
546+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
547+
548+ list = extbbslist_new(NULL, 0, 0);
549+
550+
551+ editctx = extbbslist_startedit(list);
552+ if (editctx == NULL) {
553+ printf("extbbslist_startedit\n");
554+ extbbslist_delete(list);
555+ return UNITTEST_RESULT_FAIL;
556+ }
557+ err = test_extbbslist_appenditem(editctx, input, input_len);
558+ if (err < 0) {
559+ result = UNITTEST_RESULT_FAIL;
560+ }
561+ extbbslist_endedit(list, editctx, False);
562+
563+ num = extbbslist_number(list);
564+ if (num != 0) {
565+ printf("extbbslist_number 002\n");
566+ result = UNITTEST_RESULT_FAIL;
567+ }
568+
569+ extbbslist_delete(list);
570+
571+ return result;
572+}
573+
574+LOCAL UNITTEST_RESULT test_extbbslist_7()
575+{
576+ extbbslist_t *list;
577+ extbbslist_editcontext_t *editctx;
578+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
579+ W err;
580+ testextbbslist_input_t input[] = {
581+ {
582+ test_extbbslist_testtitle001,
583+ tc_strlen(test_extbbslist_testtitle001),
584+ test_extbbslist_testTCurl005,
585+ tc_strlen(test_extbbslist_testTCurl005),
586+ },
587+ {
588+ test_extbbslist_testtitle002,
589+ tc_strlen(test_extbbslist_testtitle002),
590+ test_extbbslist_testTCurl006,
591+ tc_strlen(test_extbbslist_testTCurl006),
592+ },
593+ {
594+ test_extbbslist_testtitle003,
595+ tc_strlen(test_extbbslist_testtitle003),
596+ test_extbbslist_testTCurl007,
597+ tc_strlen(test_extbbslist_testTCurl007),
598+ },
599+ {
600+ test_extbbslist_testtitle004,
601+ tc_strlen(test_extbbslist_testtitle004),
602+ test_extbbslist_testTCurl008,
603+ tc_strlen(test_extbbslist_testTCurl008),
604+ },
605+ };
606+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
607+ testextbbslist_expected_t expected[] = {
608+ {
609+ test_extbbslist_testtitle001,
610+ tc_strlen(test_extbbslist_testtitle001),
611+ test_extbbslist_testurl005,
612+ strlen(test_extbbslist_testurl005)
613+ },
614+ {
615+ test_extbbslist_testtitle002,
616+ tc_strlen(test_extbbslist_testtitle002),
617+ test_extbbslist_testurl006,
618+ strlen(test_extbbslist_testurl006)
619+ },
620+ {
621+ test_extbbslist_testtitle004,
622+ tc_strlen(test_extbbslist_testtitle004),
623+ test_extbbslist_testurl008,
624+ strlen(test_extbbslist_testurl008)
625+ },
626+ };
627+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
628+
629+ list = extbbslist_new(NULL, 0, 0);
630+
631+ editctx = extbbslist_startedit(list);
632+ if (editctx == NULL) {
633+ printf("extbbslist_startedit\n");
634+ extbbslist_delete(list);
635+ return UNITTEST_RESULT_FAIL;
636+ }
637+ err = test_extbbslist_appenditem(editctx, input, input_len);
638+ if (err < 0) {
639+ result = UNITTEST_RESULT_FAIL;
640+ }
641+ extbbslist_editcontext_deleteitem(editctx, 2);
642+ extbbslist_endedit(list, editctx, True);
643+
644+ err = test_extbbslist_checkexpected(list, expected, expected_len);
645+ if (err < 0) {
646+ result = UNITTEST_RESULT_FAIL;
647+ }
648+
649+ extbbslist_delete(list);
650+
651+ return result;
652+}
653+
654+LOCAL UNITTEST_RESULT test_extbbslist_8()
655+{
656+ extbbslist_t *list;
657+ extbbslist_editcontext_t *editctx;
658+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
659+ W err, num;
660+ testextbbslist_input_t input[] = {
661+ {
662+ test_extbbslist_testtitle001,
663+ tc_strlen(test_extbbslist_testtitle001),
664+ test_extbbslist_testTCurl005,
665+ tc_strlen(test_extbbslist_testTCurl005),
666+ },
667+ {
668+ test_extbbslist_testtitle002,
669+ tc_strlen(test_extbbslist_testtitle002),
670+ test_extbbslist_testTCurl006,
671+ tc_strlen(test_extbbslist_testTCurl006),
672+ },
673+ {
674+ test_extbbslist_testtitle003,
675+ tc_strlen(test_extbbslist_testtitle003),
676+ test_extbbslist_testTCurl007,
677+ tc_strlen(test_extbbslist_testTCurl007),
678+ },
679+ {
680+ test_extbbslist_testtitle004,
681+ tc_strlen(test_extbbslist_testtitle004),
682+ test_extbbslist_testTCurl008,
683+ tc_strlen(test_extbbslist_testTCurl008),
684+ },
685+ };
686+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
687+
688+ list = extbbslist_new(NULL, 0, 0);
689+
690+ editctx = extbbslist_startedit(list);
691+ if (editctx == NULL) {
692+ printf("extbbslist_startedit\n");
693+ extbbslist_delete(list);
694+ return UNITTEST_RESULT_FAIL;
695+ }
696+ err = test_extbbslist_appenditem(editctx, input, input_len);
697+ if (err < 0) {
698+ result = UNITTEST_RESULT_FAIL;
699+ }
700+ extbbslist_editcontext_deleteitem(editctx, 2);
701+ extbbslist_endedit(list, editctx, True);
702+
703+ num = extbbslist_number(list);
704+ if (num != 3) {
705+ printf("extbbslist_number 002\n");
706+ result = UNITTEST_RESULT_FAIL;
707+ }
708+
709+ extbbslist_delete(list);
710+
711+ return result;
712+}
713+
714+LOCAL UNITTEST_RESULT test_extbbslist_swap_common(testextbbslist_input_t *input, W input_len, W i0, W i1, testextbbslist_expected_t *expected, W expected_len)
715+{
716+ extbbslist_t *list;
717+ extbbslist_editcontext_t *editctx;
718+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
719+ W err;
720+
721+ list = extbbslist_new(NULL, 0, 0);
722+
723+ editctx = extbbslist_startedit(list);
724+ if (editctx == NULL) {
725+ printf("extbbslist_startedit\n");
726+ extbbslist_delete(list);
727+ return UNITTEST_RESULT_FAIL;
728+ }
729+ err = test_extbbslist_appenditem(editctx, input, input_len);
730+ if (err < 0) {
731+ result = UNITTEST_RESULT_FAIL;
732+ }
733+ extbbslist_editcontext_swapitem(editctx, i0, i1);
734+ extbbslist_endedit(list, editctx, True);
735+
736+ err = test_extbbslist_checkexpected(list, expected, expected_len);
737+ if (err < 0) {
738+ result = UNITTEST_RESULT_FAIL;
739+ }
740+
741+ extbbslist_delete(list);
742+
743+ return result;
744+}
745+
746+LOCAL UNITTEST_RESULT test_extbbslist_9()
747+{
748+ testextbbslist_input_t input[] = {
749+ {
750+ test_extbbslist_testtitle001,
751+ tc_strlen(test_extbbslist_testtitle001),
752+ test_extbbslist_testTCurl005,
753+ tc_strlen(test_extbbslist_testTCurl005),
754+ },
755+ {
756+ test_extbbslist_testtitle002,
757+ tc_strlen(test_extbbslist_testtitle002),
758+ test_extbbslist_testTCurl006,
759+ tc_strlen(test_extbbslist_testTCurl006),
760+ },
761+ {
762+ test_extbbslist_testtitle003,
763+ tc_strlen(test_extbbslist_testtitle003),
764+ test_extbbslist_testTCurl007,
765+ tc_strlen(test_extbbslist_testTCurl007),
766+ },
767+ {
768+ test_extbbslist_testtitle004,
769+ tc_strlen(test_extbbslist_testtitle004),
770+ test_extbbslist_testTCurl008,
771+ tc_strlen(test_extbbslist_testTCurl008),
772+ },
773+ };
774+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
775+ testextbbslist_expected_t expected[] = {
776+ {
777+ test_extbbslist_testtitle002,
778+ tc_strlen(test_extbbslist_testtitle002),
779+ test_extbbslist_testurl006,
780+ strlen(test_extbbslist_testurl006)
781+ },
782+ {
783+ test_extbbslist_testtitle001,
784+ tc_strlen(test_extbbslist_testtitle001),
785+ test_extbbslist_testurl005,
786+ strlen(test_extbbslist_testurl005)
787+ },
788+ {
789+ test_extbbslist_testtitle003,
790+ tc_strlen(test_extbbslist_testtitle003),
791+ test_extbbslist_testurl007,
792+ strlen(test_extbbslist_testurl007)
793+ },
794+ {
795+ test_extbbslist_testtitle004,
796+ tc_strlen(test_extbbslist_testtitle004),
797+ test_extbbslist_testurl008,
798+ strlen(test_extbbslist_testurl008)
799+ },
800+ };
801+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
802+
803+ return test_extbbslist_swap_common(input, input_len, 0, 1, expected, expected_len);
804+}
805+
806+LOCAL UNITTEST_RESULT test_extbbslist_10()
807+{
808+ testextbbslist_input_t input[] = {
809+ {
810+ test_extbbslist_testtitle001,
811+ tc_strlen(test_extbbslist_testtitle001),
812+ test_extbbslist_testTCurl005,
813+ tc_strlen(test_extbbslist_testTCurl005),
814+ },
815+ {
816+ test_extbbslist_testtitle002,
817+ tc_strlen(test_extbbslist_testtitle002),
818+ test_extbbslist_testTCurl006,
819+ tc_strlen(test_extbbslist_testTCurl006),
820+ },
821+ {
822+ test_extbbslist_testtitle003,
823+ tc_strlen(test_extbbslist_testtitle003),
824+ test_extbbslist_testTCurl007,
825+ tc_strlen(test_extbbslist_testTCurl007),
826+ },
827+ {
828+ test_extbbslist_testtitle004,
829+ tc_strlen(test_extbbslist_testtitle004),
830+ test_extbbslist_testTCurl008,
831+ tc_strlen(test_extbbslist_testTCurl008),
832+ },
833+ };
834+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
835+ testextbbslist_expected_t expected[] = {
836+ {
837+ test_extbbslist_testtitle003,
838+ tc_strlen(test_extbbslist_testtitle003),
839+ test_extbbslist_testurl007,
840+ strlen(test_extbbslist_testurl007)
841+ },
842+ {
843+ test_extbbslist_testtitle002,
844+ tc_strlen(test_extbbslist_testtitle002),
845+ test_extbbslist_testurl006,
846+ strlen(test_extbbslist_testurl006)
847+ },
848+ {
849+ test_extbbslist_testtitle001,
850+ tc_strlen(test_extbbslist_testtitle001),
851+ test_extbbslist_testurl005,
852+ strlen(test_extbbslist_testurl005)
853+ },
854+ {
855+ test_extbbslist_testtitle004,
856+ tc_strlen(test_extbbslist_testtitle004),
857+ test_extbbslist_testurl008,
858+ strlen(test_extbbslist_testurl008)
859+ },
860+ };
861+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
862+
863+ return test_extbbslist_swap_common(input, input_len, 0, 2, expected, expected_len);
864+}
865+
866+LOCAL UNITTEST_RESULT test_extbbslist_11()
867+{
868+ testextbbslist_input_t input[] = {
869+ {
870+ test_extbbslist_testtitle001,
871+ tc_strlen(test_extbbslist_testtitle001),
872+ test_extbbslist_testTCurl005,
873+ tc_strlen(test_extbbslist_testTCurl005),
874+ },
875+ {
876+ test_extbbslist_testtitle002,
877+ tc_strlen(test_extbbslist_testtitle002),
878+ test_extbbslist_testTCurl006,
879+ tc_strlen(test_extbbslist_testTCurl006),
880+ },
881+ {
882+ test_extbbslist_testtitle003,
883+ tc_strlen(test_extbbslist_testtitle003),
884+ test_extbbslist_testTCurl007,
885+ tc_strlen(test_extbbslist_testTCurl007),
886+ },
887+ {
888+ test_extbbslist_testtitle004,
889+ tc_strlen(test_extbbslist_testtitle004),
890+ test_extbbslist_testTCurl008,
891+ tc_strlen(test_extbbslist_testTCurl008),
892+ },
893+ };
894+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
895+ testextbbslist_expected_t expected[] = {
896+ {
897+ test_extbbslist_testtitle001,
898+ tc_strlen(test_extbbslist_testtitle001),
899+ test_extbbslist_testurl005,
900+ strlen(test_extbbslist_testurl005)
901+ },
902+ {
903+ test_extbbslist_testtitle004,
904+ tc_strlen(test_extbbslist_testtitle004),
905+ test_extbbslist_testurl008,
906+ strlen(test_extbbslist_testurl008)
907+ },
908+ {
909+ test_extbbslist_testtitle003,
910+ tc_strlen(test_extbbslist_testtitle003),
911+ test_extbbslist_testurl007,
912+ strlen(test_extbbslist_testurl007)
913+ },
914+ {
915+ test_extbbslist_testtitle002,
916+ tc_strlen(test_extbbslist_testtitle002),
917+ test_extbbslist_testurl006,
918+ strlen(test_extbbslist_testurl006)
919+ },
920+ };
921+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
922+
923+ return test_extbbslist_swap_common(input, input_len, 1, 3, expected, expected_len);
924+}
925+
926+LOCAL UNITTEST_RESULT test_extbbslist_12()
927+{
928+ testextbbslist_input_t input[] = {
929+ {
930+ test_extbbslist_testtitle001,
931+ tc_strlen(test_extbbslist_testtitle001),
932+ test_extbbslist_testTCurl005,
933+ tc_strlen(test_extbbslist_testTCurl005),
934+ },
935+ {
936+ test_extbbslist_testtitle002,
937+ tc_strlen(test_extbbslist_testtitle002),
938+ test_extbbslist_testTCurl006,
939+ tc_strlen(test_extbbslist_testTCurl006),
940+ },
941+ {
942+ test_extbbslist_testtitle003,
943+ tc_strlen(test_extbbslist_testtitle003),
944+ test_extbbslist_testTCurl007,
945+ tc_strlen(test_extbbslist_testTCurl007),
946+ },
947+ {
948+ test_extbbslist_testtitle004,
949+ tc_strlen(test_extbbslist_testtitle004),
950+ test_extbbslist_testTCurl008,
951+ tc_strlen(test_extbbslist_testTCurl008),
952+ },
953+ };
954+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
955+ testextbbslist_expected_t expected[] = {
956+ {
957+ test_extbbslist_testtitle001,
958+ tc_strlen(test_extbbslist_testtitle001),
959+ test_extbbslist_testurl005,
960+ strlen(test_extbbslist_testurl005)
961+ },
962+ {
963+ test_extbbslist_testtitle002,
964+ tc_strlen(test_extbbslist_testtitle002),
965+ test_extbbslist_testurl006,
966+ strlen(test_extbbslist_testurl006)
967+ },
968+ {
969+ test_extbbslist_testtitle004,
970+ tc_strlen(test_extbbslist_testtitle004),
971+ test_extbbslist_testurl008,
972+ strlen(test_extbbslist_testurl008)
973+ },
974+ {
975+ test_extbbslist_testtitle003,
976+ tc_strlen(test_extbbslist_testtitle003),
977+ test_extbbslist_testurl007,
978+ strlen(test_extbbslist_testurl007)
979+ },
980+ };
981+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
982+
983+ return test_extbbslist_swap_common(input, input_len, 2, 3, expected, expected_len);
984+}
985+
986+LOCAL UNITTEST_RESULT test_extbbslist_13()
987+{
988+ testextbbslist_input_t input[] = {
989+ {
990+ test_extbbslist_testtitle001,
991+ tc_strlen(test_extbbslist_testtitle001),
992+ test_extbbslist_testTCurl005,
993+ tc_strlen(test_extbbslist_testTCurl005),
994+ },
995+ {
996+ test_extbbslist_testtitle002,
997+ tc_strlen(test_extbbslist_testtitle002),
998+ test_extbbslist_testTCurl006,
999+ tc_strlen(test_extbbslist_testTCurl006),
1000+ },
1001+ {
1002+ test_extbbslist_testtitle003,
1003+ tc_strlen(test_extbbslist_testtitle003),
1004+ test_extbbslist_testTCurl007,
1005+ tc_strlen(test_extbbslist_testTCurl007),
1006+ },
1007+ {
1008+ test_extbbslist_testtitle004,
1009+ tc_strlen(test_extbbslist_testtitle004),
1010+ test_extbbslist_testTCurl008,
1011+ tc_strlen(test_extbbslist_testTCurl008),
1012+ },
1013+ };
1014+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1015+ testextbbslist_expected_t expected[] = {
1016+ {
1017+ test_extbbslist_testtitle001,
1018+ tc_strlen(test_extbbslist_testtitle001),
1019+ test_extbbslist_testurl005,
1020+ strlen(test_extbbslist_testurl005)
1021+ },
1022+ {
1023+ test_extbbslist_testtitle002,
1024+ tc_strlen(test_extbbslist_testtitle002),
1025+ test_extbbslist_testurl006,
1026+ strlen(test_extbbslist_testurl006)
1027+ },
1028+ {
1029+ test_extbbslist_testtitle003,
1030+ tc_strlen(test_extbbslist_testtitle003),
1031+ test_extbbslist_testurl007,
1032+ strlen(test_extbbslist_testurl007)
1033+ },
1034+ {
1035+ test_extbbslist_testtitle004,
1036+ tc_strlen(test_extbbslist_testtitle004),
1037+ test_extbbslist_testurl008,
1038+ strlen(test_extbbslist_testurl008)
1039+ },
1040+ };
1041+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
1042+
1043+ return test_extbbslist_swap_common(input, input_len, 0, 4, expected, expected_len);
1044+}
1045+
1046+LOCAL UNITTEST_RESULT test_extbbslist_14()
1047+{
1048+ testextbbslist_input_t input[] = {
1049+ {
1050+ test_extbbslist_testtitle001,
1051+ tc_strlen(test_extbbslist_testtitle001),
1052+ test_extbbslist_testTCurl005,
1053+ tc_strlen(test_extbbslist_testTCurl005),
1054+ },
1055+ {
1056+ test_extbbslist_testtitle002,
1057+ tc_strlen(test_extbbslist_testtitle002),
1058+ test_extbbslist_testTCurl006,
1059+ tc_strlen(test_extbbslist_testTCurl006),
1060+ },
1061+ {
1062+ test_extbbslist_testtitle003,
1063+ tc_strlen(test_extbbslist_testtitle003),
1064+ test_extbbslist_testTCurl007,
1065+ tc_strlen(test_extbbslist_testTCurl007),
1066+ },
1067+ {
1068+ test_extbbslist_testtitle004,
1069+ tc_strlen(test_extbbslist_testtitle004),
1070+ test_extbbslist_testTCurl008,
1071+ tc_strlen(test_extbbslist_testTCurl008),
1072+ },
1073+ };
1074+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1075+ testextbbslist_expected_t expected[] = {
1076+ {
1077+ test_extbbslist_testtitle001,
1078+ tc_strlen(test_extbbslist_testtitle001),
1079+ test_extbbslist_testurl005,
1080+ strlen(test_extbbslist_testurl005)
1081+ },
1082+ {
1083+ test_extbbslist_testtitle002,
1084+ tc_strlen(test_extbbslist_testtitle002),
1085+ test_extbbslist_testurl006,
1086+ strlen(test_extbbslist_testurl006)
1087+ },
1088+ {
1089+ test_extbbslist_testtitle003,
1090+ tc_strlen(test_extbbslist_testtitle003),
1091+ test_extbbslist_testurl007,
1092+ strlen(test_extbbslist_testurl007)
1093+ },
1094+ {
1095+ test_extbbslist_testtitle004,
1096+ tc_strlen(test_extbbslist_testtitle004),
1097+ test_extbbslist_testurl008,
1098+ strlen(test_extbbslist_testurl008)
1099+ },
1100+ };
1101+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
1102+
1103+ return test_extbbslist_swap_common(input, input_len, 4, 0, expected, expected_len);
1104+}
1105+
1106+LOCAL UNITTEST_RESULT test_extbbslist_15()
1107+{
1108+ testextbbslist_input_t input[] = {
1109+ {
1110+ test_extbbslist_testtitle001,
1111+ tc_strlen(test_extbbslist_testtitle001),
1112+ test_extbbslist_testTCurl005,
1113+ tc_strlen(test_extbbslist_testTCurl005),
1114+ },
1115+ {
1116+ test_extbbslist_testtitle002,
1117+ tc_strlen(test_extbbslist_testtitle002),
1118+ test_extbbslist_testTCurl006,
1119+ tc_strlen(test_extbbslist_testTCurl006),
1120+ },
1121+ {
1122+ test_extbbslist_testtitle003,
1123+ tc_strlen(test_extbbslist_testtitle003),
1124+ test_extbbslist_testTCurl007,
1125+ tc_strlen(test_extbbslist_testTCurl007),
1126+ },
1127+ {
1128+ test_extbbslist_testtitle004,
1129+ tc_strlen(test_extbbslist_testtitle004),
1130+ test_extbbslist_testTCurl008,
1131+ tc_strlen(test_extbbslist_testTCurl008),
1132+ },
1133+ };
1134+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1135+ testextbbslist_expected_t expected[] = {
1136+ {
1137+ test_extbbslist_testtitle001,
1138+ tc_strlen(test_extbbslist_testtitle001),
1139+ test_extbbslist_testurl005,
1140+ strlen(test_extbbslist_testurl005)
1141+ },
1142+ {
1143+ test_extbbslist_testtitle002,
1144+ tc_strlen(test_extbbslist_testtitle002),
1145+ test_extbbslist_testurl006,
1146+ strlen(test_extbbslist_testurl006)
1147+ },
1148+ {
1149+ test_extbbslist_testtitle003,
1150+ tc_strlen(test_extbbslist_testtitle003),
1151+ test_extbbslist_testurl007,
1152+ strlen(test_extbbslist_testurl007)
1153+ },
1154+ {
1155+ test_extbbslist_testtitle004,
1156+ tc_strlen(test_extbbslist_testtitle004),
1157+ test_extbbslist_testurl008,
1158+ strlen(test_extbbslist_testurl008)
1159+ },
1160+ };
1161+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
1162+
1163+ return test_extbbslist_swap_common(input, input_len, -1, 0, expected, expected_len);
1164+}
1165+
1166+LOCAL UNITTEST_RESULT test_extbbslist_16()
1167+{
1168+ testextbbslist_input_t input[] = {
1169+ {
1170+ test_extbbslist_testtitle001,
1171+ tc_strlen(test_extbbslist_testtitle001),
1172+ test_extbbslist_testTCurl005,
1173+ tc_strlen(test_extbbslist_testTCurl005),
1174+ },
1175+ {
1176+ test_extbbslist_testtitle002,
1177+ tc_strlen(test_extbbslist_testtitle002),
1178+ test_extbbslist_testTCurl006,
1179+ tc_strlen(test_extbbslist_testTCurl006),
1180+ },
1181+ {
1182+ test_extbbslist_testtitle003,
1183+ tc_strlen(test_extbbslist_testtitle003),
1184+ test_extbbslist_testTCurl007,
1185+ tc_strlen(test_extbbslist_testTCurl007),
1186+ },
1187+ {
1188+ test_extbbslist_testtitle004,
1189+ tc_strlen(test_extbbslist_testtitle004),
1190+ test_extbbslist_testTCurl008,
1191+ tc_strlen(test_extbbslist_testTCurl008),
1192+ },
1193+ };
1194+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1195+ testextbbslist_expected_t expected[] = {
1196+ {
1197+ test_extbbslist_testtitle001,
1198+ tc_strlen(test_extbbslist_testtitle001),
1199+ test_extbbslist_testurl005,
1200+ strlen(test_extbbslist_testurl005)
1201+ },
1202+ {
1203+ test_extbbslist_testtitle002,
1204+ tc_strlen(test_extbbslist_testtitle002),
1205+ test_extbbslist_testurl006,
1206+ strlen(test_extbbslist_testurl006)
1207+ },
1208+ {
1209+ test_extbbslist_testtitle003,
1210+ tc_strlen(test_extbbslist_testtitle003),
1211+ test_extbbslist_testurl007,
1212+ strlen(test_extbbslist_testurl007)
1213+ },
1214+ {
1215+ test_extbbslist_testtitle004,
1216+ tc_strlen(test_extbbslist_testtitle004),
1217+ test_extbbslist_testurl008,
1218+ strlen(test_extbbslist_testurl008)
1219+ },
1220+ };
1221+ W expected_len = sizeof(expected)/sizeof(testextbbslist_expected_t);
1222+
1223+ return test_extbbslist_swap_common(input, input_len, 0, -1, expected, expected_len);
1224+}
1225+
1226+LOCAL UNITTEST_RESULT test_extbbslist_swap_selected_common(testextbbslist_input_t *input, W input_len, W sel_before, W i0, W i1, W sel_expected)
1227+{
1228+ extbbslist_t *list;
1229+ extbbslist_editcontext_t *editctx;
1230+ UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
1231+ W sel, err;
1232+
1233+ list = extbbslist_new(NULL, 0, 0);
1234+
1235+ editctx = extbbslist_startedit(list);
1236+ if (editctx == NULL) {
1237+ printf("extbbslist_startedit\n");
1238+ extbbslist_delete(list);
1239+ return UNITTEST_RESULT_FAIL;
1240+ }
1241+
1242+ err = test_extbbslist_appenditem(editctx, input, input_len);
1243+ if (err < 0) {
1244+ result = UNITTEST_RESULT_FAIL;
1245+ }
1246+ extbbslist_editcontext_setselect(editctx, sel_before);
1247+ extbbslist_editcontext_swapitem(editctx, i0, i1);
1248+
1249+ sel = extbbslist_editcontext_getselect(editctx);
1250+ if (sel != sel_expected) {
1251+ printf("extbbslist_editcontext_getselected fail: expected = %d, result = %d\n", sel_expected, sel);
1252+ result = UNITTEST_RESULT_FAIL;
1253+ }
1254+
1255+ extbbslist_endedit(list, editctx, True);
1256+
1257+ extbbslist_delete(list);
1258+
1259+ return result;
1260+}
1261+
1262+LOCAL UNITTEST_RESULT test_extbbslist_17()
1263+{
1264+ testextbbslist_input_t input[] = {
1265+ {
1266+ test_extbbslist_testtitle001,
1267+ tc_strlen(test_extbbslist_testtitle001),
1268+ test_extbbslist_testTCurl005,
1269+ tc_strlen(test_extbbslist_testTCurl005),
1270+ },
1271+ {
1272+ test_extbbslist_testtitle002,
1273+ tc_strlen(test_extbbslist_testtitle002),
1274+ test_extbbslist_testTCurl006,
1275+ tc_strlen(test_extbbslist_testTCurl006),
1276+ },
1277+ {
1278+ test_extbbslist_testtitle003,
1279+ tc_strlen(test_extbbslist_testtitle003),
1280+ test_extbbslist_testTCurl007,
1281+ tc_strlen(test_extbbslist_testTCurl007),
1282+ },
1283+ {
1284+ test_extbbslist_testtitle004,
1285+ tc_strlen(test_extbbslist_testtitle004),
1286+ test_extbbslist_testTCurl008,
1287+ tc_strlen(test_extbbslist_testTCurl008),
1288+ },
1289+ };
1290+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1291+
1292+ return test_extbbslist_swap_selected_common(input, input_len, 0, 0, 1, 1);
1293+}
1294+
1295+LOCAL UNITTEST_RESULT test_extbbslist_18()
1296+{
1297+ testextbbslist_input_t input[] = {
1298+ {
1299+ test_extbbslist_testtitle001,
1300+ tc_strlen(test_extbbslist_testtitle001),
1301+ test_extbbslist_testTCurl005,
1302+ tc_strlen(test_extbbslist_testTCurl005),
1303+ },
1304+ {
1305+ test_extbbslist_testtitle002,
1306+ tc_strlen(test_extbbslist_testtitle002),
1307+ test_extbbslist_testTCurl006,
1308+ tc_strlen(test_extbbslist_testTCurl006),
1309+ },
1310+ {
1311+ test_extbbslist_testtitle003,
1312+ tc_strlen(test_extbbslist_testtitle003),
1313+ test_extbbslist_testTCurl007,
1314+ tc_strlen(test_extbbslist_testTCurl007),
1315+ },
1316+ {
1317+ test_extbbslist_testtitle004,
1318+ tc_strlen(test_extbbslist_testtitle004),
1319+ test_extbbslist_testTCurl008,
1320+ tc_strlen(test_extbbslist_testTCurl008),
1321+ },
1322+ };
1323+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1324+
1325+ return test_extbbslist_swap_selected_common(input, input_len, 1, 0, 1, 0);
1326+}
1327+
1328+LOCAL UNITTEST_RESULT test_extbbslist_19()
1329+{
1330+ testextbbslist_input_t input[] = {
1331+ {
1332+ test_extbbslist_testtitle001,
1333+ tc_strlen(test_extbbslist_testtitle001),
1334+ test_extbbslist_testTCurl005,
1335+ tc_strlen(test_extbbslist_testTCurl005),
1336+ },
1337+ {
1338+ test_extbbslist_testtitle002,
1339+ tc_strlen(test_extbbslist_testtitle002),
1340+ test_extbbslist_testTCurl006,
1341+ tc_strlen(test_extbbslist_testTCurl006),
1342+ },
1343+ {
1344+ test_extbbslist_testtitle003,
1345+ tc_strlen(test_extbbslist_testtitle003),
1346+ test_extbbslist_testTCurl007,
1347+ tc_strlen(test_extbbslist_testTCurl007),
1348+ },
1349+ {
1350+ test_extbbslist_testtitle004,
1351+ tc_strlen(test_extbbslist_testtitle004),
1352+ test_extbbslist_testTCurl008,
1353+ tc_strlen(test_extbbslist_testTCurl008),
1354+ },
1355+ };
1356+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1357+
1358+ return test_extbbslist_swap_selected_common(input, input_len, 0, 0, 2, 2);
1359+}
1360+
1361+LOCAL UNITTEST_RESULT test_extbbslist_20()
1362+{
1363+ testextbbslist_input_t input[] = {
1364+ {
1365+ test_extbbslist_testtitle001,
1366+ tc_strlen(test_extbbslist_testtitle001),
1367+ test_extbbslist_testTCurl005,
1368+ tc_strlen(test_extbbslist_testTCurl005),
1369+ },
1370+ {
1371+ test_extbbslist_testtitle002,
1372+ tc_strlen(test_extbbslist_testtitle002),
1373+ test_extbbslist_testTCurl006,
1374+ tc_strlen(test_extbbslist_testTCurl006),
1375+ },
1376+ {
1377+ test_extbbslist_testtitle003,
1378+ tc_strlen(test_extbbslist_testtitle003),
1379+ test_extbbslist_testTCurl007,
1380+ tc_strlen(test_extbbslist_testTCurl007),
1381+ },
1382+ {
1383+ test_extbbslist_testtitle004,
1384+ tc_strlen(test_extbbslist_testtitle004),
1385+ test_extbbslist_testTCurl008,
1386+ tc_strlen(test_extbbslist_testTCurl008),
1387+ },
1388+ };
1389+ W input_len = sizeof(input)/sizeof(testextbbslist_input_t);
1390+
1391+ return test_extbbslist_swap_selected_common(input, input_len, 0, 0, 4, 0);
1392+}
1393+
2651394 EXPORT VOID test_extbbslist_main(unittest_driver_t *driver)
2661395 {
2671396 UNITTEST_DRIVER_REGIST(driver, test_extbbslist_1);
2681397 UNITTEST_DRIVER_REGIST(driver, test_extbbslist_2);
1398+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_3);
1399+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_4);
1400+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_5);
1401+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_6);
1402+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_7);
1403+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_8);
1404+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_9);
1405+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_10);
1406+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_11);
1407+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_12);
1408+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_13);
1409+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_14);
1410+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_15);
1411+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_16);
1412+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_17);
1413+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_18);
1414+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_19);
1415+ UNITTEST_DRIVER_REGIST(driver, test_extbbslist_20);
2691416 }
--- bchanl/trunk/src/extbbslist.c (revision 454)
+++ bchanl/trunk/src/extbbslist.c (revision 455)
@@ -555,7 +555,7 @@
555555 if (i0 == i1) {
556556 return 0;
557557 }
558- if (i1 > i0) {
558+ if (i0 > i1) {
559559 buf = i1;
560560 i1 = i0;
561561 i0 = buf;
@@ -572,6 +572,12 @@
572572 }
573573 item1_next = extbbslist_item_nextnode(item1);
574574
575+ if (ctx->selected.index == i0) {
576+ ctx->selected.index = i1;
577+ } else if (ctx->selected.index == i1) {
578+ ctx->selected.index = i0;
579+ }
580+
575581 if (i0 + 1 == i1) {
576582 extbbslist_item_QueRemove(item1);
577583 extbbslist_item_QueInsert(item1, item0);
@@ -594,13 +600,15 @@
594600 if (item == NULL) {
595601 return -1; /* TODO */
596602 }
603+ extbbslist_item_delete(item);
597604 ctx->num--;
598605 if (ctx->selected.index == i) {
599606 ctx->selected.item = NULL;
600607 ctx->selected.index = -1;
601608 }
602- ctx->selected.item = item;
603- ctx->selected.index = i;
609+ if (ctx->selected.index > i) {
610+ ctx->selected.index--;
611+ }
604612 return 0;
605613 }
606614
@@ -742,6 +750,10 @@
742750
743751 sentinel = extbbslist_sentinelnode(list);
744752 extbbslist_item_QueInsert(sentinel, next);
753+
754+ list->num = ctx->num;
755+ } else {
756+ list->num = 0;
745757 }
746758 }
747759
Show on old repository browser