1 | /*
|
---|
2 | * Copyright (c) 2024 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 <str.h>
|
---|
35 | #include <ui/ui.h>
|
---|
36 | #include <ui/list.h>
|
---|
37 | #include <ui/scrollbar.h>
|
---|
38 | #include <vfs/vfs.h>
|
---|
39 | #include "../private/list.h"
|
---|
40 |
|
---|
41 | PCUT_INIT;
|
---|
42 |
|
---|
43 | PCUT_TEST_SUITE(list);
|
---|
44 |
|
---|
45 | /** Test response */
|
---|
46 | typedef struct {
|
---|
47 | bool activate_req;
|
---|
48 | ui_list_t *activate_req_list;
|
---|
49 |
|
---|
50 | bool selected;
|
---|
51 | ui_list_entry_t *selected_entry;
|
---|
52 | } test_resp_t;
|
---|
53 |
|
---|
54 | static void test_list_activate_req(ui_list_t *, void *);
|
---|
55 | static void test_list_selected(ui_list_entry_t *, void *);
|
---|
56 | static int test_list_compare(ui_list_entry_t *, ui_list_entry_t *);
|
---|
57 |
|
---|
58 | static ui_list_cb_t test_cb = {
|
---|
59 | .activate_req = test_list_activate_req,
|
---|
60 | .selected = test_list_selected,
|
---|
61 | .compare = test_list_compare
|
---|
62 | };
|
---|
63 |
|
---|
64 | /** Create and destroy file list. */
|
---|
65 | PCUT_TEST(create_destroy)
|
---|
66 | {
|
---|
67 | ui_t *ui;
|
---|
68 | ui_window_t *window;
|
---|
69 | ui_wnd_params_t params;
|
---|
70 | ui_list_t *list;
|
---|
71 | errno_t rc;
|
---|
72 |
|
---|
73 | rc = ui_create_disp(NULL, &ui);
|
---|
74 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
75 |
|
---|
76 | ui_wnd_params_init(¶ms);
|
---|
77 | params.caption = "Test";
|
---|
78 |
|
---|
79 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
80 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
81 |
|
---|
82 | rc = ui_list_create(window, true, &list);
|
---|
83 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
84 |
|
---|
85 | ui_list_destroy(list);
|
---|
86 | ui_window_destroy(window);
|
---|
87 | ui_destroy(ui);
|
---|
88 | }
|
---|
89 |
|
---|
90 | /** ui_list_set_cb() sets callback */
|
---|
91 | PCUT_TEST(set_cb)
|
---|
92 | {
|
---|
93 | ui_t *ui;
|
---|
94 | ui_window_t *window;
|
---|
95 | ui_wnd_params_t params;
|
---|
96 | ui_list_t *list;
|
---|
97 | errno_t rc;
|
---|
98 | test_resp_t resp;
|
---|
99 |
|
---|
100 | rc = ui_create_disp(NULL, &ui);
|
---|
101 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
102 |
|
---|
103 | ui_wnd_params_init(¶ms);
|
---|
104 | params.caption = "Test";
|
---|
105 |
|
---|
106 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
107 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
108 |
|
---|
109 | rc = ui_list_create(window, true, &list);
|
---|
110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
111 |
|
---|
112 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
113 | PCUT_ASSERT_EQUALS(&test_cb, list->cb);
|
---|
114 | PCUT_ASSERT_EQUALS(&resp, list->cb_arg);
|
---|
115 |
|
---|
116 | ui_list_destroy(list);
|
---|
117 | ui_window_destroy(window);
|
---|
118 | ui_destroy(ui);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /** ui_list_get_cb_arg() returns the callback argument */
|
---|
122 | PCUT_TEST(get_cb_arg)
|
---|
123 | {
|
---|
124 | ui_t *ui;
|
---|
125 | ui_window_t *window;
|
---|
126 | ui_wnd_params_t params;
|
---|
127 | ui_list_t *list;
|
---|
128 | errno_t rc;
|
---|
129 | test_resp_t resp;
|
---|
130 | void *arg;
|
---|
131 |
|
---|
132 | rc = ui_create_disp(NULL, &ui);
|
---|
133 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
134 |
|
---|
135 | ui_wnd_params_init(¶ms);
|
---|
136 | params.caption = "Test";
|
---|
137 |
|
---|
138 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
139 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
140 |
|
---|
141 | rc = ui_list_create(window, true, &list);
|
---|
142 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
143 |
|
---|
144 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
145 | arg = ui_list_get_cb_arg(list);
|
---|
146 | PCUT_ASSERT_EQUALS((void *)&resp, arg);
|
---|
147 |
|
---|
148 | ui_list_destroy(list);
|
---|
149 | ui_window_destroy(window);
|
---|
150 | ui_destroy(ui);
|
---|
151 | }
|
---|
152 |
|
---|
153 | /** ui_list_entry_height() gives the correct height */
|
---|
154 | PCUT_TEST(entry_height)
|
---|
155 | {
|
---|
156 | ui_t *ui;
|
---|
157 | ui_window_t *window;
|
---|
158 | ui_wnd_params_t params;
|
---|
159 | ui_list_t *list;
|
---|
160 | errno_t rc;
|
---|
161 | gfx_coord_t height;
|
---|
162 |
|
---|
163 | rc = ui_create_disp(NULL, &ui);
|
---|
164 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
165 |
|
---|
166 | ui_wnd_params_init(¶ms);
|
---|
167 | params.caption = "Test";
|
---|
168 |
|
---|
169 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
170 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
171 |
|
---|
172 | rc = ui_list_create(window, true, &list);
|
---|
173 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
174 |
|
---|
175 | /* Font height is 13, padding: 2 (top) + 2 (bottom) */
|
---|
176 | height = ui_list_entry_height(list);
|
---|
177 | PCUT_ASSERT_INT_EQUALS(17, height);
|
---|
178 |
|
---|
179 | ui_list_destroy(list);
|
---|
180 | ui_window_destroy(window);
|
---|
181 | ui_destroy(ui);
|
---|
182 | }
|
---|
183 |
|
---|
184 | /** Test ui_list_entry_paint() */
|
---|
185 | PCUT_TEST(entry_paint)
|
---|
186 | {
|
---|
187 | ui_t *ui;
|
---|
188 | ui_window_t *window;
|
---|
189 | ui_wnd_params_t params;
|
---|
190 | ui_list_t *list;
|
---|
191 | ui_list_entry_attr_t attr;
|
---|
192 | errno_t rc;
|
---|
193 |
|
---|
194 | rc = ui_create_disp(NULL, &ui);
|
---|
195 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
196 |
|
---|
197 | ui_wnd_params_init(¶ms);
|
---|
198 | params.caption = "Test";
|
---|
199 |
|
---|
200 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
201 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
202 |
|
---|
203 | rc = ui_list_create(window, true, &list);
|
---|
204 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
205 |
|
---|
206 | ui_list_entry_attr_init(&attr);
|
---|
207 | attr.caption = "a";
|
---|
208 | attr.arg = (void *)1;
|
---|
209 |
|
---|
210 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
211 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
212 |
|
---|
213 | rc = ui_list_entry_paint(ui_list_first(list), 0);
|
---|
214 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
215 |
|
---|
216 | ui_list_destroy(list);
|
---|
217 | ui_window_destroy(window);
|
---|
218 | ui_destroy(ui);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /** Test ui_list_paint() */
|
---|
222 | PCUT_TEST(paint)
|
---|
223 | {
|
---|
224 | ui_t *ui;
|
---|
225 | ui_window_t *window;
|
---|
226 | ui_wnd_params_t params;
|
---|
227 | ui_list_t *list;
|
---|
228 | errno_t rc;
|
---|
229 |
|
---|
230 | rc = ui_create_disp(NULL, &ui);
|
---|
231 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
232 |
|
---|
233 | ui_wnd_params_init(¶ms);
|
---|
234 | params.caption = "Test";
|
---|
235 |
|
---|
236 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
237 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
238 |
|
---|
239 | rc = ui_list_create(window, true, &list);
|
---|
240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
241 |
|
---|
242 | rc = ui_list_paint(list);
|
---|
243 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
244 |
|
---|
245 | ui_list_destroy(list);
|
---|
246 | ui_window_destroy(window);
|
---|
247 | ui_destroy(ui);
|
---|
248 | }
|
---|
249 |
|
---|
250 | /** ui_list_ctl() returns a valid UI control */
|
---|
251 | PCUT_TEST(ctl)
|
---|
252 | {
|
---|
253 | ui_t *ui;
|
---|
254 | ui_window_t *window;
|
---|
255 | ui_wnd_params_t params;
|
---|
256 | ui_list_t *list;
|
---|
257 | ui_control_t *control;
|
---|
258 | errno_t rc;
|
---|
259 |
|
---|
260 | rc = ui_create_disp(NULL, &ui);
|
---|
261 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
262 |
|
---|
263 | ui_wnd_params_init(¶ms);
|
---|
264 | params.caption = "Test";
|
---|
265 |
|
---|
266 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
267 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
268 |
|
---|
269 | rc = ui_list_create(window, true, &list);
|
---|
270 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
271 |
|
---|
272 | control = ui_list_ctl(list);
|
---|
273 | PCUT_ASSERT_NOT_NULL(control);
|
---|
274 |
|
---|
275 | ui_list_destroy(list);
|
---|
276 | ui_window_destroy(window);
|
---|
277 | ui_destroy(ui);
|
---|
278 | }
|
---|
279 |
|
---|
280 | /** Test ui_list_kbd_event() */
|
---|
281 | PCUT_TEST(kbd_event)
|
---|
282 | {
|
---|
283 | ui_t *ui;
|
---|
284 | ui_window_t *window;
|
---|
285 | ui_wnd_params_t params;
|
---|
286 | ui_list_t *list;
|
---|
287 | ui_evclaim_t claimed;
|
---|
288 | kbd_event_t event;
|
---|
289 | errno_t rc;
|
---|
290 |
|
---|
291 | /* Active list should claim events */
|
---|
292 |
|
---|
293 | rc = ui_create_disp(NULL, &ui);
|
---|
294 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
295 |
|
---|
296 | ui_wnd_params_init(¶ms);
|
---|
297 | params.caption = "Test";
|
---|
298 |
|
---|
299 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
300 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
301 |
|
---|
302 | rc = ui_list_create(window, true, &list);
|
---|
303 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
304 |
|
---|
305 | event.type = KEY_PRESS;
|
---|
306 | event.key = KC_ESCAPE;
|
---|
307 | event.mods = 0;
|
---|
308 | event.c = '\0';
|
---|
309 |
|
---|
310 | claimed = ui_list_kbd_event(list, &event);
|
---|
311 | PCUT_ASSERT_EQUALS(ui_claimed, claimed);
|
---|
312 |
|
---|
313 | ui_list_destroy(list);
|
---|
314 |
|
---|
315 | /* Inactive list should not claim events */
|
---|
316 |
|
---|
317 | rc = ui_create_disp(NULL, &ui);
|
---|
318 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
319 |
|
---|
320 | ui_wnd_params_init(¶ms);
|
---|
321 | params.caption = "Test";
|
---|
322 |
|
---|
323 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
324 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
325 |
|
---|
326 | rc = ui_list_create(window, false, &list);
|
---|
327 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
328 |
|
---|
329 | event.type = KEY_PRESS;
|
---|
330 | event.key = KC_ESCAPE;
|
---|
331 | event.mods = 0;
|
---|
332 | event.c = '\0';
|
---|
333 |
|
---|
334 | claimed = ui_list_kbd_event(list, &event);
|
---|
335 | PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
|
---|
336 |
|
---|
337 | ui_list_destroy(list);
|
---|
338 | ui_window_destroy(window);
|
---|
339 | ui_destroy(ui);
|
---|
340 | }
|
---|
341 |
|
---|
342 | /** Test ui_list_pos_event() */
|
---|
343 | PCUT_TEST(pos_event)
|
---|
344 | {
|
---|
345 | ui_t *ui;
|
---|
346 | ui_window_t *window;
|
---|
347 | ui_wnd_params_t params;
|
---|
348 | ui_list_t *list;
|
---|
349 | ui_evclaim_t claimed;
|
---|
350 | pos_event_t event;
|
---|
351 | gfx_rect_t rect;
|
---|
352 | ui_list_entry_attr_t attr;
|
---|
353 | errno_t rc;
|
---|
354 |
|
---|
355 | rc = ui_create_disp(NULL, &ui);
|
---|
356 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
357 |
|
---|
358 | ui_wnd_params_init(¶ms);
|
---|
359 | params.caption = "Test";
|
---|
360 |
|
---|
361 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
362 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
363 |
|
---|
364 | rc = ui_list_create(window, true, &list);
|
---|
365 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
366 |
|
---|
367 | rect.p0.x = 10;
|
---|
368 | rect.p0.y = 20;
|
---|
369 | rect.p1.x = 50;
|
---|
370 | rect.p1.y = 220;
|
---|
371 |
|
---|
372 | ui_list_set_rect(list, &rect);
|
---|
373 |
|
---|
374 | ui_list_entry_attr_init(&attr);
|
---|
375 | attr.caption = "a";
|
---|
376 | attr.arg = (void *)1;
|
---|
377 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
378 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
379 |
|
---|
380 | attr.caption = "b";
|
---|
381 | attr.arg = (void *)2;
|
---|
382 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
383 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
384 |
|
---|
385 | attr.caption = "c";
|
---|
386 | attr.arg = (void *)3;
|
---|
387 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
388 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
389 |
|
---|
390 | list->cursor = ui_list_first(list);
|
---|
391 | list->cursor_idx = 0;
|
---|
392 | list->page = ui_list_first(list);
|
---|
393 | list->page_idx = 0;
|
---|
394 |
|
---|
395 | event.pos_id = 0;
|
---|
396 | event.type = POS_PRESS;
|
---|
397 | event.btn_num = 1;
|
---|
398 |
|
---|
399 | /* Clicking on the middle entry should select it */
|
---|
400 | event.hpos = 20;
|
---|
401 | event.vpos = 40;
|
---|
402 |
|
---|
403 | claimed = ui_list_pos_event(list, &event);
|
---|
404 | PCUT_ASSERT_EQUALS(ui_claimed, claimed);
|
---|
405 |
|
---|
406 | PCUT_ASSERT_NOT_NULL(list->cursor);
|
---|
407 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
---|
408 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
---|
409 |
|
---|
410 | /* Clicking on the top edge should do a page-up */
|
---|
411 | event.hpos = 20;
|
---|
412 | event.vpos = 20;
|
---|
413 | claimed = ui_list_pos_event(list, &event);
|
---|
414 | PCUT_ASSERT_EQUALS(ui_claimed, claimed);
|
---|
415 |
|
---|
416 | PCUT_ASSERT_NOT_NULL(list->cursor);
|
---|
417 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
418 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
419 |
|
---|
420 | ui_list_destroy(list);
|
---|
421 | ui_window_destroy(window);
|
---|
422 | ui_destroy(ui);
|
---|
423 | }
|
---|
424 |
|
---|
425 | /** ui_list_set_rect() sets internal field */
|
---|
426 | PCUT_TEST(set_rect)
|
---|
427 | {
|
---|
428 | ui_t *ui;
|
---|
429 | ui_window_t *window;
|
---|
430 | ui_wnd_params_t params;
|
---|
431 | ui_list_t *list;
|
---|
432 | gfx_rect_t rect;
|
---|
433 | errno_t rc;
|
---|
434 |
|
---|
435 | rc = ui_create_disp(NULL, &ui);
|
---|
436 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
437 |
|
---|
438 | ui_wnd_params_init(¶ms);
|
---|
439 | params.caption = "Test";
|
---|
440 |
|
---|
441 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
442 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
443 |
|
---|
444 | rc = ui_list_create(window, true, &list);
|
---|
445 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
446 |
|
---|
447 | rect.p0.x = 1;
|
---|
448 | rect.p0.y = 2;
|
---|
449 | rect.p1.x = 3;
|
---|
450 | rect.p1.y = 4;
|
---|
451 |
|
---|
452 | ui_list_set_rect(list, &rect);
|
---|
453 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, list->rect.p0.x);
|
---|
454 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, list->rect.p0.y);
|
---|
455 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, list->rect.p1.x);
|
---|
456 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, list->rect.p1.y);
|
---|
457 |
|
---|
458 | ui_list_destroy(list);
|
---|
459 | ui_window_destroy(window);
|
---|
460 | ui_destroy(ui);
|
---|
461 | }
|
---|
462 |
|
---|
463 | /** ui_list_page_size() returns correct size */
|
---|
464 | PCUT_TEST(page_size)
|
---|
465 | {
|
---|
466 | ui_t *ui;
|
---|
467 | ui_window_t *window;
|
---|
468 | ui_wnd_params_t params;
|
---|
469 | ui_list_t *list;
|
---|
470 | gfx_rect_t rect;
|
---|
471 | errno_t rc;
|
---|
472 |
|
---|
473 | rc = ui_create_disp(NULL, &ui);
|
---|
474 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
475 |
|
---|
476 | ui_wnd_params_init(¶ms);
|
---|
477 | params.caption = "Test";
|
---|
478 |
|
---|
479 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
480 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
481 |
|
---|
482 | rc = ui_list_create(window, true, &list);
|
---|
483 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
484 |
|
---|
485 | rect.p0.x = 10;
|
---|
486 | rect.p0.y = 20;
|
---|
487 | rect.p1.x = 50;
|
---|
488 | rect.p1.y = 220;
|
---|
489 |
|
---|
490 | ui_list_set_rect(list, &rect);
|
---|
491 |
|
---|
492 | /* NOTE If page size changes, we have problems elsewhere in the tests */
|
---|
493 | PCUT_ASSERT_INT_EQUALS(11, ui_list_page_size(list));
|
---|
494 |
|
---|
495 | ui_list_destroy(list);
|
---|
496 | ui_window_destroy(window);
|
---|
497 | ui_destroy(ui);
|
---|
498 | }
|
---|
499 |
|
---|
500 | /** ui_list_inside_rect() gives correct interior rectangle */
|
---|
501 | PCUT_TEST(inside_rect)
|
---|
502 | {
|
---|
503 | ui_t *ui;
|
---|
504 | ui_window_t *window;
|
---|
505 | ui_wnd_params_t params;
|
---|
506 | ui_list_t *list;
|
---|
507 | gfx_rect_t rect;
|
---|
508 | gfx_rect_t irect;
|
---|
509 | errno_t rc;
|
---|
510 |
|
---|
511 | rc = ui_create_disp(NULL, &ui);
|
---|
512 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
513 |
|
---|
514 | ui_wnd_params_init(¶ms);
|
---|
515 | params.caption = "Test";
|
---|
516 |
|
---|
517 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
518 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
519 |
|
---|
520 | rc = ui_list_create(window, true, &list);
|
---|
521 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
522 |
|
---|
523 | rect.p0.x = 10;
|
---|
524 | rect.p0.y = 20;
|
---|
525 | rect.p1.x = 50;
|
---|
526 | rect.p1.y = 220;
|
---|
527 |
|
---|
528 | ui_list_set_rect(list, &rect);
|
---|
529 |
|
---|
530 | ui_list_inside_rect(list, &irect);
|
---|
531 | PCUT_ASSERT_INT_EQUALS(10 + 2, irect.p0.x);
|
---|
532 | PCUT_ASSERT_INT_EQUALS(20 + 2, irect.p0.y);
|
---|
533 | PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, irect.p1.x);
|
---|
534 | PCUT_ASSERT_INT_EQUALS(220 - 2, irect.p1.y);
|
---|
535 |
|
---|
536 | ui_list_destroy(list);
|
---|
537 | ui_window_destroy(window);
|
---|
538 | ui_destroy(ui);
|
---|
539 | }
|
---|
540 |
|
---|
541 | /** ui_list_scrollbar_rect() gives correct scrollbar rectangle */
|
---|
542 | PCUT_TEST(scrollbar_rect)
|
---|
543 | {
|
---|
544 | ui_t *ui;
|
---|
545 | ui_window_t *window;
|
---|
546 | ui_wnd_params_t params;
|
---|
547 | ui_list_t *list;
|
---|
548 | gfx_rect_t rect;
|
---|
549 | gfx_rect_t srect;
|
---|
550 | errno_t rc;
|
---|
551 |
|
---|
552 | rc = ui_create_disp(NULL, &ui);
|
---|
553 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
554 |
|
---|
555 | ui_wnd_params_init(¶ms);
|
---|
556 | params.caption = "Test";
|
---|
557 |
|
---|
558 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
559 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
560 |
|
---|
561 | rc = ui_list_create(window, true, &list);
|
---|
562 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
563 |
|
---|
564 | rect.p0.x = 10;
|
---|
565 | rect.p0.y = 20;
|
---|
566 | rect.p1.x = 50;
|
---|
567 | rect.p1.y = 220;
|
---|
568 |
|
---|
569 | ui_list_set_rect(list, &rect);
|
---|
570 |
|
---|
571 | ui_list_scrollbar_rect(list, &srect);
|
---|
572 | PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, srect.p0.x);
|
---|
573 | PCUT_ASSERT_INT_EQUALS(20 + 2, srect.p0.y);
|
---|
574 | PCUT_ASSERT_INT_EQUALS(50 - 2, srect.p1.x);
|
---|
575 | PCUT_ASSERT_INT_EQUALS(220 - 2, srect.p1.y);
|
---|
576 |
|
---|
577 | ui_list_destroy(list);
|
---|
578 | ui_window_destroy(window);
|
---|
579 | ui_destroy(ui);
|
---|
580 | }
|
---|
581 |
|
---|
582 | /** ui_list_scrollbar_update() updates scrollbar position */
|
---|
583 | PCUT_TEST(scrollbar_update)
|
---|
584 | {
|
---|
585 | ui_t *ui;
|
---|
586 | ui_window_t *window;
|
---|
587 | ui_wnd_params_t params;
|
---|
588 | ui_list_t *list;
|
---|
589 | gfx_rect_t rect;
|
---|
590 | ui_list_entry_attr_t attr;
|
---|
591 | ui_list_entry_t *entry;
|
---|
592 | gfx_coord_t pos;
|
---|
593 | gfx_coord_t move_len;
|
---|
594 | errno_t rc;
|
---|
595 |
|
---|
596 | rc = ui_create_disp(NULL, &ui);
|
---|
597 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
598 |
|
---|
599 | ui_wnd_params_init(¶ms);
|
---|
600 | params.caption = "Test";
|
---|
601 |
|
---|
602 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
603 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
604 |
|
---|
605 | rc = ui_list_create(window, true, &list);
|
---|
606 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
607 |
|
---|
608 | rect.p0.x = 0;
|
---|
609 | rect.p0.y = 0;
|
---|
610 | rect.p1.x = 50;
|
---|
611 | rect.p1.y = 38;
|
---|
612 |
|
---|
613 | ui_list_set_rect(list, &rect);
|
---|
614 |
|
---|
615 | ui_list_entry_attr_init(&attr);
|
---|
616 | attr.caption = "a";
|
---|
617 | attr.arg = (void *)1;
|
---|
618 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
619 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
620 |
|
---|
621 | attr.caption = "b";
|
---|
622 | attr.arg = (void *)2;
|
---|
623 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
624 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
625 |
|
---|
626 | attr.caption = "c";
|
---|
627 | attr.arg = (void *)3;
|
---|
628 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
629 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
630 |
|
---|
631 | entry = ui_list_next(ui_list_first(list));
|
---|
632 |
|
---|
633 | list->cursor = entry;
|
---|
634 | list->cursor_idx = 1;
|
---|
635 | list->page = entry;
|
---|
636 | list->page_idx = 1;
|
---|
637 |
|
---|
638 | ui_list_scrollbar_update(list);
|
---|
639 |
|
---|
640 | /* Now scrollbar thumb should be all the way down */
|
---|
641 | move_len = ui_scrollbar_move_length(list->scrollbar);
|
---|
642 | pos = ui_scrollbar_get_pos(list->scrollbar);
|
---|
643 | PCUT_ASSERT_INT_EQUALS(move_len, pos);
|
---|
644 |
|
---|
645 | ui_list_destroy(list);
|
---|
646 | ui_window_destroy(window);
|
---|
647 | ui_destroy(ui);
|
---|
648 | }
|
---|
649 |
|
---|
650 | /** ui_list_is_active() returns list activity state */
|
---|
651 | PCUT_TEST(is_active)
|
---|
652 | {
|
---|
653 | ui_t *ui;
|
---|
654 | ui_window_t *window;
|
---|
655 | ui_wnd_params_t params;
|
---|
656 | ui_list_t *list;
|
---|
657 | errno_t rc;
|
---|
658 |
|
---|
659 | rc = ui_create_disp(NULL, &ui);
|
---|
660 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
661 |
|
---|
662 | ui_wnd_params_init(¶ms);
|
---|
663 | params.caption = "Test";
|
---|
664 |
|
---|
665 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
666 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
667 |
|
---|
668 | rc = ui_list_create(window, true, &list);
|
---|
669 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
670 | PCUT_ASSERT_TRUE(ui_list_is_active(list));
|
---|
671 | ui_list_destroy(list);
|
---|
672 |
|
---|
673 | rc = ui_list_create(window, false, &list);
|
---|
674 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
675 | PCUT_ASSERT_FALSE(ui_list_is_active(list));
|
---|
676 | ui_list_destroy(list);
|
---|
677 | ui_window_destroy(window);
|
---|
678 | ui_destroy(ui);
|
---|
679 | }
|
---|
680 |
|
---|
681 | /** ui_list_activate() activates list */
|
---|
682 | PCUT_TEST(activate)
|
---|
683 | {
|
---|
684 | ui_t *ui;
|
---|
685 | ui_window_t *window;
|
---|
686 | ui_wnd_params_t params;
|
---|
687 | ui_list_t *list;
|
---|
688 | errno_t rc;
|
---|
689 |
|
---|
690 | rc = ui_create_disp(NULL, &ui);
|
---|
691 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
692 |
|
---|
693 | ui_wnd_params_init(¶ms);
|
---|
694 | params.caption = "Test";
|
---|
695 |
|
---|
696 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
697 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
698 |
|
---|
699 | rc = ui_list_create(window, false, &list);
|
---|
700 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
701 |
|
---|
702 | PCUT_ASSERT_FALSE(ui_list_is_active(list));
|
---|
703 | rc = ui_list_activate(list);
|
---|
704 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
705 | PCUT_ASSERT_TRUE(ui_list_is_active(list));
|
---|
706 |
|
---|
707 | ui_list_destroy(list);
|
---|
708 | ui_window_destroy(window);
|
---|
709 | ui_destroy(ui);
|
---|
710 | }
|
---|
711 |
|
---|
712 | /** ui_list_deactivate() deactivates list */
|
---|
713 | PCUT_TEST(deactivate)
|
---|
714 | {
|
---|
715 | ui_t *ui;
|
---|
716 | ui_window_t *window;
|
---|
717 | ui_wnd_params_t params;
|
---|
718 | ui_list_t *list;
|
---|
719 | errno_t rc;
|
---|
720 |
|
---|
721 | rc = ui_create_disp(NULL, &ui);
|
---|
722 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
723 |
|
---|
724 | ui_wnd_params_init(¶ms);
|
---|
725 | params.caption = "Test";
|
---|
726 |
|
---|
727 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
728 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
729 |
|
---|
730 | rc = ui_list_create(window, true, &list);
|
---|
731 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
732 |
|
---|
733 | PCUT_ASSERT_TRUE(ui_list_is_active(list));
|
---|
734 | ui_list_deactivate(list);
|
---|
735 | PCUT_ASSERT_FALSE(ui_list_is_active(list));
|
---|
736 |
|
---|
737 | ui_list_destroy(list);
|
---|
738 | ui_window_destroy(window);
|
---|
739 | ui_destroy(ui);
|
---|
740 | }
|
---|
741 |
|
---|
742 | /** ui_list_get_cursor() returns the current cursor position */
|
---|
743 | PCUT_TEST(get_cursor)
|
---|
744 | {
|
---|
745 | ui_t *ui;
|
---|
746 | ui_window_t *window;
|
---|
747 | ui_wnd_params_t params;
|
---|
748 | ui_list_t *list;
|
---|
749 | ui_list_entry_attr_t attr;
|
---|
750 | ui_list_entry_t *entry;
|
---|
751 | ui_list_entry_t *cursor;
|
---|
752 | errno_t rc;
|
---|
753 |
|
---|
754 | rc = ui_create_disp(NULL, &ui);
|
---|
755 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
756 |
|
---|
757 | ui_wnd_params_init(¶ms);
|
---|
758 | params.caption = "Test";
|
---|
759 |
|
---|
760 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
761 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
762 |
|
---|
763 | rc = ui_list_create(window, true, &list);
|
---|
764 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
765 |
|
---|
766 | ui_list_entry_attr_init(&attr);
|
---|
767 |
|
---|
768 | /* Append entry and get pointer to it */
|
---|
769 | attr.caption = "a";
|
---|
770 | attr.arg = (void *)1;
|
---|
771 | entry = NULL;
|
---|
772 | rc = ui_list_entry_append(list, &attr, &entry);
|
---|
773 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
774 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
775 |
|
---|
776 | /* Cursor should be at the only entry */
|
---|
777 | cursor = ui_list_get_cursor(list);
|
---|
778 | PCUT_ASSERT_EQUALS(entry, cursor);
|
---|
779 |
|
---|
780 | ui_list_destroy(list);
|
---|
781 | ui_window_destroy(window);
|
---|
782 | ui_destroy(ui);
|
---|
783 | }
|
---|
784 |
|
---|
785 | /** ui_list_set_cursor() sets list cursor position */
|
---|
786 | PCUT_TEST(set_cursor)
|
---|
787 | {
|
---|
788 | ui_t *ui;
|
---|
789 | ui_window_t *window;
|
---|
790 | ui_wnd_params_t params;
|
---|
791 | ui_list_t *list;
|
---|
792 | ui_list_entry_attr_t attr;
|
---|
793 | ui_list_entry_t *e1;
|
---|
794 | ui_list_entry_t *e2;
|
---|
795 | errno_t rc;
|
---|
796 |
|
---|
797 | rc = ui_create_disp(NULL, &ui);
|
---|
798 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
799 |
|
---|
800 | ui_wnd_params_init(¶ms);
|
---|
801 | params.caption = "Test";
|
---|
802 |
|
---|
803 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
804 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
805 |
|
---|
806 | rc = ui_list_create(window, true, &list);
|
---|
807 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
808 |
|
---|
809 | ui_list_entry_attr_init(&attr);
|
---|
810 |
|
---|
811 | /* Append entry and get pointer to it */
|
---|
812 | attr.caption = "a";
|
---|
813 | attr.arg = (void *)1;
|
---|
814 | rc = ui_list_entry_append(list, &attr, &e1);
|
---|
815 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
816 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
817 |
|
---|
818 | /* Append entry and get pointer to it */
|
---|
819 | attr.caption = "b";
|
---|
820 | attr.arg = (void *)2;
|
---|
821 | rc = ui_list_entry_append(list, &attr, &e2);
|
---|
822 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
823 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
824 |
|
---|
825 | /* Append entry */
|
---|
826 | attr.caption = "c";
|
---|
827 | attr.arg = (void *)3;
|
---|
828 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
829 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
830 |
|
---|
831 | /* Cursor should be at the first entry */
|
---|
832 | PCUT_ASSERT_EQUALS(e1, list->cursor);
|
---|
833 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
834 |
|
---|
835 | /* Set cursor to the second entry */
|
---|
836 | ui_list_set_cursor(list, e2);
|
---|
837 | PCUT_ASSERT_EQUALS(e2, list->cursor);
|
---|
838 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
---|
839 |
|
---|
840 | ui_list_destroy(list);
|
---|
841 | ui_window_destroy(window);
|
---|
842 | ui_destroy(ui);
|
---|
843 | }
|
---|
844 |
|
---|
845 | /** ui_list_entry_attr_init() initializes entry attribute structure */
|
---|
846 | PCUT_TEST(entry_attr_init)
|
---|
847 | {
|
---|
848 | ui_list_entry_attr_t attr;
|
---|
849 |
|
---|
850 | ui_list_entry_attr_init(&attr);
|
---|
851 | PCUT_ASSERT_NULL(attr.caption);
|
---|
852 | PCUT_ASSERT_NULL(attr.arg);
|
---|
853 | PCUT_ASSERT_NULL(attr.color);
|
---|
854 | PCUT_ASSERT_NULL(attr.bgcolor);
|
---|
855 | }
|
---|
856 |
|
---|
857 | /** ui_list_entry_append() appends new entry */
|
---|
858 | PCUT_TEST(entry_append)
|
---|
859 | {
|
---|
860 | ui_t *ui;
|
---|
861 | ui_window_t *window;
|
---|
862 | ui_wnd_params_t params;
|
---|
863 | ui_list_t *list;
|
---|
864 | ui_list_entry_attr_t attr;
|
---|
865 | ui_list_entry_t *entry;
|
---|
866 | errno_t rc;
|
---|
867 |
|
---|
868 | rc = ui_create_disp(NULL, &ui);
|
---|
869 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
870 |
|
---|
871 | ui_wnd_params_init(¶ms);
|
---|
872 | params.caption = "Test";
|
---|
873 |
|
---|
874 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
875 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
876 |
|
---|
877 | rc = ui_list_create(window, true, &list);
|
---|
878 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
879 |
|
---|
880 | ui_list_entry_attr_init(&attr);
|
---|
881 |
|
---|
882 | /* Append entry without retrieving pointer to it */
|
---|
883 | attr.caption = "a";
|
---|
884 | attr.arg = (void *)1;
|
---|
885 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
886 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
887 |
|
---|
888 | PCUT_ASSERT_INT_EQUALS(1, list_count(&list->entries));
|
---|
889 |
|
---|
890 | /* Append entry and get pointer to it */
|
---|
891 | attr.caption = "b";
|
---|
892 | attr.arg = (void *)2;
|
---|
893 | entry = NULL;
|
---|
894 | rc = ui_list_entry_append(list, &attr, &entry);
|
---|
895 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
896 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
897 | PCUT_ASSERT_EQUALS(attr.arg, entry->arg);
|
---|
898 |
|
---|
899 | PCUT_ASSERT_INT_EQUALS(2, list_count(&list->entries));
|
---|
900 |
|
---|
901 | ui_list_destroy(list);
|
---|
902 | ui_window_destroy(window);
|
---|
903 | ui_destroy(ui);
|
---|
904 | }
|
---|
905 |
|
---|
906 | /** ui_list_entry_move_up() moves entry up */
|
---|
907 | PCUT_TEST(entry_move_up)
|
---|
908 | {
|
---|
909 | ui_t *ui;
|
---|
910 | ui_window_t *window;
|
---|
911 | ui_wnd_params_t params;
|
---|
912 | ui_list_t *list;
|
---|
913 | ui_list_entry_attr_t attr;
|
---|
914 | ui_list_entry_t *e1, *e2, *e3;
|
---|
915 | ui_list_entry_t *e;
|
---|
916 | errno_t rc;
|
---|
917 |
|
---|
918 | rc = ui_create_disp(NULL, &ui);
|
---|
919 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
920 |
|
---|
921 | ui_wnd_params_init(¶ms);
|
---|
922 | params.caption = "Test";
|
---|
923 |
|
---|
924 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
925 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
926 |
|
---|
927 | rc = ui_list_create(window, true, &list);
|
---|
928 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
929 |
|
---|
930 | ui_list_entry_attr_init(&attr);
|
---|
931 |
|
---|
932 | /* Create entries */
|
---|
933 |
|
---|
934 | attr.caption = "a";
|
---|
935 | attr.arg = (void *)1;
|
---|
936 | rc = ui_list_entry_append(list, &attr, &e1);
|
---|
937 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
938 |
|
---|
939 | attr.caption = "b";
|
---|
940 | attr.arg = (void *)2;
|
---|
941 | rc = ui_list_entry_append(list, &attr, &e2);
|
---|
942 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
943 |
|
---|
944 | attr.caption = "c";
|
---|
945 | attr.arg = (void *)3;
|
---|
946 | rc = ui_list_entry_append(list, &attr, &e3);
|
---|
947 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
948 |
|
---|
949 | e = ui_list_first(list);
|
---|
950 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
951 |
|
---|
952 | /* Moving first entry up should have no effect */
|
---|
953 | ui_list_entry_move_up(e1);
|
---|
954 |
|
---|
955 | e = ui_list_first(list);
|
---|
956 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
957 |
|
---|
958 | e = ui_list_next(e);
|
---|
959 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
960 |
|
---|
961 | e = ui_list_next(e);
|
---|
962 | PCUT_ASSERT_EQUALS(e3, e);
|
---|
963 |
|
---|
964 | e = ui_list_next(e);
|
---|
965 | PCUT_ASSERT_NULL(e);
|
---|
966 |
|
---|
967 | /* Move second entry up */
|
---|
968 | ui_list_entry_move_up(e2);
|
---|
969 |
|
---|
970 | e = ui_list_first(list);
|
---|
971 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
972 |
|
---|
973 | e = ui_list_next(e);
|
---|
974 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
975 |
|
---|
976 | e = ui_list_next(e);
|
---|
977 | PCUT_ASSERT_EQUALS(e3, e);
|
---|
978 |
|
---|
979 | e = ui_list_next(e);
|
---|
980 | PCUT_ASSERT_NULL(e);
|
---|
981 |
|
---|
982 | ui_list_destroy(list);
|
---|
983 | ui_window_destroy(window);
|
---|
984 | ui_destroy(ui);
|
---|
985 | }
|
---|
986 |
|
---|
987 | /** ui_list_entry_move_down() moves entry down */
|
---|
988 | PCUT_TEST(entry_move_down)
|
---|
989 | {
|
---|
990 | ui_t *ui;
|
---|
991 | ui_window_t *window;
|
---|
992 | ui_wnd_params_t params;
|
---|
993 | ui_list_t *list;
|
---|
994 | ui_list_entry_attr_t attr;
|
---|
995 | ui_list_entry_t *e1, *e2, *e3;
|
---|
996 | ui_list_entry_t *e;
|
---|
997 | errno_t rc;
|
---|
998 |
|
---|
999 | rc = ui_create_disp(NULL, &ui);
|
---|
1000 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1001 |
|
---|
1002 | ui_wnd_params_init(¶ms);
|
---|
1003 | params.caption = "Test";
|
---|
1004 |
|
---|
1005 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1006 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1007 |
|
---|
1008 | rc = ui_list_create(window, true, &list);
|
---|
1009 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1010 |
|
---|
1011 | ui_list_entry_attr_init(&attr);
|
---|
1012 |
|
---|
1013 | /* Create entries */
|
---|
1014 |
|
---|
1015 | attr.caption = "a";
|
---|
1016 | attr.arg = (void *)1;
|
---|
1017 | rc = ui_list_entry_append(list, &attr, &e1);
|
---|
1018 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1019 |
|
---|
1020 | attr.caption = "b";
|
---|
1021 | attr.arg = (void *)2;
|
---|
1022 | rc = ui_list_entry_append(list, &attr, &e2);
|
---|
1023 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1024 |
|
---|
1025 | attr.caption = "c";
|
---|
1026 | attr.arg = (void *)3;
|
---|
1027 | rc = ui_list_entry_append(list, &attr, &e3);
|
---|
1028 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1029 |
|
---|
1030 | e = ui_list_first(list);
|
---|
1031 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
1032 |
|
---|
1033 | /* Moving last entry down should have no effect */
|
---|
1034 | ui_list_entry_move_down(e3);
|
---|
1035 |
|
---|
1036 | e = ui_list_first(list);
|
---|
1037 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
1038 |
|
---|
1039 | e = ui_list_next(e);
|
---|
1040 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
1041 |
|
---|
1042 | e = ui_list_next(e);
|
---|
1043 | PCUT_ASSERT_EQUALS(e3, e);
|
---|
1044 |
|
---|
1045 | e = ui_list_next(e);
|
---|
1046 | PCUT_ASSERT_NULL(e);
|
---|
1047 |
|
---|
1048 | /* Move second-to-last entry down */
|
---|
1049 | ui_list_entry_move_down(e2);
|
---|
1050 |
|
---|
1051 | e = ui_list_first(list);
|
---|
1052 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
1053 |
|
---|
1054 | e = ui_list_next(e);
|
---|
1055 | PCUT_ASSERT_EQUALS(e3, e);
|
---|
1056 |
|
---|
1057 | e = ui_list_next(e);
|
---|
1058 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
1059 |
|
---|
1060 | e = ui_list_next(e);
|
---|
1061 | PCUT_ASSERT_NULL(e);
|
---|
1062 |
|
---|
1063 | ui_list_destroy(list);
|
---|
1064 | ui_window_destroy(window);
|
---|
1065 | ui_destroy(ui);
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | /** ui_list_entry_delete() deletes entry */
|
---|
1069 | PCUT_TEST(entry_delete)
|
---|
1070 | {
|
---|
1071 | ui_t *ui;
|
---|
1072 | ui_window_t *window;
|
---|
1073 | ui_wnd_params_t params;
|
---|
1074 | ui_list_t *list;
|
---|
1075 | ui_list_entry_t *entry;
|
---|
1076 | ui_list_entry_attr_t attr;
|
---|
1077 | errno_t rc;
|
---|
1078 |
|
---|
1079 | rc = ui_create_disp(NULL, &ui);
|
---|
1080 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1081 |
|
---|
1082 | ui_wnd_params_init(¶ms);
|
---|
1083 | params.caption = "Test";
|
---|
1084 |
|
---|
1085 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1086 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1087 |
|
---|
1088 | rc = ui_list_create(window, true, &list);
|
---|
1089 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1090 |
|
---|
1091 | attr.caption = "a";
|
---|
1092 | attr.arg = (void *)1;
|
---|
1093 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1094 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1095 |
|
---|
1096 | attr.caption = "b";
|
---|
1097 | attr.arg = (void *)2;
|
---|
1098 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1099 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1100 |
|
---|
1101 | PCUT_ASSERT_INT_EQUALS(2, list_count(&list->entries));
|
---|
1102 |
|
---|
1103 | entry = ui_list_first(list);
|
---|
1104 | ui_list_entry_delete(entry);
|
---|
1105 |
|
---|
1106 | PCUT_ASSERT_INT_EQUALS(1, list_count(&list->entries));
|
---|
1107 |
|
---|
1108 | entry = ui_list_first(list);
|
---|
1109 | ui_list_entry_delete(entry);
|
---|
1110 |
|
---|
1111 | PCUT_ASSERT_INT_EQUALS(0, list_count(&list->entries));
|
---|
1112 |
|
---|
1113 | ui_list_destroy(list);
|
---|
1114 | ui_window_destroy(window);
|
---|
1115 | ui_destroy(ui);
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /** ui_list_entry_get_arg() gets entry argument */
|
---|
1119 | PCUT_TEST(entry_get_arg)
|
---|
1120 | {
|
---|
1121 | ui_t *ui;
|
---|
1122 | ui_window_t *window;
|
---|
1123 | ui_wnd_params_t params;
|
---|
1124 | ui_list_t *list;
|
---|
1125 | ui_list_entry_attr_t attr;
|
---|
1126 | ui_list_entry_t *entry;
|
---|
1127 | void *arg;
|
---|
1128 | errno_t rc;
|
---|
1129 |
|
---|
1130 | rc = ui_create_disp(NULL, &ui);
|
---|
1131 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1132 |
|
---|
1133 | ui_wnd_params_init(¶ms);
|
---|
1134 | params.caption = "Test";
|
---|
1135 |
|
---|
1136 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1137 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1138 |
|
---|
1139 | rc = ui_list_create(window, true, &list);
|
---|
1140 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1141 |
|
---|
1142 | ui_list_entry_attr_init(&attr);
|
---|
1143 |
|
---|
1144 | /* Append entry and get pointer to it */
|
---|
1145 | attr.caption = "a";
|
---|
1146 | attr.arg = (void *)1;
|
---|
1147 | entry = NULL;
|
---|
1148 | rc = ui_list_entry_append(list, &attr, &entry);
|
---|
1149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1150 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1151 |
|
---|
1152 | arg = ui_list_entry_get_arg(entry);
|
---|
1153 | PCUT_ASSERT_EQUALS(attr.arg, arg);
|
---|
1154 |
|
---|
1155 | ui_list_destroy(list);
|
---|
1156 | ui_window_destroy(window);
|
---|
1157 | ui_destroy(ui);
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | /** ui_list_entry_get_list() returns the containing list */
|
---|
1161 | PCUT_TEST(entry_get_list)
|
---|
1162 | {
|
---|
1163 | ui_t *ui;
|
---|
1164 | ui_window_t *window;
|
---|
1165 | ui_wnd_params_t params;
|
---|
1166 | ui_list_t *list;
|
---|
1167 | ui_list_t *elist;
|
---|
1168 | ui_list_entry_attr_t attr;
|
---|
1169 | ui_list_entry_t *entry;
|
---|
1170 | errno_t rc;
|
---|
1171 |
|
---|
1172 | rc = ui_create_disp(NULL, &ui);
|
---|
1173 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1174 |
|
---|
1175 | ui_wnd_params_init(¶ms);
|
---|
1176 | params.caption = "Test";
|
---|
1177 |
|
---|
1178 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1180 |
|
---|
1181 | rc = ui_list_create(window, true, &list);
|
---|
1182 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1183 |
|
---|
1184 | ui_list_entry_attr_init(&attr);
|
---|
1185 |
|
---|
1186 | /* Append entry and get pointer to it */
|
---|
1187 | attr.caption = "a";
|
---|
1188 | attr.arg = (void *)1;
|
---|
1189 | entry = NULL;
|
---|
1190 | rc = ui_list_entry_append(list, &attr, &entry);
|
---|
1191 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1192 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1193 |
|
---|
1194 | /* Get the containing list */
|
---|
1195 | elist = ui_list_entry_get_list(entry);
|
---|
1196 | PCUT_ASSERT_EQUALS(list, elist);
|
---|
1197 |
|
---|
1198 | ui_list_destroy(list);
|
---|
1199 | ui_window_destroy(window);
|
---|
1200 | ui_destroy(ui);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | /** ui_list_entry_set_caption() sets entry captino */
|
---|
1204 | PCUT_TEST(entry_set_caption)
|
---|
1205 | {
|
---|
1206 | ui_t *ui;
|
---|
1207 | ui_window_t *window;
|
---|
1208 | ui_wnd_params_t params;
|
---|
1209 | ui_list_t *list;
|
---|
1210 | ui_list_entry_attr_t attr;
|
---|
1211 | ui_list_entry_t *entry;
|
---|
1212 | errno_t rc;
|
---|
1213 |
|
---|
1214 | rc = ui_create_disp(NULL, &ui);
|
---|
1215 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1216 |
|
---|
1217 | ui_wnd_params_init(¶ms);
|
---|
1218 | params.caption = "Test";
|
---|
1219 |
|
---|
1220 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1221 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1222 |
|
---|
1223 | rc = ui_list_create(window, true, &list);
|
---|
1224 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1225 |
|
---|
1226 | ui_list_entry_attr_init(&attr);
|
---|
1227 |
|
---|
1228 | /* Append entry and get pointer to it */
|
---|
1229 | attr.caption = "a";
|
---|
1230 | attr.arg = (void *)1;
|
---|
1231 | entry = NULL;
|
---|
1232 | rc = ui_list_entry_append(list, &attr, &entry);
|
---|
1233 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1234 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1235 |
|
---|
1236 | /* Change caption */
|
---|
1237 | rc = ui_list_entry_set_caption(entry, "b");
|
---|
1238 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1239 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
---|
1240 |
|
---|
1241 | ui_list_destroy(list);
|
---|
1242 | ui_window_destroy(window);
|
---|
1243 | ui_destroy(ui);
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | /** ui_list_entries_cnt() returns the number of entries */
|
---|
1247 | PCUT_TEST(entries_cnt)
|
---|
1248 | {
|
---|
1249 | ui_t *ui;
|
---|
1250 | ui_window_t *window;
|
---|
1251 | ui_wnd_params_t params;
|
---|
1252 | ui_list_t *list;
|
---|
1253 | ui_list_entry_attr_t attr;
|
---|
1254 | errno_t rc;
|
---|
1255 |
|
---|
1256 | rc = ui_create_disp(NULL, &ui);
|
---|
1257 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1258 |
|
---|
1259 | ui_wnd_params_init(¶ms);
|
---|
1260 | params.caption = "Test";
|
---|
1261 |
|
---|
1262 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1263 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1264 |
|
---|
1265 | rc = ui_list_create(window, true, &list);
|
---|
1266 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1267 |
|
---|
1268 | PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(list));
|
---|
1269 |
|
---|
1270 | ui_list_entry_attr_init(&attr);
|
---|
1271 |
|
---|
1272 | /* Append entry */
|
---|
1273 | attr.caption = "a";
|
---|
1274 | attr.arg = (void *)1;
|
---|
1275 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1276 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1277 |
|
---|
1278 | PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(list));
|
---|
1279 |
|
---|
1280 | /* Append another entry */
|
---|
1281 | attr.caption = "b";
|
---|
1282 | attr.arg = (void *)2;
|
---|
1283 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1284 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1285 |
|
---|
1286 | PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(list));
|
---|
1287 |
|
---|
1288 | ui_list_destroy(list);
|
---|
1289 | ui_window_destroy(window);
|
---|
1290 | ui_destroy(ui);
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | /** ui_list_sort() sorts UI list entries */
|
---|
1294 | PCUT_TEST(sort)
|
---|
1295 | {
|
---|
1296 | ui_t *ui;
|
---|
1297 | ui_window_t *window;
|
---|
1298 | ui_wnd_params_t params;
|
---|
1299 | ui_list_t *list;
|
---|
1300 | ui_list_entry_t *entry;
|
---|
1301 | ui_list_entry_attr_t attr;
|
---|
1302 | test_resp_t resp;
|
---|
1303 | errno_t rc;
|
---|
1304 |
|
---|
1305 | rc = ui_create_disp(NULL, &ui);
|
---|
1306 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1307 |
|
---|
1308 | ui_wnd_params_init(¶ms);
|
---|
1309 | params.caption = "Test";
|
---|
1310 |
|
---|
1311 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1312 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1313 |
|
---|
1314 | rc = ui_list_create(window, true, &list);
|
---|
1315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1316 |
|
---|
1317 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
1318 |
|
---|
1319 | ui_list_entry_attr_init(&attr);
|
---|
1320 |
|
---|
1321 | attr.caption = "b";
|
---|
1322 | attr.arg = (void *)1;
|
---|
1323 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1324 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1325 |
|
---|
1326 | attr.caption = "c";
|
---|
1327 | attr.arg = (void *)3;
|
---|
1328 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1329 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1330 |
|
---|
1331 | attr.caption = "a";
|
---|
1332 | attr.arg = (void *)2;
|
---|
1333 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1334 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1335 |
|
---|
1336 | rc = ui_list_sort(list);
|
---|
1337 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1338 |
|
---|
1339 | entry = ui_list_first(list);
|
---|
1340 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
---|
1341 | PCUT_ASSERT_EQUALS((void *)2, entry->arg);
|
---|
1342 |
|
---|
1343 | entry = ui_list_next(entry);
|
---|
1344 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
---|
1345 | PCUT_ASSERT_EQUALS((void *)1, entry->arg);
|
---|
1346 |
|
---|
1347 | entry = ui_list_next(entry);
|
---|
1348 | PCUT_ASSERT_STR_EQUALS("c", entry->caption);
|
---|
1349 | PCUT_ASSERT_EQUALS((void *)3, entry->arg);
|
---|
1350 |
|
---|
1351 | ui_list_destroy(list);
|
---|
1352 | ui_window_destroy(window);
|
---|
1353 | ui_destroy(ui);
|
---|
1354 | }
|
---|
1355 |
|
---|
1356 | /** ui_list_cursor_center()...XXX */
|
---|
1357 | PCUT_TEST(cursor_center)
|
---|
1358 | {
|
---|
1359 | ui_t *ui;
|
---|
1360 | ui_window_t *window;
|
---|
1361 | ui_wnd_params_t params;
|
---|
1362 | ui_list_t *list;
|
---|
1363 | ui_list_entry_t *a, *b, *c, *d, *e;
|
---|
1364 | ui_list_entry_attr_t attr;
|
---|
1365 | gfx_rect_t rect;
|
---|
1366 | test_resp_t resp;
|
---|
1367 | errno_t rc;
|
---|
1368 |
|
---|
1369 | rc = ui_create_disp(NULL, &ui);
|
---|
1370 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1371 |
|
---|
1372 | ui_wnd_params_init(¶ms);
|
---|
1373 | params.caption = "Test";
|
---|
1374 |
|
---|
1375 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1376 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1377 |
|
---|
1378 | rc = ui_list_create(window, true, &list);
|
---|
1379 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1380 |
|
---|
1381 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
1382 |
|
---|
1383 | rect.p0.x = 10;
|
---|
1384 | rect.p0.y = 20;
|
---|
1385 | rect.p1.x = 50;
|
---|
1386 | rect.p1.y = 80;
|
---|
1387 |
|
---|
1388 | ui_list_set_rect(list, &rect);
|
---|
1389 |
|
---|
1390 | PCUT_ASSERT_INT_EQUALS(3, ui_list_page_size(list));
|
---|
1391 |
|
---|
1392 | ui_list_entry_attr_init(&attr);
|
---|
1393 |
|
---|
1394 | attr.caption = "a";
|
---|
1395 | attr.arg = (void *)1;
|
---|
1396 | rc = ui_list_entry_append(list, &attr, &a);
|
---|
1397 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1398 |
|
---|
1399 | attr.caption = "b";
|
---|
1400 | attr.arg = (void *)2;
|
---|
1401 | rc = ui_list_entry_append(list, &attr, &b);
|
---|
1402 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1403 |
|
---|
1404 | /* We only have two entries, but three fit onto the page */
|
---|
1405 | ui_list_cursor_center(list, b);
|
---|
1406 | PCUT_ASSERT_EQUALS(b, list->cursor);
|
---|
1407 | /* Page should start at the beginning */
|
---|
1408 | PCUT_ASSERT_EQUALS(a, list->page);
|
---|
1409 | PCUT_ASSERT_EQUALS(0, list->page_idx);
|
---|
1410 |
|
---|
1411 | /* Add more entries */
|
---|
1412 |
|
---|
1413 | attr.caption = "c";
|
---|
1414 | attr.arg = (void *)3;
|
---|
1415 | rc = ui_list_entry_append(list, &attr, &c);
|
---|
1416 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1417 |
|
---|
1418 | attr.caption = "d";
|
---|
1419 | attr.arg = (void *)4;
|
---|
1420 | rc = ui_list_entry_append(list, &attr, &d);
|
---|
1421 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1422 |
|
---|
1423 | attr.caption = "e";
|
---|
1424 | attr.arg = (void *)5;
|
---|
1425 | rc = ui_list_entry_append(list, &attr, &e);
|
---|
1426 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1427 |
|
---|
1428 | ui_list_cursor_center(list, c);
|
---|
1429 | PCUT_ASSERT_EQUALS(c, list->cursor);
|
---|
1430 | /*
|
---|
1431 | * We have enough entries, c should be in the middle of the three
|
---|
1432 | * entries on the page, i.e., page should start on 'b'.
|
---|
1433 | */
|
---|
1434 | PCUT_ASSERT_EQUALS(b, list->page);
|
---|
1435 | PCUT_ASSERT_EQUALS(1, list->page_idx);
|
---|
1436 |
|
---|
1437 | ui_list_destroy(list);
|
---|
1438 | ui_window_destroy(window);
|
---|
1439 | ui_destroy(ui);
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | /** ui_list_clear_entries() removes all entries from list */
|
---|
1443 | PCUT_TEST(clear_entries)
|
---|
1444 | {
|
---|
1445 | ui_t *ui;
|
---|
1446 | ui_window_t *window;
|
---|
1447 | ui_wnd_params_t params;
|
---|
1448 | ui_list_t *list;
|
---|
1449 | ui_list_entry_attr_t attr;
|
---|
1450 | errno_t rc;
|
---|
1451 |
|
---|
1452 | rc = ui_create_disp(NULL, &ui);
|
---|
1453 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1454 |
|
---|
1455 | ui_wnd_params_init(¶ms);
|
---|
1456 | params.caption = "Test";
|
---|
1457 |
|
---|
1458 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1459 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1460 |
|
---|
1461 | rc = ui_list_create(window, true, &list);
|
---|
1462 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1463 |
|
---|
1464 | ui_list_entry_attr_init(&attr);
|
---|
1465 | attr.caption = "a";
|
---|
1466 | attr.arg = (void *)1;
|
---|
1467 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1468 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1469 |
|
---|
1470 | attr.caption = "a";
|
---|
1471 | attr.arg = (void *)2;
|
---|
1472 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1473 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1474 |
|
---|
1475 | PCUT_ASSERT_INT_EQUALS(2, list_count(&list->entries));
|
---|
1476 |
|
---|
1477 | ui_list_clear_entries(list);
|
---|
1478 | PCUT_ASSERT_INT_EQUALS(0, list_count(&list->entries));
|
---|
1479 |
|
---|
1480 | ui_list_destroy(list);
|
---|
1481 | ui_window_destroy(window);
|
---|
1482 | ui_destroy(ui);
|
---|
1483 | }
|
---|
1484 |
|
---|
1485 | /** ui_list_first() returns valid entry or @c NULL as appropriate */
|
---|
1486 | PCUT_TEST(first)
|
---|
1487 | {
|
---|
1488 | ui_t *ui;
|
---|
1489 | ui_window_t *window;
|
---|
1490 | ui_wnd_params_t params;
|
---|
1491 | ui_list_t *list;
|
---|
1492 | ui_list_entry_t *entry;
|
---|
1493 | ui_list_entry_attr_t attr;
|
---|
1494 | errno_t rc;
|
---|
1495 |
|
---|
1496 | rc = ui_create_disp(NULL, &ui);
|
---|
1497 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1498 |
|
---|
1499 | ui_wnd_params_init(¶ms);
|
---|
1500 | params.caption = "Test";
|
---|
1501 |
|
---|
1502 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1503 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1504 |
|
---|
1505 | rc = ui_list_create(window, true, &list);
|
---|
1506 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1507 |
|
---|
1508 | ui_list_entry_attr_init(&attr);
|
---|
1509 |
|
---|
1510 | entry = ui_list_first(list);
|
---|
1511 | PCUT_ASSERT_NULL(entry);
|
---|
1512 |
|
---|
1513 | /* Add one entry */
|
---|
1514 | attr.caption = "a";
|
---|
1515 | attr.arg = (void *)1;
|
---|
1516 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1517 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1518 |
|
---|
1519 | /* Now try getting it */
|
---|
1520 | entry = ui_list_first(list);
|
---|
1521 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1522 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
---|
1523 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
---|
1524 |
|
---|
1525 | /* Add another entry */
|
---|
1526 | attr.caption = "b";
|
---|
1527 | attr.arg = (void *)2;
|
---|
1528 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1529 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1530 |
|
---|
1531 | /* We should still get the first entry */
|
---|
1532 | entry = ui_list_first(list);
|
---|
1533 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1534 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
---|
1535 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
---|
1536 |
|
---|
1537 | ui_list_destroy(list);
|
---|
1538 | ui_window_destroy(window);
|
---|
1539 | ui_destroy(ui);
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | /** ui_list_last() returns valid entry or @c NULL as appropriate */
|
---|
1543 | PCUT_TEST(last)
|
---|
1544 | {
|
---|
1545 | ui_t *ui;
|
---|
1546 | ui_window_t *window;
|
---|
1547 | ui_wnd_params_t params;
|
---|
1548 | ui_list_t *list;
|
---|
1549 | ui_list_entry_t *entry;
|
---|
1550 | ui_list_entry_attr_t attr;
|
---|
1551 | errno_t rc;
|
---|
1552 |
|
---|
1553 | rc = ui_create_disp(NULL, &ui);
|
---|
1554 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1555 |
|
---|
1556 | ui_wnd_params_init(¶ms);
|
---|
1557 | params.caption = "Test";
|
---|
1558 |
|
---|
1559 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1560 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1561 |
|
---|
1562 | rc = ui_list_create(window, true, &list);
|
---|
1563 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1564 |
|
---|
1565 | ui_list_entry_attr_init(&attr);
|
---|
1566 |
|
---|
1567 | entry = ui_list_last(list);
|
---|
1568 | PCUT_ASSERT_NULL(entry);
|
---|
1569 |
|
---|
1570 | /* Add one entry */
|
---|
1571 | attr.caption = "a";
|
---|
1572 | attr.arg = (void *)1;
|
---|
1573 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1574 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1575 |
|
---|
1576 | /* Now try getting it */
|
---|
1577 | entry = ui_list_last(list);
|
---|
1578 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1579 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
---|
1580 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
---|
1581 |
|
---|
1582 | /* Add another entry */
|
---|
1583 | attr.caption = "b";
|
---|
1584 | attr.arg = (void *)2;
|
---|
1585 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1586 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1587 |
|
---|
1588 | /* We should get new entry now */
|
---|
1589 | entry = ui_list_last(list);
|
---|
1590 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1591 | attr.caption = "b";
|
---|
1592 | attr.arg = (void *)2;
|
---|
1593 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
---|
1594 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)entry->arg);
|
---|
1595 |
|
---|
1596 | ui_list_destroy(list);
|
---|
1597 | ui_window_destroy(window);
|
---|
1598 | ui_destroy(ui);
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | /** ui_list_next() returns the next entry or @c NULL as appropriate */
|
---|
1602 | PCUT_TEST(next)
|
---|
1603 | {
|
---|
1604 | ui_t *ui;
|
---|
1605 | ui_window_t *window;
|
---|
1606 | ui_wnd_params_t params;
|
---|
1607 | ui_list_t *list;
|
---|
1608 | ui_list_entry_t *entry;
|
---|
1609 | ui_list_entry_attr_t attr;
|
---|
1610 | errno_t rc;
|
---|
1611 |
|
---|
1612 | rc = ui_create_disp(NULL, &ui);
|
---|
1613 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1614 |
|
---|
1615 | ui_wnd_params_init(¶ms);
|
---|
1616 | params.caption = "Test";
|
---|
1617 |
|
---|
1618 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1619 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1620 |
|
---|
1621 | rc = ui_list_create(window, true, &list);
|
---|
1622 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1623 |
|
---|
1624 | ui_list_entry_attr_init(&attr);
|
---|
1625 |
|
---|
1626 | /* Add one entry */
|
---|
1627 | attr.caption = "a";
|
---|
1628 | attr.arg = (void *)1;
|
---|
1629 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1630 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1631 |
|
---|
1632 | /* Now try getting its successor */
|
---|
1633 | entry = ui_list_first(list);
|
---|
1634 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1635 |
|
---|
1636 | entry = ui_list_next(entry);
|
---|
1637 | PCUT_ASSERT_NULL(entry);
|
---|
1638 |
|
---|
1639 | /* Add another entry */
|
---|
1640 | attr.caption = "b";
|
---|
1641 | attr.arg = (void *)2;
|
---|
1642 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1643 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1644 |
|
---|
1645 | /* Try getting the successor of first entry again */
|
---|
1646 | entry = ui_list_first(list);
|
---|
1647 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1648 |
|
---|
1649 | entry = ui_list_next(entry);
|
---|
1650 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1651 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
---|
1652 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)entry->arg);
|
---|
1653 |
|
---|
1654 | ui_list_destroy(list);
|
---|
1655 | ui_window_destroy(window);
|
---|
1656 | ui_destroy(ui);
|
---|
1657 | }
|
---|
1658 |
|
---|
1659 | /** ui_list_prev() returns the previous entry or @c NULL as appropriate */
|
---|
1660 | PCUT_TEST(prev)
|
---|
1661 | {
|
---|
1662 | ui_t *ui;
|
---|
1663 | ui_window_t *window;
|
---|
1664 | ui_wnd_params_t params;
|
---|
1665 | ui_list_t *list;
|
---|
1666 | ui_list_entry_t *entry;
|
---|
1667 | ui_list_entry_attr_t attr;
|
---|
1668 | errno_t rc;
|
---|
1669 |
|
---|
1670 | rc = ui_create_disp(NULL, &ui);
|
---|
1671 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1672 |
|
---|
1673 | ui_wnd_params_init(¶ms);
|
---|
1674 | params.caption = "Test";
|
---|
1675 |
|
---|
1676 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1677 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1678 |
|
---|
1679 | rc = ui_list_create(window, true, &list);
|
---|
1680 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1681 |
|
---|
1682 | ui_list_entry_attr_init(&attr);
|
---|
1683 |
|
---|
1684 | /* Add one entry */
|
---|
1685 | attr.caption = "a";
|
---|
1686 | attr.arg = (void *)1;
|
---|
1687 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1688 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1689 |
|
---|
1690 | /* Now try getting its predecessor */
|
---|
1691 | entry = ui_list_last(list);
|
---|
1692 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1693 |
|
---|
1694 | entry = ui_list_prev(entry);
|
---|
1695 | PCUT_ASSERT_NULL(entry);
|
---|
1696 |
|
---|
1697 | /* Add another entry */
|
---|
1698 | attr.caption = "b";
|
---|
1699 | attr.arg = (void *)2;
|
---|
1700 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1701 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1702 |
|
---|
1703 | /* Try getting the predecessor of the new entry */
|
---|
1704 | entry = ui_list_last(list);
|
---|
1705 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1706 |
|
---|
1707 | entry = ui_list_prev(entry);
|
---|
1708 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1709 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
---|
1710 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
---|
1711 |
|
---|
1712 | ui_list_destroy(list);
|
---|
1713 | ui_window_destroy(window);
|
---|
1714 | ui_destroy(ui);
|
---|
1715 | }
|
---|
1716 |
|
---|
1717 | /** ui_list_page_nth_entry() .. */
|
---|
1718 | PCUT_TEST(page_nth_entry)
|
---|
1719 | {
|
---|
1720 | ui_t *ui;
|
---|
1721 | ui_window_t *window;
|
---|
1722 | ui_wnd_params_t params;
|
---|
1723 | ui_list_t *list;
|
---|
1724 | ui_list_entry_t *entry;
|
---|
1725 | ui_list_entry_attr_t attr;
|
---|
1726 | gfx_rect_t rect;
|
---|
1727 | size_t idx;
|
---|
1728 | errno_t rc;
|
---|
1729 |
|
---|
1730 | rc = ui_create_disp(NULL, &ui);
|
---|
1731 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1732 |
|
---|
1733 | ui_wnd_params_init(¶ms);
|
---|
1734 | params.caption = "Test";
|
---|
1735 |
|
---|
1736 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1737 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1738 |
|
---|
1739 | rc = ui_list_create(window, true, &list);
|
---|
1740 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1741 |
|
---|
1742 | ui_list_entry_attr_init(&attr);
|
---|
1743 |
|
---|
1744 | /* Add some entries */
|
---|
1745 | attr.caption = "a";
|
---|
1746 | attr.arg = (void *)1;
|
---|
1747 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1748 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1749 |
|
---|
1750 | attr.caption = "b";
|
---|
1751 | attr.arg = (void *)2;
|
---|
1752 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1753 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1754 |
|
---|
1755 | attr.caption = "c";
|
---|
1756 | attr.arg = (void *)3;
|
---|
1757 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1758 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1759 |
|
---|
1760 | list->page = ui_list_next(ui_list_first(list));
|
---|
1761 | list->page_idx = 1;
|
---|
1762 |
|
---|
1763 | rect.p0.x = 0;
|
---|
1764 | rect.p0.y = 0;
|
---|
1765 | rect.p1.x = 100;
|
---|
1766 | rect.p1.y = 100;
|
---|
1767 | ui_list_set_rect(list, &rect);
|
---|
1768 |
|
---|
1769 | entry = ui_list_page_nth_entry(list, 0, &idx);
|
---|
1770 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1771 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
---|
1772 | PCUT_ASSERT_INT_EQUALS(1, idx);
|
---|
1773 |
|
---|
1774 | entry = ui_list_page_nth_entry(list, 1, &idx);
|
---|
1775 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
1776 | PCUT_ASSERT_STR_EQUALS("c", entry->caption);
|
---|
1777 | PCUT_ASSERT_INT_EQUALS(2, idx);
|
---|
1778 |
|
---|
1779 | entry = ui_list_page_nth_entry(list, 2, &idx);
|
---|
1780 | PCUT_ASSERT_NULL(entry);
|
---|
1781 |
|
---|
1782 | ui_list_destroy(list);
|
---|
1783 | ui_window_destroy(window);
|
---|
1784 | ui_destroy(ui);
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | /** ui_list_cursor_move() moves cursor and scrolls */
|
---|
1788 | PCUT_TEST(cursor_move)
|
---|
1789 | {
|
---|
1790 | ui_t *ui;
|
---|
1791 | ui_window_t *window;
|
---|
1792 | ui_wnd_params_t params;
|
---|
1793 | ui_list_t *list;
|
---|
1794 | ui_list_entry_attr_t attr;
|
---|
1795 | gfx_rect_t rect;
|
---|
1796 | errno_t rc;
|
---|
1797 | rc = ui_create_disp(NULL, &ui);
|
---|
1798 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1799 |
|
---|
1800 | ui_wnd_params_init(¶ms);
|
---|
1801 | params.caption = "Test";
|
---|
1802 |
|
---|
1803 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1804 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1805 |
|
---|
1806 | rc = ui_list_create(window, true, &list);
|
---|
1807 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1808 |
|
---|
1809 | rect.p0.x = 0;
|
---|
1810 | rect.p0.y = 0;
|
---|
1811 | rect.p1.x = 10;
|
---|
1812 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
1813 | ui_list_set_rect(list, &rect);
|
---|
1814 |
|
---|
1815 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
1816 |
|
---|
1817 | /* Add tree entries (more than page size, which is 2) */
|
---|
1818 |
|
---|
1819 | ui_list_entry_attr_init(&attr);
|
---|
1820 |
|
---|
1821 | attr.caption = "a";
|
---|
1822 | attr.arg = (void *)1;
|
---|
1823 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1824 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1825 |
|
---|
1826 | attr.caption = "b";
|
---|
1827 | attr.arg = (void *)2;
|
---|
1828 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1829 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1830 |
|
---|
1831 | attr.caption = "c";
|
---|
1832 | attr.arg = (void *)3;
|
---|
1833 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1834 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1835 |
|
---|
1836 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
1837 | list->cursor = ui_list_last(list);
|
---|
1838 | list->cursor_idx = 2;
|
---|
1839 | list->page = ui_list_prev(list->cursor);
|
---|
1840 | list->page_idx = 1;
|
---|
1841 |
|
---|
1842 | /* Move cursor one entry up */
|
---|
1843 | ui_list_cursor_move(list, ui_list_prev(list->cursor),
|
---|
1844 | list->cursor_idx - 1);
|
---|
1845 |
|
---|
1846 | /* Cursor and page start should now both be at the second entry */
|
---|
1847 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
---|
1848 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
---|
1849 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
---|
1850 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
1851 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
1852 |
|
---|
1853 | /* Move cursor to the first entry. This should scroll up. */
|
---|
1854 | ui_list_cursor_move(list, ui_list_first(list), 0);
|
---|
1855 |
|
---|
1856 | /* Cursor and page start should now both be at the first entry */
|
---|
1857 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
1858 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
1859 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
1860 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
1861 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
1862 |
|
---|
1863 | /* Move cursor to the last entry. */
|
---|
1864 | ui_list_cursor_move(list, ui_list_last(list), 2);
|
---|
1865 |
|
---|
1866 | /* Cursor should be on the last entry and page on the next to last */
|
---|
1867 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
1868 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
1869 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
1870 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
1871 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
1872 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
1873 |
|
---|
1874 | ui_list_destroy(list);
|
---|
1875 | ui_window_destroy(window);
|
---|
1876 | ui_destroy(ui);
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 | /** ui_list_cursor_up() moves cursor one entry up */
|
---|
1880 | PCUT_TEST(cursor_up)
|
---|
1881 | {
|
---|
1882 | ui_t *ui;
|
---|
1883 | ui_window_t *window;
|
---|
1884 | ui_wnd_params_t params;
|
---|
1885 | ui_list_t *list;
|
---|
1886 | ui_list_entry_attr_t attr;
|
---|
1887 | gfx_rect_t rect;
|
---|
1888 | errno_t rc;
|
---|
1889 | rc = ui_create_disp(NULL, &ui);
|
---|
1890 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1891 |
|
---|
1892 | ui_wnd_params_init(¶ms);
|
---|
1893 | params.caption = "Test";
|
---|
1894 |
|
---|
1895 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1896 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1897 |
|
---|
1898 | rc = ui_list_create(window, true, &list);
|
---|
1899 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1900 |
|
---|
1901 | rect.p0.x = 0;
|
---|
1902 | rect.p0.y = 0;
|
---|
1903 | rect.p1.x = 10;
|
---|
1904 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
1905 | ui_list_set_rect(list, &rect);
|
---|
1906 |
|
---|
1907 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
1908 |
|
---|
1909 | /* Add tree entries (more than page size, which is 2) */
|
---|
1910 |
|
---|
1911 | ui_list_entry_attr_init(&attr);
|
---|
1912 |
|
---|
1913 | attr.caption = "a";
|
---|
1914 | attr.arg = (void *)1;
|
---|
1915 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1916 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1917 |
|
---|
1918 | attr.caption = "b";
|
---|
1919 | attr.arg = (void *)2;
|
---|
1920 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1921 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1922 |
|
---|
1923 | attr.caption = "c";
|
---|
1924 | attr.arg = (void *)3;
|
---|
1925 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
1926 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1927 |
|
---|
1928 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
1929 | list->cursor = ui_list_last(list);
|
---|
1930 | list->cursor_idx = 2;
|
---|
1931 | list->page = ui_list_prev(list->cursor);
|
---|
1932 | list->page_idx = 1;
|
---|
1933 |
|
---|
1934 | /* Move cursor one entry up */
|
---|
1935 | ui_list_cursor_up(list);
|
---|
1936 |
|
---|
1937 | /* Cursor and page start should now both be at the second entry */
|
---|
1938 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
---|
1939 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
---|
1940 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
---|
1941 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
1942 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
1943 |
|
---|
1944 | /* Move cursor one entry up. This should scroll up. */
|
---|
1945 | ui_list_cursor_up(list);
|
---|
1946 |
|
---|
1947 | /* Cursor and page start should now both be at the first entry */
|
---|
1948 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
1949 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
1950 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
1951 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
1952 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
1953 |
|
---|
1954 | /* Moving further up should do nothing (we are at the top). */
|
---|
1955 | ui_list_cursor_up(list);
|
---|
1956 |
|
---|
1957 | /* Cursor and page start should still be at the first entry */
|
---|
1958 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
1959 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
1960 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
1961 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
1962 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
1963 |
|
---|
1964 | ui_list_destroy(list);
|
---|
1965 | ui_window_destroy(window);
|
---|
1966 | ui_destroy(ui);
|
---|
1967 | }
|
---|
1968 |
|
---|
1969 | /** ui_list_cursor_down() moves cursor one entry down */
|
---|
1970 | PCUT_TEST(cursor_down)
|
---|
1971 | {
|
---|
1972 | ui_t *ui;
|
---|
1973 | ui_window_t *window;
|
---|
1974 | ui_wnd_params_t params;
|
---|
1975 | ui_list_t *list;
|
---|
1976 | ui_list_entry_attr_t attr;
|
---|
1977 | gfx_rect_t rect;
|
---|
1978 | errno_t rc;
|
---|
1979 |
|
---|
1980 | rc = ui_create_disp(NULL, &ui);
|
---|
1981 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1982 |
|
---|
1983 | ui_wnd_params_init(¶ms);
|
---|
1984 | params.caption = "Test";
|
---|
1985 |
|
---|
1986 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
1987 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1988 |
|
---|
1989 | rc = ui_list_create(window, true, &list);
|
---|
1990 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1991 |
|
---|
1992 | rect.p0.x = 0;
|
---|
1993 | rect.p0.y = 0;
|
---|
1994 | rect.p1.x = 10;
|
---|
1995 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
1996 | ui_list_set_rect(list, &rect);
|
---|
1997 |
|
---|
1998 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
1999 |
|
---|
2000 | /* Add tree entries (more than page size, which is 2) */
|
---|
2001 |
|
---|
2002 | ui_list_entry_attr_init(&attr);
|
---|
2003 |
|
---|
2004 | attr.caption = "a";
|
---|
2005 | attr.arg = (void *)1;
|
---|
2006 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2007 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2008 |
|
---|
2009 | attr.caption = "b";
|
---|
2010 | attr.arg = (void *)2;
|
---|
2011 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2012 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2013 |
|
---|
2014 | attr.caption = "c";
|
---|
2015 | attr.arg = (void *)3;
|
---|
2016 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2017 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2018 |
|
---|
2019 | /* Cursor and page start to the first entry */
|
---|
2020 | list->cursor = ui_list_first(list);
|
---|
2021 | list->cursor_idx = 0;
|
---|
2022 | list->page = list->cursor;
|
---|
2023 | list->page_idx = 0;
|
---|
2024 |
|
---|
2025 | /* Move cursor one entry down */
|
---|
2026 | ui_list_cursor_down(list);
|
---|
2027 |
|
---|
2028 | /* Cursor should now be at the second entry, page stays the same */
|
---|
2029 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
---|
2030 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
---|
2031 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
---|
2032 | PCUT_ASSERT_EQUALS(ui_list_first(list), list->page);
|
---|
2033 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2034 |
|
---|
2035 | /* Move cursor one entry down. This should scroll down. */
|
---|
2036 | ui_list_cursor_down(list);
|
---|
2037 |
|
---|
2038 | /* Cursor should now be at the third and page at the second entry. */
|
---|
2039 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2040 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2041 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2042 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2043 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2044 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2045 |
|
---|
2046 | /* Moving further down should do nothing (we are at the bottom). */
|
---|
2047 | ui_list_cursor_down(list);
|
---|
2048 |
|
---|
2049 | /* Cursor should still be at the third and page at the second entry. */
|
---|
2050 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2051 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2052 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2053 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2054 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2055 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2056 |
|
---|
2057 | ui_list_destroy(list);
|
---|
2058 | ui_window_destroy(window);
|
---|
2059 | ui_destroy(ui);
|
---|
2060 | }
|
---|
2061 |
|
---|
2062 | /** ui_list_cursor_top() moves cursor to the first entry */
|
---|
2063 | PCUT_TEST(cursor_top)
|
---|
2064 | {
|
---|
2065 | ui_t *ui;
|
---|
2066 | ui_window_t *window;
|
---|
2067 | ui_wnd_params_t params;
|
---|
2068 | ui_list_t *list;
|
---|
2069 | ui_list_entry_attr_t attr;
|
---|
2070 | gfx_rect_t rect;
|
---|
2071 | errno_t rc;
|
---|
2072 |
|
---|
2073 | rc = ui_create_disp(NULL, &ui);
|
---|
2074 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2075 |
|
---|
2076 | ui_wnd_params_init(¶ms);
|
---|
2077 | params.caption = "Test";
|
---|
2078 |
|
---|
2079 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2080 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2081 |
|
---|
2082 | rc = ui_list_create(window, true, &list);
|
---|
2083 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2084 |
|
---|
2085 | rect.p0.x = 0;
|
---|
2086 | rect.p0.y = 0;
|
---|
2087 | rect.p1.x = 10;
|
---|
2088 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2089 | ui_list_set_rect(list, &rect);
|
---|
2090 |
|
---|
2091 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2092 |
|
---|
2093 | /* Add tree entries (more than page size, which is 2) */
|
---|
2094 |
|
---|
2095 | ui_list_entry_attr_init(&attr);
|
---|
2096 |
|
---|
2097 | attr.caption = "a";
|
---|
2098 | attr.arg = (void *)1;
|
---|
2099 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2101 |
|
---|
2102 | attr.caption = "b";
|
---|
2103 | attr.arg = (void *)2;
|
---|
2104 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2106 |
|
---|
2107 | attr.caption = "c";
|
---|
2108 | attr.arg = (void *)3;
|
---|
2109 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2111 |
|
---|
2112 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
2113 | list->cursor = ui_list_last(list);
|
---|
2114 | list->cursor_idx = 2;
|
---|
2115 | list->page = ui_list_prev(list->cursor);
|
---|
2116 | list->page_idx = 1;
|
---|
2117 |
|
---|
2118 | /* Move cursor to the top. This should scroll up. */
|
---|
2119 | ui_list_cursor_top(list);
|
---|
2120 |
|
---|
2121 | /* Cursor and page start should now both be at the first entry */
|
---|
2122 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2123 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2124 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2125 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
2126 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2127 |
|
---|
2128 | ui_list_destroy(list);
|
---|
2129 | ui_window_destroy(window);
|
---|
2130 | ui_destroy(ui);
|
---|
2131 | }
|
---|
2132 |
|
---|
2133 | /** ui_list_cursor_bottom() moves cursor to the last entry */
|
---|
2134 | PCUT_TEST(cursor_bottom)
|
---|
2135 | {
|
---|
2136 | ui_t *ui;
|
---|
2137 | ui_window_t *window;
|
---|
2138 | ui_wnd_params_t params;
|
---|
2139 | ui_list_t *list;
|
---|
2140 | ui_list_entry_attr_t attr;
|
---|
2141 | gfx_rect_t rect;
|
---|
2142 | errno_t rc;
|
---|
2143 |
|
---|
2144 | rc = ui_create_disp(NULL, &ui);
|
---|
2145 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2146 |
|
---|
2147 | ui_wnd_params_init(¶ms);
|
---|
2148 | params.caption = "Test";
|
---|
2149 |
|
---|
2150 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2151 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2152 |
|
---|
2153 | rc = ui_list_create(window, true, &list);
|
---|
2154 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2155 |
|
---|
2156 | rect.p0.x = 0;
|
---|
2157 | rect.p0.y = 0;
|
---|
2158 | rect.p1.x = 10;
|
---|
2159 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2160 | ui_list_set_rect(list, &rect);
|
---|
2161 |
|
---|
2162 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2163 |
|
---|
2164 | /* Add tree entries (more than page size, which is 2) */
|
---|
2165 |
|
---|
2166 | ui_list_entry_attr_init(&attr);
|
---|
2167 |
|
---|
2168 | attr.caption = "a";
|
---|
2169 | attr.arg = (void *)1;
|
---|
2170 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2171 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2172 |
|
---|
2173 | attr.caption = "b";
|
---|
2174 | attr.arg = (void *)2;
|
---|
2175 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2176 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2177 |
|
---|
2178 | attr.caption = "c";
|
---|
2179 | attr.arg = (void *)3;
|
---|
2180 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2181 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2182 |
|
---|
2183 | /* Cursor and page start to the first entry */
|
---|
2184 | list->cursor = ui_list_first(list);
|
---|
2185 | list->cursor_idx = 0;
|
---|
2186 | list->page = list->cursor;
|
---|
2187 | list->page_idx = 0;
|
---|
2188 |
|
---|
2189 | /* Move cursor to the bottom. This should scroll down. */
|
---|
2190 | ui_list_cursor_bottom(list);
|
---|
2191 |
|
---|
2192 | /* Cursor should now be at the third and page at the second entry. */
|
---|
2193 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2194 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2195 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2196 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2197 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2198 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2199 |
|
---|
2200 | ui_list_destroy(list);
|
---|
2201 | ui_window_destroy(window);
|
---|
2202 | ui_destroy(ui);
|
---|
2203 | }
|
---|
2204 |
|
---|
2205 | /** ui_list_page_up() moves one page up */
|
---|
2206 | PCUT_TEST(page_up)
|
---|
2207 | {
|
---|
2208 | ui_t *ui;
|
---|
2209 | ui_window_t *window;
|
---|
2210 | ui_wnd_params_t params;
|
---|
2211 | ui_list_t *list;
|
---|
2212 | ui_list_entry_attr_t attr;
|
---|
2213 | gfx_rect_t rect;
|
---|
2214 | errno_t rc;
|
---|
2215 |
|
---|
2216 | rc = ui_create_disp(NULL, &ui);
|
---|
2217 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2218 |
|
---|
2219 | ui_wnd_params_init(¶ms);
|
---|
2220 | params.caption = "Test";
|
---|
2221 |
|
---|
2222 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2223 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2224 |
|
---|
2225 | rc = ui_list_create(window, true, &list);
|
---|
2226 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2227 |
|
---|
2228 | rect.p0.x = 0;
|
---|
2229 | rect.p0.y = 0;
|
---|
2230 | rect.p1.x = 10;
|
---|
2231 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2232 | ui_list_set_rect(list, &rect);
|
---|
2233 |
|
---|
2234 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2235 |
|
---|
2236 | /* Add five entries (2 full pages, one partial) */
|
---|
2237 |
|
---|
2238 | ui_list_entry_attr_init(&attr);
|
---|
2239 |
|
---|
2240 | attr.caption = "a";
|
---|
2241 | attr.arg = (void *)1;
|
---|
2242 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2243 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2244 |
|
---|
2245 | attr.caption = "b";
|
---|
2246 | attr.arg = (void *)2;
|
---|
2247 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2248 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2249 |
|
---|
2250 | attr.caption = "c";
|
---|
2251 | attr.arg = (void *)3;
|
---|
2252 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2253 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2254 |
|
---|
2255 | attr.caption = "d";
|
---|
2256 | attr.arg = (void *)4;
|
---|
2257 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2258 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2259 |
|
---|
2260 | attr.caption = "e";
|
---|
2261 | attr.arg = (void *)5;
|
---|
2262 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2263 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2264 |
|
---|
2265 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
2266 | list->cursor = ui_list_last(list);
|
---|
2267 | list->cursor_idx = 4;
|
---|
2268 | list->page = ui_list_prev(list->cursor);
|
---|
2269 | list->page_idx = 3;
|
---|
2270 |
|
---|
2271 | /* Move one page up */
|
---|
2272 | ui_list_page_up(list);
|
---|
2273 |
|
---|
2274 | /* Page should now start at second entry and cursor at third */
|
---|
2275 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2276 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2277 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2278 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2279 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2280 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2281 |
|
---|
2282 | /* Move one page up again. */
|
---|
2283 | ui_list_page_up(list);
|
---|
2284 |
|
---|
2285 | /* Cursor and page start should now both be at the first entry */
|
---|
2286 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2287 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2288 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2289 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
2290 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2291 |
|
---|
2292 | /* Moving further up should do nothing (we are at the top). */
|
---|
2293 | ui_list_page_up(list);
|
---|
2294 |
|
---|
2295 | /* Cursor and page start should still be at the first entry */
|
---|
2296 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2297 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2298 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2299 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
---|
2300 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2301 |
|
---|
2302 | ui_list_destroy(list);
|
---|
2303 | ui_window_destroy(window);
|
---|
2304 | ui_destroy(ui);
|
---|
2305 | }
|
---|
2306 |
|
---|
2307 | /** ui_list_page_up() moves one page down */
|
---|
2308 | PCUT_TEST(page_down)
|
---|
2309 | {
|
---|
2310 | ui_t *ui;
|
---|
2311 | ui_window_t *window;
|
---|
2312 | ui_wnd_params_t params;
|
---|
2313 | ui_list_t *list;
|
---|
2314 | ui_list_entry_attr_t attr;
|
---|
2315 | gfx_rect_t rect;
|
---|
2316 | errno_t rc;
|
---|
2317 |
|
---|
2318 | rc = ui_create_disp(NULL, &ui);
|
---|
2319 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2320 |
|
---|
2321 | ui_wnd_params_init(¶ms);
|
---|
2322 | params.caption = "Test";
|
---|
2323 |
|
---|
2324 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2325 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2326 |
|
---|
2327 | rc = ui_list_create(window, true, &list);
|
---|
2328 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2329 |
|
---|
2330 | rect.p0.x = 0;
|
---|
2331 | rect.p0.y = 0;
|
---|
2332 | rect.p1.x = 10;
|
---|
2333 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2334 | ui_list_set_rect(list, &rect);
|
---|
2335 |
|
---|
2336 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2337 |
|
---|
2338 | /* Add five entries (2 full pages, one partial) */
|
---|
2339 |
|
---|
2340 | ui_list_entry_attr_init(&attr);
|
---|
2341 |
|
---|
2342 | attr.caption = "a";
|
---|
2343 | attr.arg = (void *)1;
|
---|
2344 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2345 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2346 |
|
---|
2347 | attr.caption = "b";
|
---|
2348 | attr.arg = (void *)2;
|
---|
2349 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2350 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2351 |
|
---|
2352 | attr.caption = "c";
|
---|
2353 | attr.arg = (void *)3;
|
---|
2354 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2355 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2356 |
|
---|
2357 | attr.caption = "d";
|
---|
2358 | attr.arg = (void *)4;
|
---|
2359 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2360 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2361 |
|
---|
2362 | attr.caption = "e";
|
---|
2363 | attr.arg = (void *)5;
|
---|
2364 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2365 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2366 |
|
---|
2367 | /* Cursor and page to the first entry */
|
---|
2368 | list->cursor = ui_list_first(list);
|
---|
2369 | list->cursor_idx = 0;
|
---|
2370 | list->page = list->cursor;
|
---|
2371 | list->page_idx = 0;
|
---|
2372 |
|
---|
2373 | /* Move one page down */
|
---|
2374 | ui_list_page_down(list);
|
---|
2375 |
|
---|
2376 | /* Page and cursor should point to the third entry */
|
---|
2377 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2378 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2379 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2380 | PCUT_ASSERT_STR_EQUALS("c", list->page->caption);
|
---|
2381 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->page->arg);
|
---|
2382 | PCUT_ASSERT_INT_EQUALS(2, list->page_idx);
|
---|
2383 |
|
---|
2384 | /* Move one page down again. */
|
---|
2385 | ui_list_page_down(list);
|
---|
2386 |
|
---|
2387 | /* Cursor should point to last and page to next-to-last entry */
|
---|
2388 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
---|
2389 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
---|
2390 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
---|
2391 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
---|
2392 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
---|
2393 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
---|
2394 |
|
---|
2395 | /* Moving further down should do nothing (we are at the bottom). */
|
---|
2396 | ui_list_page_down(list);
|
---|
2397 |
|
---|
2398 | /* Cursor should still point to last and page to next-to-last entry */
|
---|
2399 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
---|
2400 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
---|
2401 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
---|
2402 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
---|
2403 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
---|
2404 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
---|
2405 |
|
---|
2406 | ui_list_destroy(list);
|
---|
2407 | ui_window_destroy(window);
|
---|
2408 | ui_destroy(ui);
|
---|
2409 | }
|
---|
2410 |
|
---|
2411 | /** ui_list_scroll_up() scrolls up by one row */
|
---|
2412 | PCUT_TEST(scroll_up)
|
---|
2413 | {
|
---|
2414 | ui_t *ui;
|
---|
2415 | ui_window_t *window;
|
---|
2416 | ui_wnd_params_t params;
|
---|
2417 | ui_list_t *list;
|
---|
2418 | ui_list_entry_attr_t attr;
|
---|
2419 | gfx_rect_t rect;
|
---|
2420 | errno_t rc;
|
---|
2421 |
|
---|
2422 | rc = ui_create_disp(NULL, &ui);
|
---|
2423 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2424 |
|
---|
2425 | ui_wnd_params_init(¶ms);
|
---|
2426 | params.caption = "Test";
|
---|
2427 |
|
---|
2428 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2429 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2430 |
|
---|
2431 | rc = ui_list_create(window, true, &list);
|
---|
2432 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2433 |
|
---|
2434 | rect.p0.x = 0;
|
---|
2435 | rect.p0.y = 0;
|
---|
2436 | rect.p1.x = 10;
|
---|
2437 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2438 | ui_list_set_rect(list, &rect);
|
---|
2439 |
|
---|
2440 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2441 |
|
---|
2442 | /* Add tree entries (more than page size, which is 2) */
|
---|
2443 |
|
---|
2444 | ui_list_entry_attr_init(&attr);
|
---|
2445 |
|
---|
2446 | attr.caption = "a";
|
---|
2447 | attr.arg = (void *)1;
|
---|
2448 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2449 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2450 |
|
---|
2451 | attr.caption = "b";
|
---|
2452 | attr.arg = (void *)2;
|
---|
2453 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2454 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2455 |
|
---|
2456 | attr.caption = "c";
|
---|
2457 | attr.arg = (void *)3;
|
---|
2458 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2459 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2460 |
|
---|
2461 | /* Cursor to the last entry, page to the second */
|
---|
2462 | list->cursor = ui_list_last(list);
|
---|
2463 | list->cursor_idx = 2;
|
---|
2464 | list->page = ui_list_prev(list->cursor);
|
---|
2465 | list->page_idx = 1;
|
---|
2466 |
|
---|
2467 | /* Scroll one entry up */
|
---|
2468 | ui_list_scroll_up(list);
|
---|
2469 |
|
---|
2470 | /* Page should start on the first entry, cursor unchanged */
|
---|
2471 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2472 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2473 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2474 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
---|
2475 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
---|
2476 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2477 |
|
---|
2478 | /* Try scrolling one more entry up */
|
---|
2479 | ui_list_scroll_up(list);
|
---|
2480 |
|
---|
2481 | /* We were at the beginning, so nothing should have changed */
|
---|
2482 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
---|
2483 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
---|
2484 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
---|
2485 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
---|
2486 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
---|
2487 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2488 |
|
---|
2489 | ui_list_destroy(list);
|
---|
2490 | ui_window_destroy(window);
|
---|
2491 | ui_destroy(ui);
|
---|
2492 | }
|
---|
2493 |
|
---|
2494 | /** ui_list_scroll_down() scrolls down by one row */
|
---|
2495 | PCUT_TEST(scroll_down)
|
---|
2496 | {
|
---|
2497 | ui_t *ui;
|
---|
2498 | ui_window_t *window;
|
---|
2499 | ui_wnd_params_t params;
|
---|
2500 | ui_list_t *list;
|
---|
2501 | ui_list_entry_attr_t attr;
|
---|
2502 | gfx_rect_t rect;
|
---|
2503 | errno_t rc;
|
---|
2504 |
|
---|
2505 | rc = ui_create_disp(NULL, &ui);
|
---|
2506 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2507 |
|
---|
2508 | ui_wnd_params_init(¶ms);
|
---|
2509 | params.caption = "Test";
|
---|
2510 |
|
---|
2511 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2512 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2513 |
|
---|
2514 | rc = ui_list_create(window, true, &list);
|
---|
2515 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2516 |
|
---|
2517 | rect.p0.x = 0;
|
---|
2518 | rect.p0.y = 0;
|
---|
2519 | rect.p1.x = 10;
|
---|
2520 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2521 | ui_list_set_rect(list, &rect);
|
---|
2522 |
|
---|
2523 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2524 |
|
---|
2525 | /* Add tree entries (more than page size, which is 2) */
|
---|
2526 |
|
---|
2527 | ui_list_entry_attr_init(&attr);
|
---|
2528 |
|
---|
2529 | attr.caption = "a";
|
---|
2530 | attr.arg = (void *)1;
|
---|
2531 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2532 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2533 |
|
---|
2534 | attr.caption = "b";
|
---|
2535 | attr.arg = (void *)2;
|
---|
2536 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2537 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2538 |
|
---|
2539 | attr.caption = "c";
|
---|
2540 | attr.arg = (void *)3;
|
---|
2541 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2542 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2543 |
|
---|
2544 | /* Cursor and page start to the first entry */
|
---|
2545 | list->cursor = ui_list_first(list);
|
---|
2546 | list->cursor_idx = 0;
|
---|
2547 | list->page = list->cursor;
|
---|
2548 | list->page_idx = 0;
|
---|
2549 |
|
---|
2550 | /* Scroll one entry down */
|
---|
2551 | ui_list_scroll_down(list);
|
---|
2552 |
|
---|
2553 | /* Page should start on the second entry, cursor unchanged */
|
---|
2554 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2555 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2556 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2557 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2558 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2559 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2560 |
|
---|
2561 | /* Try scrolling one more entry down */
|
---|
2562 | ui_list_scroll_down(list);
|
---|
2563 |
|
---|
2564 | /* We were at the end, so nothing should have changed */
|
---|
2565 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2566 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2567 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2568 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2569 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2570 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2571 |
|
---|
2572 | ui_list_destroy(list);
|
---|
2573 | ui_window_destroy(window);
|
---|
2574 | ui_destroy(ui);
|
---|
2575 | }
|
---|
2576 |
|
---|
2577 | /** ui_list_scroll_page_up() scrolls up by one page */
|
---|
2578 | PCUT_TEST(scroll_page_up)
|
---|
2579 | {
|
---|
2580 | ui_t *ui;
|
---|
2581 | ui_window_t *window;
|
---|
2582 | ui_wnd_params_t params;
|
---|
2583 | ui_list_t *list;
|
---|
2584 | ui_list_entry_attr_t attr;
|
---|
2585 | gfx_rect_t rect;
|
---|
2586 | errno_t rc;
|
---|
2587 |
|
---|
2588 | rc = ui_create_disp(NULL, &ui);
|
---|
2589 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2590 |
|
---|
2591 | ui_wnd_params_init(¶ms);
|
---|
2592 | params.caption = "Test";
|
---|
2593 |
|
---|
2594 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2595 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2596 |
|
---|
2597 | rc = ui_list_create(window, true, &list);
|
---|
2598 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2599 |
|
---|
2600 | rect.p0.x = 0;
|
---|
2601 | rect.p0.y = 0;
|
---|
2602 | rect.p1.x = 10;
|
---|
2603 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2604 | ui_list_set_rect(list, &rect);
|
---|
2605 |
|
---|
2606 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2607 |
|
---|
2608 | /* Add five entries (more than twice the page size, which is 2) */
|
---|
2609 |
|
---|
2610 | ui_list_entry_attr_init(&attr);
|
---|
2611 |
|
---|
2612 | attr.caption = "a";
|
---|
2613 | attr.arg = (void *)1;
|
---|
2614 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2615 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2616 |
|
---|
2617 | attr.caption = "b";
|
---|
2618 | attr.arg = (void *)2;
|
---|
2619 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2620 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2621 |
|
---|
2622 | attr.caption = "c";
|
---|
2623 | attr.arg = (void *)3;
|
---|
2624 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2625 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2626 |
|
---|
2627 | attr.caption = "d";
|
---|
2628 | attr.arg = (void *)4;
|
---|
2629 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2630 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2631 |
|
---|
2632 | attr.caption = "e";
|
---|
2633 | attr.arg = (void *)5;
|
---|
2634 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2635 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2636 |
|
---|
2637 | /* Cursor to the last entry, page to the second last */
|
---|
2638 | list->cursor = ui_list_last(list);
|
---|
2639 | list->cursor_idx = 4;
|
---|
2640 | list->page = ui_list_prev(list->cursor);
|
---|
2641 | list->page_idx = 3;
|
---|
2642 |
|
---|
2643 | /* Scroll one page up */
|
---|
2644 | ui_list_scroll_page_up(list);
|
---|
2645 |
|
---|
2646 | /* Page should start on 'b', cursor unchanged */
|
---|
2647 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
---|
2648 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
---|
2649 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
---|
2650 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2651 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2652 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2653 |
|
---|
2654 | /* Page up again */
|
---|
2655 | ui_list_scroll_page_up(list);
|
---|
2656 |
|
---|
2657 | /* Page should now be at the beginning, cursor unchanged */
|
---|
2658 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
---|
2659 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
---|
2660 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
---|
2661 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
---|
2662 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
---|
2663 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2664 |
|
---|
2665 | /* Page up again */
|
---|
2666 | ui_list_scroll_page_up(list);
|
---|
2667 |
|
---|
2668 | /* We were at the beginning, nothing should have changed */
|
---|
2669 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
---|
2670 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
---|
2671 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
---|
2672 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
---|
2673 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
---|
2674 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
---|
2675 |
|
---|
2676 | ui_list_destroy(list);
|
---|
2677 | ui_window_destroy(window);
|
---|
2678 | ui_destroy(ui);
|
---|
2679 | }
|
---|
2680 |
|
---|
2681 | /** ui_list_scroll_page_up() scrolls down by one page */
|
---|
2682 | PCUT_TEST(scroll_page_down)
|
---|
2683 | {
|
---|
2684 | ui_t *ui;
|
---|
2685 | ui_window_t *window;
|
---|
2686 | ui_wnd_params_t params;
|
---|
2687 | ui_list_t *list;
|
---|
2688 | ui_list_entry_attr_t attr;
|
---|
2689 | gfx_rect_t rect;
|
---|
2690 | errno_t rc;
|
---|
2691 |
|
---|
2692 | rc = ui_create_disp(NULL, &ui);
|
---|
2693 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2694 |
|
---|
2695 | ui_wnd_params_init(¶ms);
|
---|
2696 | params.caption = "Test";
|
---|
2697 |
|
---|
2698 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2699 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2700 |
|
---|
2701 | rc = ui_list_create(window, true, &list);
|
---|
2702 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2703 |
|
---|
2704 | rect.p0.x = 0;
|
---|
2705 | rect.p0.y = 0;
|
---|
2706 | rect.p1.x = 10;
|
---|
2707 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2708 | ui_list_set_rect(list, &rect);
|
---|
2709 |
|
---|
2710 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2711 |
|
---|
2712 | /* Add five entries (more than twice the page size, which is 2) */
|
---|
2713 |
|
---|
2714 | ui_list_entry_attr_init(&attr);
|
---|
2715 |
|
---|
2716 | attr.caption = "a";
|
---|
2717 | attr.arg = (void *)1;
|
---|
2718 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2719 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2720 |
|
---|
2721 | attr.caption = "b";
|
---|
2722 | attr.arg = (void *)2;
|
---|
2723 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2724 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2725 |
|
---|
2726 | attr.caption = "c";
|
---|
2727 | attr.arg = (void *)3;
|
---|
2728 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2729 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2730 |
|
---|
2731 | attr.caption = "d";
|
---|
2732 | attr.arg = (void *)4;
|
---|
2733 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2734 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2735 |
|
---|
2736 | attr.caption = "e";
|
---|
2737 | attr.arg = (void *)5;
|
---|
2738 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2739 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2740 |
|
---|
2741 | /* Cursor and page to the first entry */
|
---|
2742 | list->cursor = ui_list_first(list);
|
---|
2743 | list->cursor_idx = 0;
|
---|
2744 | list->page = ui_list_first(list);
|
---|
2745 | list->page_idx = 0;
|
---|
2746 |
|
---|
2747 | /* Scroll one page down */
|
---|
2748 | ui_list_scroll_page_down(list);
|
---|
2749 |
|
---|
2750 | /* Page should start on 'c', cursor unchanged */
|
---|
2751 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2752 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2753 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2754 | PCUT_ASSERT_STR_EQUALS("c", list->page->caption);
|
---|
2755 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->page->arg);
|
---|
2756 | PCUT_ASSERT_INT_EQUALS(2, list->page_idx);
|
---|
2757 |
|
---|
2758 | /* Page down again */
|
---|
2759 | ui_list_scroll_page_down(list);
|
---|
2760 |
|
---|
2761 | /* Page should now start at 'd', cursor unchanged */
|
---|
2762 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2763 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2764 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2765 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
---|
2766 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
---|
2767 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
---|
2768 |
|
---|
2769 | /* Page down again */
|
---|
2770 | ui_list_scroll_page_down(list);
|
---|
2771 |
|
---|
2772 | /* We were at the end, nothing should have changed */
|
---|
2773 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2774 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2775 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2776 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
---|
2777 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
---|
2778 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
---|
2779 |
|
---|
2780 | ui_list_destroy(list);
|
---|
2781 | ui_window_destroy(window);
|
---|
2782 | ui_destroy(ui);
|
---|
2783 | }
|
---|
2784 |
|
---|
2785 | /** ui_list_scroll_pos() scrolls to a particular entry */
|
---|
2786 | PCUT_TEST(scroll_pos)
|
---|
2787 | {
|
---|
2788 | ui_t *ui;
|
---|
2789 | ui_window_t *window;
|
---|
2790 | ui_wnd_params_t params;
|
---|
2791 | ui_list_t *list;
|
---|
2792 | ui_list_entry_attr_t attr;
|
---|
2793 | gfx_rect_t rect;
|
---|
2794 | errno_t rc;
|
---|
2795 |
|
---|
2796 | rc = ui_create_disp(NULL, &ui);
|
---|
2797 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2798 |
|
---|
2799 | ui_wnd_params_init(¶ms);
|
---|
2800 | params.caption = "Test";
|
---|
2801 |
|
---|
2802 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2803 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2804 |
|
---|
2805 | rc = ui_list_create(window, true, &list);
|
---|
2806 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2807 |
|
---|
2808 | rect.p0.x = 0;
|
---|
2809 | rect.p0.y = 0;
|
---|
2810 | rect.p1.x = 10;
|
---|
2811 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
2812 | ui_list_set_rect(list, &rect);
|
---|
2813 |
|
---|
2814 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
---|
2815 |
|
---|
2816 | /* Add five entries (more than twice the page size, which is 2) */
|
---|
2817 |
|
---|
2818 | ui_list_entry_attr_init(&attr);
|
---|
2819 |
|
---|
2820 | attr.caption = "a";
|
---|
2821 | attr.arg = (void *)1;
|
---|
2822 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2823 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2824 |
|
---|
2825 | attr.caption = "b";
|
---|
2826 | attr.arg = (void *)2;
|
---|
2827 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2828 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2829 |
|
---|
2830 | attr.caption = "c";
|
---|
2831 | attr.arg = (void *)3;
|
---|
2832 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2833 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2834 |
|
---|
2835 | attr.caption = "d";
|
---|
2836 | attr.arg = (void *)4;
|
---|
2837 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2838 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2839 |
|
---|
2840 | attr.caption = "e";
|
---|
2841 | attr.arg = (void *)5;
|
---|
2842 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2843 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2844 |
|
---|
2845 | /* Cursor and page to the first entry */
|
---|
2846 | list->cursor = ui_list_first(list);
|
---|
2847 | list->cursor_idx = 0;
|
---|
2848 | list->page = ui_list_first(list);
|
---|
2849 | list->page_idx = 0;
|
---|
2850 |
|
---|
2851 | /* Scroll to entry 1 (one down) */
|
---|
2852 | ui_list_scroll_pos(list, 1);
|
---|
2853 |
|
---|
2854 | /* Page should start on 'b', cursor unchanged */
|
---|
2855 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2856 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2857 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2858 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
---|
2859 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
---|
2860 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
---|
2861 |
|
---|
2862 | /* Scroll to entry 3 (i.e. the end) */
|
---|
2863 | ui_list_scroll_pos(list, 3);
|
---|
2864 |
|
---|
2865 | /* Page should now start at 'd', cursor unchanged */
|
---|
2866 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
---|
2867 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
---|
2868 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
---|
2869 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
---|
2870 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
---|
2871 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
---|
2872 |
|
---|
2873 | ui_list_destroy(list);
|
---|
2874 | ui_window_destroy(window);
|
---|
2875 | ui_destroy(ui);
|
---|
2876 | }
|
---|
2877 |
|
---|
2878 | /** ui_list_activate_req() sends activation request */
|
---|
2879 | PCUT_TEST(activate_req)
|
---|
2880 | {
|
---|
2881 | ui_t *ui;
|
---|
2882 | ui_window_t *window;
|
---|
2883 | ui_wnd_params_t params;
|
---|
2884 | ui_list_t *list;
|
---|
2885 | errno_t rc;
|
---|
2886 | test_resp_t resp;
|
---|
2887 |
|
---|
2888 | rc = ui_create_disp(NULL, &ui);
|
---|
2889 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2890 |
|
---|
2891 | ui_wnd_params_init(¶ms);
|
---|
2892 | params.caption = "Test";
|
---|
2893 |
|
---|
2894 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2895 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2896 |
|
---|
2897 | rc = ui_list_create(window, true, &list);
|
---|
2898 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2899 |
|
---|
2900 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
2901 |
|
---|
2902 | resp.activate_req = false;
|
---|
2903 | resp.activate_req_list = NULL;
|
---|
2904 |
|
---|
2905 | ui_list_activate_req(list);
|
---|
2906 | PCUT_ASSERT_TRUE(resp.activate_req);
|
---|
2907 | PCUT_ASSERT_EQUALS(list, resp.activate_req_list);
|
---|
2908 |
|
---|
2909 | ui_list_destroy(list);
|
---|
2910 | ui_window_destroy(window);
|
---|
2911 | ui_destroy(ui);
|
---|
2912 | }
|
---|
2913 |
|
---|
2914 | /** ui_list_selected() runs selected callback */
|
---|
2915 | PCUT_TEST(selected)
|
---|
2916 | {
|
---|
2917 | ui_t *ui;
|
---|
2918 | ui_window_t *window;
|
---|
2919 | ui_wnd_params_t params;
|
---|
2920 | ui_list_t *list;
|
---|
2921 | ui_list_entry_attr_t attr;
|
---|
2922 | ui_list_entry_t *entry;
|
---|
2923 | errno_t rc;
|
---|
2924 | test_resp_t resp;
|
---|
2925 |
|
---|
2926 | rc = ui_create_disp(NULL, &ui);
|
---|
2927 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2928 |
|
---|
2929 | ui_wnd_params_init(¶ms);
|
---|
2930 | params.caption = "Test";
|
---|
2931 |
|
---|
2932 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2933 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2934 |
|
---|
2935 | rc = ui_list_create(window, true, &list);
|
---|
2936 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2937 |
|
---|
2938 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
2939 |
|
---|
2940 | ui_list_entry_attr_init(&attr);
|
---|
2941 | attr.caption = "Hello";
|
---|
2942 | attr.arg = &resp;
|
---|
2943 |
|
---|
2944 | rc = ui_list_entry_append(list, &attr, &entry);
|
---|
2945 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2946 |
|
---|
2947 | resp.selected = false;
|
---|
2948 | resp.selected_entry = NULL;
|
---|
2949 |
|
---|
2950 | ui_list_selected(entry);
|
---|
2951 | PCUT_ASSERT_TRUE(resp.selected);
|
---|
2952 | PCUT_ASSERT_EQUALS(entry, resp.selected_entry);
|
---|
2953 |
|
---|
2954 | ui_list_destroy(list);
|
---|
2955 | ui_window_destroy(window);
|
---|
2956 | ui_destroy(ui);
|
---|
2957 | }
|
---|
2958 |
|
---|
2959 | /** ui_list_entry_ptr_cmp compares two indirectly referenced entries */
|
---|
2960 | PCUT_TEST(entry_ptr_cmp)
|
---|
2961 | {
|
---|
2962 | ui_t *ui;
|
---|
2963 | ui_window_t *window;
|
---|
2964 | ui_wnd_params_t params;
|
---|
2965 | ui_list_t *list;
|
---|
2966 | ui_list_entry_t *a, *b;
|
---|
2967 | ui_list_entry_attr_t attr;
|
---|
2968 | test_resp_t resp;
|
---|
2969 | int rel;
|
---|
2970 | errno_t rc;
|
---|
2971 |
|
---|
2972 | rc = ui_create_disp(NULL, &ui);
|
---|
2973 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2974 |
|
---|
2975 | ui_wnd_params_init(¶ms);
|
---|
2976 | params.caption = "Test";
|
---|
2977 |
|
---|
2978 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
2979 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2980 |
|
---|
2981 | rc = ui_list_create(window, true, &list);
|
---|
2982 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2983 |
|
---|
2984 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
2985 |
|
---|
2986 | ui_list_entry_attr_init(&attr);
|
---|
2987 |
|
---|
2988 | attr.caption = "a";
|
---|
2989 | attr.arg = (void *)2;
|
---|
2990 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2991 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2992 |
|
---|
2993 | attr.caption = "b";
|
---|
2994 | attr.arg = (void *)1;
|
---|
2995 | rc = ui_list_entry_append(list, &attr, NULL);
|
---|
2996 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
2997 |
|
---|
2998 | a = ui_list_first(list);
|
---|
2999 | PCUT_ASSERT_NOT_NULL(a);
|
---|
3000 | b = ui_list_next(a);
|
---|
3001 | PCUT_ASSERT_NOT_NULL(b);
|
---|
3002 |
|
---|
3003 | /* a < b */
|
---|
3004 | rel = ui_list_entry_ptr_cmp(&a, &b);
|
---|
3005 | PCUT_ASSERT_TRUE(rel < 0);
|
---|
3006 |
|
---|
3007 | /* b > a */
|
---|
3008 | rel = ui_list_entry_ptr_cmp(&b, &a);
|
---|
3009 | PCUT_ASSERT_TRUE(rel > 0);
|
---|
3010 |
|
---|
3011 | /* a == a */
|
---|
3012 | rel = ui_list_entry_ptr_cmp(&a, &a);
|
---|
3013 | PCUT_ASSERT_INT_EQUALS(0, rel);
|
---|
3014 |
|
---|
3015 | ui_list_destroy(list);
|
---|
3016 | ui_window_destroy(window);
|
---|
3017 | ui_destroy(ui);
|
---|
3018 | }
|
---|
3019 |
|
---|
3020 | /** ui_list_entry_get_idx() returns entry index */
|
---|
3021 | PCUT_TEST(entry_get_idx)
|
---|
3022 | {
|
---|
3023 | ui_t *ui;
|
---|
3024 | ui_window_t *window;
|
---|
3025 | ui_wnd_params_t params;
|
---|
3026 | ui_list_t *list;
|
---|
3027 | ui_list_entry_t *a, *b;
|
---|
3028 | ui_list_entry_attr_t attr;
|
---|
3029 | test_resp_t resp;
|
---|
3030 | errno_t rc;
|
---|
3031 |
|
---|
3032 | rc = ui_create_disp(NULL, &ui);
|
---|
3033 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
3034 |
|
---|
3035 | ui_wnd_params_init(¶ms);
|
---|
3036 | params.caption = "Test";
|
---|
3037 |
|
---|
3038 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
3039 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
3040 |
|
---|
3041 | rc = ui_list_create(window, true, &list);
|
---|
3042 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
3043 |
|
---|
3044 | ui_list_set_cb(list, &test_cb, &resp);
|
---|
3045 |
|
---|
3046 | ui_list_entry_attr_init(&attr);
|
---|
3047 |
|
---|
3048 | attr.caption = "a";
|
---|
3049 | attr.arg = (void *)2;
|
---|
3050 | rc = ui_list_entry_append(list, &attr, &a);
|
---|
3051 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
3052 |
|
---|
3053 | attr.caption = "b";
|
---|
3054 | attr.arg = (void *)1;
|
---|
3055 | rc = ui_list_entry_append(list, &attr, &b);
|
---|
3056 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
3057 |
|
---|
3058 | PCUT_ASSERT_INT_EQUALS(0, ui_list_entry_get_idx(a));
|
---|
3059 | PCUT_ASSERT_INT_EQUALS(1, ui_list_entry_get_idx(b));
|
---|
3060 |
|
---|
3061 | ui_list_destroy(list);
|
---|
3062 | ui_window_destroy(window);
|
---|
3063 | ui_destroy(ui);
|
---|
3064 | }
|
---|
3065 |
|
---|
3066 | static void test_list_activate_req(ui_list_t *list, void *arg)
|
---|
3067 | {
|
---|
3068 | test_resp_t *resp = (test_resp_t *)arg;
|
---|
3069 |
|
---|
3070 | resp->activate_req = true;
|
---|
3071 | resp->activate_req_list = list;
|
---|
3072 | }
|
---|
3073 |
|
---|
3074 | static void test_list_selected(ui_list_entry_t *entry, void *arg)
|
---|
3075 | {
|
---|
3076 | test_resp_t *resp = (test_resp_t *)arg;
|
---|
3077 |
|
---|
3078 | resp->selected = true;
|
---|
3079 | resp->selected_entry = entry;
|
---|
3080 | }
|
---|
3081 |
|
---|
3082 | static int test_list_compare(ui_list_entry_t *a, ui_list_entry_t *b)
|
---|
3083 | {
|
---|
3084 | return str_cmp(a->caption, b->caption);
|
---|
3085 | }
|
---|
3086 |
|
---|
3087 | PCUT_EXPORT(list);
|
---|