source: mainline/uspace/app/nav/test/panel.c@ 39ab17c

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 39ab17c was 39ab17c, checked in by jxsvoboda <5887334+jxsvoboda@…>, 4 years ago

Activating panel using the mouse

  • Property mode set to 100644
File size: 34.1 KB
Line 
1/*
2 * Copyright (c) 2021 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
16 *
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.
27 */
28
29#include <errno.h>
30#include <io/kbd_event.h>
31#include <io/pos_event.h>
32#include <pcut/pcut.h>
33#include <stdio.h>
34#include <ui/ui.h>
35#include <vfs/vfs.h>
36#include "../panel.h"
37
38PCUT_INIT;
39
40PCUT_TEST_SUITE(panel);
41
42/** Test response */
43typedef struct {
44 bool activate_req;
45 panel_t *activate_req_panel;
46} test_resp_t;
47
48static void test_panel_activate_req(void *, panel_t *);
49
50static panel_cb_t test_cb = {
51 .activate_req = test_panel_activate_req
52};
53
54/** Create and destroy panel. */
55PCUT_TEST(create_destroy)
56{
57 panel_t *panel;
58 errno_t rc;
59
60 rc = panel_create(NULL, true, &panel);
61 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
62
63 panel_destroy(panel);
64}
65
66/** panel_set_cb() sets callback */
67PCUT_TEST(set_cb)
68{
69 panel_t *panel;
70 errno_t rc;
71 test_resp_t resp;
72
73 rc = panel_create(NULL, true, &panel);
74 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
75
76 panel_set_cb(panel, &test_cb, &resp);
77 PCUT_ASSERT_EQUALS(&test_cb, panel->cb);
78 PCUT_ASSERT_EQUALS(&resp, panel->cb_arg);
79
80 panel_destroy(panel);
81}
82
83/** Test panel_entry_paint() */
84PCUT_TEST(entry_paint)
85{
86 ui_t *ui;
87 ui_window_t *window;
88 ui_wnd_params_t params;
89 panel_t *panel;
90 panel_entry_attr_t attr;
91 errno_t rc;
92
93 rc = ui_create_disp(NULL, &ui);
94 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
95
96 ui_wnd_params_init(&params);
97 params.caption = "Test";
98
99 rc = ui_window_create(ui, &params, &window);
100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
101
102 rc = panel_create(window, true, &panel);
103 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
104
105 panel_entry_attr_init(&attr);
106 attr.name = "a";
107 attr.size = 1;
108
109 rc = panel_entry_append(panel, &attr);
110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
111
112 rc = panel_entry_paint(panel_first(panel), 0);
113 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
114
115 panel_destroy(panel);
116 ui_window_destroy(window);
117 ui_destroy(ui);
118}
119
120/** Test panel_paint() */
121PCUT_TEST(paint)
122{
123 ui_t *ui;
124 ui_window_t *window;
125 ui_wnd_params_t params;
126 panel_t *panel;
127 errno_t rc;
128
129 rc = ui_create_disp(NULL, &ui);
130 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
131
132 ui_wnd_params_init(&params);
133 params.caption = "Test";
134
135 rc = ui_window_create(ui, &params, &window);
136 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
137
138 rc = panel_create(window, true, &panel);
139 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
140
141 rc = panel_paint(panel);
142 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
143
144 panel_destroy(panel);
145 ui_window_destroy(window);
146 ui_destroy(ui);
147}
148
149/** panel_ctl() returns a valid UI control */
150PCUT_TEST(ctl)
151{
152 panel_t *panel;
153 ui_control_t *control;
154 errno_t rc;
155
156 rc = panel_create(NULL, true, &panel);
157 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
158
159 control = panel_ctl(panel);
160 PCUT_ASSERT_NOT_NULL(control);
161
162 panel_destroy(panel);
163}
164
165/** Test panel_kbd_event() */
166PCUT_TEST(kbd_event)
167{
168 panel_t *panel;
169 ui_evclaim_t claimed;
170 kbd_event_t event;
171 errno_t rc;
172
173 /* Active panel should claim events */
174
175 rc = panel_create(NULL, true, &panel);
176 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
177
178 event.type = KEY_PRESS;
179 event.key = KC_ESCAPE;
180 event.mods = 0;
181 event.c = '\0';
182
183 claimed = panel_kbd_event(panel, &event);
184 PCUT_ASSERT_EQUALS(ui_claimed, claimed);
185
186 panel_destroy(panel);
187
188 /* Inactive panel should not claim events */
189
190 rc = panel_create(NULL, false, &panel);
191 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
192
193 event.type = KEY_PRESS;
194 event.key = KC_ESCAPE;
195 event.mods = 0;
196 event.c = '\0';
197
198 claimed = panel_kbd_event(panel, &event);
199 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
200
201 panel_destroy(panel);
202}
203
204/** Test panel_pos_event() */
205PCUT_TEST(pos_event)
206{
207 panel_t *panel;
208 ui_evclaim_t claimed;
209 pos_event_t event;
210 errno_t rc;
211
212 rc = panel_create(NULL, true, &panel);
213 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
214
215 event.pos_id = 0;
216 event.type = POS_PRESS;
217 event.btn_num = 1;
218 event.hpos = 0;
219 event.vpos = 0;
220
221 claimed = panel_pos_event(panel, &event);
222 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
223
224 panel_destroy(panel);
225}
226
227/** panel_set_rect() sets internal field */
228PCUT_TEST(set_rect)
229{
230 panel_t *panel;
231 gfx_rect_t rect;
232 errno_t rc;
233
234 rc = panel_create(NULL, true, &panel);
235 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
236
237 rect.p0.x = 1;
238 rect.p0.y = 2;
239 rect.p1.x = 3;
240 rect.p1.y = 4;
241
242 panel_set_rect(panel, &rect);
243 PCUT_ASSERT_INT_EQUALS(rect.p0.x, panel->rect.p0.x);
244 PCUT_ASSERT_INT_EQUALS(rect.p0.y, panel->rect.p0.y);
245 PCUT_ASSERT_INT_EQUALS(rect.p1.x, panel->rect.p1.x);
246 PCUT_ASSERT_INT_EQUALS(rect.p1.y, panel->rect.p1.y);
247
248 panel_destroy(panel);
249}
250
251/** panel_page_size() returns correct size */
252PCUT_TEST(page_size)
253{
254 panel_t *panel;
255 gfx_rect_t rect;
256 errno_t rc;
257
258 rc = panel_create(NULL, true, &panel);
259 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
260
261 rect.p0.x = 10;
262 rect.p0.y = 20;
263 rect.p1.x = 30;
264 rect.p1.y = 40;
265
266 panel_set_rect(panel, &rect);
267
268 /* NOTE If page size changes, we have problems elsewhere in the tests */
269 PCUT_ASSERT_INT_EQUALS(18, panel_page_size(panel));
270
271 panel_destroy(panel);
272}
273
274/** panel_is_active() returns panel activity state */
275PCUT_TEST(is_active)
276{
277 panel_t *panel;
278 errno_t rc;
279
280 rc = panel_create(NULL, true, &panel);
281 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
282 PCUT_ASSERT_TRUE(panel_is_active(panel));
283 panel_destroy(panel);
284
285 rc = panel_create(NULL, false, &panel);
286 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
287 PCUT_ASSERT_FALSE(panel_is_active(panel));
288 panel_destroy(panel);
289}
290
291/** panel_activate() activates panel */
292PCUT_TEST(activate)
293{
294 ui_t *ui;
295 ui_window_t *window;
296 ui_wnd_params_t params;
297 panel_t *panel;
298 errno_t rc;
299
300 rc = ui_create_disp(NULL, &ui);
301 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
302
303 ui_wnd_params_init(&params);
304 params.caption = "Test";
305
306 rc = ui_window_create(ui, &params, &window);
307 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
308
309 rc = panel_create(window, false, &panel);
310 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
311
312 PCUT_ASSERT_FALSE(panel_is_active(panel));
313 rc = panel_activate(panel);
314 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
315 PCUT_ASSERT_TRUE(panel_is_active(panel));
316
317 panel_destroy(panel);
318 ui_window_destroy(window);
319 ui_destroy(ui);
320}
321
322/** panel_deactivate() deactivates panel */
323PCUT_TEST(deactivate)
324{
325 ui_t *ui;
326 ui_window_t *window;
327 ui_wnd_params_t params;
328 panel_t *panel;
329 errno_t rc;
330
331 rc = ui_create_disp(NULL, &ui);
332 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
333
334 ui_wnd_params_init(&params);
335 params.caption = "Test";
336
337 rc = ui_window_create(ui, &params, &window);
338 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
339
340 rc = panel_create(window, true, &panel);
341 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
342
343 PCUT_ASSERT_TRUE(panel_is_active(panel));
344 panel_deactivate(panel);
345 PCUT_ASSERT_FALSE(panel_is_active(panel));
346
347 panel_destroy(panel);
348 ui_window_destroy(window);
349 ui_destroy(ui);
350}
351
352/** panel_entry_append() appends new entry */
353PCUT_TEST(entry_append)
354{
355 panel_t *panel;
356 panel_entry_attr_t attr;
357 errno_t rc;
358
359 rc = panel_create(NULL, true, &panel);
360 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
361
362 panel_entry_attr_init(&attr);
363
364 attr.name = "a";
365 attr.size = 1;
366 rc = panel_entry_append(panel, &attr);
367 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
368
369 PCUT_ASSERT_INT_EQUALS(1, list_count(&panel->entries));
370
371 attr.name = "b";
372 attr.size = 2;
373 rc = panel_entry_append(panel, &attr);
374 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
375
376 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
377
378 panel_destroy(panel);
379}
380
381/** panel_entry_delete() deletes entry */
382PCUT_TEST(entry_delete)
383{
384 panel_t *panel;
385 panel_entry_t *entry;
386 panel_entry_attr_t attr;
387 errno_t rc;
388
389 rc = panel_create(NULL, true, &panel);
390 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
391
392 attr.name = "a";
393 attr.size = 1;
394 rc = panel_entry_append(panel, &attr);
395 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
396
397 attr.name = "b";
398 attr.size = 2;
399 rc = panel_entry_append(panel, &attr);
400 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
401
402 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
403
404 entry = panel_first(panel);
405 panel_entry_delete(entry);
406
407 PCUT_ASSERT_INT_EQUALS(1, list_count(&panel->entries));
408
409 entry = panel_first(panel);
410 panel_entry_delete(entry);
411
412 PCUT_ASSERT_INT_EQUALS(0, list_count(&panel->entries));
413
414 panel_destroy(panel);
415}
416
417/** panel_clear_entries() removes all entries from panel */
418PCUT_TEST(clear_entries)
419{
420 panel_t *panel;
421 panel_entry_attr_t attr;
422 errno_t rc;
423
424 rc = panel_create(NULL, true, &panel);
425 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
426
427 panel_entry_attr_init(&attr);
428 attr.name = "a";
429 attr.size = 1;
430 rc = panel_entry_append(panel, &attr);
431 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
432
433 attr.name = "a";
434 attr.size = 2;
435 rc = panel_entry_append(panel, &attr);
436 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
437
438 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
439
440 panel_clear_entries(panel);
441 PCUT_ASSERT_INT_EQUALS(0, list_count(&panel->entries));
442
443 panel_destroy(panel);
444}
445
446/** panel_read_dir() reads the contents of a directory */
447PCUT_TEST(read_dir)
448{
449 panel_t *panel;
450 panel_entry_t *entry;
451 char buf[L_tmpnam];
452 char *fname;
453 char *p;
454 errno_t rc;
455 FILE *f;
456 int rv;
457
458 /* Create name for temporary directory */
459 p = tmpnam(buf);
460 PCUT_ASSERT_NOT_NULL(p);
461
462 /* Create temporary directory */
463 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
464 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
465
466 rv = asprintf(&fname, "%s/%s", p, "a");
467 PCUT_ASSERT_TRUE(rv >= 0);
468
469 f = fopen(fname, "wb");
470 PCUT_ASSERT_NOT_NULL(f);
471
472 rv = fprintf(f, "X");
473 PCUT_ASSERT_TRUE(rv >= 0);
474
475 rv = fclose(f);
476 PCUT_ASSERT_INT_EQUALS(0, rv);
477
478 rc = panel_create(NULL, true, &panel);
479 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
480
481 rc = panel_read_dir(panel, p);
482 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
483
484 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
485
486 entry = panel_first(panel);
487 PCUT_ASSERT_NOT_NULL(entry);
488 PCUT_ASSERT_STR_EQUALS("..", entry->name);
489
490 entry = panel_next(entry);
491 PCUT_ASSERT_NOT_NULL(entry);
492 PCUT_ASSERT_STR_EQUALS("a", entry->name);
493 PCUT_ASSERT_INT_EQUALS(1, entry->size);
494
495 panel_destroy(panel);
496
497 rv = remove(fname);
498 PCUT_ASSERT_INT_EQUALS(0, rv);
499
500 rv = remove(p);
501 PCUT_ASSERT_INT_EQUALS(0, rv);
502
503 free(fname);
504}
505
506/** When moving to parent directory from a subdir, we seek to the
507 * coresponding entry
508 */
509PCUT_TEST(read_dir_up)
510{
511 panel_t *panel;
512 char buf[L_tmpnam];
513 char *subdir_a;
514 char *subdir_b;
515 char *subdir_c;
516 char *p;
517 errno_t rc;
518 int rv;
519
520 /* Create name for temporary directory */
521 p = tmpnam(buf);
522 PCUT_ASSERT_NOT_NULL(p);
523
524 /* Create temporary directory */
525 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
526 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
527
528 /* Create some subdirectories */
529
530 rv = asprintf(&subdir_a, "%s/%s", p, "a");
531 PCUT_ASSERT_TRUE(rv >= 0);
532 rc = vfs_link_path(subdir_a, KIND_DIRECTORY, NULL);
533 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
534
535 rv = asprintf(&subdir_b, "%s/%s", p, "b");
536 PCUT_ASSERT_TRUE(rv >= 0);
537 rc = vfs_link_path(subdir_b, KIND_DIRECTORY, NULL);
538 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
539
540 rv = asprintf(&subdir_c, "%s/%s", p, "c");
541 PCUT_ASSERT_TRUE(rv >= 0);
542 rc = vfs_link_path(subdir_c, KIND_DIRECTORY, NULL);
543 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
544
545 rc = panel_create(NULL, true, &panel);
546 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
547
548 /* Start in subdirectory "b" */
549 rc = panel_read_dir(panel, subdir_b);
550 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
551
552 /* Now go up (into p) */
553
554 rc = panel_read_dir(panel, "..");
555 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
556
557 PCUT_ASSERT_NOT_NULL(panel->cursor);
558 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);
559
560 panel_destroy(panel);
561
562 rv = remove(subdir_a);
563 PCUT_ASSERT_INT_EQUALS(0, rv);
564
565 rv = remove(subdir_b);
566 PCUT_ASSERT_INT_EQUALS(0, rv);
567
568 rv = remove(subdir_c);
569 PCUT_ASSERT_INT_EQUALS(0, rv);
570
571 rv = remove(p);
572 PCUT_ASSERT_INT_EQUALS(0, rv);
573
574 free(subdir_a);
575 free(subdir_b);
576 free(subdir_c);
577}
578
579/** panel_sort() sorts panel entries */
580PCUT_TEST(sort)
581{
582 panel_t *panel;
583 panel_entry_t *entry;
584 panel_entry_attr_t attr;
585 errno_t rc;
586
587 rc = panel_create(NULL, true, &panel);
588 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
589
590 panel_entry_attr_init(&attr);
591
592 attr.name = "b";
593 attr.size = 1;
594 rc = panel_entry_append(panel, &attr);
595 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
596
597 attr.name = "c";
598 attr.size = 3;
599 rc = panel_entry_append(panel, &attr);
600 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
601
602 attr.name = "a";
603 attr.size = 2;
604 rc = panel_entry_append(panel, &attr);
605 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
606
607 rc = panel_sort(panel);
608 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
609
610 entry = panel_first(panel);
611 PCUT_ASSERT_STR_EQUALS("a", entry->name);
612 PCUT_ASSERT_INT_EQUALS(2, entry->size);
613
614 entry = panel_next(entry);
615 PCUT_ASSERT_STR_EQUALS("b", entry->name);
616 PCUT_ASSERT_INT_EQUALS(1, entry->size);
617
618 entry = panel_next(entry);
619 PCUT_ASSERT_STR_EQUALS("c", entry->name);
620 PCUT_ASSERT_INT_EQUALS(3, entry->size);
621
622 panel_destroy(panel);
623}
624
625/** panel_entry_ptr_cmp compares two indirectly referenced entries */
626PCUT_TEST(entry_ptr_cmp)
627{
628 panel_t *panel;
629 panel_entry_t *a, *b;
630 panel_entry_attr_t attr;
631 int rel;
632 errno_t rc;
633
634 rc = panel_create(NULL, true, &panel);
635 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
636
637 panel_entry_attr_init(&attr);
638
639 attr.name = "a";
640 attr.size = 2;
641 rc = panel_entry_append(panel, &attr);
642 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
643
644 attr.name = "b";
645 attr.size = 1;
646 rc = panel_entry_append(panel, &attr);
647 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
648
649 a = panel_first(panel);
650 PCUT_ASSERT_NOT_NULL(a);
651 b = panel_next(a);
652 PCUT_ASSERT_NOT_NULL(b);
653
654 /* a < b */
655 rel = panel_entry_ptr_cmp(&a, &b);
656 PCUT_ASSERT_TRUE(rel < 0);
657
658 /* b > a */
659 rel = panel_entry_ptr_cmp(&b, &a);
660 PCUT_ASSERT_TRUE(rel > 0);
661
662 /* a == a */
663 rel = panel_entry_ptr_cmp(&a, &a);
664 PCUT_ASSERT_INT_EQUALS(0, rel);
665
666 panel_destroy(panel);
667}
668
669/** panel_first() returns valid entry or @c NULL as appropriate */
670PCUT_TEST(first)
671{
672 panel_t *panel;
673 panel_entry_t *entry;
674 panel_entry_attr_t attr;
675 errno_t rc;
676
677 rc = panel_create(NULL, true, &panel);
678 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
679
680 panel_entry_attr_init(&attr);
681
682 entry = panel_first(panel);
683 PCUT_ASSERT_NULL(entry);
684
685 /* Add one entry */
686 attr.name = "a";
687 attr.size = 1;
688 rc = panel_entry_append(panel, &attr);
689 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
690
691 /* Now try getting it */
692 entry = panel_first(panel);
693 PCUT_ASSERT_NOT_NULL(entry);
694 PCUT_ASSERT_STR_EQUALS("a", entry->name);
695 PCUT_ASSERT_INT_EQUALS(1, entry->size);
696
697 /* Add another entry */
698 attr.name = "b";
699 attr.size = 2;
700 rc = panel_entry_append(panel, &attr);
701 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
702
703 /* We should still get the first entry */
704 entry = panel_first(panel);
705 PCUT_ASSERT_NOT_NULL(entry);
706 PCUT_ASSERT_STR_EQUALS("a", entry->name);
707 PCUT_ASSERT_INT_EQUALS(1, entry->size);
708
709 panel_destroy(panel);
710}
711
712/** panel_last() returns valid entry or @c NULL as appropriate */
713PCUT_TEST(last)
714{
715 panel_t *panel;
716 panel_entry_t *entry;
717 panel_entry_attr_t attr;
718 errno_t rc;
719
720 rc = panel_create(NULL, true, &panel);
721 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
722
723 panel_entry_attr_init(&attr);
724
725 entry = panel_last(panel);
726 PCUT_ASSERT_NULL(entry);
727
728 /* Add one entry */
729 attr.name = "a";
730 attr.size = 1;
731 rc = panel_entry_append(panel, &attr);
732 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
733
734 /* Now try getting it */
735 entry = panel_last(panel);
736 PCUT_ASSERT_NOT_NULL(entry);
737 PCUT_ASSERT_STR_EQUALS("a", entry->name);
738 PCUT_ASSERT_INT_EQUALS(1, entry->size);
739
740 /* Add another entry */
741 attr.name = "b";
742 attr.size = 2;
743 rc = panel_entry_append(panel, &attr);
744 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
745
746 /* We should get new entry now */
747 entry = panel_last(panel);
748 PCUT_ASSERT_NOT_NULL(entry);
749 attr.name = "b";
750 attr.size = 2;
751 PCUT_ASSERT_STR_EQUALS("b", entry->name);
752 PCUT_ASSERT_INT_EQUALS(2, entry->size);
753
754 panel_destroy(panel);
755}
756
757/** panel_next() returns the next entry or @c NULL as appropriate */
758PCUT_TEST(next)
759{
760 panel_t *panel;
761 panel_entry_t *entry;
762 panel_entry_attr_t attr;
763 errno_t rc;
764
765 rc = panel_create(NULL, true, &panel);
766 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
767
768 panel_entry_attr_init(&attr);
769
770 /* Add one entry */
771 attr.name = "a";
772 attr.size = 1;
773 rc = panel_entry_append(panel, &attr);
774 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
775
776 /* Now try getting its successor */
777 entry = panel_first(panel);
778 PCUT_ASSERT_NOT_NULL(entry);
779
780 entry = panel_next(entry);
781 PCUT_ASSERT_NULL(entry);
782
783 /* Add another entry */
784 attr.name = "b";
785 attr.size = 2;
786 rc = panel_entry_append(panel, &attr);
787 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
788
789 /* Try getting the successor of first entry again */
790 entry = panel_first(panel);
791 PCUT_ASSERT_NOT_NULL(entry);
792
793 entry = panel_next(entry);
794 PCUT_ASSERT_NOT_NULL(entry);
795 PCUT_ASSERT_STR_EQUALS("b", entry->name);
796 PCUT_ASSERT_INT_EQUALS(2, entry->size);
797
798 panel_destroy(panel);
799}
800
801/** panel_prev() returns the previous entry or @c NULL as appropriate */
802PCUT_TEST(prev)
803{
804 panel_t *panel;
805 panel_entry_t *entry;
806 panel_entry_attr_t attr;
807 errno_t rc;
808
809 rc = panel_create(NULL, true, &panel);
810 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
811
812 panel_entry_attr_init(&attr);
813
814 /* Add one entry */
815 attr.name = "a";
816 attr.size = 1;
817 rc = panel_entry_append(panel, &attr);
818 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
819
820 /* Now try getting its predecessor */
821 entry = panel_last(panel);
822 PCUT_ASSERT_NOT_NULL(entry);
823
824 entry = panel_prev(entry);
825 PCUT_ASSERT_NULL(entry);
826
827 /* Add another entry */
828 attr.name = "b";
829 attr.size = 2;
830 rc = panel_entry_append(panel, &attr);
831 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
832
833 /* Try getting the predecessor of the new entry */
834 entry = panel_last(panel);
835 PCUT_ASSERT_NOT_NULL(entry);
836
837 entry = panel_prev(entry);
838 PCUT_ASSERT_NOT_NULL(entry);
839 PCUT_ASSERT_STR_EQUALS("a", entry->name);
840 PCUT_ASSERT_INT_EQUALS(1, entry->size);
841
842 panel_destroy(panel);
843}
844
845/** panel_cursor_move() ... */
846PCUT_TEST(cursor_move)
847{
848}
849
850/** panel_cursor_up() moves cursor one entry up */
851PCUT_TEST(cursor_up)
852{
853 ui_t *ui;
854 ui_window_t *window;
855 ui_wnd_params_t params;
856 panel_t *panel;
857 panel_entry_attr_t attr;
858 gfx_rect_t rect;
859 errno_t rc;
860
861 rc = ui_create_disp(NULL, &ui);
862 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
863
864 ui_wnd_params_init(&params);
865 params.caption = "Test";
866
867 rc = ui_window_create(ui, &params, &window);
868 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
869
870 rc = panel_create(window, true, &panel);
871 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
872
873 rect.p0.x = 0;
874 rect.p0.y = 0;
875 rect.p1.x = 10;
876 rect.p1.y = 4; // XXX Assuming this makes page size 2
877 panel_set_rect(panel, &rect);
878
879 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
880
881 /* Add tree entries (more than page size, which is 2) */
882
883 panel_entry_attr_init(&attr);
884
885 attr.name = "a";
886 attr.size = 1;
887 rc = panel_entry_append(panel, &attr);
888 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
889
890 attr.name = "b";
891 attr.size = 2;
892 rc = panel_entry_append(panel, &attr);
893 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
894
895 attr.name = "c";
896 attr.size = 3;
897 rc = panel_entry_append(panel, &attr);
898 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
899
900 /* Cursor to the last entry and page start to the next-to-last entry */
901 panel->cursor = panel_last(panel);
902 panel->cursor_idx = 2;
903 panel->page = panel_prev(panel->cursor);
904 panel->page_idx = 1;
905
906 /* Move cursor one entry up */
907 panel_cursor_up(panel);
908
909 /* Cursor and page start should now both be at the second entry */
910 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);
911 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);
912 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx);
913 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
914 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
915
916 /* Move cursor one entry up. This should scroll up. */
917 panel_cursor_up(panel);
918
919 /* Cursor and page start should now both be at the first entry */
920 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
921 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
922 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
923 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
924 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
925
926 /* Moving further up should do nothing (we are at the top). */
927 panel_cursor_up(panel);
928
929 /* Cursor and page start should still be at the first entry */
930 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
931 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
932 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
933 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
934 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
935
936 panel_destroy(panel);
937 ui_window_destroy(window);
938 ui_destroy(ui);
939}
940
941/** panel_cursor_down() moves cursor one entry down */
942PCUT_TEST(cursor_down)
943{
944 ui_t *ui;
945 ui_window_t *window;
946 ui_wnd_params_t params;
947 panel_t *panel;
948 panel_entry_attr_t attr;
949 gfx_rect_t rect;
950 errno_t rc;
951
952 rc = ui_create_disp(NULL, &ui);
953 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
954
955 ui_wnd_params_init(&params);
956 params.caption = "Test";
957
958 rc = ui_window_create(ui, &params, &window);
959 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
960
961 rc = panel_create(window, true, &panel);
962 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
963
964 rect.p0.x = 0;
965 rect.p0.y = 0;
966 rect.p1.x = 10;
967 rect.p1.y = 4; // XXX Assuming this makes page size 2
968 panel_set_rect(panel, &rect);
969
970 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
971
972 /* Add tree entries (more than page size, which is 2) */
973
974 panel_entry_attr_init(&attr);
975
976 attr.name = "a";
977 attr.size = 1;
978 rc = panel_entry_append(panel, &attr);
979 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
980
981 attr.name = "b";
982 attr.size = 2;
983 rc = panel_entry_append(panel, &attr);
984 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
985
986 attr.name = "c";
987 attr.size = 3;
988 rc = panel_entry_append(panel, &attr);
989 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
990
991 /* Cursor and page start to the first entry */
992 panel->cursor = panel_first(panel);
993 panel->cursor_idx = 0;
994 panel->page = panel->cursor;
995 panel->page_idx = 0;
996
997 /* Move cursor one entry down */
998 panel_cursor_down(panel);
999
1000 /* Cursor should now be at the second entry, page stays the same */
1001 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);
1002 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);
1003 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx);
1004 PCUT_ASSERT_EQUALS(panel_first(panel), panel->page);
1005 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
1006
1007 /* Move cursor one entry down. This should scroll down. */
1008 panel_cursor_down(panel);
1009
1010 /* Cursor should now be at the third and page at the second entry. */
1011 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1012 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1013 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1014 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
1015 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
1016 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
1017
1018 /* Moving further down should do nothing (we are at the bottom). */
1019 panel_cursor_down(panel);
1020
1021 /* Cursor should still be at the third and page at the second entry. */
1022 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1023 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1024 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1025 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
1026 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
1027 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
1028
1029 panel_destroy(panel);
1030 ui_window_destroy(window);
1031 ui_destroy(ui);
1032}
1033
1034/** panel_cursor_top() moves cursor to the first entry */
1035PCUT_TEST(cursor_top)
1036{
1037 ui_t *ui;
1038 ui_window_t *window;
1039 ui_wnd_params_t params;
1040 panel_t *panel;
1041 panel_entry_attr_t attr;
1042 gfx_rect_t rect;
1043 errno_t rc;
1044
1045 rc = ui_create_disp(NULL, &ui);
1046 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1047
1048 ui_wnd_params_init(&params);
1049 params.caption = "Test";
1050
1051 rc = ui_window_create(ui, &params, &window);
1052 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1053
1054 rc = panel_create(window, true, &panel);
1055 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1056
1057 rect.p0.x = 0;
1058 rect.p0.y = 0;
1059 rect.p1.x = 10;
1060 rect.p1.y = 4; // XXX Assuming this makes page size 2
1061 panel_set_rect(panel, &rect);
1062
1063 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1064
1065 /* Add tree entries (more than page size, which is 2) */
1066
1067 panel_entry_attr_init(&attr);
1068
1069 attr.name = "a";
1070 attr.size = 1;
1071 rc = panel_entry_append(panel, &attr);
1072 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1073
1074 attr.name = "b";
1075 attr.size = 2;
1076 rc = panel_entry_append(panel, &attr);
1077 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1078
1079 attr.name = "c";
1080 attr.size = 3;
1081 rc = panel_entry_append(panel, &attr);
1082 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1083
1084 /* Cursor to the last entry and page start to the next-to-last entry */
1085 panel->cursor = panel_last(panel);
1086 panel->cursor_idx = 2;
1087 panel->page = panel_prev(panel->cursor);
1088 panel->page_idx = 1;
1089
1090 /* Move cursor to the top. This should scroll up. */
1091 panel_cursor_top(panel);
1092
1093 /* Cursor and page start should now both be at the first entry */
1094 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
1095 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
1096 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
1097 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
1098 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
1099
1100 panel_destroy(panel);
1101 ui_window_destroy(window);
1102 ui_destroy(ui);
1103}
1104
1105/** panel_cursor_bottom() moves cursor to the last entry */
1106PCUT_TEST(cursor_bottom)
1107{
1108 ui_t *ui;
1109 ui_window_t *window;
1110 ui_wnd_params_t params;
1111 panel_t *panel;
1112 panel_entry_attr_t attr;
1113 gfx_rect_t rect;
1114 errno_t rc;
1115
1116 rc = ui_create_disp(NULL, &ui);
1117 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1118
1119 ui_wnd_params_init(&params);
1120 params.caption = "Test";
1121
1122 rc = ui_window_create(ui, &params, &window);
1123 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1124
1125 rc = panel_create(window, true, &panel);
1126 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1127
1128 rect.p0.x = 0;
1129 rect.p0.y = 0;
1130 rect.p1.x = 10;
1131 rect.p1.y = 4; // XXX Assuming this makes page size 2
1132 panel_set_rect(panel, &rect);
1133
1134 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1135
1136 /* Add tree entries (more than page size, which is 2) */
1137
1138 panel_entry_attr_init(&attr);
1139
1140 attr.name = "a";
1141 attr.size = 1;
1142 rc = panel_entry_append(panel, &attr);
1143 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1144
1145 attr.name = "b";
1146 attr.size = 2;
1147 rc = panel_entry_append(panel, &attr);
1148 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1149
1150 attr.name = "c";
1151 attr.size = 3;
1152 rc = panel_entry_append(panel, &attr);
1153 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1154
1155 /* Cursor and page start to the first entry */
1156 panel->cursor = panel_first(panel);
1157 panel->cursor_idx = 0;
1158 panel->page = panel->cursor;
1159 panel->page_idx = 0;
1160
1161 /* Move cursor to the bottom. This should scroll down. */
1162 panel_cursor_bottom(panel);
1163
1164 /* Cursor should now be at the third and page at the second entry. */
1165 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1166 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1167 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1168 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
1169 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
1170 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
1171
1172 panel_destroy(panel);
1173 ui_window_destroy(window);
1174 ui_destroy(ui);
1175}
1176
1177/** panel_page_up() moves one page up */
1178PCUT_TEST(page_up)
1179{
1180 ui_t *ui;
1181 ui_window_t *window;
1182 ui_wnd_params_t params;
1183 panel_t *panel;
1184 panel_entry_attr_t attr;
1185 gfx_rect_t rect;
1186 errno_t rc;
1187
1188 rc = ui_create_disp(NULL, &ui);
1189 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1190
1191 ui_wnd_params_init(&params);
1192 params.caption = "Test";
1193
1194 rc = ui_window_create(ui, &params, &window);
1195 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1196
1197 rc = panel_create(window, true, &panel);
1198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1199
1200 rect.p0.x = 0;
1201 rect.p0.y = 0;
1202 rect.p1.x = 10;
1203 rect.p1.y = 4; // XXX Assuming this makes page size 2
1204 panel_set_rect(panel, &rect);
1205
1206 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1207
1208 /* Add five entries (2 full pages, one partial) */
1209
1210 panel_entry_attr_init(&attr);
1211
1212 attr.name = "a";
1213 attr.size = 1;
1214 rc = panel_entry_append(panel, &attr);
1215 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1216
1217 attr.name = "b";
1218 attr.size = 2;
1219 rc = panel_entry_append(panel, &attr);
1220 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1221
1222 attr.name = "c";
1223 attr.size = 3;
1224 rc = panel_entry_append(panel, &attr);
1225 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1226
1227 attr.name = "d";
1228 attr.size = 4;
1229 rc = panel_entry_append(panel, &attr);
1230 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1231
1232 attr.name = "e";
1233 attr.size = 5;
1234 rc = panel_entry_append(panel, &attr);
1235 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1236
1237 /* Cursor to the last entry and page start to the next-to-last entry */
1238 panel->cursor = panel_last(panel);
1239 panel->cursor_idx = 4;
1240 panel->page = panel_prev(panel->cursor);
1241 panel->page_idx = 3;
1242
1243 /* Move one page up */
1244 panel_page_up(panel);
1245
1246 /* Page should now start at second entry and cursor at third */
1247 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1248 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1249 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1250 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
1251 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
1252 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
1253
1254 /* Move one page up again. */
1255 panel_page_up(panel);
1256
1257 /* Cursor and page start should now both be at the first entry */
1258 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
1259 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
1260 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
1261 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
1262 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
1263
1264 /* Moving further up should do nothing (we are at the top). */
1265 panel_page_up(panel);
1266
1267 /* Cursor and page start should still be at the first entry */
1268 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
1269 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
1270 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
1271 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
1272 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
1273
1274 panel_destroy(panel);
1275 ui_window_destroy(window);
1276 ui_destroy(ui);
1277}
1278
1279/** panel_page_up() moves one page down */
1280PCUT_TEST(page_down)
1281{
1282 ui_t *ui;
1283 ui_window_t *window;
1284 ui_wnd_params_t params;
1285 panel_t *panel;
1286 panel_entry_attr_t attr;
1287 gfx_rect_t rect;
1288 errno_t rc;
1289
1290 rc = ui_create_disp(NULL, &ui);
1291 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1292
1293 ui_wnd_params_init(&params);
1294 params.caption = "Test";
1295
1296 rc = ui_window_create(ui, &params, &window);
1297 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1298
1299 rc = panel_create(window, true, &panel);
1300 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1301
1302 rect.p0.x = 0;
1303 rect.p0.y = 0;
1304 rect.p1.x = 10;
1305 rect.p1.y = 4; // XXX Assuming this makes page size 2
1306 panel_set_rect(panel, &rect);
1307
1308 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1309
1310 /* Add five entries (2 full pages, one partial) */
1311
1312 panel_entry_attr_init(&attr);
1313
1314 attr.name = "a";
1315 attr.size = 1;
1316 rc = panel_entry_append(panel, &attr);
1317 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1318
1319 attr.name = "b";
1320 attr.size = 2;
1321 rc = panel_entry_append(panel, &attr);
1322 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1323
1324 attr.name = "c";
1325 attr.size = 3;
1326 rc = panel_entry_append(panel, &attr);
1327 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1328
1329 attr.name = "d";
1330 attr.size = 4;
1331 rc = panel_entry_append(panel, &attr);
1332 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1333
1334 attr.name = "e";
1335 attr.size = 5;
1336 rc = panel_entry_append(panel, &attr);
1337 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1338
1339 /* Cursor and page to the first entry */
1340 panel->cursor = panel_first(panel);
1341 panel->cursor_idx = 0;
1342 panel->page = panel->cursor;
1343 panel->page_idx = 0;
1344
1345 /* Move one page down */
1346 panel_page_down(panel);
1347
1348 /* Page and cursor should point to the third entry */
1349 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1350 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1351 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1352 PCUT_ASSERT_STR_EQUALS("c", panel->page->name);
1353 PCUT_ASSERT_INT_EQUALS(3, panel->page->size);
1354 PCUT_ASSERT_INT_EQUALS(2, panel->page_idx);
1355
1356 /* Move one page down again. */
1357 panel_page_down(panel);
1358
1359 /* Cursor should point to last and page to next-to-last entry */
1360 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name);
1361 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size);
1362 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx);
1363 PCUT_ASSERT_STR_EQUALS("d", panel->page->name);
1364 PCUT_ASSERT_INT_EQUALS(4, panel->page->size);
1365 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx);
1366
1367 /* Moving further down should do nothing (we are at the bottom). */
1368 panel_page_down(panel);
1369
1370 /* Cursor should still point to last and page to next-to-last entry */
1371 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name);
1372 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size);
1373 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx);
1374 PCUT_ASSERT_STR_EQUALS("d", panel->page->name);
1375 PCUT_ASSERT_INT_EQUALS(4, panel->page->size);
1376 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx);
1377
1378 panel_destroy(panel);
1379 ui_window_destroy(window);
1380 ui_destroy(ui);
1381}
1382
1383/** panel_open() opens a directory entry */
1384PCUT_TEST(open)
1385{
1386 ui_t *ui;
1387 ui_window_t *window;
1388 ui_wnd_params_t params;
1389 panel_t *panel;
1390 panel_entry_t *entry;
1391 char buf[L_tmpnam];
1392 char *sdname;
1393 char *p;
1394 errno_t rc;
1395 int rv;
1396
1397 rc = ui_create_disp(NULL, &ui);
1398 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1399
1400 ui_wnd_params_init(&params);
1401 params.caption = "Test";
1402
1403 rc = ui_window_create(ui, &params, &window);
1404 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1405
1406 /* Create name for temporary directory */
1407 p = tmpnam(buf);
1408 PCUT_ASSERT_NOT_NULL(p);
1409
1410 /* Create temporary directory */
1411 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
1412 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1413
1414 rv = asprintf(&sdname, "%s/%s", p, "a");
1415 PCUT_ASSERT_TRUE(rv >= 0);
1416
1417 /* Create sub-directory */
1418 rc = vfs_link_path(sdname, KIND_DIRECTORY, NULL);
1419 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1420
1421 rc = panel_create(window, true, &panel);
1422 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1423
1424 rc = panel_read_dir(panel, p);
1425 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1426 PCUT_ASSERT_STR_EQUALS(p, panel->dir);
1427
1428 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
1429
1430 entry = panel_first(panel);
1431 PCUT_ASSERT_NOT_NULL(entry);
1432 PCUT_ASSERT_STR_EQUALS("..", entry->name);
1433
1434 entry = panel_next(entry);
1435 PCUT_ASSERT_NOT_NULL(entry);
1436 PCUT_ASSERT_STR_EQUALS("a", entry->name);
1437 PCUT_ASSERT_TRUE(entry->isdir);
1438
1439 rc = panel_open(panel, entry);
1440 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1441
1442 PCUT_ASSERT_STR_EQUALS(sdname, panel->dir);
1443
1444 panel_destroy(panel);
1445 ui_window_destroy(window);
1446 ui_destroy(ui);
1447
1448 rv = remove(sdname);
1449 PCUT_ASSERT_INT_EQUALS(0, rv);
1450
1451 rv = remove(p);
1452 PCUT_ASSERT_INT_EQUALS(0, rv);
1453
1454 free(sdname);
1455}
1456
1457/** panel_activate_req() sends activation request */
1458PCUT_TEST(activate_req)
1459{
1460 panel_t *panel;
1461 errno_t rc;
1462 test_resp_t resp;
1463
1464 rc = panel_create(NULL, true, &panel);
1465 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1466
1467 panel_set_cb(panel, &test_cb, &resp);
1468
1469 resp.activate_req = false;
1470 resp.activate_req_panel = NULL;
1471
1472 panel_activate_req(panel);
1473 PCUT_ASSERT_TRUE(resp.activate_req);
1474 PCUT_ASSERT_EQUALS(panel, resp.activate_req_panel);
1475
1476 panel_destroy(panel);
1477}
1478
1479static void test_panel_activate_req(void *arg, panel_t *panel)
1480{
1481 test_resp_t *resp = (test_resp_t *)arg;
1482
1483 resp->activate_req = true;
1484 resp->activate_req_panel = panel;
1485}
1486
1487PCUT_EXPORT(panel);
Note: See TracBrowser for help on using the repository browser.