2 * Copyright (c) 2024 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <io/kbd_event.h>
31 #include <io/pos_event.h>
32 #include <pcut/pcut.h>
37 #include <ui/scrollbar.h>
39 #include "../private/list.h"
43 PCUT_TEST_SUITE(list
);
48 ui_list_t
*activate_req_list
;
51 ui_list_entry_t
*selected_entry
;
54 static void test_list_activate_req(ui_list_t
*, void *);
55 static void test_list_selected(ui_list_entry_t
*, void *);
56 static int test_list_compare(ui_list_entry_t
*, ui_list_entry_t
*);
58 static ui_list_cb_t test_cb
= {
59 .activate_req
= test_list_activate_req
,
60 .selected
= test_list_selected
,
61 .compare
= test_list_compare
64 /** Create and destroy file list. */
65 PCUT_TEST(create_destroy
)
69 ui_wnd_params_t params
;
73 rc
= ui_create_disp(NULL
, &ui
);
74 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
76 ui_wnd_params_init(¶ms
);
77 params
.caption
= "Test";
79 rc
= ui_window_create(ui
, ¶ms
, &window
);
80 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
82 rc
= ui_list_create(window
, true, &list
);
83 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
85 ui_list_destroy(list
);
86 ui_window_destroy(window
);
90 /** ui_list_set_cb() sets callback */
95 ui_wnd_params_t params
;
100 rc
= ui_create_disp(NULL
, &ui
);
101 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
103 ui_wnd_params_init(¶ms
);
104 params
.caption
= "Test";
106 rc
= ui_window_create(ui
, ¶ms
, &window
);
107 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
109 rc
= ui_list_create(window
, true, &list
);
110 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
112 ui_list_set_cb(list
, &test_cb
, &resp
);
113 PCUT_ASSERT_EQUALS(&test_cb
, list
->cb
);
114 PCUT_ASSERT_EQUALS(&resp
, list
->cb_arg
);
116 ui_list_destroy(list
);
117 ui_window_destroy(window
);
121 /** ui_list_get_cb_arg() returns the callback argument */
122 PCUT_TEST(get_cb_arg
)
126 ui_wnd_params_t params
;
132 rc
= ui_create_disp(NULL
, &ui
);
133 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
135 ui_wnd_params_init(¶ms
);
136 params
.caption
= "Test";
138 rc
= ui_window_create(ui
, ¶ms
, &window
);
139 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
141 rc
= ui_list_create(window
, true, &list
);
142 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
144 ui_list_set_cb(list
, &test_cb
, &resp
);
145 arg
= ui_list_get_cb_arg(list
);
146 PCUT_ASSERT_EQUALS((void *)&resp
, arg
);
148 ui_list_destroy(list
);
149 ui_window_destroy(window
);
153 /** ui_list_entry_height() gives the correct height */
154 PCUT_TEST(entry_height
)
158 ui_wnd_params_t params
;
163 rc
= ui_create_disp(NULL
, &ui
);
164 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
166 ui_wnd_params_init(¶ms
);
167 params
.caption
= "Test";
169 rc
= ui_window_create(ui
, ¶ms
, &window
);
170 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
172 rc
= ui_list_create(window
, true, &list
);
173 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
175 /* Font height is 13, padding: 2 (top) + 2 (bottom) */
176 height
= ui_list_entry_height(list
);
177 PCUT_ASSERT_INT_EQUALS(17, height
);
179 ui_list_destroy(list
);
180 ui_window_destroy(window
);
184 /** Test ui_list_entry_paint() */
185 PCUT_TEST(entry_paint
)
189 ui_wnd_params_t params
;
191 ui_list_entry_attr_t attr
;
194 rc
= ui_create_disp(NULL
, &ui
);
195 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
197 ui_wnd_params_init(¶ms
);
198 params
.caption
= "Test";
200 rc
= ui_window_create(ui
, ¶ms
, &window
);
201 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
203 rc
= ui_list_create(window
, true, &list
);
204 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
206 ui_list_entry_attr_init(&attr
);
208 attr
.arg
= (void *)1;
210 rc
= ui_list_entry_append(list
, &attr
, NULL
);
211 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
213 rc
= ui_list_entry_paint(ui_list_first(list
), 0);
214 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
216 ui_list_destroy(list
);
217 ui_window_destroy(window
);
221 /** Test ui_list_paint() */
226 ui_wnd_params_t params
;
230 rc
= ui_create_disp(NULL
, &ui
);
231 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
233 ui_wnd_params_init(¶ms
);
234 params
.caption
= "Test";
236 rc
= ui_window_create(ui
, ¶ms
, &window
);
237 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
239 rc
= ui_list_create(window
, true, &list
);
240 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
242 rc
= ui_list_paint(list
);
243 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
245 ui_list_destroy(list
);
246 ui_window_destroy(window
);
250 /** ui_list_ctl() returns a valid UI control */
255 ui_wnd_params_t params
;
257 ui_control_t
*control
;
260 rc
= ui_create_disp(NULL
, &ui
);
261 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
263 ui_wnd_params_init(¶ms
);
264 params
.caption
= "Test";
266 rc
= ui_window_create(ui
, ¶ms
, &window
);
267 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
269 rc
= ui_list_create(window
, true, &list
);
270 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
272 control
= ui_list_ctl(list
);
273 PCUT_ASSERT_NOT_NULL(control
);
275 ui_list_destroy(list
);
276 ui_window_destroy(window
);
280 /** Test ui_list_kbd_event() */
285 ui_wnd_params_t params
;
287 ui_evclaim_t claimed
;
291 /* Active list should claim events */
293 rc
= ui_create_disp(NULL
, &ui
);
294 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
296 ui_wnd_params_init(¶ms
);
297 params
.caption
= "Test";
299 rc
= ui_window_create(ui
, ¶ms
, &window
);
300 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
302 rc
= ui_list_create(window
, true, &list
);
303 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
305 event
.type
= KEY_PRESS
;
306 event
.key
= KC_ESCAPE
;
310 claimed
= ui_list_kbd_event(list
, &event
);
311 PCUT_ASSERT_EQUALS(ui_claimed
, claimed
);
313 ui_list_destroy(list
);
315 /* Inactive list should not claim events */
317 rc
= ui_create_disp(NULL
, &ui
);
318 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
320 ui_wnd_params_init(¶ms
);
321 params
.caption
= "Test";
323 rc
= ui_window_create(ui
, ¶ms
, &window
);
324 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
326 rc
= ui_list_create(window
, false, &list
);
327 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
329 event
.type
= KEY_PRESS
;
330 event
.key
= KC_ESCAPE
;
334 claimed
= ui_list_kbd_event(list
, &event
);
335 PCUT_ASSERT_EQUALS(ui_unclaimed
, claimed
);
337 ui_list_destroy(list
);
338 ui_window_destroy(window
);
342 /** Test ui_list_pos_event() */
347 ui_wnd_params_t params
;
349 ui_evclaim_t claimed
;
352 ui_list_entry_attr_t attr
;
355 rc
= ui_create_disp(NULL
, &ui
);
356 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
358 ui_wnd_params_init(¶ms
);
359 params
.caption
= "Test";
361 rc
= ui_window_create(ui
, ¶ms
, &window
);
362 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
364 rc
= ui_list_create(window
, true, &list
);
365 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
372 ui_list_set_rect(list
, &rect
);
374 ui_list_entry_attr_init(&attr
);
376 attr
.arg
= (void *)1;
377 rc
= ui_list_entry_append(list
, &attr
, NULL
);
378 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
381 attr
.arg
= (void *)2;
382 rc
= ui_list_entry_append(list
, &attr
, NULL
);
383 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
386 attr
.arg
= (void *)3;
387 rc
= ui_list_entry_append(list
, &attr
, NULL
);
388 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
390 list
->cursor
= ui_list_first(list
);
391 list
->cursor_idx
= 0;
392 list
->page
= ui_list_first(list
);
396 event
.type
= POS_PRESS
;
399 /* Clicking on the middle entry should select it */
403 claimed
= ui_list_pos_event(list
, &event
);
404 PCUT_ASSERT_EQUALS(ui_claimed
, claimed
);
406 PCUT_ASSERT_NOT_NULL(list
->cursor
);
407 PCUT_ASSERT_STR_EQUALS("b", list
->cursor
->caption
);
408 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->cursor
->arg
);
410 /* Clicking on the top edge should do a page-up */
413 claimed
= ui_list_pos_event(list
, &event
);
414 PCUT_ASSERT_EQUALS(ui_claimed
, claimed
);
416 PCUT_ASSERT_NOT_NULL(list
->cursor
);
417 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
418 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
420 ui_list_destroy(list
);
421 ui_window_destroy(window
);
425 /** ui_list_set_rect() sets internal field */
430 ui_wnd_params_t params
;
435 rc
= ui_create_disp(NULL
, &ui
);
436 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
438 ui_wnd_params_init(¶ms
);
439 params
.caption
= "Test";
441 rc
= ui_window_create(ui
, ¶ms
, &window
);
442 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
444 rc
= ui_list_create(window
, true, &list
);
445 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
452 ui_list_set_rect(list
, &rect
);
453 PCUT_ASSERT_INT_EQUALS(rect
.p0
.x
, list
->rect
.p0
.x
);
454 PCUT_ASSERT_INT_EQUALS(rect
.p0
.y
, list
->rect
.p0
.y
);
455 PCUT_ASSERT_INT_EQUALS(rect
.p1
.x
, list
->rect
.p1
.x
);
456 PCUT_ASSERT_INT_EQUALS(rect
.p1
.y
, list
->rect
.p1
.y
);
458 ui_list_destroy(list
);
459 ui_window_destroy(window
);
463 /** ui_list_page_size() returns correct size */
468 ui_wnd_params_t params
;
473 rc
= ui_create_disp(NULL
, &ui
);
474 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
476 ui_wnd_params_init(¶ms
);
477 params
.caption
= "Test";
479 rc
= ui_window_create(ui
, ¶ms
, &window
);
480 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
482 rc
= ui_list_create(window
, true, &list
);
483 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
490 ui_list_set_rect(list
, &rect
);
492 /* NOTE If page size changes, we have problems elsewhere in the tests */
493 PCUT_ASSERT_INT_EQUALS(11, ui_list_page_size(list
));
495 ui_list_destroy(list
);
496 ui_window_destroy(window
);
500 /** ui_list_inside_rect() gives correct interior rectangle */
501 PCUT_TEST(inside_rect
)
505 ui_wnd_params_t params
;
511 rc
= ui_create_disp(NULL
, &ui
);
512 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
514 ui_wnd_params_init(¶ms
);
515 params
.caption
= "Test";
517 rc
= ui_window_create(ui
, ¶ms
, &window
);
518 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
520 rc
= ui_list_create(window
, true, &list
);
521 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
528 ui_list_set_rect(list
, &rect
);
530 ui_list_inside_rect(list
, &irect
);
531 PCUT_ASSERT_INT_EQUALS(10 + 2, irect
.p0
.x
);
532 PCUT_ASSERT_INT_EQUALS(20 + 2, irect
.p0
.y
);
533 PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, irect
.p1
.x
);
534 PCUT_ASSERT_INT_EQUALS(220 - 2, irect
.p1
.y
);
536 ui_list_destroy(list
);
537 ui_window_destroy(window
);
541 /** ui_list_scrollbar_rect() gives correct scrollbar rectangle */
542 PCUT_TEST(scrollbar_rect
)
546 ui_wnd_params_t params
;
552 rc
= ui_create_disp(NULL
, &ui
);
553 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
555 ui_wnd_params_init(¶ms
);
556 params
.caption
= "Test";
558 rc
= ui_window_create(ui
, ¶ms
, &window
);
559 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
561 rc
= ui_list_create(window
, true, &list
);
562 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
569 ui_list_set_rect(list
, &rect
);
571 ui_list_scrollbar_rect(list
, &srect
);
572 PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, srect
.p0
.x
);
573 PCUT_ASSERT_INT_EQUALS(20 + 2, srect
.p0
.y
);
574 PCUT_ASSERT_INT_EQUALS(50 - 2, srect
.p1
.x
);
575 PCUT_ASSERT_INT_EQUALS(220 - 2, srect
.p1
.y
);
577 ui_list_destroy(list
);
578 ui_window_destroy(window
);
582 /** ui_list_scrollbar_update() updates scrollbar position */
583 PCUT_TEST(scrollbar_update
)
587 ui_wnd_params_t params
;
590 ui_list_entry_attr_t attr
;
591 ui_list_entry_t
*entry
;
593 gfx_coord_t move_len
;
596 rc
= ui_create_disp(NULL
, &ui
);
597 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
599 ui_wnd_params_init(¶ms
);
600 params
.caption
= "Test";
602 rc
= ui_window_create(ui
, ¶ms
, &window
);
603 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
605 rc
= ui_list_create(window
, true, &list
);
606 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
613 ui_list_set_rect(list
, &rect
);
615 ui_list_entry_attr_init(&attr
);
617 attr
.arg
= (void *)1;
618 rc
= ui_list_entry_append(list
, &attr
, NULL
);
619 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
622 attr
.arg
= (void *)2;
623 rc
= ui_list_entry_append(list
, &attr
, NULL
);
624 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
627 attr
.arg
= (void *)3;
628 rc
= ui_list_entry_append(list
, &attr
, NULL
);
629 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
631 entry
= ui_list_next(ui_list_first(list
));
633 list
->cursor
= entry
;
634 list
->cursor_idx
= 1;
638 ui_list_scrollbar_update(list
);
640 /* Now scrollbar thumb should be all the way down */
641 move_len
= ui_scrollbar_move_length(list
->scrollbar
);
642 pos
= ui_scrollbar_get_pos(list
->scrollbar
);
643 PCUT_ASSERT_INT_EQUALS(move_len
, pos
);
645 ui_list_destroy(list
);
646 ui_window_destroy(window
);
650 /** ui_list_is_active() returns list activity state */
655 ui_wnd_params_t params
;
659 rc
= ui_create_disp(NULL
, &ui
);
660 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
662 ui_wnd_params_init(¶ms
);
663 params
.caption
= "Test";
665 rc
= ui_window_create(ui
, ¶ms
, &window
);
666 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
668 rc
= ui_list_create(window
, true, &list
);
669 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
670 PCUT_ASSERT_TRUE(ui_list_is_active(list
));
671 ui_list_destroy(list
);
673 rc
= ui_list_create(window
, false, &list
);
674 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
675 PCUT_ASSERT_FALSE(ui_list_is_active(list
));
676 ui_list_destroy(list
);
677 ui_window_destroy(window
);
681 /** ui_list_activate() activates list */
686 ui_wnd_params_t params
;
690 rc
= ui_create_disp(NULL
, &ui
);
691 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
693 ui_wnd_params_init(¶ms
);
694 params
.caption
= "Test";
696 rc
= ui_window_create(ui
, ¶ms
, &window
);
697 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
699 rc
= ui_list_create(window
, false, &list
);
700 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
702 PCUT_ASSERT_FALSE(ui_list_is_active(list
));
703 rc
= ui_list_activate(list
);
704 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
705 PCUT_ASSERT_TRUE(ui_list_is_active(list
));
707 ui_list_destroy(list
);
708 ui_window_destroy(window
);
712 /** ui_list_deactivate() deactivates list */
713 PCUT_TEST(deactivate
)
717 ui_wnd_params_t params
;
721 rc
= ui_create_disp(NULL
, &ui
);
722 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
724 ui_wnd_params_init(¶ms
);
725 params
.caption
= "Test";
727 rc
= ui_window_create(ui
, ¶ms
, &window
);
728 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
730 rc
= ui_list_create(window
, true, &list
);
731 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
733 PCUT_ASSERT_TRUE(ui_list_is_active(list
));
734 ui_list_deactivate(list
);
735 PCUT_ASSERT_FALSE(ui_list_is_active(list
));
737 ui_list_destroy(list
);
738 ui_window_destroy(window
);
742 /** ui_list_get_cursor() returns the current cursor position */
743 PCUT_TEST(get_cursor
)
747 ui_wnd_params_t params
;
749 ui_list_entry_attr_t attr
;
750 ui_list_entry_t
*entry
;
751 ui_list_entry_t
*cursor
;
754 rc
= ui_create_disp(NULL
, &ui
);
755 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
757 ui_wnd_params_init(¶ms
);
758 params
.caption
= "Test";
760 rc
= ui_window_create(ui
, ¶ms
, &window
);
761 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
763 rc
= ui_list_create(window
, true, &list
);
764 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
766 ui_list_entry_attr_init(&attr
);
768 /* Append entry and get pointer to it */
770 attr
.arg
= (void *)1;
772 rc
= ui_list_entry_append(list
, &attr
, &entry
);
773 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
774 PCUT_ASSERT_NOT_NULL(entry
);
776 /* Cursor should be at the only entry */
777 cursor
= ui_list_get_cursor(list
);
778 PCUT_ASSERT_EQUALS(entry
, cursor
);
780 ui_list_destroy(list
);
781 ui_window_destroy(window
);
785 /** ui_list_set_cursor() sets list cursor position */
786 PCUT_TEST(set_cursor
)
790 ui_wnd_params_t params
;
792 ui_list_entry_attr_t attr
;
797 rc
= ui_create_disp(NULL
, &ui
);
798 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
800 ui_wnd_params_init(¶ms
);
801 params
.caption
= "Test";
803 rc
= ui_window_create(ui
, ¶ms
, &window
);
804 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
806 rc
= ui_list_create(window
, true, &list
);
807 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
809 ui_list_entry_attr_init(&attr
);
811 /* Append entry and get pointer to it */
813 attr
.arg
= (void *)1;
814 rc
= ui_list_entry_append(list
, &attr
, &e1
);
815 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
816 PCUT_ASSERT_NOT_NULL(e1
);
818 /* Append entry and get pointer to it */
820 attr
.arg
= (void *)2;
821 rc
= ui_list_entry_append(list
, &attr
, &e2
);
822 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
823 PCUT_ASSERT_NOT_NULL(e2
);
827 attr
.arg
= (void *)3;
828 rc
= ui_list_entry_append(list
, &attr
, NULL
);
829 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
831 /* Cursor should be at the first entry */
832 PCUT_ASSERT_EQUALS(e1
, list
->cursor
);
833 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
835 /* Set cursor to the second entry */
836 ui_list_set_cursor(list
, e2
);
837 PCUT_ASSERT_EQUALS(e2
, list
->cursor
);
838 PCUT_ASSERT_INT_EQUALS(1, list
->cursor_idx
);
840 ui_list_destroy(list
);
841 ui_window_destroy(window
);
845 /** ui_list_entry_attr_init() initializes entry attribute structure */
846 PCUT_TEST(entry_attr_init
)
848 ui_list_entry_attr_t attr
;
850 ui_list_entry_attr_init(&attr
);
851 PCUT_ASSERT_NULL(attr
.caption
);
852 PCUT_ASSERT_NULL(attr
.arg
);
853 PCUT_ASSERT_NULL(attr
.color
);
854 PCUT_ASSERT_NULL(attr
.bgcolor
);
857 /** ui_list_entry_append() appends new entry */
858 PCUT_TEST(entry_append
)
862 ui_wnd_params_t params
;
864 ui_list_entry_attr_t attr
;
865 ui_list_entry_t
*entry
;
868 rc
= ui_create_disp(NULL
, &ui
);
869 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
871 ui_wnd_params_init(¶ms
);
872 params
.caption
= "Test";
874 rc
= ui_window_create(ui
, ¶ms
, &window
);
875 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
877 rc
= ui_list_create(window
, true, &list
);
878 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
880 ui_list_entry_attr_init(&attr
);
882 /* Append entry without retrieving pointer to it */
884 attr
.arg
= (void *)1;
885 rc
= ui_list_entry_append(list
, &attr
, NULL
);
886 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
888 PCUT_ASSERT_INT_EQUALS(1, list_count(&list
->entries
));
890 /* Append entry and get pointer to it */
892 attr
.arg
= (void *)2;
894 rc
= ui_list_entry_append(list
, &attr
, &entry
);
895 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
896 PCUT_ASSERT_NOT_NULL(entry
);
897 PCUT_ASSERT_EQUALS(attr
.arg
, entry
->arg
);
899 PCUT_ASSERT_INT_EQUALS(2, list_count(&list
->entries
));
901 ui_list_destroy(list
);
902 ui_window_destroy(window
);
906 /** ui_list_entry_move_up() moves entry up */
907 PCUT_TEST(entry_move_up
)
911 ui_wnd_params_t params
;
913 ui_list_entry_attr_t attr
;
914 ui_list_entry_t
*e1
, *e2
, *e3
;
918 rc
= ui_create_disp(NULL
, &ui
);
919 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
921 ui_wnd_params_init(¶ms
);
922 params
.caption
= "Test";
924 rc
= ui_window_create(ui
, ¶ms
, &window
);
925 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
927 rc
= ui_list_create(window
, true, &list
);
928 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
930 ui_list_entry_attr_init(&attr
);
935 attr
.arg
= (void *)1;
936 rc
= ui_list_entry_append(list
, &attr
, &e1
);
937 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
940 attr
.arg
= (void *)2;
941 rc
= ui_list_entry_append(list
, &attr
, &e2
);
942 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
945 attr
.arg
= (void *)3;
946 rc
= ui_list_entry_append(list
, &attr
, &e3
);
947 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
949 e
= ui_list_first(list
);
950 PCUT_ASSERT_EQUALS(e1
, e
);
952 /* Moving first entry up should have no effect */
953 ui_list_entry_move_up(e1
);
955 e
= ui_list_first(list
);
956 PCUT_ASSERT_EQUALS(e1
, e
);
959 PCUT_ASSERT_EQUALS(e2
, e
);
962 PCUT_ASSERT_EQUALS(e3
, e
);
967 /* Move second entry up */
968 ui_list_entry_move_up(e2
);
970 e
= ui_list_first(list
);
971 PCUT_ASSERT_EQUALS(e2
, e
);
974 PCUT_ASSERT_EQUALS(e1
, e
);
977 PCUT_ASSERT_EQUALS(e3
, e
);
982 ui_list_destroy(list
);
983 ui_window_destroy(window
);
987 /** ui_list_entry_move_down() moves entry down */
988 PCUT_TEST(entry_move_down
)
992 ui_wnd_params_t params
;
994 ui_list_entry_attr_t attr
;
995 ui_list_entry_t
*e1
, *e2
, *e3
;
999 rc
= ui_create_disp(NULL
, &ui
);
1000 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1002 ui_wnd_params_init(¶ms
);
1003 params
.caption
= "Test";
1005 rc
= ui_window_create(ui
, ¶ms
, &window
);
1006 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1008 rc
= ui_list_create(window
, true, &list
);
1009 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1011 ui_list_entry_attr_init(&attr
);
1013 /* Create entries */
1016 attr
.arg
= (void *)1;
1017 rc
= ui_list_entry_append(list
, &attr
, &e1
);
1018 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1021 attr
.arg
= (void *)2;
1022 rc
= ui_list_entry_append(list
, &attr
, &e2
);
1023 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1026 attr
.arg
= (void *)3;
1027 rc
= ui_list_entry_append(list
, &attr
, &e3
);
1028 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1030 e
= ui_list_first(list
);
1031 PCUT_ASSERT_EQUALS(e1
, e
);
1033 /* Moving last entry down should have no effect */
1034 ui_list_entry_move_down(e3
);
1036 e
= ui_list_first(list
);
1037 PCUT_ASSERT_EQUALS(e1
, e
);
1039 e
= ui_list_next(e
);
1040 PCUT_ASSERT_EQUALS(e2
, e
);
1042 e
= ui_list_next(e
);
1043 PCUT_ASSERT_EQUALS(e3
, e
);
1045 e
= ui_list_next(e
);
1046 PCUT_ASSERT_NULL(e
);
1048 /* Move second-to-last entry down */
1049 ui_list_entry_move_down(e2
);
1051 e
= ui_list_first(list
);
1052 PCUT_ASSERT_EQUALS(e1
, e
);
1054 e
= ui_list_next(e
);
1055 PCUT_ASSERT_EQUALS(e3
, e
);
1057 e
= ui_list_next(e
);
1058 PCUT_ASSERT_EQUALS(e2
, e
);
1060 e
= ui_list_next(e
);
1061 PCUT_ASSERT_NULL(e
);
1063 ui_list_destroy(list
);
1064 ui_window_destroy(window
);
1068 /** ui_list_entry_delete() deletes entry */
1069 PCUT_TEST(entry_delete
)
1072 ui_window_t
*window
;
1073 ui_wnd_params_t params
;
1075 ui_list_entry_t
*entry
;
1076 ui_list_entry_attr_t attr
;
1079 rc
= ui_create_disp(NULL
, &ui
);
1080 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1082 ui_wnd_params_init(¶ms
);
1083 params
.caption
= "Test";
1085 rc
= ui_window_create(ui
, ¶ms
, &window
);
1086 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1088 rc
= ui_list_create(window
, true, &list
);
1089 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1092 attr
.arg
= (void *)1;
1093 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1094 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1097 attr
.arg
= (void *)2;
1098 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1099 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1101 PCUT_ASSERT_INT_EQUALS(2, list_count(&list
->entries
));
1103 entry
= ui_list_first(list
);
1104 ui_list_entry_delete(entry
);
1106 PCUT_ASSERT_INT_EQUALS(1, list_count(&list
->entries
));
1108 entry
= ui_list_first(list
);
1109 ui_list_entry_delete(entry
);
1111 PCUT_ASSERT_INT_EQUALS(0, list_count(&list
->entries
));
1113 ui_list_destroy(list
);
1114 ui_window_destroy(window
);
1118 /** ui_list_entry_get_arg() gets entry argument */
1119 PCUT_TEST(entry_get_arg
)
1122 ui_window_t
*window
;
1123 ui_wnd_params_t params
;
1125 ui_list_entry_attr_t attr
;
1126 ui_list_entry_t
*entry
;
1130 rc
= ui_create_disp(NULL
, &ui
);
1131 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1133 ui_wnd_params_init(¶ms
);
1134 params
.caption
= "Test";
1136 rc
= ui_window_create(ui
, ¶ms
, &window
);
1137 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1139 rc
= ui_list_create(window
, true, &list
);
1140 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1142 ui_list_entry_attr_init(&attr
);
1144 /* Append entry and get pointer to it */
1146 attr
.arg
= (void *)1;
1148 rc
= ui_list_entry_append(list
, &attr
, &entry
);
1149 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1150 PCUT_ASSERT_NOT_NULL(entry
);
1152 arg
= ui_list_entry_get_arg(entry
);
1153 PCUT_ASSERT_EQUALS(attr
.arg
, arg
);
1155 ui_list_destroy(list
);
1156 ui_window_destroy(window
);
1160 /** ui_list_entry_get_list() returns the containing list */
1161 PCUT_TEST(entry_get_list
)
1164 ui_window_t
*window
;
1165 ui_wnd_params_t params
;
1168 ui_list_entry_attr_t attr
;
1169 ui_list_entry_t
*entry
;
1172 rc
= ui_create_disp(NULL
, &ui
);
1173 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1175 ui_wnd_params_init(¶ms
);
1176 params
.caption
= "Test";
1178 rc
= ui_window_create(ui
, ¶ms
, &window
);
1179 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1181 rc
= ui_list_create(window
, true, &list
);
1182 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1184 ui_list_entry_attr_init(&attr
);
1186 /* Append entry and get pointer to it */
1188 attr
.arg
= (void *)1;
1190 rc
= ui_list_entry_append(list
, &attr
, &entry
);
1191 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1192 PCUT_ASSERT_NOT_NULL(entry
);
1194 /* Get the containing list */
1195 elist
= ui_list_entry_get_list(entry
);
1196 PCUT_ASSERT_EQUALS(list
, elist
);
1198 ui_list_destroy(list
);
1199 ui_window_destroy(window
);
1203 /** ui_list_entry_set_caption() sets entry captino */
1204 PCUT_TEST(entry_set_caption
)
1207 ui_window_t
*window
;
1208 ui_wnd_params_t params
;
1210 ui_list_entry_attr_t attr
;
1211 ui_list_entry_t
*entry
;
1214 rc
= ui_create_disp(NULL
, &ui
);
1215 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1217 ui_wnd_params_init(¶ms
);
1218 params
.caption
= "Test";
1220 rc
= ui_window_create(ui
, ¶ms
, &window
);
1221 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1223 rc
= ui_list_create(window
, true, &list
);
1224 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1226 ui_list_entry_attr_init(&attr
);
1228 /* Append entry and get pointer to it */
1230 attr
.arg
= (void *)1;
1232 rc
= ui_list_entry_append(list
, &attr
, &entry
);
1233 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1234 PCUT_ASSERT_NOT_NULL(entry
);
1236 /* Change caption */
1237 rc
= ui_list_entry_set_caption(entry
, "b");
1238 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1239 PCUT_ASSERT_STR_EQUALS("b", entry
->caption
);
1241 ui_list_destroy(list
);
1242 ui_window_destroy(window
);
1246 /** ui_list_entries_cnt() returns the number of entries */
1247 PCUT_TEST(entries_cnt
)
1250 ui_window_t
*window
;
1251 ui_wnd_params_t params
;
1253 ui_list_entry_attr_t attr
;
1256 rc
= ui_create_disp(NULL
, &ui
);
1257 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1259 ui_wnd_params_init(¶ms
);
1260 params
.caption
= "Test";
1262 rc
= ui_window_create(ui
, ¶ms
, &window
);
1263 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1265 rc
= ui_list_create(window
, true, &list
);
1266 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1268 PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(list
));
1270 ui_list_entry_attr_init(&attr
);
1274 attr
.arg
= (void *)1;
1275 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1276 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1278 PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(list
));
1280 /* Append another entry */
1282 attr
.arg
= (void *)2;
1283 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1284 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1286 PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(list
));
1288 ui_list_destroy(list
);
1289 ui_window_destroy(window
);
1293 /** ui_list_sort() sorts UI list entries */
1297 ui_window_t
*window
;
1298 ui_wnd_params_t params
;
1300 ui_list_entry_t
*entry
;
1301 ui_list_entry_attr_t attr
;
1305 rc
= ui_create_disp(NULL
, &ui
);
1306 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1308 ui_wnd_params_init(¶ms
);
1309 params
.caption
= "Test";
1311 rc
= ui_window_create(ui
, ¶ms
, &window
);
1312 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1314 rc
= ui_list_create(window
, true, &list
);
1315 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1317 ui_list_set_cb(list
, &test_cb
, &resp
);
1319 ui_list_entry_attr_init(&attr
);
1322 attr
.arg
= (void *)1;
1323 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1324 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1327 attr
.arg
= (void *)3;
1328 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1329 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1332 attr
.arg
= (void *)2;
1333 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1334 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1336 rc
= ui_list_sort(list
);
1337 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1339 entry
= ui_list_first(list
);
1340 PCUT_ASSERT_STR_EQUALS("a", entry
->caption
);
1341 PCUT_ASSERT_EQUALS((void *)2, entry
->arg
);
1343 entry
= ui_list_next(entry
);
1344 PCUT_ASSERT_STR_EQUALS("b", entry
->caption
);
1345 PCUT_ASSERT_EQUALS((void *)1, entry
->arg
);
1347 entry
= ui_list_next(entry
);
1348 PCUT_ASSERT_STR_EQUALS("c", entry
->caption
);
1349 PCUT_ASSERT_EQUALS((void *)3, entry
->arg
);
1351 ui_list_destroy(list
);
1352 ui_window_destroy(window
);
1356 /** ui_list_cursor_center()...XXX */
1357 PCUT_TEST(cursor_center
)
1360 ui_window_t
*window
;
1361 ui_wnd_params_t params
;
1363 ui_list_entry_t
*a
, *b
, *c
, *d
, *e
;
1364 ui_list_entry_attr_t attr
;
1369 rc
= ui_create_disp(NULL
, &ui
);
1370 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1372 ui_wnd_params_init(¶ms
);
1373 params
.caption
= "Test";
1375 rc
= ui_window_create(ui
, ¶ms
, &window
);
1376 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1378 rc
= ui_list_create(window
, true, &list
);
1379 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1381 ui_list_set_cb(list
, &test_cb
, &resp
);
1388 ui_list_set_rect(list
, &rect
);
1390 PCUT_ASSERT_INT_EQUALS(3, ui_list_page_size(list
));
1392 ui_list_entry_attr_init(&attr
);
1395 attr
.arg
= (void *)1;
1396 rc
= ui_list_entry_append(list
, &attr
, &a
);
1397 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1400 attr
.arg
= (void *)2;
1401 rc
= ui_list_entry_append(list
, &attr
, &b
);
1402 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1404 /* We only have two entries, but three fit onto the page */
1405 ui_list_cursor_center(list
, b
);
1406 PCUT_ASSERT_EQUALS(b
, list
->cursor
);
1407 /* Page should start at the beginning */
1408 PCUT_ASSERT_EQUALS(a
, list
->page
);
1409 PCUT_ASSERT_EQUALS(0, list
->page_idx
);
1411 /* Add more entries */
1414 attr
.arg
= (void *)3;
1415 rc
= ui_list_entry_append(list
, &attr
, &c
);
1416 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1419 attr
.arg
= (void *)4;
1420 rc
= ui_list_entry_append(list
, &attr
, &d
);
1421 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1424 attr
.arg
= (void *)5;
1425 rc
= ui_list_entry_append(list
, &attr
, &e
);
1426 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1428 ui_list_cursor_center(list
, c
);
1429 PCUT_ASSERT_EQUALS(c
, list
->cursor
);
1431 * We have enough entries, c should be in the middle of the three
1432 * entries on the page, i.e., page should start on 'b'.
1434 PCUT_ASSERT_EQUALS(b
, list
->page
);
1435 PCUT_ASSERT_EQUALS(1, list
->page_idx
);
1437 ui_list_destroy(list
);
1438 ui_window_destroy(window
);
1442 /** ui_list_clear_entries() removes all entries from list */
1443 PCUT_TEST(clear_entries
)
1446 ui_window_t
*window
;
1447 ui_wnd_params_t params
;
1449 ui_list_entry_attr_t attr
;
1452 rc
= ui_create_disp(NULL
, &ui
);
1453 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1455 ui_wnd_params_init(¶ms
);
1456 params
.caption
= "Test";
1458 rc
= ui_window_create(ui
, ¶ms
, &window
);
1459 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1461 rc
= ui_list_create(window
, true, &list
);
1462 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1464 ui_list_entry_attr_init(&attr
);
1466 attr
.arg
= (void *)1;
1467 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1468 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1471 attr
.arg
= (void *)2;
1472 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1473 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1475 PCUT_ASSERT_INT_EQUALS(2, list_count(&list
->entries
));
1477 ui_list_clear_entries(list
);
1478 PCUT_ASSERT_INT_EQUALS(0, list_count(&list
->entries
));
1480 ui_list_destroy(list
);
1481 ui_window_destroy(window
);
1485 /** ui_list_first() returns valid entry or @c NULL as appropriate */
1489 ui_window_t
*window
;
1490 ui_wnd_params_t params
;
1492 ui_list_entry_t
*entry
;
1493 ui_list_entry_attr_t attr
;
1496 rc
= ui_create_disp(NULL
, &ui
);
1497 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1499 ui_wnd_params_init(¶ms
);
1500 params
.caption
= "Test";
1502 rc
= ui_window_create(ui
, ¶ms
, &window
);
1503 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1505 rc
= ui_list_create(window
, true, &list
);
1506 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1508 ui_list_entry_attr_init(&attr
);
1510 entry
= ui_list_first(list
);
1511 PCUT_ASSERT_NULL(entry
);
1515 attr
.arg
= (void *)1;
1516 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1517 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1519 /* Now try getting it */
1520 entry
= ui_list_first(list
);
1521 PCUT_ASSERT_NOT_NULL(entry
);
1522 PCUT_ASSERT_STR_EQUALS("a", entry
->caption
);
1523 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry
->arg
);
1525 /* Add another entry */
1527 attr
.arg
= (void *)2;
1528 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1529 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1531 /* We should still get the first entry */
1532 entry
= ui_list_first(list
);
1533 PCUT_ASSERT_NOT_NULL(entry
);
1534 PCUT_ASSERT_STR_EQUALS("a", entry
->caption
);
1535 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry
->arg
);
1537 ui_list_destroy(list
);
1538 ui_window_destroy(window
);
1542 /** ui_list_last() returns valid entry or @c NULL as appropriate */
1546 ui_window_t
*window
;
1547 ui_wnd_params_t params
;
1549 ui_list_entry_t
*entry
;
1550 ui_list_entry_attr_t attr
;
1553 rc
= ui_create_disp(NULL
, &ui
);
1554 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1556 ui_wnd_params_init(¶ms
);
1557 params
.caption
= "Test";
1559 rc
= ui_window_create(ui
, ¶ms
, &window
);
1560 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1562 rc
= ui_list_create(window
, true, &list
);
1563 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1565 ui_list_entry_attr_init(&attr
);
1567 entry
= ui_list_last(list
);
1568 PCUT_ASSERT_NULL(entry
);
1572 attr
.arg
= (void *)1;
1573 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1574 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1576 /* Now try getting it */
1577 entry
= ui_list_last(list
);
1578 PCUT_ASSERT_NOT_NULL(entry
);
1579 PCUT_ASSERT_STR_EQUALS("a", entry
->caption
);
1580 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry
->arg
);
1582 /* Add another entry */
1584 attr
.arg
= (void *)2;
1585 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1586 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1588 /* We should get new entry now */
1589 entry
= ui_list_last(list
);
1590 PCUT_ASSERT_NOT_NULL(entry
);
1592 attr
.arg
= (void *)2;
1593 PCUT_ASSERT_STR_EQUALS("b", entry
->caption
);
1594 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)entry
->arg
);
1596 ui_list_destroy(list
);
1597 ui_window_destroy(window
);
1601 /** ui_list_next() returns the next entry or @c NULL as appropriate */
1605 ui_window_t
*window
;
1606 ui_wnd_params_t params
;
1608 ui_list_entry_t
*entry
;
1609 ui_list_entry_attr_t attr
;
1612 rc
= ui_create_disp(NULL
, &ui
);
1613 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1615 ui_wnd_params_init(¶ms
);
1616 params
.caption
= "Test";
1618 rc
= ui_window_create(ui
, ¶ms
, &window
);
1619 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1621 rc
= ui_list_create(window
, true, &list
);
1622 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1624 ui_list_entry_attr_init(&attr
);
1628 attr
.arg
= (void *)1;
1629 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1630 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1632 /* Now try getting its successor */
1633 entry
= ui_list_first(list
);
1634 PCUT_ASSERT_NOT_NULL(entry
);
1636 entry
= ui_list_next(entry
);
1637 PCUT_ASSERT_NULL(entry
);
1639 /* Add another entry */
1641 attr
.arg
= (void *)2;
1642 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1643 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1645 /* Try getting the successor of first entry again */
1646 entry
= ui_list_first(list
);
1647 PCUT_ASSERT_NOT_NULL(entry
);
1649 entry
= ui_list_next(entry
);
1650 PCUT_ASSERT_NOT_NULL(entry
);
1651 PCUT_ASSERT_STR_EQUALS("b", entry
->caption
);
1652 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)entry
->arg
);
1654 ui_list_destroy(list
);
1655 ui_window_destroy(window
);
1659 /** ui_list_prev() returns the previous entry or @c NULL as appropriate */
1663 ui_window_t
*window
;
1664 ui_wnd_params_t params
;
1666 ui_list_entry_t
*entry
;
1667 ui_list_entry_attr_t attr
;
1670 rc
= ui_create_disp(NULL
, &ui
);
1671 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1673 ui_wnd_params_init(¶ms
);
1674 params
.caption
= "Test";
1676 rc
= ui_window_create(ui
, ¶ms
, &window
);
1677 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1679 rc
= ui_list_create(window
, true, &list
);
1680 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1682 ui_list_entry_attr_init(&attr
);
1686 attr
.arg
= (void *)1;
1687 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1688 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1690 /* Now try getting its predecessor */
1691 entry
= ui_list_last(list
);
1692 PCUT_ASSERT_NOT_NULL(entry
);
1694 entry
= ui_list_prev(entry
);
1695 PCUT_ASSERT_NULL(entry
);
1697 /* Add another entry */
1699 attr
.arg
= (void *)2;
1700 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1701 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1703 /* Try getting the predecessor of the new entry */
1704 entry
= ui_list_last(list
);
1705 PCUT_ASSERT_NOT_NULL(entry
);
1707 entry
= ui_list_prev(entry
);
1708 PCUT_ASSERT_NOT_NULL(entry
);
1709 PCUT_ASSERT_STR_EQUALS("a", entry
->caption
);
1710 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry
->arg
);
1712 ui_list_destroy(list
);
1713 ui_window_destroy(window
);
1717 /** ui_list_page_nth_entry() .. */
1718 PCUT_TEST(page_nth_entry
)
1721 ui_window_t
*window
;
1722 ui_wnd_params_t params
;
1724 ui_list_entry_t
*entry
;
1725 ui_list_entry_attr_t attr
;
1730 rc
= ui_create_disp(NULL
, &ui
);
1731 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1733 ui_wnd_params_init(¶ms
);
1734 params
.caption
= "Test";
1736 rc
= ui_window_create(ui
, ¶ms
, &window
);
1737 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1739 rc
= ui_list_create(window
, true, &list
);
1740 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1742 ui_list_entry_attr_init(&attr
);
1744 /* Add some entries */
1746 attr
.arg
= (void *)1;
1747 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1748 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1751 attr
.arg
= (void *)2;
1752 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1753 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1756 attr
.arg
= (void *)3;
1757 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1758 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1760 list
->page
= ui_list_next(ui_list_first(list
));
1767 ui_list_set_rect(list
, &rect
);
1769 entry
= ui_list_page_nth_entry(list
, 0, &idx
);
1770 PCUT_ASSERT_NOT_NULL(entry
);
1771 PCUT_ASSERT_STR_EQUALS("b", entry
->caption
);
1772 PCUT_ASSERT_INT_EQUALS(1, idx
);
1774 entry
= ui_list_page_nth_entry(list
, 1, &idx
);
1775 PCUT_ASSERT_NOT_NULL(entry
);
1776 PCUT_ASSERT_STR_EQUALS("c", entry
->caption
);
1777 PCUT_ASSERT_INT_EQUALS(2, idx
);
1779 entry
= ui_list_page_nth_entry(list
, 2, &idx
);
1780 PCUT_ASSERT_NULL(entry
);
1782 ui_list_destroy(list
);
1783 ui_window_destroy(window
);
1787 /** ui_list_cursor_move() moves cursor and scrolls */
1788 PCUT_TEST(cursor_move
)
1791 ui_window_t
*window
;
1792 ui_wnd_params_t params
;
1794 ui_list_entry_attr_t attr
;
1797 rc
= ui_create_disp(NULL
, &ui
);
1798 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1800 ui_wnd_params_init(¶ms
);
1801 params
.caption
= "Test";
1803 rc
= ui_window_create(ui
, ¶ms
, &window
);
1804 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1806 rc
= ui_list_create(window
, true, &list
);
1807 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1812 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
1813 ui_list_set_rect(list
, &rect
);
1815 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
1817 /* Add tree entries (more than page size, which is 2) */
1819 ui_list_entry_attr_init(&attr
);
1822 attr
.arg
= (void *)1;
1823 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1824 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1827 attr
.arg
= (void *)2;
1828 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1829 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1832 attr
.arg
= (void *)3;
1833 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1834 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1836 /* Cursor to the last entry and page start to the next-to-last entry */
1837 list
->cursor
= ui_list_last(list
);
1838 list
->cursor_idx
= 2;
1839 list
->page
= ui_list_prev(list
->cursor
);
1842 /* Move cursor one entry up */
1843 ui_list_cursor_move(list
, ui_list_prev(list
->cursor
),
1844 list
->cursor_idx
- 1);
1846 /* Cursor and page start should now both be at the second entry */
1847 PCUT_ASSERT_STR_EQUALS("b", list
->cursor
->caption
);
1848 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->cursor
->arg
);
1849 PCUT_ASSERT_INT_EQUALS(1, list
->cursor_idx
);
1850 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
1851 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
1853 /* Move cursor to the first entry. This should scroll up. */
1854 ui_list_cursor_move(list
, ui_list_first(list
), 0);
1856 /* Cursor and page start should now both be at the first entry */
1857 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
1858 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
1859 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
1860 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
1861 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
1863 /* Move cursor to the last entry. */
1864 ui_list_cursor_move(list
, ui_list_last(list
), 2);
1866 /* Cursor should be on the last entry and page on the next to last */
1867 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
1868 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
1869 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
1870 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
1871 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
1872 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
1874 ui_list_destroy(list
);
1875 ui_window_destroy(window
);
1879 /** ui_list_cursor_up() moves cursor one entry up */
1880 PCUT_TEST(cursor_up
)
1883 ui_window_t
*window
;
1884 ui_wnd_params_t params
;
1886 ui_list_entry_attr_t attr
;
1889 rc
= ui_create_disp(NULL
, &ui
);
1890 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1892 ui_wnd_params_init(¶ms
);
1893 params
.caption
= "Test";
1895 rc
= ui_window_create(ui
, ¶ms
, &window
);
1896 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1898 rc
= ui_list_create(window
, true, &list
);
1899 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1904 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
1905 ui_list_set_rect(list
, &rect
);
1907 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
1909 /* Add tree entries (more than page size, which is 2) */
1911 ui_list_entry_attr_init(&attr
);
1914 attr
.arg
= (void *)1;
1915 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1916 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1919 attr
.arg
= (void *)2;
1920 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1921 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1924 attr
.arg
= (void *)3;
1925 rc
= ui_list_entry_append(list
, &attr
, NULL
);
1926 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1928 /* Cursor to the last entry and page start to the next-to-last entry */
1929 list
->cursor
= ui_list_last(list
);
1930 list
->cursor_idx
= 2;
1931 list
->page
= ui_list_prev(list
->cursor
);
1934 /* Move cursor one entry up */
1935 ui_list_cursor_up(list
);
1937 /* Cursor and page start should now both be at the second entry */
1938 PCUT_ASSERT_STR_EQUALS("b", list
->cursor
->caption
);
1939 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->cursor
->arg
);
1940 PCUT_ASSERT_INT_EQUALS(1, list
->cursor_idx
);
1941 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
1942 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
1944 /* Move cursor one entry up. This should scroll up. */
1945 ui_list_cursor_up(list
);
1947 /* Cursor and page start should now both be at the first entry */
1948 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
1949 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
1950 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
1951 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
1952 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
1954 /* Moving further up should do nothing (we are at the top). */
1955 ui_list_cursor_up(list
);
1957 /* Cursor and page start should still be at the first entry */
1958 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
1959 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
1960 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
1961 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
1962 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
1964 ui_list_destroy(list
);
1965 ui_window_destroy(window
);
1969 /** ui_list_cursor_down() moves cursor one entry down */
1970 PCUT_TEST(cursor_down
)
1973 ui_window_t
*window
;
1974 ui_wnd_params_t params
;
1976 ui_list_entry_attr_t attr
;
1980 rc
= ui_create_disp(NULL
, &ui
);
1981 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1983 ui_wnd_params_init(¶ms
);
1984 params
.caption
= "Test";
1986 rc
= ui_window_create(ui
, ¶ms
, &window
);
1987 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1989 rc
= ui_list_create(window
, true, &list
);
1990 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1995 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
1996 ui_list_set_rect(list
, &rect
);
1998 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2000 /* Add tree entries (more than page size, which is 2) */
2002 ui_list_entry_attr_init(&attr
);
2005 attr
.arg
= (void *)1;
2006 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2007 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2010 attr
.arg
= (void *)2;
2011 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2012 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2015 attr
.arg
= (void *)3;
2016 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2017 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2019 /* Cursor and page start to the first entry */
2020 list
->cursor
= ui_list_first(list
);
2021 list
->cursor_idx
= 0;
2022 list
->page
= list
->cursor
;
2025 /* Move cursor one entry down */
2026 ui_list_cursor_down(list
);
2028 /* Cursor should now be at the second entry, page stays the same */
2029 PCUT_ASSERT_STR_EQUALS("b", list
->cursor
->caption
);
2030 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->cursor
->arg
);
2031 PCUT_ASSERT_INT_EQUALS(1, list
->cursor_idx
);
2032 PCUT_ASSERT_EQUALS(ui_list_first(list
), list
->page
);
2033 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2035 /* Move cursor one entry down. This should scroll down. */
2036 ui_list_cursor_down(list
);
2038 /* Cursor should now be at the third and page at the second entry. */
2039 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2040 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2041 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2042 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2043 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2044 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2046 /* Moving further down should do nothing (we are at the bottom). */
2047 ui_list_cursor_down(list
);
2049 /* Cursor should still be at the third and page at the second entry. */
2050 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2051 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2052 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2053 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2054 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2055 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2057 ui_list_destroy(list
);
2058 ui_window_destroy(window
);
2062 /** ui_list_cursor_top() moves cursor to the first entry */
2063 PCUT_TEST(cursor_top
)
2066 ui_window_t
*window
;
2067 ui_wnd_params_t params
;
2069 ui_list_entry_attr_t attr
;
2073 rc
= ui_create_disp(NULL
, &ui
);
2074 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2076 ui_wnd_params_init(¶ms
);
2077 params
.caption
= "Test";
2079 rc
= ui_window_create(ui
, ¶ms
, &window
);
2080 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2082 rc
= ui_list_create(window
, true, &list
);
2083 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2088 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2089 ui_list_set_rect(list
, &rect
);
2091 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2093 /* Add tree entries (more than page size, which is 2) */
2095 ui_list_entry_attr_init(&attr
);
2098 attr
.arg
= (void *)1;
2099 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2100 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2103 attr
.arg
= (void *)2;
2104 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2105 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2108 attr
.arg
= (void *)3;
2109 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2110 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2112 /* Cursor to the last entry and page start to the next-to-last entry */
2113 list
->cursor
= ui_list_last(list
);
2114 list
->cursor_idx
= 2;
2115 list
->page
= ui_list_prev(list
->cursor
);
2118 /* Move cursor to the top. This should scroll up. */
2119 ui_list_cursor_top(list
);
2121 /* Cursor and page start should now both be at the first entry */
2122 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2123 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2124 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2125 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
2126 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2128 ui_list_destroy(list
);
2129 ui_window_destroy(window
);
2133 /** ui_list_cursor_bottom() moves cursor to the last entry */
2134 PCUT_TEST(cursor_bottom
)
2137 ui_window_t
*window
;
2138 ui_wnd_params_t params
;
2140 ui_list_entry_attr_t attr
;
2144 rc
= ui_create_disp(NULL
, &ui
);
2145 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2147 ui_wnd_params_init(¶ms
);
2148 params
.caption
= "Test";
2150 rc
= ui_window_create(ui
, ¶ms
, &window
);
2151 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2153 rc
= ui_list_create(window
, true, &list
);
2154 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2159 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2160 ui_list_set_rect(list
, &rect
);
2162 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2164 /* Add tree entries (more than page size, which is 2) */
2166 ui_list_entry_attr_init(&attr
);
2169 attr
.arg
= (void *)1;
2170 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2171 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2174 attr
.arg
= (void *)2;
2175 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2176 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2179 attr
.arg
= (void *)3;
2180 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2181 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2183 /* Cursor and page start to the first entry */
2184 list
->cursor
= ui_list_first(list
);
2185 list
->cursor_idx
= 0;
2186 list
->page
= list
->cursor
;
2189 /* Move cursor to the bottom. This should scroll down. */
2190 ui_list_cursor_bottom(list
);
2192 /* Cursor should now be at the third and page at the second entry. */
2193 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2194 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2195 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2196 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2197 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2198 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2200 ui_list_destroy(list
);
2201 ui_window_destroy(window
);
2205 /** ui_list_page_up() moves one page up */
2209 ui_window_t
*window
;
2210 ui_wnd_params_t params
;
2212 ui_list_entry_attr_t attr
;
2216 rc
= ui_create_disp(NULL
, &ui
);
2217 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2219 ui_wnd_params_init(¶ms
);
2220 params
.caption
= "Test";
2222 rc
= ui_window_create(ui
, ¶ms
, &window
);
2223 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2225 rc
= ui_list_create(window
, true, &list
);
2226 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2231 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2232 ui_list_set_rect(list
, &rect
);
2234 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2236 /* Add five entries (2 full pages, one partial) */
2238 ui_list_entry_attr_init(&attr
);
2241 attr
.arg
= (void *)1;
2242 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2243 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2246 attr
.arg
= (void *)2;
2247 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2248 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2251 attr
.arg
= (void *)3;
2252 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2253 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2256 attr
.arg
= (void *)4;
2257 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2258 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2261 attr
.arg
= (void *)5;
2262 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2263 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2265 /* Cursor to the last entry and page start to the next-to-last entry */
2266 list
->cursor
= ui_list_last(list
);
2267 list
->cursor_idx
= 4;
2268 list
->page
= ui_list_prev(list
->cursor
);
2271 /* Move one page up */
2272 ui_list_page_up(list
);
2274 /* Page should now start at second entry and cursor at third */
2275 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2276 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2277 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2278 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2279 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2280 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2282 /* Move one page up again. */
2283 ui_list_page_up(list
);
2285 /* Cursor and page start should now both be at the first entry */
2286 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2287 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2288 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2289 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
2290 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2292 /* Moving further up should do nothing (we are at the top). */
2293 ui_list_page_up(list
);
2295 /* Cursor and page start should still be at the first entry */
2296 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2297 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2298 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2299 PCUT_ASSERT_EQUALS(list
->cursor
, list
->page
);
2300 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2302 ui_list_destroy(list
);
2303 ui_window_destroy(window
);
2307 /** ui_list_page_up() moves one page down */
2308 PCUT_TEST(page_down
)
2311 ui_window_t
*window
;
2312 ui_wnd_params_t params
;
2314 ui_list_entry_attr_t attr
;
2318 rc
= ui_create_disp(NULL
, &ui
);
2319 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2321 ui_wnd_params_init(¶ms
);
2322 params
.caption
= "Test";
2324 rc
= ui_window_create(ui
, ¶ms
, &window
);
2325 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2327 rc
= ui_list_create(window
, true, &list
);
2328 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2333 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2334 ui_list_set_rect(list
, &rect
);
2336 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2338 /* Add five entries (2 full pages, one partial) */
2340 ui_list_entry_attr_init(&attr
);
2343 attr
.arg
= (void *)1;
2344 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2345 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2348 attr
.arg
= (void *)2;
2349 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2350 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2353 attr
.arg
= (void *)3;
2354 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2355 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2358 attr
.arg
= (void *)4;
2359 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2360 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2363 attr
.arg
= (void *)5;
2364 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2365 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2367 /* Cursor and page to the first entry */
2368 list
->cursor
= ui_list_first(list
);
2369 list
->cursor_idx
= 0;
2370 list
->page
= list
->cursor
;
2373 /* Move one page down */
2374 ui_list_page_down(list
);
2376 /* Page and cursor should point to the third entry */
2377 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2378 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2379 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2380 PCUT_ASSERT_STR_EQUALS("c", list
->page
->caption
);
2381 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->page
->arg
);
2382 PCUT_ASSERT_INT_EQUALS(2, list
->page_idx
);
2384 /* Move one page down again. */
2385 ui_list_page_down(list
);
2387 /* Cursor should point to last and page to next-to-last entry */
2388 PCUT_ASSERT_STR_EQUALS("e", list
->cursor
->caption
);
2389 PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list
->cursor
->arg
);
2390 PCUT_ASSERT_INT_EQUALS(4, list
->cursor_idx
);
2391 PCUT_ASSERT_STR_EQUALS("d", list
->page
->caption
);
2392 PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list
->page
->arg
);
2393 PCUT_ASSERT_INT_EQUALS(3, list
->page_idx
);
2395 /* Moving further down should do nothing (we are at the bottom). */
2396 ui_list_page_down(list
);
2398 /* Cursor should still point to last and page to next-to-last entry */
2399 PCUT_ASSERT_STR_EQUALS("e", list
->cursor
->caption
);
2400 PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list
->cursor
->arg
);
2401 PCUT_ASSERT_INT_EQUALS(4, list
->cursor_idx
);
2402 PCUT_ASSERT_STR_EQUALS("d", list
->page
->caption
);
2403 PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list
->page
->arg
);
2404 PCUT_ASSERT_INT_EQUALS(3, list
->page_idx
);
2406 ui_list_destroy(list
);
2407 ui_window_destroy(window
);
2411 /** ui_list_scroll_up() scrolls up by one row */
2412 PCUT_TEST(scroll_up
)
2415 ui_window_t
*window
;
2416 ui_wnd_params_t params
;
2418 ui_list_entry_attr_t attr
;
2422 rc
= ui_create_disp(NULL
, &ui
);
2423 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2425 ui_wnd_params_init(¶ms
);
2426 params
.caption
= "Test";
2428 rc
= ui_window_create(ui
, ¶ms
, &window
);
2429 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2431 rc
= ui_list_create(window
, true, &list
);
2432 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2437 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2438 ui_list_set_rect(list
, &rect
);
2440 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2442 /* Add tree entries (more than page size, which is 2) */
2444 ui_list_entry_attr_init(&attr
);
2447 attr
.arg
= (void *)1;
2448 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2449 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2452 attr
.arg
= (void *)2;
2453 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2454 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2457 attr
.arg
= (void *)3;
2458 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2459 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2461 /* Cursor to the last entry, page to the second */
2462 list
->cursor
= ui_list_last(list
);
2463 list
->cursor_idx
= 2;
2464 list
->page
= ui_list_prev(list
->cursor
);
2467 /* Scroll one entry up */
2468 ui_list_scroll_up(list
);
2470 /* Page should start on the first entry, cursor unchanged */
2471 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2472 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2473 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2474 PCUT_ASSERT_STR_EQUALS("a", list
->page
->caption
);
2475 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->page
->arg
);
2476 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2478 /* Try scrolling one more entry up */
2479 ui_list_scroll_up(list
);
2481 /* We were at the beginning, so nothing should have changed */
2482 PCUT_ASSERT_STR_EQUALS("c", list
->cursor
->caption
);
2483 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->cursor
->arg
);
2484 PCUT_ASSERT_INT_EQUALS(2, list
->cursor_idx
);
2485 PCUT_ASSERT_STR_EQUALS("a", list
->page
->caption
);
2486 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->page
->arg
);
2487 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2489 ui_list_destroy(list
);
2490 ui_window_destroy(window
);
2494 /** ui_list_scroll_down() scrolls down by one row */
2495 PCUT_TEST(scroll_down
)
2498 ui_window_t
*window
;
2499 ui_wnd_params_t params
;
2501 ui_list_entry_attr_t attr
;
2505 rc
= ui_create_disp(NULL
, &ui
);
2506 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2508 ui_wnd_params_init(¶ms
);
2509 params
.caption
= "Test";
2511 rc
= ui_window_create(ui
, ¶ms
, &window
);
2512 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2514 rc
= ui_list_create(window
, true, &list
);
2515 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2520 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2521 ui_list_set_rect(list
, &rect
);
2523 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2525 /* Add tree entries (more than page size, which is 2) */
2527 ui_list_entry_attr_init(&attr
);
2530 attr
.arg
= (void *)1;
2531 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2532 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2535 attr
.arg
= (void *)2;
2536 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2537 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2540 attr
.arg
= (void *)3;
2541 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2542 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2544 /* Cursor and page start to the first entry */
2545 list
->cursor
= ui_list_first(list
);
2546 list
->cursor_idx
= 0;
2547 list
->page
= list
->cursor
;
2550 /* Scroll one entry down */
2551 ui_list_scroll_down(list
);
2553 /* Page should start on the second entry, cursor unchanged */
2554 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2555 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2556 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2557 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2558 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2559 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2561 /* Try scrolling one more entry down */
2562 ui_list_scroll_down(list
);
2564 /* We were at the end, so nothing should have changed */
2565 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2566 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2567 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2568 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2569 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2570 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2572 ui_list_destroy(list
);
2573 ui_window_destroy(window
);
2577 /** ui_list_scroll_page_up() scrolls up by one page */
2578 PCUT_TEST(scroll_page_up
)
2581 ui_window_t
*window
;
2582 ui_wnd_params_t params
;
2584 ui_list_entry_attr_t attr
;
2588 rc
= ui_create_disp(NULL
, &ui
);
2589 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2591 ui_wnd_params_init(¶ms
);
2592 params
.caption
= "Test";
2594 rc
= ui_window_create(ui
, ¶ms
, &window
);
2595 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2597 rc
= ui_list_create(window
, true, &list
);
2598 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2603 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2604 ui_list_set_rect(list
, &rect
);
2606 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2608 /* Add five entries (more than twice the page size, which is 2) */
2610 ui_list_entry_attr_init(&attr
);
2613 attr
.arg
= (void *)1;
2614 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2615 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2618 attr
.arg
= (void *)2;
2619 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2620 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2623 attr
.arg
= (void *)3;
2624 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2625 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2628 attr
.arg
= (void *)4;
2629 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2630 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2633 attr
.arg
= (void *)5;
2634 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2635 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2637 /* Cursor to the last entry, page to the second last */
2638 list
->cursor
= ui_list_last(list
);
2639 list
->cursor_idx
= 4;
2640 list
->page
= ui_list_prev(list
->cursor
);
2643 /* Scroll one page up */
2644 ui_list_scroll_page_up(list
);
2646 /* Page should start on 'b', cursor unchanged */
2647 PCUT_ASSERT_STR_EQUALS("e", list
->cursor
->caption
);
2648 PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list
->cursor
->arg
);
2649 PCUT_ASSERT_INT_EQUALS(4, list
->cursor_idx
);
2650 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2651 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2652 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2655 ui_list_scroll_page_up(list
);
2657 /* Page should now be at the beginning, cursor unchanged */
2658 PCUT_ASSERT_STR_EQUALS("e", list
->cursor
->caption
);
2659 PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list
->cursor
->arg
);
2660 PCUT_ASSERT_INT_EQUALS(4, list
->cursor_idx
);
2661 PCUT_ASSERT_STR_EQUALS("a", list
->page
->caption
);
2662 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->page
->arg
);
2663 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2666 ui_list_scroll_page_up(list
);
2668 /* We were at the beginning, nothing should have changed */
2669 PCUT_ASSERT_STR_EQUALS("e", list
->cursor
->caption
);
2670 PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list
->cursor
->arg
);
2671 PCUT_ASSERT_INT_EQUALS(4, list
->cursor_idx
);
2672 PCUT_ASSERT_STR_EQUALS("a", list
->page
->caption
);
2673 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->page
->arg
);
2674 PCUT_ASSERT_INT_EQUALS(0, list
->page_idx
);
2676 ui_list_destroy(list
);
2677 ui_window_destroy(window
);
2681 /** ui_list_scroll_page_up() scrolls down by one page */
2682 PCUT_TEST(scroll_page_down
)
2685 ui_window_t
*window
;
2686 ui_wnd_params_t params
;
2688 ui_list_entry_attr_t attr
;
2692 rc
= ui_create_disp(NULL
, &ui
);
2693 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2695 ui_wnd_params_init(¶ms
);
2696 params
.caption
= "Test";
2698 rc
= ui_window_create(ui
, ¶ms
, &window
);
2699 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2701 rc
= ui_list_create(window
, true, &list
);
2702 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2707 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2708 ui_list_set_rect(list
, &rect
);
2710 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2712 /* Add five entries (more than twice the page size, which is 2) */
2714 ui_list_entry_attr_init(&attr
);
2717 attr
.arg
= (void *)1;
2718 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2719 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2722 attr
.arg
= (void *)2;
2723 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2724 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2727 attr
.arg
= (void *)3;
2728 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2729 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2732 attr
.arg
= (void *)4;
2733 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2734 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2737 attr
.arg
= (void *)5;
2738 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2739 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2741 /* Cursor and page to the first entry */
2742 list
->cursor
= ui_list_first(list
);
2743 list
->cursor_idx
= 0;
2744 list
->page
= ui_list_first(list
);
2747 /* Scroll one page down */
2748 ui_list_scroll_page_down(list
);
2750 /* Page should start on 'c', cursor unchanged */
2751 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2752 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2753 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2754 PCUT_ASSERT_STR_EQUALS("c", list
->page
->caption
);
2755 PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list
->page
->arg
);
2756 PCUT_ASSERT_INT_EQUALS(2, list
->page_idx
);
2758 /* Page down again */
2759 ui_list_scroll_page_down(list
);
2761 /* Page should now start at 'd', cursor unchanged */
2762 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2763 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2764 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2765 PCUT_ASSERT_STR_EQUALS("d", list
->page
->caption
);
2766 PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list
->page
->arg
);
2767 PCUT_ASSERT_INT_EQUALS(3, list
->page_idx
);
2769 /* Page down again */
2770 ui_list_scroll_page_down(list
);
2772 /* We were at the end, nothing should have changed */
2773 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2774 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2775 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2776 PCUT_ASSERT_STR_EQUALS("d", list
->page
->caption
);
2777 PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list
->page
->arg
);
2778 PCUT_ASSERT_INT_EQUALS(3, list
->page_idx
);
2780 ui_list_destroy(list
);
2781 ui_window_destroy(window
);
2785 /** ui_list_scroll_pos() scrolls to a particular entry */
2786 PCUT_TEST(scroll_pos
)
2789 ui_window_t
*window
;
2790 ui_wnd_params_t params
;
2792 ui_list_entry_attr_t attr
;
2796 rc
= ui_create_disp(NULL
, &ui
);
2797 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2799 ui_wnd_params_init(¶ms
);
2800 params
.caption
= "Test";
2802 rc
= ui_window_create(ui
, ¶ms
, &window
);
2803 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2805 rc
= ui_list_create(window
, true, &list
);
2806 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2811 rect
.p1
.y
= 38; /* Assuming this makes page size 2 */
2812 ui_list_set_rect(list
, &rect
);
2814 PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list
));
2816 /* Add five entries (more than twice the page size, which is 2) */
2818 ui_list_entry_attr_init(&attr
);
2821 attr
.arg
= (void *)1;
2822 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2823 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2826 attr
.arg
= (void *)2;
2827 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2828 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2831 attr
.arg
= (void *)3;
2832 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2833 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2836 attr
.arg
= (void *)4;
2837 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2838 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2841 attr
.arg
= (void *)5;
2842 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2843 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2845 /* Cursor and page to the first entry */
2846 list
->cursor
= ui_list_first(list
);
2847 list
->cursor_idx
= 0;
2848 list
->page
= ui_list_first(list
);
2851 /* Scroll to entry 1 (one down) */
2852 ui_list_scroll_pos(list
, 1);
2854 /* Page should start on 'b', cursor unchanged */
2855 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2856 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2857 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2858 PCUT_ASSERT_STR_EQUALS("b", list
->page
->caption
);
2859 PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list
->page
->arg
);
2860 PCUT_ASSERT_INT_EQUALS(1, list
->page_idx
);
2862 /* Scroll to entry 3 (i.e. the end) */
2863 ui_list_scroll_pos(list
, 3);
2865 /* Page should now start at 'd', cursor unchanged */
2866 PCUT_ASSERT_STR_EQUALS("a", list
->cursor
->caption
);
2867 PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list
->cursor
->arg
);
2868 PCUT_ASSERT_INT_EQUALS(0, list
->cursor_idx
);
2869 PCUT_ASSERT_STR_EQUALS("d", list
->page
->caption
);
2870 PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list
->page
->arg
);
2871 PCUT_ASSERT_INT_EQUALS(3, list
->page_idx
);
2873 ui_list_destroy(list
);
2874 ui_window_destroy(window
);
2878 /** ui_list_activate_req() sends activation request */
2879 PCUT_TEST(activate_req
)
2882 ui_window_t
*window
;
2883 ui_wnd_params_t params
;
2888 rc
= ui_create_disp(NULL
, &ui
);
2889 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2891 ui_wnd_params_init(¶ms
);
2892 params
.caption
= "Test";
2894 rc
= ui_window_create(ui
, ¶ms
, &window
);
2895 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2897 rc
= ui_list_create(window
, true, &list
);
2898 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2900 ui_list_set_cb(list
, &test_cb
, &resp
);
2902 resp
.activate_req
= false;
2903 resp
.activate_req_list
= NULL
;
2905 ui_list_activate_req(list
);
2906 PCUT_ASSERT_TRUE(resp
.activate_req
);
2907 PCUT_ASSERT_EQUALS(list
, resp
.activate_req_list
);
2909 ui_list_destroy(list
);
2910 ui_window_destroy(window
);
2914 /** ui_list_selected() runs selected callback */
2918 ui_window_t
*window
;
2919 ui_wnd_params_t params
;
2921 ui_list_entry_attr_t attr
;
2922 ui_list_entry_t
*entry
;
2926 rc
= ui_create_disp(NULL
, &ui
);
2927 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2929 ui_wnd_params_init(¶ms
);
2930 params
.caption
= "Test";
2932 rc
= ui_window_create(ui
, ¶ms
, &window
);
2933 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2935 rc
= ui_list_create(window
, true, &list
);
2936 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2938 ui_list_set_cb(list
, &test_cb
, &resp
);
2940 ui_list_entry_attr_init(&attr
);
2941 attr
.caption
= "Hello";
2944 rc
= ui_list_entry_append(list
, &attr
, &entry
);
2945 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2947 resp
.selected
= false;
2948 resp
.selected_entry
= NULL
;
2950 ui_list_selected(entry
);
2951 PCUT_ASSERT_TRUE(resp
.selected
);
2952 PCUT_ASSERT_EQUALS(entry
, resp
.selected_entry
);
2954 ui_list_destroy(list
);
2955 ui_window_destroy(window
);
2959 /** ui_list_entry_ptr_cmp compares two indirectly referenced entries */
2960 PCUT_TEST(entry_ptr_cmp
)
2963 ui_window_t
*window
;
2964 ui_wnd_params_t params
;
2966 ui_list_entry_t
*a
, *b
;
2967 ui_list_entry_attr_t attr
;
2972 rc
= ui_create_disp(NULL
, &ui
);
2973 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2975 ui_wnd_params_init(¶ms
);
2976 params
.caption
= "Test";
2978 rc
= ui_window_create(ui
, ¶ms
, &window
);
2979 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2981 rc
= ui_list_create(window
, true, &list
);
2982 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2984 ui_list_set_cb(list
, &test_cb
, &resp
);
2986 ui_list_entry_attr_init(&attr
);
2989 attr
.arg
= (void *)2;
2990 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2991 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2994 attr
.arg
= (void *)1;
2995 rc
= ui_list_entry_append(list
, &attr
, NULL
);
2996 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
2998 a
= ui_list_first(list
);
2999 PCUT_ASSERT_NOT_NULL(a
);
3000 b
= ui_list_next(a
);
3001 PCUT_ASSERT_NOT_NULL(b
);
3004 rel
= ui_list_entry_ptr_cmp(&a
, &b
);
3005 PCUT_ASSERT_TRUE(rel
< 0);
3008 rel
= ui_list_entry_ptr_cmp(&b
, &a
);
3009 PCUT_ASSERT_TRUE(rel
> 0);
3012 rel
= ui_list_entry_ptr_cmp(&a
, &a
);
3013 PCUT_ASSERT_INT_EQUALS(0, rel
);
3015 ui_list_destroy(list
);
3016 ui_window_destroy(window
);
3020 /** ui_list_entry_get_idx() returns entry index */
3021 PCUT_TEST(entry_get_idx
)
3024 ui_window_t
*window
;
3025 ui_wnd_params_t params
;
3027 ui_list_entry_t
*a
, *b
;
3028 ui_list_entry_attr_t attr
;
3032 rc
= ui_create_disp(NULL
, &ui
);
3033 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
3035 ui_wnd_params_init(¶ms
);
3036 params
.caption
= "Test";
3038 rc
= ui_window_create(ui
, ¶ms
, &window
);
3039 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
3041 rc
= ui_list_create(window
, true, &list
);
3042 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
3044 ui_list_set_cb(list
, &test_cb
, &resp
);
3046 ui_list_entry_attr_init(&attr
);
3049 attr
.arg
= (void *)2;
3050 rc
= ui_list_entry_append(list
, &attr
, &a
);
3051 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
3054 attr
.arg
= (void *)1;
3055 rc
= ui_list_entry_append(list
, &attr
, &b
);
3056 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
3058 PCUT_ASSERT_INT_EQUALS(0, ui_list_entry_get_idx(a
));
3059 PCUT_ASSERT_INT_EQUALS(1, ui_list_entry_get_idx(b
));
3061 ui_list_destroy(list
);
3062 ui_window_destroy(window
);
3066 static void test_list_activate_req(ui_list_t
*list
, void *arg
)
3068 test_resp_t
*resp
= (test_resp_t
*)arg
;
3070 resp
->activate_req
= true;
3071 resp
->activate_req_list
= list
;
3074 static void test_list_selected(ui_list_entry_t
*entry
, void *arg
)
3076 test_resp_t
*resp
= (test_resp_t
*)arg
;
3078 resp
->selected
= true;
3079 resp
->selected_entry
= entry
;
3082 static int test_list_compare(ui_list_entry_t
*a
, ui_list_entry_t
*b
)
3084 return str_cmp(a
->caption
, b
->caption
);