source: mainline/uspace/app/nav/test/panel.c@ 97c3c59

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

When moving up a dir, seek to the directory just exited

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