source: mainline/uspace/app/nav/test/panel.c@ 75357c5

Last change on this file since 75357c5 was 75357c5, checked in by Jiri Svoboda <jiri@…>, 4 years ago

Different color for service-special files

  • Property mode set to 100644
File size: 31.3 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 free(fname);
474}
475
476/** panel_sort() sorts panel entries */
477PCUT_TEST(sort)
478{
479 panel_t *panel;
480 panel_entry_t *entry;
481 panel_entry_attr_t attr;
482 errno_t rc;
483
484 rc = panel_create(NULL, true, &panel);
485 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
486
487 panel_entry_attr_init(&attr);
488
489 attr.name = "b";
490 attr.size = 1;
491 rc = panel_entry_append(panel, &attr);
492 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
493
494 attr.name = "c";
495 attr.size = 3;
496 rc = panel_entry_append(panel, &attr);
497 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
498
499 attr.name = "a";
500 attr.size = 2;
501 rc = panel_entry_append(panel, &attr);
502 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
503
504 rc = panel_sort(panel);
505 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
506
507 entry = panel_first(panel);
508 PCUT_ASSERT_STR_EQUALS("a", entry->name);
509 PCUT_ASSERT_INT_EQUALS(2, entry->size);
510
511 entry = panel_next(entry);
512 PCUT_ASSERT_STR_EQUALS("b", entry->name);
513 PCUT_ASSERT_INT_EQUALS(1, entry->size);
514
515 entry = panel_next(entry);
516 PCUT_ASSERT_STR_EQUALS("c", entry->name);
517 PCUT_ASSERT_INT_EQUALS(3, entry->size);
518
519 panel_destroy(panel);
520}
521
522/** panel_entry_ptr_cmp compares two indirectly referenced entries */
523PCUT_TEST(entry_ptr_cmp)
524{
525 panel_t *panel;
526 panel_entry_t *a, *b;
527 panel_entry_attr_t attr;
528 int rel;
529 errno_t rc;
530
531 rc = panel_create(NULL, true, &panel);
532 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
533
534 panel_entry_attr_init(&attr);
535
536 attr.name = "a";
537 attr.size = 2;
538 rc = panel_entry_append(panel, &attr);
539 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
540
541 attr.name = "b";
542 attr.size = 1;
543 rc = panel_entry_append(panel, &attr);
544 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
545
546 a = panel_first(panel);
547 PCUT_ASSERT_NOT_NULL(a);
548 b = panel_next(a);
549 PCUT_ASSERT_NOT_NULL(b);
550
551 /* a < b */
552 rel = panel_entry_ptr_cmp(&a, &b);
553 PCUT_ASSERT_TRUE(rel < 0);
554
555 /* b > a */
556 rel = panel_entry_ptr_cmp(&b, &a);
557 PCUT_ASSERT_TRUE(rel > 0);
558
559 /* a == a */
560 rel = panel_entry_ptr_cmp(&a, &a);
561 PCUT_ASSERT_INT_EQUALS(0, rel);
562
563 panel_destroy(panel);
564}
565
566/** panel_first() returns valid entry or @c NULL as appropriate */
567PCUT_TEST(first)
568{
569 panel_t *panel;
570 panel_entry_t *entry;
571 panel_entry_attr_t attr;
572 errno_t rc;
573
574 rc = panel_create(NULL, true, &panel);
575 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
576
577 panel_entry_attr_init(&attr);
578
579 entry = panel_first(panel);
580 PCUT_ASSERT_NULL(entry);
581
582 /* Add one entry */
583 attr.name = "a";
584 attr.size = 1;
585 rc = panel_entry_append(panel, &attr);
586 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
587
588 /* Now try getting it */
589 entry = panel_first(panel);
590 PCUT_ASSERT_NOT_NULL(entry);
591 PCUT_ASSERT_STR_EQUALS("a", entry->name);
592 PCUT_ASSERT_INT_EQUALS(1, entry->size);
593
594 /* Add another entry */
595 attr.name = "b";
596 attr.size= 2;
597 rc = panel_entry_append(panel, &attr);
598 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
599
600 /* We should still get the first entry */
601 entry = panel_first(panel);
602 PCUT_ASSERT_NOT_NULL(entry);
603 PCUT_ASSERT_STR_EQUALS("a", entry->name);
604 PCUT_ASSERT_INT_EQUALS(1, entry->size);
605
606 panel_destroy(panel);
607}
608
609/** panel_last() returns valid entry or @c NULL as appropriate */
610PCUT_TEST(last)
611{
612 panel_t *panel;
613 panel_entry_t *entry;
614 panel_entry_attr_t attr;
615 errno_t rc;
616
617 rc = panel_create(NULL, true, &panel);
618 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
619
620 panel_entry_attr_init(&attr);
621
622 entry = panel_last(panel);
623 PCUT_ASSERT_NULL(entry);
624
625 /* Add one entry */
626 attr.name = "a";
627 attr.size = 1;
628 rc = panel_entry_append(panel, &attr);
629 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
630
631 /* Now try getting it */
632 entry = panel_last(panel);
633 PCUT_ASSERT_NOT_NULL(entry);
634 PCUT_ASSERT_STR_EQUALS("a", entry->name);
635 PCUT_ASSERT_INT_EQUALS(1, entry->size);
636
637 /* Add another entry */
638 attr.name = "b";
639 attr.size = 2;
640 rc = panel_entry_append(panel, &attr);
641 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
642
643 /* We should get new entry now */
644 entry = panel_last(panel);
645 PCUT_ASSERT_NOT_NULL(entry);
646 attr.name = "b";
647 attr.size = 2;
648 PCUT_ASSERT_STR_EQUALS("b", entry->name);
649 PCUT_ASSERT_INT_EQUALS(2, entry->size);
650
651 panel_destroy(panel);
652}
653
654/** panel_next() returns the next entry or @c NULL as appropriate */
655PCUT_TEST(next)
656{
657 panel_t *panel;
658 panel_entry_t *entry;
659 panel_entry_attr_t attr;
660 errno_t rc;
661
662 rc = panel_create(NULL, true, &panel);
663 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
664
665 panel_entry_attr_init(&attr);
666
667 /* Add one entry */
668 attr.name = "a";
669 attr.size = 1;
670 rc = panel_entry_append(panel, &attr);
671 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
672
673 /* Now try getting its successor */
674 entry = panel_first(panel);
675 PCUT_ASSERT_NOT_NULL(entry);
676
677 entry = panel_next(entry);
678 PCUT_ASSERT_NULL(entry);
679
680 /* Add another entry */
681 attr.name = "b";
682 attr.size = 2;
683 rc = panel_entry_append(panel, &attr);
684 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
685
686 /* Try getting the successor of first entry again */
687 entry = panel_first(panel);
688 PCUT_ASSERT_NOT_NULL(entry);
689
690 entry = panel_next(entry);
691 PCUT_ASSERT_NOT_NULL(entry);
692 PCUT_ASSERT_STR_EQUALS("b", entry->name);
693 PCUT_ASSERT_INT_EQUALS(2, entry->size);
694
695 panel_destroy(panel);
696}
697
698/** panel_prev() returns the previous entry or @c NULL as appropriate */
699PCUT_TEST(prev)
700{
701 panel_t *panel;
702 panel_entry_t *entry;
703 panel_entry_attr_t attr;
704 errno_t rc;
705
706 rc = panel_create(NULL, true, &panel);
707 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
708
709 panel_entry_attr_init(&attr);
710
711 /* Add one entry */
712 attr.name = "a";
713 attr.size = 1;
714 rc = panel_entry_append(panel, &attr);
715 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
716
717 /* Now try getting its predecessor */
718 entry = panel_last(panel);
719 PCUT_ASSERT_NOT_NULL(entry);
720
721 entry = panel_prev(entry);
722 PCUT_ASSERT_NULL(entry);
723
724 /* Add another entry */
725 attr.name = "b";
726 attr.size = 2;
727 rc = panel_entry_append(panel, &attr);
728 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
729
730 /* Try getting the predecessor of the new entry */
731 entry = panel_last(panel);
732 PCUT_ASSERT_NOT_NULL(entry);
733
734 entry = panel_prev(entry);
735 PCUT_ASSERT_NOT_NULL(entry);
736 PCUT_ASSERT_STR_EQUALS("a", entry->name);
737 PCUT_ASSERT_INT_EQUALS(1, entry->size);
738
739 panel_destroy(panel);
740}
741
742/** panel_cursor_move() ... */
743PCUT_TEST(cursor_move)
744{
745}
746
747/** panel_cursor_up() moves cursor one entry up */
748PCUT_TEST(cursor_up)
749{
750 ui_t *ui;
751 ui_window_t *window;
752 ui_wnd_params_t params;
753 panel_t *panel;
754 panel_entry_attr_t attr;
755 gfx_rect_t rect;
756 errno_t rc;
757
758 rc = ui_create_disp(NULL, &ui);
759 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
760
761 ui_wnd_params_init(&params);
762 params.caption = "Test";
763
764 rc = ui_window_create(ui, &params, &window);
765 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
766
767 rc = panel_create(window, true, &panel);
768 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
769
770 rect.p0.x = 0;
771 rect.p0.y = 0;
772 rect.p1.x = 10;
773 rect.p1.y = 4; // XXX Assuming this makes page size 2
774 panel_set_rect(panel, &rect);
775
776 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
777
778 /* Add tree entries (more than page size, which is 2) */
779
780 panel_entry_attr_init(&attr);
781
782 attr.name = "a";
783 attr.size = 1;
784 rc = panel_entry_append(panel, &attr);
785 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
786
787 attr.name = "b";
788 attr.size = 2;
789 rc = panel_entry_append(panel, &attr);
790 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
791
792 attr.name = "c";
793 attr.size = 3;
794 rc = panel_entry_append(panel, &attr);
795 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
796
797 /* Cursor to the last entry and page start to the next-to-last entry */
798 panel->cursor = panel_last(panel);
799 panel->cursor_idx = 2;
800 panel->page = panel_prev(panel->cursor);
801 panel->page_idx = 1;
802
803 /* Move cursor one entry up */
804 panel_cursor_up(panel);
805
806 /* Cursor and page start should now both be at the second entry */
807 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);
808 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);
809 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx);
810 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
811 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
812
813 /* Move cursor one entry up. This should scroll up. */
814 panel_cursor_up(panel);
815
816 /* Cursor and page start should now both be at the first entry */
817 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
818 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
819 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
820 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
821 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
822
823 /* Moving further up should do nothing (we are at the top). */
824 panel_cursor_up(panel);
825
826 /* Cursor and page start should still be at the first entry */
827 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
828 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
829 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
830 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
831 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
832
833 panel_destroy(panel);
834 ui_window_destroy(window);
835 ui_destroy(ui);
836}
837
838/** panel_cursor_down() moves cursor one entry down */
839PCUT_TEST(cursor_down)
840{
841 ui_t *ui;
842 ui_window_t *window;
843 ui_wnd_params_t params;
844 panel_t *panel;
845 panel_entry_attr_t attr;
846 gfx_rect_t rect;
847 errno_t rc;
848
849 rc = ui_create_disp(NULL, &ui);
850 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
851
852 ui_wnd_params_init(&params);
853 params.caption = "Test";
854
855 rc = ui_window_create(ui, &params, &window);
856 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
857
858 rc = panel_create(window, true, &panel);
859 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
860
861 rect.p0.x = 0;
862 rect.p0.y = 0;
863 rect.p1.x = 10;
864 rect.p1.y = 4; // XXX Assuming this makes page size 2
865 panel_set_rect(panel, &rect);
866
867 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
868
869 /* Add tree entries (more than page size, which is 2) */
870
871 panel_entry_attr_init(&attr);
872
873 attr.name = "a";
874 attr.size = 1;
875 rc = panel_entry_append(panel, &attr);
876 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
877
878 attr.name = "b";
879 attr.size = 2;
880 rc = panel_entry_append(panel, &attr);
881 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
882
883 attr.name = "c";
884 attr.size = 3;
885 rc = panel_entry_append(panel, &attr);
886 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
887
888 /* Cursor and page start to the first entry */
889 panel->cursor = panel_first(panel);
890 panel->cursor_idx = 0;
891 panel->page = panel->cursor;
892 panel->page_idx = 0;
893
894 /* Move cursor one entry down */
895 panel_cursor_down(panel);
896
897 /* Cursor should now be at the second entry, page stays the same */
898 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);
899 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);
900 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx);
901 PCUT_ASSERT_EQUALS(panel_first(panel), panel->page);
902 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
903
904 /* Move cursor one entry down. This should scroll down. */
905 panel_cursor_down(panel);
906
907 /* Cursor should now be at the third and page at the second entry. */
908 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
909 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
910 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
911 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
912 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
913 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
914
915 /* Moving further down should do nothing (we are at the bottom). */
916 panel_cursor_down(panel);
917
918 /* Cursor should still be at the third and page at the second entry. */
919 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
920 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
921 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
922 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
923 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
924 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
925
926 panel_destroy(panel);
927 ui_window_destroy(window);
928 ui_destroy(ui);
929}
930
931/** panel_cursor_top() moves cursor to the first entry */
932PCUT_TEST(cursor_top)
933{
934 ui_t *ui;
935 ui_window_t *window;
936 ui_wnd_params_t params;
937 panel_t *panel;
938 panel_entry_attr_t attr;
939 gfx_rect_t rect;
940 errno_t rc;
941
942 rc = ui_create_disp(NULL, &ui);
943 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
944
945 ui_wnd_params_init(&params);
946 params.caption = "Test";
947
948 rc = ui_window_create(ui, &params, &window);
949 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
950
951 rc = panel_create(window, true, &panel);
952 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
953
954 rect.p0.x = 0;
955 rect.p0.y = 0;
956 rect.p1.x = 10;
957 rect.p1.y = 4; // XXX Assuming this makes page size 2
958 panel_set_rect(panel, &rect);
959
960 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
961
962 /* Add tree entries (more than page size, which is 2) */
963
964 panel_entry_attr_init(&attr);
965
966 attr.name = "a";
967 attr.size = 1;
968 rc = panel_entry_append(panel, &attr);
969 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
970
971 attr.name = "b";
972 attr.size = 2;
973 rc = panel_entry_append(panel, &attr);
974 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
975
976 attr.name = "c";
977 attr.size = 3;
978 rc = panel_entry_append(panel, &attr);
979 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
980
981 /* Cursor to the last entry and page start to the next-to-last entry */
982 panel->cursor = panel_last(panel);
983 panel->cursor_idx = 2;
984 panel->page = panel_prev(panel->cursor);
985 panel->page_idx = 1;
986
987 /* Move cursor to the top. This should scroll up. */
988 panel_cursor_top(panel);
989
990 /* Cursor and page start should now both be at the first entry */
991 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
992 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
993 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
994 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
995 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
996
997 panel_destroy(panel);
998 ui_window_destroy(window);
999 ui_destroy(ui);
1000}
1001
1002/** panel_cursor_bottom() moves cursor to the last entry */
1003PCUT_TEST(cursor_bottom)
1004{
1005 ui_t *ui;
1006 ui_window_t *window;
1007 ui_wnd_params_t params;
1008 panel_t *panel;
1009 panel_entry_attr_t attr;
1010 gfx_rect_t rect;
1011 errno_t rc;
1012
1013 rc = ui_create_disp(NULL, &ui);
1014 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1015
1016 ui_wnd_params_init(&params);
1017 params.caption = "Test";
1018
1019 rc = ui_window_create(ui, &params, &window);
1020 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1021
1022 rc = panel_create(window, true, &panel);
1023 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1024
1025 rect.p0.x = 0;
1026 rect.p0.y = 0;
1027 rect.p1.x = 10;
1028 rect.p1.y = 4; // XXX Assuming this makes page size 2
1029 panel_set_rect(panel, &rect);
1030
1031 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1032
1033 /* Add tree entries (more than page size, which is 2) */
1034
1035 panel_entry_attr_init(&attr);
1036
1037 attr.name = "a";
1038 attr.size = 1;
1039 rc = panel_entry_append(panel, &attr);
1040 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1041
1042 attr.name = "b";
1043 attr.size = 2;
1044 rc = panel_entry_append(panel, &attr);
1045 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1046
1047 attr.name = "c";
1048 attr.size = 3;
1049 rc = panel_entry_append(panel, &attr);
1050 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1051
1052 /* Cursor and page start to the first entry */
1053 panel->cursor = panel_first(panel);
1054 panel->cursor_idx = 0;
1055 panel->page = panel->cursor;
1056 panel->page_idx = 0;
1057
1058 /* Move cursor to the bottom. This should scroll down. */
1059 panel_cursor_bottom(panel);
1060
1061 /* Cursor should now be at the third and page at the second entry. */
1062 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1063 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1064 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1065 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
1066 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
1067 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
1068
1069 panel_destroy(panel);
1070 ui_window_destroy(window);
1071 ui_destroy(ui);
1072}
1073
1074/** panel_page_up() moves one page up */
1075PCUT_TEST(page_up)
1076{
1077 ui_t *ui;
1078 ui_window_t *window;
1079 ui_wnd_params_t params;
1080 panel_t *panel;
1081 panel_entry_attr_t attr;
1082 gfx_rect_t rect;
1083 errno_t rc;
1084
1085 rc = ui_create_disp(NULL, &ui);
1086 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1087
1088 ui_wnd_params_init(&params);
1089 params.caption = "Test";
1090
1091 rc = ui_window_create(ui, &params, &window);
1092 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1093
1094 rc = panel_create(window, true, &panel);
1095 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1096
1097 rect.p0.x = 0;
1098 rect.p0.y = 0;
1099 rect.p1.x = 10;
1100 rect.p1.y = 4; // XXX Assuming this makes page size 2
1101 panel_set_rect(panel, &rect);
1102
1103 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1104
1105 /* Add five entries (2 full pages, one partial) */
1106
1107 panel_entry_attr_init(&attr);
1108
1109 attr.name = "a";
1110 attr.size = 1;
1111 rc = panel_entry_append(panel, &attr);
1112 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1113
1114 attr.name = "b";
1115 attr.size = 2;
1116 rc = panel_entry_append(panel, &attr);
1117 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1118
1119 attr.name = "c";
1120 attr.size = 3;
1121 rc = panel_entry_append(panel, &attr);
1122 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1123
1124 attr.name = "d";
1125 attr.size = 4;
1126 rc = panel_entry_append(panel, &attr);
1127 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1128
1129 attr.name = "e";
1130 attr.size = 5;
1131 rc = panel_entry_append(panel, &attr);
1132 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1133
1134 /* Cursor to the last entry and page start to the next-to-last entry */
1135 panel->cursor = panel_last(panel);
1136 panel->cursor_idx = 4;
1137 panel->page = panel_prev(panel->cursor);
1138 panel->page_idx = 3;
1139
1140 /* Move one page up */
1141 panel_page_up(panel);
1142
1143 /* Page should now start at second entry and cursor at third */
1144 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1145 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1146 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1147 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);
1148 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);
1149 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);
1150
1151 /* Move one page up again. */
1152 panel_page_up(panel);
1153
1154 /* Cursor and page start should now both be at the first entry */
1155 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
1156 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
1157 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
1158 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
1159 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
1160
1161 /* Moving further up should do nothing (we are at the top). */
1162 panel_page_up(panel);
1163
1164 /* Cursor and page start should still be at the first entry */
1165 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);
1166 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);
1167 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);
1168 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);
1169 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);
1170
1171 panel_destroy(panel);
1172 ui_window_destroy(window);
1173 ui_destroy(ui);
1174}
1175
1176/** panel_page_up() moves one page down */
1177PCUT_TEST(page_down)
1178{
1179 ui_t *ui;
1180 ui_window_t *window;
1181 ui_wnd_params_t params;
1182 panel_t *panel;
1183 panel_entry_attr_t attr;
1184 gfx_rect_t rect;
1185 errno_t rc;
1186
1187 rc = ui_create_disp(NULL, &ui);
1188 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1189
1190 ui_wnd_params_init(&params);
1191 params.caption = "Test";
1192
1193 rc = ui_window_create(ui, &params, &window);
1194 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1195
1196 rc = panel_create(window, true, &panel);
1197 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1198
1199 rect.p0.x = 0;
1200 rect.p0.y = 0;
1201 rect.p1.x = 10;
1202 rect.p1.y = 4; // XXX Assuming this makes page size 2
1203 panel_set_rect(panel, &rect);
1204
1205 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));
1206
1207 /* Add five entries (2 full pages, one partial) */
1208
1209 panel_entry_attr_init(&attr);
1210
1211 attr.name = "a";
1212 attr.size = 1;
1213 rc = panel_entry_append(panel, &attr);
1214 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1215
1216 attr.name = "b";
1217 attr.size = 2;
1218 rc = panel_entry_append(panel, &attr);
1219 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1220
1221 attr.name = "c";
1222 attr.size = 3;
1223 rc = panel_entry_append(panel, &attr);
1224 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1225
1226 attr.name = "d";
1227 attr.size = 4;
1228 rc = panel_entry_append(panel, &attr);
1229 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1230
1231 attr.name = "e";
1232 attr.size = 5;
1233 rc = panel_entry_append(panel, &attr);
1234 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1235
1236 /* Cursor and page to the first entry */
1237 panel->cursor = panel_first(panel);
1238 panel->cursor_idx = 0;
1239 panel->page = panel->cursor;
1240 panel->page_idx = 0;
1241
1242 /* Move one page down */
1243 panel_page_down(panel);
1244
1245 /* Page and cursor should point to the third entry */
1246 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
1247 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
1248 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);
1249 PCUT_ASSERT_STR_EQUALS("c", panel->page->name);
1250 PCUT_ASSERT_INT_EQUALS(3, panel->page->size);
1251 PCUT_ASSERT_INT_EQUALS(2, panel->page_idx);
1252
1253 /* Move one page down again. */
1254 panel_page_down(panel);
1255
1256 /* Cursor should point to last and page to next-to-last entry */
1257 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name);
1258 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size);
1259 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx);
1260 PCUT_ASSERT_STR_EQUALS("d", panel->page->name);
1261 PCUT_ASSERT_INT_EQUALS(4, panel->page->size);
1262 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx);
1263
1264 /* Moving further down should do nothing (we are at the bottom). */
1265 panel_page_down(panel);
1266
1267 /* Cursor should still point to last and page to next-to-last entry */
1268 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name);
1269 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size);
1270 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx);
1271 PCUT_ASSERT_STR_EQUALS("d", panel->page->name);
1272 PCUT_ASSERT_INT_EQUALS(4, panel->page->size);
1273 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx);
1274
1275 panel_destroy(panel);
1276 ui_window_destroy(window);
1277 ui_destroy(ui);
1278}
1279
1280/** panel_open() opens a directory entry */
1281PCUT_TEST(open)
1282{
1283 ui_t *ui;
1284 ui_window_t *window;
1285 ui_wnd_params_t params;
1286 panel_t *panel;
1287 panel_entry_t *entry;
1288 char buf[L_tmpnam];
1289 char *sdname;
1290 char *p;
1291 errno_t rc;
1292 int rv;
1293
1294 rc = ui_create_disp(NULL, &ui);
1295 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1296
1297 ui_wnd_params_init(&params);
1298 params.caption = "Test";
1299
1300 rc = ui_window_create(ui, &params, &window);
1301 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1302
1303 /* Create name for temporary directory */
1304 p = tmpnam(buf);
1305 PCUT_ASSERT_NOT_NULL(p);
1306
1307 /* Create temporary directory */
1308 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
1309 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1310
1311 rv = asprintf(&sdname, "%s/%s", p, "a");
1312 PCUT_ASSERT_TRUE(rv >= 0);
1313
1314 /* Create sub-directory */
1315 rc = vfs_link_path(sdname, KIND_DIRECTORY, NULL);
1316 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1317
1318 rc = panel_create(window, true, &panel);
1319 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1320
1321 rc = panel_read_dir(panel, p);
1322 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1323 PCUT_ASSERT_STR_EQUALS(p, panel->dir);
1324
1325 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
1326
1327 entry = panel_first(panel);
1328 PCUT_ASSERT_NOT_NULL(entry);
1329 PCUT_ASSERT_STR_EQUALS("..", entry->name);
1330
1331 entry = panel_next(entry);
1332 PCUT_ASSERT_NOT_NULL(entry);
1333 PCUT_ASSERT_STR_EQUALS("a", entry->name);
1334 PCUT_ASSERT_TRUE(entry->isdir);
1335
1336 rc = panel_open(panel, entry);
1337 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1338
1339 PCUT_ASSERT_STR_EQUALS(sdname, panel->dir);
1340
1341 panel_destroy(panel);
1342 ui_window_destroy(window);
1343 ui_destroy(ui);
1344
1345 rv = remove(sdname);
1346 PCUT_ASSERT_INT_EQUALS(0, rv);
1347
1348 rv = remove(p);
1349 PCUT_ASSERT_INT_EQUALS(0, rv);
1350
1351 free(sdname);
1352}
1353
1354PCUT_EXPORT(panel);
Note: See TracBrowser for help on using the repository browser.