| [7cf5ddb] | 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 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 |
|
|---|
| [37087c8] | 121 | /** ui_list_get_cb_arg() returns the callback argument */
|
|---|
| [c0757e1f] | 122 | PCUT_TEST(get_cb_arg)
|
|---|
| 123 | {
|
|---|
| [37087c8] | 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);
|
|---|
| [c0757e1f] | 151 | }
|
|---|
| 152 |
|
|---|
| [7cf5ddb] | 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 |
|
|---|
| [37087c8] | 785 | /** ui_list_set_cursor() sets list cursor position */
|
|---|
| [c0757e1f] | 786 | PCUT_TEST(set_cursor)
|
|---|
| 787 | {
|
|---|
| [37087c8] | 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);
|
|---|
| [c0757e1f] | 843 | }
|
|---|
| 844 |
|
|---|
| [7cf5ddb] | 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_delete() deletes entry */
|
|---|
| 907 | PCUT_TEST(entry_delete)
|
|---|
| 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_t *entry;
|
|---|
| 914 | ui_list_entry_attr_t attr;
|
|---|
| 915 | errno_t rc;
|
|---|
| 916 |
|
|---|
| 917 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 918 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 919 |
|
|---|
| 920 | ui_wnd_params_init(¶ms);
|
|---|
| 921 | params.caption = "Test";
|
|---|
| 922 |
|
|---|
| 923 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 924 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 925 |
|
|---|
| 926 | rc = ui_list_create(window, true, &list);
|
|---|
| 927 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 928 |
|
|---|
| 929 | attr.caption = "a";
|
|---|
| 930 | attr.arg = (void *)1;
|
|---|
| 931 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 932 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 933 |
|
|---|
| 934 | attr.caption = "b";
|
|---|
| 935 | attr.arg = (void *)2;
|
|---|
| 936 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 937 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 938 |
|
|---|
| 939 | PCUT_ASSERT_INT_EQUALS(2, list_count(&list->entries));
|
|---|
| 940 |
|
|---|
| 941 | entry = ui_list_first(list);
|
|---|
| 942 | ui_list_entry_delete(entry);
|
|---|
| 943 |
|
|---|
| 944 | PCUT_ASSERT_INT_EQUALS(1, list_count(&list->entries));
|
|---|
| 945 |
|
|---|
| 946 | entry = ui_list_first(list);
|
|---|
| 947 | ui_list_entry_delete(entry);
|
|---|
| 948 |
|
|---|
| 949 | PCUT_ASSERT_INT_EQUALS(0, list_count(&list->entries));
|
|---|
| 950 |
|
|---|
| 951 | ui_list_destroy(list);
|
|---|
| 952 | ui_window_destroy(window);
|
|---|
| 953 | ui_destroy(ui);
|
|---|
| 954 | }
|
|---|
| 955 |
|
|---|
| 956 | /** ui_list_entry_get_arg() gets entry argument */
|
|---|
| 957 | PCUT_TEST(entry_get_arg)
|
|---|
| 958 | {
|
|---|
| 959 | ui_t *ui;
|
|---|
| 960 | ui_window_t *window;
|
|---|
| 961 | ui_wnd_params_t params;
|
|---|
| 962 | ui_list_t *list;
|
|---|
| 963 | ui_list_entry_attr_t attr;
|
|---|
| 964 | ui_list_entry_t *entry;
|
|---|
| 965 | void *arg;
|
|---|
| 966 | errno_t rc;
|
|---|
| 967 |
|
|---|
| 968 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 969 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 970 |
|
|---|
| 971 | ui_wnd_params_init(¶ms);
|
|---|
| 972 | params.caption = "Test";
|
|---|
| 973 |
|
|---|
| 974 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 975 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 976 |
|
|---|
| 977 | rc = ui_list_create(window, true, &list);
|
|---|
| 978 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 979 |
|
|---|
| 980 | ui_list_entry_attr_init(&attr);
|
|---|
| 981 |
|
|---|
| 982 | /* Append entry and get pointer to it */
|
|---|
| 983 | attr.caption = "a";
|
|---|
| 984 | attr.arg = (void *)1;
|
|---|
| 985 | entry = NULL;
|
|---|
| 986 | rc = ui_list_entry_append(list, &attr, &entry);
|
|---|
| 987 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 988 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 989 |
|
|---|
| 990 | arg = ui_list_entry_get_arg(entry);
|
|---|
| 991 | PCUT_ASSERT_EQUALS(attr.arg, arg);
|
|---|
| 992 |
|
|---|
| 993 | ui_list_destroy(list);
|
|---|
| 994 | ui_window_destroy(window);
|
|---|
| 995 | ui_destroy(ui);
|
|---|
| 996 | }
|
|---|
| 997 |
|
|---|
| [37087c8] | 998 | /** ui_list_entry_get_list() returns the containing list */
|
|---|
| [c0757e1f] | 999 | PCUT_TEST(entry_get_list)
|
|---|
| 1000 | {
|
|---|
| [37087c8] | 1001 | ui_t *ui;
|
|---|
| 1002 | ui_window_t *window;
|
|---|
| 1003 | ui_wnd_params_t params;
|
|---|
| 1004 | ui_list_t *list;
|
|---|
| 1005 | ui_list_t *elist;
|
|---|
| 1006 | ui_list_entry_attr_t attr;
|
|---|
| 1007 | ui_list_entry_t *entry;
|
|---|
| 1008 | errno_t rc;
|
|---|
| 1009 |
|
|---|
| 1010 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1011 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1012 |
|
|---|
| 1013 | ui_wnd_params_init(¶ms);
|
|---|
| 1014 | params.caption = "Test";
|
|---|
| 1015 |
|
|---|
| 1016 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1017 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1018 |
|
|---|
| 1019 | rc = ui_list_create(window, true, &list);
|
|---|
| 1020 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1021 |
|
|---|
| 1022 | ui_list_entry_attr_init(&attr);
|
|---|
| 1023 |
|
|---|
| 1024 | /* Append entry and get pointer to it */
|
|---|
| 1025 | attr.caption = "a";
|
|---|
| 1026 | attr.arg = (void *)1;
|
|---|
| 1027 | entry = NULL;
|
|---|
| 1028 | rc = ui_list_entry_append(list, &attr, &entry);
|
|---|
| 1029 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1030 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1031 |
|
|---|
| 1032 | /* Get the containing list */
|
|---|
| 1033 | elist = ui_list_entry_get_list(entry);
|
|---|
| 1034 | PCUT_ASSERT_EQUALS(list, elist);
|
|---|
| 1035 |
|
|---|
| 1036 | ui_list_destroy(list);
|
|---|
| 1037 | ui_window_destroy(window);
|
|---|
| 1038 | ui_destroy(ui);
|
|---|
| [c0757e1f] | 1039 | }
|
|---|
| 1040 |
|
|---|
| [5e758e4] | 1041 | /** ui_list_entry_set_caption() sets entry captino */
|
|---|
| 1042 | PCUT_TEST(entry_set_caption)
|
|---|
| 1043 | {
|
|---|
| 1044 | ui_t *ui;
|
|---|
| 1045 | ui_window_t *window;
|
|---|
| 1046 | ui_wnd_params_t params;
|
|---|
| 1047 | ui_list_t *list;
|
|---|
| 1048 | ui_list_entry_attr_t attr;
|
|---|
| 1049 | ui_list_entry_t *entry;
|
|---|
| 1050 | errno_t rc;
|
|---|
| 1051 |
|
|---|
| 1052 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1053 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1054 |
|
|---|
| 1055 | ui_wnd_params_init(¶ms);
|
|---|
| 1056 | params.caption = "Test";
|
|---|
| 1057 |
|
|---|
| 1058 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1059 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1060 |
|
|---|
| 1061 | rc = ui_list_create(window, true, &list);
|
|---|
| 1062 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1063 |
|
|---|
| 1064 | ui_list_entry_attr_init(&attr);
|
|---|
| 1065 |
|
|---|
| 1066 | /* Append entry and get pointer to it */
|
|---|
| 1067 | attr.caption = "a";
|
|---|
| 1068 | attr.arg = (void *)1;
|
|---|
| 1069 | entry = NULL;
|
|---|
| 1070 | rc = ui_list_entry_append(list, &attr, &entry);
|
|---|
| 1071 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1072 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1073 |
|
|---|
| 1074 | /* Change caption */
|
|---|
| 1075 | rc = ui_list_entry_set_caption(entry, "b");
|
|---|
| 1076 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1077 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
|---|
| 1078 |
|
|---|
| 1079 | ui_list_destroy(list);
|
|---|
| 1080 | ui_window_destroy(window);
|
|---|
| 1081 | ui_destroy(ui);
|
|---|
| 1082 | }
|
|---|
| 1083 |
|
|---|
| [7cf5ddb] | 1084 | /** ui_list_entries_cnt() returns the number of entries */
|
|---|
| 1085 | PCUT_TEST(entries_cnt)
|
|---|
| 1086 | {
|
|---|
| 1087 | ui_t *ui;
|
|---|
| 1088 | ui_window_t *window;
|
|---|
| 1089 | ui_wnd_params_t params;
|
|---|
| 1090 | ui_list_t *list;
|
|---|
| 1091 | ui_list_entry_attr_t attr;
|
|---|
| 1092 | errno_t rc;
|
|---|
| 1093 |
|
|---|
| 1094 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1095 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1096 |
|
|---|
| 1097 | ui_wnd_params_init(¶ms);
|
|---|
| 1098 | params.caption = "Test";
|
|---|
| 1099 |
|
|---|
| 1100 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1101 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1102 |
|
|---|
| 1103 | rc = ui_list_create(window, true, &list);
|
|---|
| 1104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1105 |
|
|---|
| 1106 | PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(list));
|
|---|
| 1107 |
|
|---|
| 1108 | ui_list_entry_attr_init(&attr);
|
|---|
| 1109 |
|
|---|
| 1110 | /* Append entry */
|
|---|
| 1111 | attr.caption = "a";
|
|---|
| 1112 | attr.arg = (void *)1;
|
|---|
| 1113 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1114 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1115 |
|
|---|
| 1116 | PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(list));
|
|---|
| 1117 |
|
|---|
| 1118 | /* Append another entry */
|
|---|
| 1119 | attr.caption = "b";
|
|---|
| 1120 | attr.arg = (void *)2;
|
|---|
| 1121 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1122 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1123 |
|
|---|
| 1124 | PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(list));
|
|---|
| 1125 |
|
|---|
| 1126 | ui_list_destroy(list);
|
|---|
| 1127 | ui_window_destroy(window);
|
|---|
| 1128 | ui_destroy(ui);
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 | /** ui_list_sort() sorts UI list entries */
|
|---|
| 1132 | PCUT_TEST(sort)
|
|---|
| 1133 | {
|
|---|
| 1134 | ui_t *ui;
|
|---|
| 1135 | ui_window_t *window;
|
|---|
| 1136 | ui_wnd_params_t params;
|
|---|
| 1137 | ui_list_t *list;
|
|---|
| 1138 | ui_list_entry_t *entry;
|
|---|
| 1139 | ui_list_entry_attr_t attr;
|
|---|
| 1140 | test_resp_t resp;
|
|---|
| 1141 | errno_t rc;
|
|---|
| 1142 |
|
|---|
| 1143 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1144 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1145 |
|
|---|
| 1146 | ui_wnd_params_init(¶ms);
|
|---|
| 1147 | params.caption = "Test";
|
|---|
| 1148 |
|
|---|
| 1149 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1150 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1151 |
|
|---|
| 1152 | rc = ui_list_create(window, true, &list);
|
|---|
| 1153 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1154 |
|
|---|
| 1155 | ui_list_set_cb(list, &test_cb, &resp);
|
|---|
| 1156 |
|
|---|
| 1157 | ui_list_entry_attr_init(&attr);
|
|---|
| 1158 |
|
|---|
| 1159 | attr.caption = "b";
|
|---|
| 1160 | attr.arg = (void *)1;
|
|---|
| 1161 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1162 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1163 |
|
|---|
| 1164 | attr.caption = "c";
|
|---|
| 1165 | attr.arg = (void *)3;
|
|---|
| 1166 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1167 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1168 |
|
|---|
| 1169 | attr.caption = "a";
|
|---|
| 1170 | attr.arg = (void *)2;
|
|---|
| 1171 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1173 |
|
|---|
| 1174 | rc = ui_list_sort(list);
|
|---|
| 1175 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1176 |
|
|---|
| 1177 | entry = ui_list_first(list);
|
|---|
| 1178 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
|---|
| 1179 | PCUT_ASSERT_EQUALS((void *)2, entry->arg);
|
|---|
| 1180 |
|
|---|
| 1181 | entry = ui_list_next(entry);
|
|---|
| 1182 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
|---|
| 1183 | PCUT_ASSERT_EQUALS((void *)1, entry->arg);
|
|---|
| 1184 |
|
|---|
| 1185 | entry = ui_list_next(entry);
|
|---|
| 1186 | PCUT_ASSERT_STR_EQUALS("c", entry->caption);
|
|---|
| 1187 | PCUT_ASSERT_EQUALS((void *)3, entry->arg);
|
|---|
| 1188 |
|
|---|
| 1189 | ui_list_destroy(list);
|
|---|
| 1190 | ui_window_destroy(window);
|
|---|
| 1191 | ui_destroy(ui);
|
|---|
| 1192 | }
|
|---|
| 1193 |
|
|---|
| 1194 | /** ui_list_cursor_center()...XXX */
|
|---|
| 1195 | PCUT_TEST(cursor_center)
|
|---|
| 1196 | {
|
|---|
| 1197 | ui_t *ui;
|
|---|
| 1198 | ui_window_t *window;
|
|---|
| 1199 | ui_wnd_params_t params;
|
|---|
| 1200 | ui_list_t *list;
|
|---|
| 1201 | ui_list_entry_t *a, *b, *c, *d, *e;
|
|---|
| 1202 | ui_list_entry_attr_t attr;
|
|---|
| 1203 | gfx_rect_t rect;
|
|---|
| 1204 | test_resp_t resp;
|
|---|
| 1205 | errno_t rc;
|
|---|
| 1206 |
|
|---|
| 1207 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1208 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1209 |
|
|---|
| 1210 | ui_wnd_params_init(¶ms);
|
|---|
| 1211 | params.caption = "Test";
|
|---|
| 1212 |
|
|---|
| 1213 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1214 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1215 |
|
|---|
| 1216 | rc = ui_list_create(window, true, &list);
|
|---|
| 1217 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1218 |
|
|---|
| 1219 | ui_list_set_cb(list, &test_cb, &resp);
|
|---|
| 1220 |
|
|---|
| 1221 | rect.p0.x = 10;
|
|---|
| 1222 | rect.p0.y = 20;
|
|---|
| 1223 | rect.p1.x = 50;
|
|---|
| 1224 | rect.p1.y = 80;
|
|---|
| 1225 |
|
|---|
| 1226 | ui_list_set_rect(list, &rect);
|
|---|
| 1227 |
|
|---|
| 1228 | PCUT_ASSERT_INT_EQUALS(3, ui_list_page_size(list));
|
|---|
| 1229 |
|
|---|
| 1230 | ui_list_entry_attr_init(&attr);
|
|---|
| 1231 |
|
|---|
| 1232 | attr.caption = "a";
|
|---|
| 1233 | attr.arg = (void *)1;
|
|---|
| 1234 | rc = ui_list_entry_append(list, &attr, &a);
|
|---|
| 1235 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1236 |
|
|---|
| 1237 | attr.caption = "b";
|
|---|
| 1238 | attr.arg = (void *)2;
|
|---|
| 1239 | rc = ui_list_entry_append(list, &attr, &b);
|
|---|
| 1240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1241 |
|
|---|
| 1242 | /* We only have two entries, but three fit onto the page */
|
|---|
| 1243 | ui_list_cursor_center(list, b);
|
|---|
| 1244 | PCUT_ASSERT_EQUALS(b, list->cursor);
|
|---|
| 1245 | /* Page should start at the beginning */
|
|---|
| 1246 | PCUT_ASSERT_EQUALS(a, list->page);
|
|---|
| 1247 | PCUT_ASSERT_EQUALS(0, list->page_idx);
|
|---|
| 1248 |
|
|---|
| 1249 | /* Add more entries */
|
|---|
| 1250 |
|
|---|
| 1251 | attr.caption = "c";
|
|---|
| 1252 | attr.arg = (void *)3;
|
|---|
| 1253 | rc = ui_list_entry_append(list, &attr, &c);
|
|---|
| 1254 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1255 |
|
|---|
| 1256 | attr.caption = "d";
|
|---|
| 1257 | attr.arg = (void *)4;
|
|---|
| 1258 | rc = ui_list_entry_append(list, &attr, &d);
|
|---|
| 1259 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1260 |
|
|---|
| 1261 | attr.caption = "e";
|
|---|
| 1262 | attr.arg = (void *)5;
|
|---|
| 1263 | rc = ui_list_entry_append(list, &attr, &e);
|
|---|
| 1264 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1265 |
|
|---|
| 1266 | ui_list_cursor_center(list, c);
|
|---|
| 1267 | PCUT_ASSERT_EQUALS(c, list->cursor);
|
|---|
| 1268 | /*
|
|---|
| 1269 | * We have enough entries, c should be in the middle of the three
|
|---|
| 1270 | * entries on the page, i.e., page should start on 'b'.
|
|---|
| 1271 | */
|
|---|
| 1272 | PCUT_ASSERT_EQUALS(b, list->page);
|
|---|
| 1273 | PCUT_ASSERT_EQUALS(1, list->page_idx);
|
|---|
| 1274 |
|
|---|
| 1275 | ui_list_destroy(list);
|
|---|
| 1276 | ui_window_destroy(window);
|
|---|
| 1277 | ui_destroy(ui);
|
|---|
| 1278 | }
|
|---|
| 1279 |
|
|---|
| 1280 | /** ui_list_clear_entries() removes all entries from list */
|
|---|
| 1281 | PCUT_TEST(clear_entries)
|
|---|
| 1282 | {
|
|---|
| 1283 | ui_t *ui;
|
|---|
| 1284 | ui_window_t *window;
|
|---|
| 1285 | ui_wnd_params_t params;
|
|---|
| 1286 | ui_list_t *list;
|
|---|
| 1287 | ui_list_entry_attr_t attr;
|
|---|
| 1288 | errno_t rc;
|
|---|
| 1289 |
|
|---|
| 1290 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1291 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1292 |
|
|---|
| 1293 | ui_wnd_params_init(¶ms);
|
|---|
| 1294 | params.caption = "Test";
|
|---|
| 1295 |
|
|---|
| 1296 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1297 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1298 |
|
|---|
| 1299 | rc = ui_list_create(window, true, &list);
|
|---|
| 1300 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1301 |
|
|---|
| 1302 | ui_list_entry_attr_init(&attr);
|
|---|
| 1303 | attr.caption = "a";
|
|---|
| 1304 | attr.arg = (void *)1;
|
|---|
| 1305 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1306 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1307 |
|
|---|
| 1308 | attr.caption = "a";
|
|---|
| 1309 | attr.arg = (void *)2;
|
|---|
| 1310 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1311 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1312 |
|
|---|
| 1313 | PCUT_ASSERT_INT_EQUALS(2, list_count(&list->entries));
|
|---|
| 1314 |
|
|---|
| 1315 | ui_list_clear_entries(list);
|
|---|
| 1316 | PCUT_ASSERT_INT_EQUALS(0, list_count(&list->entries));
|
|---|
| 1317 |
|
|---|
| 1318 | ui_list_destroy(list);
|
|---|
| 1319 | ui_window_destroy(window);
|
|---|
| 1320 | ui_destroy(ui);
|
|---|
| 1321 | }
|
|---|
| 1322 |
|
|---|
| 1323 | /** ui_list_first() returns valid entry or @c NULL as appropriate */
|
|---|
| 1324 | PCUT_TEST(first)
|
|---|
| 1325 | {
|
|---|
| 1326 | ui_t *ui;
|
|---|
| 1327 | ui_window_t *window;
|
|---|
| 1328 | ui_wnd_params_t params;
|
|---|
| 1329 | ui_list_t *list;
|
|---|
| 1330 | ui_list_entry_t *entry;
|
|---|
| 1331 | ui_list_entry_attr_t attr;
|
|---|
| 1332 | errno_t rc;
|
|---|
| 1333 |
|
|---|
| 1334 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1335 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1336 |
|
|---|
| 1337 | ui_wnd_params_init(¶ms);
|
|---|
| 1338 | params.caption = "Test";
|
|---|
| 1339 |
|
|---|
| 1340 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1341 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1342 |
|
|---|
| 1343 | rc = ui_list_create(window, true, &list);
|
|---|
| 1344 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1345 |
|
|---|
| 1346 | ui_list_entry_attr_init(&attr);
|
|---|
| 1347 |
|
|---|
| 1348 | entry = ui_list_first(list);
|
|---|
| 1349 | PCUT_ASSERT_NULL(entry);
|
|---|
| 1350 |
|
|---|
| 1351 | /* Add one entry */
|
|---|
| 1352 | attr.caption = "a";
|
|---|
| 1353 | attr.arg = (void *)1;
|
|---|
| 1354 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1355 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1356 |
|
|---|
| 1357 | /* Now try getting it */
|
|---|
| 1358 | entry = ui_list_first(list);
|
|---|
| 1359 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1360 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
|---|
| 1361 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
|---|
| 1362 |
|
|---|
| 1363 | /* Add another entry */
|
|---|
| 1364 | attr.caption = "b";
|
|---|
| 1365 | attr.arg = (void *)2;
|
|---|
| 1366 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1367 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1368 |
|
|---|
| 1369 | /* We should still get the first entry */
|
|---|
| 1370 | entry = ui_list_first(list);
|
|---|
| 1371 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1372 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
|---|
| 1373 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
|---|
| 1374 |
|
|---|
| 1375 | ui_list_destroy(list);
|
|---|
| 1376 | ui_window_destroy(window);
|
|---|
| 1377 | ui_destroy(ui);
|
|---|
| 1378 | }
|
|---|
| 1379 |
|
|---|
| 1380 | /** ui_list_last() returns valid entry or @c NULL as appropriate */
|
|---|
| 1381 | PCUT_TEST(last)
|
|---|
| 1382 | {
|
|---|
| 1383 | ui_t *ui;
|
|---|
| 1384 | ui_window_t *window;
|
|---|
| 1385 | ui_wnd_params_t params;
|
|---|
| 1386 | ui_list_t *list;
|
|---|
| 1387 | ui_list_entry_t *entry;
|
|---|
| 1388 | ui_list_entry_attr_t attr;
|
|---|
| 1389 | errno_t rc;
|
|---|
| 1390 |
|
|---|
| 1391 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1392 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1393 |
|
|---|
| 1394 | ui_wnd_params_init(¶ms);
|
|---|
| 1395 | params.caption = "Test";
|
|---|
| 1396 |
|
|---|
| 1397 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1398 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1399 |
|
|---|
| 1400 | rc = ui_list_create(window, true, &list);
|
|---|
| 1401 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1402 |
|
|---|
| 1403 | ui_list_entry_attr_init(&attr);
|
|---|
| 1404 |
|
|---|
| 1405 | entry = ui_list_last(list);
|
|---|
| 1406 | PCUT_ASSERT_NULL(entry);
|
|---|
| 1407 |
|
|---|
| 1408 | /* Add one entry */
|
|---|
| 1409 | attr.caption = "a";
|
|---|
| 1410 | attr.arg = (void *)1;
|
|---|
| 1411 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1412 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1413 |
|
|---|
| 1414 | /* Now try getting it */
|
|---|
| 1415 | entry = ui_list_last(list);
|
|---|
| 1416 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1417 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
|---|
| 1418 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
|---|
| 1419 |
|
|---|
| 1420 | /* Add another entry */
|
|---|
| 1421 | attr.caption = "b";
|
|---|
| 1422 | attr.arg = (void *)2;
|
|---|
| 1423 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1424 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1425 |
|
|---|
| 1426 | /* We should get new entry now */
|
|---|
| 1427 | entry = ui_list_last(list);
|
|---|
| 1428 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1429 | attr.caption = "b";
|
|---|
| 1430 | attr.arg = (void *)2;
|
|---|
| 1431 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
|---|
| 1432 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)entry->arg);
|
|---|
| 1433 |
|
|---|
| 1434 | ui_list_destroy(list);
|
|---|
| 1435 | ui_window_destroy(window);
|
|---|
| 1436 | ui_destroy(ui);
|
|---|
| 1437 | }
|
|---|
| 1438 |
|
|---|
| 1439 | /** ui_list_next() returns the next entry or @c NULL as appropriate */
|
|---|
| 1440 | PCUT_TEST(next)
|
|---|
| 1441 | {
|
|---|
| 1442 | ui_t *ui;
|
|---|
| 1443 | ui_window_t *window;
|
|---|
| 1444 | ui_wnd_params_t params;
|
|---|
| 1445 | ui_list_t *list;
|
|---|
| 1446 | ui_list_entry_t *entry;
|
|---|
| 1447 | ui_list_entry_attr_t attr;
|
|---|
| 1448 | errno_t rc;
|
|---|
| 1449 |
|
|---|
| 1450 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1451 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1452 |
|
|---|
| 1453 | ui_wnd_params_init(¶ms);
|
|---|
| 1454 | params.caption = "Test";
|
|---|
| 1455 |
|
|---|
| 1456 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1457 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1458 |
|
|---|
| 1459 | rc = ui_list_create(window, true, &list);
|
|---|
| 1460 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1461 |
|
|---|
| 1462 | ui_list_entry_attr_init(&attr);
|
|---|
| 1463 |
|
|---|
| 1464 | /* Add one entry */
|
|---|
| 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 | /* Now try getting its successor */
|
|---|
| 1471 | entry = ui_list_first(list);
|
|---|
| 1472 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1473 |
|
|---|
| 1474 | entry = ui_list_next(entry);
|
|---|
| 1475 | PCUT_ASSERT_NULL(entry);
|
|---|
| 1476 |
|
|---|
| 1477 | /* Add another entry */
|
|---|
| 1478 | attr.caption = "b";
|
|---|
| 1479 | attr.arg = (void *)2;
|
|---|
| 1480 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1481 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1482 |
|
|---|
| 1483 | /* Try getting the successor of first entry again */
|
|---|
| 1484 | entry = ui_list_first(list);
|
|---|
| 1485 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1486 |
|
|---|
| 1487 | entry = ui_list_next(entry);
|
|---|
| 1488 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1489 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
|---|
| 1490 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)entry->arg);
|
|---|
| 1491 |
|
|---|
| 1492 | ui_list_destroy(list);
|
|---|
| 1493 | ui_window_destroy(window);
|
|---|
| 1494 | ui_destroy(ui);
|
|---|
| 1495 | }
|
|---|
| 1496 |
|
|---|
| 1497 | /** ui_list_prev() returns the previous entry or @c NULL as appropriate */
|
|---|
| 1498 | PCUT_TEST(prev)
|
|---|
| 1499 | {
|
|---|
| 1500 | ui_t *ui;
|
|---|
| 1501 | ui_window_t *window;
|
|---|
| 1502 | ui_wnd_params_t params;
|
|---|
| 1503 | ui_list_t *list;
|
|---|
| 1504 | ui_list_entry_t *entry;
|
|---|
| 1505 | ui_list_entry_attr_t attr;
|
|---|
| 1506 | errno_t rc;
|
|---|
| 1507 |
|
|---|
| 1508 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1509 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1510 |
|
|---|
| 1511 | ui_wnd_params_init(¶ms);
|
|---|
| 1512 | params.caption = "Test";
|
|---|
| 1513 |
|
|---|
| 1514 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1515 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1516 |
|
|---|
| 1517 | rc = ui_list_create(window, true, &list);
|
|---|
| 1518 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1519 |
|
|---|
| 1520 | ui_list_entry_attr_init(&attr);
|
|---|
| 1521 |
|
|---|
| 1522 | /* Add one entry */
|
|---|
| 1523 | attr.caption = "a";
|
|---|
| 1524 | attr.arg = (void *)1;
|
|---|
| 1525 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1526 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1527 |
|
|---|
| 1528 | /* Now try getting its predecessor */
|
|---|
| 1529 | entry = ui_list_last(list);
|
|---|
| 1530 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1531 |
|
|---|
| 1532 | entry = ui_list_prev(entry);
|
|---|
| 1533 | PCUT_ASSERT_NULL(entry);
|
|---|
| 1534 |
|
|---|
| 1535 | /* Add another entry */
|
|---|
| 1536 | attr.caption = "b";
|
|---|
| 1537 | attr.arg = (void *)2;
|
|---|
| 1538 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1539 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1540 |
|
|---|
| 1541 | /* Try getting the predecessor of the new entry */
|
|---|
| 1542 | entry = ui_list_last(list);
|
|---|
| 1543 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1544 |
|
|---|
| 1545 | entry = ui_list_prev(entry);
|
|---|
| 1546 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1547 | PCUT_ASSERT_STR_EQUALS("a", entry->caption);
|
|---|
| 1548 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)entry->arg);
|
|---|
| 1549 |
|
|---|
| 1550 | ui_list_destroy(list);
|
|---|
| 1551 | ui_window_destroy(window);
|
|---|
| 1552 | ui_destroy(ui);
|
|---|
| 1553 | }
|
|---|
| 1554 |
|
|---|
| 1555 | /** ui_list_page_nth_entry() .. */
|
|---|
| 1556 | PCUT_TEST(page_nth_entry)
|
|---|
| 1557 | {
|
|---|
| 1558 | ui_t *ui;
|
|---|
| 1559 | ui_window_t *window;
|
|---|
| 1560 | ui_wnd_params_t params;
|
|---|
| 1561 | ui_list_t *list;
|
|---|
| 1562 | ui_list_entry_t *entry;
|
|---|
| 1563 | ui_list_entry_attr_t attr;
|
|---|
| 1564 | gfx_rect_t rect;
|
|---|
| 1565 | size_t idx;
|
|---|
| 1566 | errno_t rc;
|
|---|
| 1567 |
|
|---|
| 1568 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1569 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1570 |
|
|---|
| 1571 | ui_wnd_params_init(¶ms);
|
|---|
| 1572 | params.caption = "Test";
|
|---|
| 1573 |
|
|---|
| 1574 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1575 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1576 |
|
|---|
| 1577 | rc = ui_list_create(window, true, &list);
|
|---|
| 1578 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1579 |
|
|---|
| 1580 | ui_list_entry_attr_init(&attr);
|
|---|
| 1581 |
|
|---|
| 1582 | /* Add some entries */
|
|---|
| 1583 | attr.caption = "a";
|
|---|
| 1584 | attr.arg = (void *)1;
|
|---|
| 1585 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1586 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1587 |
|
|---|
| 1588 | attr.caption = "b";
|
|---|
| 1589 | attr.arg = (void *)2;
|
|---|
| 1590 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1591 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1592 |
|
|---|
| 1593 | attr.caption = "c";
|
|---|
| 1594 | attr.arg = (void *)3;
|
|---|
| 1595 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1596 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1597 |
|
|---|
| 1598 | list->page = ui_list_next(ui_list_first(list));
|
|---|
| 1599 | list->page_idx = 1;
|
|---|
| 1600 |
|
|---|
| 1601 | rect.p0.x = 0;
|
|---|
| 1602 | rect.p0.y = 0;
|
|---|
| 1603 | rect.p1.x = 100;
|
|---|
| 1604 | rect.p1.y = 100;
|
|---|
| 1605 | ui_list_set_rect(list, &rect);
|
|---|
| 1606 |
|
|---|
| 1607 | entry = ui_list_page_nth_entry(list, 0, &idx);
|
|---|
| 1608 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1609 | PCUT_ASSERT_STR_EQUALS("b", entry->caption);
|
|---|
| 1610 | PCUT_ASSERT_INT_EQUALS(1, idx);
|
|---|
| 1611 |
|
|---|
| 1612 | entry = ui_list_page_nth_entry(list, 1, &idx);
|
|---|
| 1613 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 1614 | PCUT_ASSERT_STR_EQUALS("c", entry->caption);
|
|---|
| 1615 | PCUT_ASSERT_INT_EQUALS(2, idx);
|
|---|
| 1616 |
|
|---|
| 1617 | entry = ui_list_page_nth_entry(list, 2, &idx);
|
|---|
| 1618 | PCUT_ASSERT_NULL(entry);
|
|---|
| 1619 |
|
|---|
| 1620 | ui_list_destroy(list);
|
|---|
| 1621 | ui_window_destroy(window);
|
|---|
| 1622 | ui_destroy(ui);
|
|---|
| 1623 | }
|
|---|
| 1624 |
|
|---|
| 1625 | /** ui_list_cursor_move() moves cursor and scrolls */
|
|---|
| 1626 | PCUT_TEST(cursor_move)
|
|---|
| 1627 | {
|
|---|
| 1628 | ui_t *ui;
|
|---|
| 1629 | ui_window_t *window;
|
|---|
| 1630 | ui_wnd_params_t params;
|
|---|
| 1631 | ui_list_t *list;
|
|---|
| 1632 | ui_list_entry_attr_t attr;
|
|---|
| 1633 | gfx_rect_t rect;
|
|---|
| 1634 | errno_t rc;
|
|---|
| 1635 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1636 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1637 |
|
|---|
| 1638 | ui_wnd_params_init(¶ms);
|
|---|
| 1639 | params.caption = "Test";
|
|---|
| 1640 |
|
|---|
| 1641 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1642 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1643 |
|
|---|
| 1644 | rc = ui_list_create(window, true, &list);
|
|---|
| 1645 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1646 |
|
|---|
| 1647 | rect.p0.x = 0;
|
|---|
| 1648 | rect.p0.y = 0;
|
|---|
| 1649 | rect.p1.x = 10;
|
|---|
| 1650 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 1651 | ui_list_set_rect(list, &rect);
|
|---|
| 1652 |
|
|---|
| 1653 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 1654 |
|
|---|
| 1655 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 1656 |
|
|---|
| 1657 | ui_list_entry_attr_init(&attr);
|
|---|
| 1658 |
|
|---|
| 1659 | attr.caption = "a";
|
|---|
| 1660 | attr.arg = (void *)1;
|
|---|
| 1661 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1662 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1663 |
|
|---|
| 1664 | attr.caption = "b";
|
|---|
| 1665 | attr.arg = (void *)2;
|
|---|
| 1666 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1667 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1668 |
|
|---|
| 1669 | attr.caption = "c";
|
|---|
| 1670 | attr.arg = (void *)3;
|
|---|
| 1671 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1672 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1673 |
|
|---|
| 1674 | /* Cursor to the last entry and page start to the next-to-last entry */
|
|---|
| 1675 | list->cursor = ui_list_last(list);
|
|---|
| 1676 | list->cursor_idx = 2;
|
|---|
| 1677 | list->page = ui_list_prev(list->cursor);
|
|---|
| 1678 | list->page_idx = 1;
|
|---|
| 1679 |
|
|---|
| 1680 | /* Move cursor one entry up */
|
|---|
| 1681 | ui_list_cursor_move(list, ui_list_prev(list->cursor),
|
|---|
| 1682 | list->cursor_idx - 1);
|
|---|
| 1683 |
|
|---|
| 1684 | /* Cursor and page start should now both be at the second entry */
|
|---|
| 1685 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
|---|
| 1686 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
|---|
| 1687 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
|---|
| 1688 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 1689 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 1690 |
|
|---|
| 1691 | /* Move cursor to the first entry. This should scroll up. */
|
|---|
| 1692 | ui_list_cursor_move(list, ui_list_first(list), 0);
|
|---|
| 1693 |
|
|---|
| 1694 | /* Cursor and page start should now both be at the first entry */
|
|---|
| 1695 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 1696 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 1697 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 1698 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 1699 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 1700 |
|
|---|
| 1701 | /* Move cursor to the last entry. */
|
|---|
| 1702 | ui_list_cursor_move(list, ui_list_last(list), 2);
|
|---|
| 1703 |
|
|---|
| 1704 | /* Cursor should be on the last entry and page on the next to last */
|
|---|
| 1705 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 1706 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 1707 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 1708 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 1709 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 1710 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 1711 |
|
|---|
| 1712 | ui_list_destroy(list);
|
|---|
| 1713 | ui_window_destroy(window);
|
|---|
| 1714 | ui_destroy(ui);
|
|---|
| 1715 | }
|
|---|
| 1716 |
|
|---|
| 1717 | /** ui_list_cursor_up() moves cursor one entry up */
|
|---|
| 1718 | PCUT_TEST(cursor_up)
|
|---|
| 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_attr_t attr;
|
|---|
| 1725 | gfx_rect_t rect;
|
|---|
| 1726 | errno_t rc;
|
|---|
| 1727 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1728 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1729 |
|
|---|
| 1730 | ui_wnd_params_init(¶ms);
|
|---|
| 1731 | params.caption = "Test";
|
|---|
| 1732 |
|
|---|
| 1733 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1734 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1735 |
|
|---|
| 1736 | rc = ui_list_create(window, true, &list);
|
|---|
| 1737 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1738 |
|
|---|
| 1739 | rect.p0.x = 0;
|
|---|
| 1740 | rect.p0.y = 0;
|
|---|
| 1741 | rect.p1.x = 10;
|
|---|
| 1742 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 1743 | ui_list_set_rect(list, &rect);
|
|---|
| 1744 |
|
|---|
| 1745 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 1746 |
|
|---|
| 1747 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 1748 |
|
|---|
| 1749 | ui_list_entry_attr_init(&attr);
|
|---|
| 1750 |
|
|---|
| 1751 | attr.caption = "a";
|
|---|
| 1752 | attr.arg = (void *)1;
|
|---|
| 1753 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1754 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1755 |
|
|---|
| 1756 | attr.caption = "b";
|
|---|
| 1757 | attr.arg = (void *)2;
|
|---|
| 1758 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1759 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1760 |
|
|---|
| 1761 | attr.caption = "c";
|
|---|
| 1762 | attr.arg = (void *)3;
|
|---|
| 1763 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1764 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1765 |
|
|---|
| 1766 | /* Cursor to the last entry and page start to the next-to-last entry */
|
|---|
| 1767 | list->cursor = ui_list_last(list);
|
|---|
| 1768 | list->cursor_idx = 2;
|
|---|
| 1769 | list->page = ui_list_prev(list->cursor);
|
|---|
| 1770 | list->page_idx = 1;
|
|---|
| 1771 |
|
|---|
| 1772 | /* Move cursor one entry up */
|
|---|
| 1773 | ui_list_cursor_up(list);
|
|---|
| 1774 |
|
|---|
| 1775 | /* Cursor and page start should now both be at the second entry */
|
|---|
| 1776 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
|---|
| 1777 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
|---|
| 1778 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
|---|
| 1779 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 1780 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 1781 |
|
|---|
| 1782 | /* Move cursor one entry up. This should scroll up. */
|
|---|
| 1783 | ui_list_cursor_up(list);
|
|---|
| 1784 |
|
|---|
| 1785 | /* Cursor and page start should now both be at the first entry */
|
|---|
| 1786 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 1787 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 1788 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 1789 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 1790 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 1791 |
|
|---|
| 1792 | /* Moving further up should do nothing (we are at the top). */
|
|---|
| 1793 | ui_list_cursor_up(list);
|
|---|
| 1794 |
|
|---|
| 1795 | /* Cursor and page start should still be at the first entry */
|
|---|
| 1796 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 1797 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 1798 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 1799 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 1800 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 1801 |
|
|---|
| 1802 | ui_list_destroy(list);
|
|---|
| 1803 | ui_window_destroy(window);
|
|---|
| 1804 | ui_destroy(ui);
|
|---|
| 1805 | }
|
|---|
| 1806 |
|
|---|
| 1807 | /** ui_list_cursor_down() moves cursor one entry down */
|
|---|
| 1808 | PCUT_TEST(cursor_down)
|
|---|
| 1809 | {
|
|---|
| 1810 | ui_t *ui;
|
|---|
| 1811 | ui_window_t *window;
|
|---|
| 1812 | ui_wnd_params_t params;
|
|---|
| 1813 | ui_list_t *list;
|
|---|
| 1814 | ui_list_entry_attr_t attr;
|
|---|
| 1815 | gfx_rect_t rect;
|
|---|
| 1816 | errno_t rc;
|
|---|
| 1817 |
|
|---|
| 1818 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1819 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1820 |
|
|---|
| 1821 | ui_wnd_params_init(¶ms);
|
|---|
| 1822 | params.caption = "Test";
|
|---|
| 1823 |
|
|---|
| 1824 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1825 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1826 |
|
|---|
| 1827 | rc = ui_list_create(window, true, &list);
|
|---|
| 1828 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1829 |
|
|---|
| 1830 | rect.p0.x = 0;
|
|---|
| 1831 | rect.p0.y = 0;
|
|---|
| 1832 | rect.p1.x = 10;
|
|---|
| 1833 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 1834 | ui_list_set_rect(list, &rect);
|
|---|
| 1835 |
|
|---|
| 1836 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 1837 |
|
|---|
| 1838 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 1839 |
|
|---|
| 1840 | ui_list_entry_attr_init(&attr);
|
|---|
| 1841 |
|
|---|
| 1842 | attr.caption = "a";
|
|---|
| 1843 | attr.arg = (void *)1;
|
|---|
| 1844 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1845 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1846 |
|
|---|
| 1847 | attr.caption = "b";
|
|---|
| 1848 | attr.arg = (void *)2;
|
|---|
| 1849 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1850 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1851 |
|
|---|
| 1852 | attr.caption = "c";
|
|---|
| 1853 | attr.arg = (void *)3;
|
|---|
| 1854 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1855 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1856 |
|
|---|
| 1857 | /* Cursor and page start to the first entry */
|
|---|
| 1858 | list->cursor = ui_list_first(list);
|
|---|
| 1859 | list->cursor_idx = 0;
|
|---|
| 1860 | list->page = list->cursor;
|
|---|
| 1861 | list->page_idx = 0;
|
|---|
| 1862 |
|
|---|
| 1863 | /* Move cursor one entry down */
|
|---|
| 1864 | ui_list_cursor_down(list);
|
|---|
| 1865 |
|
|---|
| 1866 | /* Cursor should now be at the second entry, page stays the same */
|
|---|
| 1867 | PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
|
|---|
| 1868 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->cursor->arg);
|
|---|
| 1869 | PCUT_ASSERT_INT_EQUALS(1, list->cursor_idx);
|
|---|
| 1870 | PCUT_ASSERT_EQUALS(ui_list_first(list), list->page);
|
|---|
| 1871 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 1872 |
|
|---|
| 1873 | /* Move cursor one entry down. This should scroll down. */
|
|---|
| 1874 | ui_list_cursor_down(list);
|
|---|
| 1875 |
|
|---|
| 1876 | /* Cursor should now be at the third and page at the second entry. */
|
|---|
| 1877 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 1878 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 1879 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 1880 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 1881 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 1882 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 1883 |
|
|---|
| 1884 | /* Moving further down should do nothing (we are at the bottom). */
|
|---|
| 1885 | ui_list_cursor_down(list);
|
|---|
| 1886 |
|
|---|
| 1887 | /* Cursor should still be at the third and page at the second entry. */
|
|---|
| 1888 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 1889 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 1890 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 1891 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 1892 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 1893 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 1894 |
|
|---|
| 1895 | ui_list_destroy(list);
|
|---|
| 1896 | ui_window_destroy(window);
|
|---|
| 1897 | ui_destroy(ui);
|
|---|
| 1898 | }
|
|---|
| 1899 |
|
|---|
| 1900 | /** ui_list_cursor_top() moves cursor to the first entry */
|
|---|
| 1901 | PCUT_TEST(cursor_top)
|
|---|
| 1902 | {
|
|---|
| 1903 | ui_t *ui;
|
|---|
| 1904 | ui_window_t *window;
|
|---|
| 1905 | ui_wnd_params_t params;
|
|---|
| 1906 | ui_list_t *list;
|
|---|
| 1907 | ui_list_entry_attr_t attr;
|
|---|
| 1908 | gfx_rect_t rect;
|
|---|
| 1909 | errno_t rc;
|
|---|
| 1910 |
|
|---|
| 1911 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1912 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1913 |
|
|---|
| 1914 | ui_wnd_params_init(¶ms);
|
|---|
| 1915 | params.caption = "Test";
|
|---|
| 1916 |
|
|---|
| 1917 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1918 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1919 |
|
|---|
| 1920 | rc = ui_list_create(window, true, &list);
|
|---|
| 1921 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1922 |
|
|---|
| 1923 | rect.p0.x = 0;
|
|---|
| 1924 | rect.p0.y = 0;
|
|---|
| 1925 | rect.p1.x = 10;
|
|---|
| 1926 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 1927 | ui_list_set_rect(list, &rect);
|
|---|
| 1928 |
|
|---|
| 1929 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 1930 |
|
|---|
| 1931 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 1932 |
|
|---|
| 1933 | ui_list_entry_attr_init(&attr);
|
|---|
| 1934 |
|
|---|
| 1935 | attr.caption = "a";
|
|---|
| 1936 | attr.arg = (void *)1;
|
|---|
| 1937 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1938 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1939 |
|
|---|
| 1940 | attr.caption = "b";
|
|---|
| 1941 | attr.arg = (void *)2;
|
|---|
| 1942 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1943 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1944 |
|
|---|
| 1945 | attr.caption = "c";
|
|---|
| 1946 | attr.arg = (void *)3;
|
|---|
| 1947 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 1948 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1949 |
|
|---|
| 1950 | /* Cursor to the last entry and page start to the next-to-last entry */
|
|---|
| 1951 | list->cursor = ui_list_last(list);
|
|---|
| 1952 | list->cursor_idx = 2;
|
|---|
| 1953 | list->page = ui_list_prev(list->cursor);
|
|---|
| 1954 | list->page_idx = 1;
|
|---|
| 1955 |
|
|---|
| 1956 | /* Move cursor to the top. This should scroll up. */
|
|---|
| 1957 | ui_list_cursor_top(list);
|
|---|
| 1958 |
|
|---|
| 1959 | /* Cursor and page start should now both be at the first entry */
|
|---|
| 1960 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 1961 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 1962 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 1963 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 1964 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 1965 |
|
|---|
| 1966 | ui_list_destroy(list);
|
|---|
| 1967 | ui_window_destroy(window);
|
|---|
| 1968 | ui_destroy(ui);
|
|---|
| 1969 | }
|
|---|
| 1970 |
|
|---|
| 1971 | /** ui_list_cursor_bottom() moves cursor to the last entry */
|
|---|
| 1972 | PCUT_TEST(cursor_bottom)
|
|---|
| 1973 | {
|
|---|
| 1974 | ui_t *ui;
|
|---|
| 1975 | ui_window_t *window;
|
|---|
| 1976 | ui_wnd_params_t params;
|
|---|
| 1977 | ui_list_t *list;
|
|---|
| 1978 | ui_list_entry_attr_t attr;
|
|---|
| 1979 | gfx_rect_t rect;
|
|---|
| 1980 | errno_t rc;
|
|---|
| 1981 |
|
|---|
| 1982 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 1983 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1984 |
|
|---|
| 1985 | ui_wnd_params_init(¶ms);
|
|---|
| 1986 | params.caption = "Test";
|
|---|
| 1987 |
|
|---|
| 1988 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 1989 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1990 |
|
|---|
| 1991 | rc = ui_list_create(window, true, &list);
|
|---|
| 1992 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1993 |
|
|---|
| 1994 | rect.p0.x = 0;
|
|---|
| 1995 | rect.p0.y = 0;
|
|---|
| 1996 | rect.p1.x = 10;
|
|---|
| 1997 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 1998 | ui_list_set_rect(list, &rect);
|
|---|
| 1999 |
|
|---|
| 2000 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2001 |
|
|---|
| 2002 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 2003 |
|
|---|
| 2004 | ui_list_entry_attr_init(&attr);
|
|---|
| 2005 |
|
|---|
| 2006 | attr.caption = "a";
|
|---|
| 2007 | attr.arg = (void *)1;
|
|---|
| 2008 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2009 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2010 |
|
|---|
| 2011 | attr.caption = "b";
|
|---|
| 2012 | attr.arg = (void *)2;
|
|---|
| 2013 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2014 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2015 |
|
|---|
| 2016 | attr.caption = "c";
|
|---|
| 2017 | attr.arg = (void *)3;
|
|---|
| 2018 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2019 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2020 |
|
|---|
| 2021 | /* Cursor and page start to the first entry */
|
|---|
| 2022 | list->cursor = ui_list_first(list);
|
|---|
| 2023 | list->cursor_idx = 0;
|
|---|
| 2024 | list->page = list->cursor;
|
|---|
| 2025 | list->page_idx = 0;
|
|---|
| 2026 |
|
|---|
| 2027 | /* Move cursor to the bottom. This should scroll down. */
|
|---|
| 2028 | ui_list_cursor_bottom(list);
|
|---|
| 2029 |
|
|---|
| 2030 | /* Cursor should now be at the third and page at the second entry. */
|
|---|
| 2031 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 2032 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 2033 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 2034 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 2035 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 2036 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 2037 |
|
|---|
| 2038 | ui_list_destroy(list);
|
|---|
| 2039 | ui_window_destroy(window);
|
|---|
| 2040 | ui_destroy(ui);
|
|---|
| 2041 | }
|
|---|
| 2042 |
|
|---|
| 2043 | /** ui_list_page_up() moves one page up */
|
|---|
| 2044 | PCUT_TEST(page_up)
|
|---|
| 2045 | {
|
|---|
| 2046 | ui_t *ui;
|
|---|
| 2047 | ui_window_t *window;
|
|---|
| 2048 | ui_wnd_params_t params;
|
|---|
| 2049 | ui_list_t *list;
|
|---|
| 2050 | ui_list_entry_attr_t attr;
|
|---|
| 2051 | gfx_rect_t rect;
|
|---|
| 2052 | errno_t rc;
|
|---|
| 2053 |
|
|---|
| 2054 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2055 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2056 |
|
|---|
| 2057 | ui_wnd_params_init(¶ms);
|
|---|
| 2058 | params.caption = "Test";
|
|---|
| 2059 |
|
|---|
| 2060 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2061 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2062 |
|
|---|
| 2063 | rc = ui_list_create(window, true, &list);
|
|---|
| 2064 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2065 |
|
|---|
| 2066 | rect.p0.x = 0;
|
|---|
| 2067 | rect.p0.y = 0;
|
|---|
| 2068 | rect.p1.x = 10;
|
|---|
| 2069 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2070 | ui_list_set_rect(list, &rect);
|
|---|
| 2071 |
|
|---|
| 2072 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2073 |
|
|---|
| 2074 | /* Add five entries (2 full pages, one partial) */
|
|---|
| 2075 |
|
|---|
| 2076 | ui_list_entry_attr_init(&attr);
|
|---|
| 2077 |
|
|---|
| 2078 | attr.caption = "a";
|
|---|
| 2079 | attr.arg = (void *)1;
|
|---|
| 2080 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2081 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2082 |
|
|---|
| 2083 | attr.caption = "b";
|
|---|
| 2084 | attr.arg = (void *)2;
|
|---|
| 2085 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2086 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2087 |
|
|---|
| 2088 | attr.caption = "c";
|
|---|
| 2089 | attr.arg = (void *)3;
|
|---|
| 2090 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2091 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2092 |
|
|---|
| 2093 | attr.caption = "d";
|
|---|
| 2094 | attr.arg = (void *)4;
|
|---|
| 2095 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2096 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2097 |
|
|---|
| 2098 | attr.caption = "e";
|
|---|
| 2099 | attr.arg = (void *)5;
|
|---|
| 2100 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2101 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2102 |
|
|---|
| 2103 | /* Cursor to the last entry and page start to the next-to-last entry */
|
|---|
| 2104 | list->cursor = ui_list_last(list);
|
|---|
| 2105 | list->cursor_idx = 4;
|
|---|
| 2106 | list->page = ui_list_prev(list->cursor);
|
|---|
| 2107 | list->page_idx = 3;
|
|---|
| 2108 |
|
|---|
| 2109 | /* Move one page up */
|
|---|
| 2110 | ui_list_page_up(list);
|
|---|
| 2111 |
|
|---|
| 2112 | /* Page should now start at second entry and cursor at third */
|
|---|
| 2113 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 2114 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 2115 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 2116 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 2117 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 2118 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 2119 |
|
|---|
| 2120 | /* Move one page up again. */
|
|---|
| 2121 | ui_list_page_up(list);
|
|---|
| 2122 |
|
|---|
| 2123 | /* Cursor and page start should now both be at the first entry */
|
|---|
| 2124 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2125 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2126 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2127 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 2128 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 2129 |
|
|---|
| 2130 | /* Moving further up should do nothing (we are at the top). */
|
|---|
| 2131 | ui_list_page_up(list);
|
|---|
| 2132 |
|
|---|
| 2133 | /* Cursor and page start should still be at the first entry */
|
|---|
| 2134 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2135 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2136 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2137 | PCUT_ASSERT_EQUALS(list->cursor, list->page);
|
|---|
| 2138 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 2139 |
|
|---|
| 2140 | ui_list_destroy(list);
|
|---|
| 2141 | ui_window_destroy(window);
|
|---|
| 2142 | ui_destroy(ui);
|
|---|
| 2143 | }
|
|---|
| 2144 |
|
|---|
| 2145 | /** ui_list_page_up() moves one page down */
|
|---|
| 2146 | PCUT_TEST(page_down)
|
|---|
| 2147 | {
|
|---|
| 2148 | ui_t *ui;
|
|---|
| 2149 | ui_window_t *window;
|
|---|
| 2150 | ui_wnd_params_t params;
|
|---|
| 2151 | ui_list_t *list;
|
|---|
| 2152 | ui_list_entry_attr_t attr;
|
|---|
| 2153 | gfx_rect_t rect;
|
|---|
| 2154 | errno_t rc;
|
|---|
| 2155 |
|
|---|
| 2156 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2157 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2158 |
|
|---|
| 2159 | ui_wnd_params_init(¶ms);
|
|---|
| 2160 | params.caption = "Test";
|
|---|
| 2161 |
|
|---|
| 2162 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2163 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2164 |
|
|---|
| 2165 | rc = ui_list_create(window, true, &list);
|
|---|
| 2166 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2167 |
|
|---|
| 2168 | rect.p0.x = 0;
|
|---|
| 2169 | rect.p0.y = 0;
|
|---|
| 2170 | rect.p1.x = 10;
|
|---|
| 2171 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2172 | ui_list_set_rect(list, &rect);
|
|---|
| 2173 |
|
|---|
| 2174 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2175 |
|
|---|
| 2176 | /* Add five entries (2 full pages, one partial) */
|
|---|
| 2177 |
|
|---|
| 2178 | ui_list_entry_attr_init(&attr);
|
|---|
| 2179 |
|
|---|
| 2180 | attr.caption = "a";
|
|---|
| 2181 | attr.arg = (void *)1;
|
|---|
| 2182 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2183 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2184 |
|
|---|
| 2185 | attr.caption = "b";
|
|---|
| 2186 | attr.arg = (void *)2;
|
|---|
| 2187 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2188 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2189 |
|
|---|
| 2190 | attr.caption = "c";
|
|---|
| 2191 | attr.arg = (void *)3;
|
|---|
| 2192 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2193 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2194 |
|
|---|
| 2195 | attr.caption = "d";
|
|---|
| 2196 | attr.arg = (void *)4;
|
|---|
| 2197 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2198 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2199 |
|
|---|
| 2200 | attr.caption = "e";
|
|---|
| 2201 | attr.arg = (void *)5;
|
|---|
| 2202 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2203 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2204 |
|
|---|
| 2205 | /* Cursor and page to the first entry */
|
|---|
| 2206 | list->cursor = ui_list_first(list);
|
|---|
| 2207 | list->cursor_idx = 0;
|
|---|
| 2208 | list->page = list->cursor;
|
|---|
| 2209 | list->page_idx = 0;
|
|---|
| 2210 |
|
|---|
| 2211 | /* Move one page down */
|
|---|
| 2212 | ui_list_page_down(list);
|
|---|
| 2213 |
|
|---|
| 2214 | /* Page and cursor should point to the third entry */
|
|---|
| 2215 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 2216 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 2217 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 2218 | PCUT_ASSERT_STR_EQUALS("c", list->page->caption);
|
|---|
| 2219 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->page->arg);
|
|---|
| 2220 | PCUT_ASSERT_INT_EQUALS(2, list->page_idx);
|
|---|
| 2221 |
|
|---|
| 2222 | /* Move one page down again. */
|
|---|
| 2223 | ui_list_page_down(list);
|
|---|
| 2224 |
|
|---|
| 2225 | /* Cursor should point to last and page to next-to-last entry */
|
|---|
| 2226 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
|---|
| 2227 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
|---|
| 2228 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
|---|
| 2229 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
|---|
| 2230 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
|---|
| 2231 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
|---|
| 2232 |
|
|---|
| 2233 | /* Moving further down should do nothing (we are at the bottom). */
|
|---|
| 2234 | ui_list_page_down(list);
|
|---|
| 2235 |
|
|---|
| 2236 | /* Cursor should still point to last and page to next-to-last entry */
|
|---|
| 2237 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
|---|
| 2238 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
|---|
| 2239 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
|---|
| 2240 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
|---|
| 2241 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
|---|
| 2242 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
|---|
| 2243 |
|
|---|
| 2244 | ui_list_destroy(list);
|
|---|
| 2245 | ui_window_destroy(window);
|
|---|
| 2246 | ui_destroy(ui);
|
|---|
| 2247 | }
|
|---|
| 2248 |
|
|---|
| 2249 | /** ui_list_scroll_up() scrolls up by one row */
|
|---|
| 2250 | PCUT_TEST(scroll_up)
|
|---|
| 2251 | {
|
|---|
| 2252 | ui_t *ui;
|
|---|
| 2253 | ui_window_t *window;
|
|---|
| 2254 | ui_wnd_params_t params;
|
|---|
| 2255 | ui_list_t *list;
|
|---|
| 2256 | ui_list_entry_attr_t attr;
|
|---|
| 2257 | gfx_rect_t rect;
|
|---|
| 2258 | errno_t rc;
|
|---|
| 2259 |
|
|---|
| 2260 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2261 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2262 |
|
|---|
| 2263 | ui_wnd_params_init(¶ms);
|
|---|
| 2264 | params.caption = "Test";
|
|---|
| 2265 |
|
|---|
| 2266 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2267 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2268 |
|
|---|
| 2269 | rc = ui_list_create(window, true, &list);
|
|---|
| 2270 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2271 |
|
|---|
| 2272 | rect.p0.x = 0;
|
|---|
| 2273 | rect.p0.y = 0;
|
|---|
| 2274 | rect.p1.x = 10;
|
|---|
| 2275 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2276 | ui_list_set_rect(list, &rect);
|
|---|
| 2277 |
|
|---|
| 2278 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2279 |
|
|---|
| 2280 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 2281 |
|
|---|
| 2282 | ui_list_entry_attr_init(&attr);
|
|---|
| 2283 |
|
|---|
| 2284 | attr.caption = "a";
|
|---|
| 2285 | attr.arg = (void *)1;
|
|---|
| 2286 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2287 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2288 |
|
|---|
| 2289 | attr.caption = "b";
|
|---|
| 2290 | attr.arg = (void *)2;
|
|---|
| 2291 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2293 |
|
|---|
| 2294 | attr.caption = "c";
|
|---|
| 2295 | attr.arg = (void *)3;
|
|---|
| 2296 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2297 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2298 |
|
|---|
| 2299 | /* Cursor to the last entry, page to the second */
|
|---|
| 2300 | list->cursor = ui_list_last(list);
|
|---|
| 2301 | list->cursor_idx = 2;
|
|---|
| 2302 | list->page = ui_list_prev(list->cursor);
|
|---|
| 2303 | list->page_idx = 1;
|
|---|
| 2304 |
|
|---|
| 2305 | /* Scroll one entry up */
|
|---|
| 2306 | ui_list_scroll_up(list);
|
|---|
| 2307 |
|
|---|
| 2308 | /* Page should start on the first entry, cursor unchanged */
|
|---|
| 2309 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 2310 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 2311 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 2312 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
|---|
| 2313 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
|---|
| 2314 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 2315 |
|
|---|
| 2316 | /* Try scrolling one more entry up */
|
|---|
| 2317 | ui_list_scroll_up(list);
|
|---|
| 2318 |
|
|---|
| 2319 | /* We were at the beginning, so nothing should have changed */
|
|---|
| 2320 | PCUT_ASSERT_STR_EQUALS("c", list->cursor->caption);
|
|---|
| 2321 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->cursor->arg);
|
|---|
| 2322 | PCUT_ASSERT_INT_EQUALS(2, list->cursor_idx);
|
|---|
| 2323 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
|---|
| 2324 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
|---|
| 2325 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 2326 |
|
|---|
| 2327 | ui_list_destroy(list);
|
|---|
| 2328 | ui_window_destroy(window);
|
|---|
| 2329 | ui_destroy(ui);
|
|---|
| 2330 | }
|
|---|
| 2331 |
|
|---|
| 2332 | /** ui_list_scroll_down() scrolls down by one row */
|
|---|
| 2333 | PCUT_TEST(scroll_down)
|
|---|
| 2334 | {
|
|---|
| 2335 | ui_t *ui;
|
|---|
| 2336 | ui_window_t *window;
|
|---|
| 2337 | ui_wnd_params_t params;
|
|---|
| 2338 | ui_list_t *list;
|
|---|
| 2339 | ui_list_entry_attr_t attr;
|
|---|
| 2340 | gfx_rect_t rect;
|
|---|
| 2341 | errno_t rc;
|
|---|
| 2342 |
|
|---|
| 2343 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2344 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2345 |
|
|---|
| 2346 | ui_wnd_params_init(¶ms);
|
|---|
| 2347 | params.caption = "Test";
|
|---|
| 2348 |
|
|---|
| 2349 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2350 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2351 |
|
|---|
| 2352 | rc = ui_list_create(window, true, &list);
|
|---|
| 2353 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2354 |
|
|---|
| 2355 | rect.p0.x = 0;
|
|---|
| 2356 | rect.p0.y = 0;
|
|---|
| 2357 | rect.p1.x = 10;
|
|---|
| 2358 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2359 | ui_list_set_rect(list, &rect);
|
|---|
| 2360 |
|
|---|
| 2361 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2362 |
|
|---|
| 2363 | /* Add tree entries (more than page size, which is 2) */
|
|---|
| 2364 |
|
|---|
| 2365 | ui_list_entry_attr_init(&attr);
|
|---|
| 2366 |
|
|---|
| 2367 | attr.caption = "a";
|
|---|
| 2368 | attr.arg = (void *)1;
|
|---|
| 2369 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2370 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2371 |
|
|---|
| 2372 | attr.caption = "b";
|
|---|
| 2373 | attr.arg = (void *)2;
|
|---|
| 2374 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2375 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2376 |
|
|---|
| 2377 | attr.caption = "c";
|
|---|
| 2378 | attr.arg = (void *)3;
|
|---|
| 2379 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2380 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2381 |
|
|---|
| 2382 | /* Cursor and page start to the first entry */
|
|---|
| 2383 | list->cursor = ui_list_first(list);
|
|---|
| 2384 | list->cursor_idx = 0;
|
|---|
| 2385 | list->page = list->cursor;
|
|---|
| 2386 | list->page_idx = 0;
|
|---|
| 2387 |
|
|---|
| 2388 | /* Scroll one entry down */
|
|---|
| 2389 | ui_list_scroll_down(list);
|
|---|
| 2390 |
|
|---|
| 2391 | /* Page should start on the second entry, cursor unchanged */
|
|---|
| 2392 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2393 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2394 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2395 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 2396 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 2397 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 2398 |
|
|---|
| 2399 | /* Try scrolling one more entry down */
|
|---|
| 2400 | ui_list_scroll_down(list);
|
|---|
| 2401 |
|
|---|
| 2402 | /* We were at the end, so nothing should have changed */
|
|---|
| 2403 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2404 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2405 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2406 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 2407 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 2408 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 2409 |
|
|---|
| 2410 | ui_list_destroy(list);
|
|---|
| 2411 | ui_window_destroy(window);
|
|---|
| 2412 | ui_destroy(ui);
|
|---|
| 2413 | }
|
|---|
| 2414 |
|
|---|
| 2415 | /** ui_list_scroll_page_up() scrolls up by one page */
|
|---|
| 2416 | PCUT_TEST(scroll_page_up)
|
|---|
| 2417 | {
|
|---|
| 2418 | ui_t *ui;
|
|---|
| 2419 | ui_window_t *window;
|
|---|
| 2420 | ui_wnd_params_t params;
|
|---|
| 2421 | ui_list_t *list;
|
|---|
| 2422 | ui_list_entry_attr_t attr;
|
|---|
| 2423 | gfx_rect_t rect;
|
|---|
| 2424 | errno_t rc;
|
|---|
| 2425 |
|
|---|
| 2426 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2427 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2428 |
|
|---|
| 2429 | ui_wnd_params_init(¶ms);
|
|---|
| 2430 | params.caption = "Test";
|
|---|
| 2431 |
|
|---|
| 2432 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2433 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2434 |
|
|---|
| 2435 | rc = ui_list_create(window, true, &list);
|
|---|
| 2436 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2437 |
|
|---|
| 2438 | rect.p0.x = 0;
|
|---|
| 2439 | rect.p0.y = 0;
|
|---|
| 2440 | rect.p1.x = 10;
|
|---|
| 2441 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2442 | ui_list_set_rect(list, &rect);
|
|---|
| 2443 |
|
|---|
| 2444 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2445 |
|
|---|
| 2446 | /* Add five entries (more than twice the page size, which is 2) */
|
|---|
| 2447 |
|
|---|
| 2448 | ui_list_entry_attr_init(&attr);
|
|---|
| 2449 |
|
|---|
| 2450 | attr.caption = "a";
|
|---|
| 2451 | attr.arg = (void *)1;
|
|---|
| 2452 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2453 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2454 |
|
|---|
| 2455 | attr.caption = "b";
|
|---|
| 2456 | attr.arg = (void *)2;
|
|---|
| 2457 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2458 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2459 |
|
|---|
| 2460 | attr.caption = "c";
|
|---|
| 2461 | attr.arg = (void *)3;
|
|---|
| 2462 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2463 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2464 |
|
|---|
| 2465 | attr.caption = "d";
|
|---|
| 2466 | attr.arg = (void *)4;
|
|---|
| 2467 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2468 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2469 |
|
|---|
| 2470 | attr.caption = "e";
|
|---|
| 2471 | attr.arg = (void *)5;
|
|---|
| 2472 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2473 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2474 |
|
|---|
| 2475 | /* Cursor to the last entry, page to the second last */
|
|---|
| 2476 | list->cursor = ui_list_last(list);
|
|---|
| 2477 | list->cursor_idx = 4;
|
|---|
| 2478 | list->page = ui_list_prev(list->cursor);
|
|---|
| 2479 | list->page_idx = 3;
|
|---|
| 2480 |
|
|---|
| 2481 | /* Scroll one page up */
|
|---|
| 2482 | ui_list_scroll_page_up(list);
|
|---|
| 2483 |
|
|---|
| 2484 | /* Page should start on 'b', cursor unchanged */
|
|---|
| 2485 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
|---|
| 2486 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
|---|
| 2487 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
|---|
| 2488 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 2489 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 2490 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 2491 |
|
|---|
| 2492 | /* Page up again */
|
|---|
| 2493 | ui_list_scroll_page_up(list);
|
|---|
| 2494 |
|
|---|
| 2495 | /* Page should now be at the beginning, cursor unchanged */
|
|---|
| 2496 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
|---|
| 2497 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
|---|
| 2498 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
|---|
| 2499 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
|---|
| 2500 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
|---|
| 2501 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 2502 |
|
|---|
| 2503 | /* Page up again */
|
|---|
| 2504 | ui_list_scroll_page_up(list);
|
|---|
| 2505 |
|
|---|
| 2506 | /* We were at the beginning, nothing should have changed */
|
|---|
| 2507 | PCUT_ASSERT_STR_EQUALS("e", list->cursor->caption);
|
|---|
| 2508 | PCUT_ASSERT_INT_EQUALS(5, (intptr_t)list->cursor->arg);
|
|---|
| 2509 | PCUT_ASSERT_INT_EQUALS(4, list->cursor_idx);
|
|---|
| 2510 | PCUT_ASSERT_STR_EQUALS("a", list->page->caption);
|
|---|
| 2511 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->page->arg);
|
|---|
| 2512 | PCUT_ASSERT_INT_EQUALS(0, list->page_idx);
|
|---|
| 2513 |
|
|---|
| 2514 | ui_list_destroy(list);
|
|---|
| 2515 | ui_window_destroy(window);
|
|---|
| 2516 | ui_destroy(ui);
|
|---|
| 2517 | }
|
|---|
| 2518 |
|
|---|
| 2519 | /** ui_list_scroll_page_up() scrolls down by one page */
|
|---|
| 2520 | PCUT_TEST(scroll_page_down)
|
|---|
| 2521 | {
|
|---|
| 2522 | ui_t *ui;
|
|---|
| 2523 | ui_window_t *window;
|
|---|
| 2524 | ui_wnd_params_t params;
|
|---|
| 2525 | ui_list_t *list;
|
|---|
| 2526 | ui_list_entry_attr_t attr;
|
|---|
| 2527 | gfx_rect_t rect;
|
|---|
| 2528 | errno_t rc;
|
|---|
| 2529 |
|
|---|
| 2530 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2531 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2532 |
|
|---|
| 2533 | ui_wnd_params_init(¶ms);
|
|---|
| 2534 | params.caption = "Test";
|
|---|
| 2535 |
|
|---|
| 2536 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2537 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2538 |
|
|---|
| 2539 | rc = ui_list_create(window, true, &list);
|
|---|
| 2540 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2541 |
|
|---|
| 2542 | rect.p0.x = 0;
|
|---|
| 2543 | rect.p0.y = 0;
|
|---|
| 2544 | rect.p1.x = 10;
|
|---|
| 2545 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2546 | ui_list_set_rect(list, &rect);
|
|---|
| 2547 |
|
|---|
| 2548 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2549 |
|
|---|
| 2550 | /* Add five entries (more than twice the page size, which is 2) */
|
|---|
| 2551 |
|
|---|
| 2552 | ui_list_entry_attr_init(&attr);
|
|---|
| 2553 |
|
|---|
| 2554 | attr.caption = "a";
|
|---|
| 2555 | attr.arg = (void *)1;
|
|---|
| 2556 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2557 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2558 |
|
|---|
| 2559 | attr.caption = "b";
|
|---|
| 2560 | attr.arg = (void *)2;
|
|---|
| 2561 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2562 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2563 |
|
|---|
| 2564 | attr.caption = "c";
|
|---|
| 2565 | attr.arg = (void *)3;
|
|---|
| 2566 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2567 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2568 |
|
|---|
| 2569 | attr.caption = "d";
|
|---|
| 2570 | attr.arg = (void *)4;
|
|---|
| 2571 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2573 |
|
|---|
| 2574 | attr.caption = "e";
|
|---|
| 2575 | attr.arg = (void *)5;
|
|---|
| 2576 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2577 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2578 |
|
|---|
| 2579 | /* Cursor and page to the first entry */
|
|---|
| 2580 | list->cursor = ui_list_first(list);
|
|---|
| 2581 | list->cursor_idx = 0;
|
|---|
| 2582 | list->page = ui_list_first(list);
|
|---|
| 2583 | list->page_idx = 0;
|
|---|
| 2584 |
|
|---|
| 2585 | /* Scroll one page down */
|
|---|
| 2586 | ui_list_scroll_page_down(list);
|
|---|
| 2587 |
|
|---|
| 2588 | /* Page should start on 'c', cursor unchanged */
|
|---|
| 2589 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2590 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2591 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2592 | PCUT_ASSERT_STR_EQUALS("c", list->page->caption);
|
|---|
| 2593 | PCUT_ASSERT_INT_EQUALS(3, (intptr_t)list->page->arg);
|
|---|
| 2594 | PCUT_ASSERT_INT_EQUALS(2, list->page_idx);
|
|---|
| 2595 |
|
|---|
| 2596 | /* Page down again */
|
|---|
| 2597 | ui_list_scroll_page_down(list);
|
|---|
| 2598 |
|
|---|
| 2599 | /* Page should now start at 'd', cursor unchanged */
|
|---|
| 2600 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2601 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2602 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2603 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
|---|
| 2604 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
|---|
| 2605 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
|---|
| 2606 |
|
|---|
| 2607 | /* Page down again */
|
|---|
| 2608 | ui_list_scroll_page_down(list);
|
|---|
| 2609 |
|
|---|
| 2610 | /* We were at the end, nothing should have changed */
|
|---|
| 2611 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2612 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2613 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2614 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
|---|
| 2615 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
|---|
| 2616 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
|---|
| 2617 |
|
|---|
| 2618 | ui_list_destroy(list);
|
|---|
| 2619 | ui_window_destroy(window);
|
|---|
| 2620 | ui_destroy(ui);
|
|---|
| 2621 | }
|
|---|
| 2622 |
|
|---|
| 2623 | /** ui_list_scroll_pos() scrolls to a particular entry */
|
|---|
| 2624 | PCUT_TEST(scroll_pos)
|
|---|
| 2625 | {
|
|---|
| 2626 | ui_t *ui;
|
|---|
| 2627 | ui_window_t *window;
|
|---|
| 2628 | ui_wnd_params_t params;
|
|---|
| 2629 | ui_list_t *list;
|
|---|
| 2630 | ui_list_entry_attr_t attr;
|
|---|
| 2631 | gfx_rect_t rect;
|
|---|
| 2632 | errno_t rc;
|
|---|
| 2633 |
|
|---|
| 2634 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2635 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2636 |
|
|---|
| 2637 | ui_wnd_params_init(¶ms);
|
|---|
| 2638 | params.caption = "Test";
|
|---|
| 2639 |
|
|---|
| 2640 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2641 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2642 |
|
|---|
| 2643 | rc = ui_list_create(window, true, &list);
|
|---|
| 2644 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2645 |
|
|---|
| 2646 | rect.p0.x = 0;
|
|---|
| 2647 | rect.p0.y = 0;
|
|---|
| 2648 | rect.p1.x = 10;
|
|---|
| 2649 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
|---|
| 2650 | ui_list_set_rect(list, &rect);
|
|---|
| 2651 |
|
|---|
| 2652 | PCUT_ASSERT_INT_EQUALS(2, ui_list_page_size(list));
|
|---|
| 2653 |
|
|---|
| 2654 | /* Add five entries (more than twice the page size, which is 2) */
|
|---|
| 2655 |
|
|---|
| 2656 | ui_list_entry_attr_init(&attr);
|
|---|
| 2657 |
|
|---|
| 2658 | attr.caption = "a";
|
|---|
| 2659 | attr.arg = (void *)1;
|
|---|
| 2660 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2661 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2662 |
|
|---|
| 2663 | attr.caption = "b";
|
|---|
| 2664 | attr.arg = (void *)2;
|
|---|
| 2665 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2666 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2667 |
|
|---|
| 2668 | attr.caption = "c";
|
|---|
| 2669 | attr.arg = (void *)3;
|
|---|
| 2670 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2671 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2672 |
|
|---|
| 2673 | attr.caption = "d";
|
|---|
| 2674 | attr.arg = (void *)4;
|
|---|
| 2675 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2676 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2677 |
|
|---|
| 2678 | attr.caption = "e";
|
|---|
| 2679 | attr.arg = (void *)5;
|
|---|
| 2680 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2681 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2682 |
|
|---|
| 2683 | /* Cursor and page to the first entry */
|
|---|
| 2684 | list->cursor = ui_list_first(list);
|
|---|
| 2685 | list->cursor_idx = 0;
|
|---|
| 2686 | list->page = ui_list_first(list);
|
|---|
| 2687 | list->page_idx = 0;
|
|---|
| 2688 |
|
|---|
| 2689 | /* Scroll to entry 1 (one down) */
|
|---|
| 2690 | ui_list_scroll_pos(list, 1);
|
|---|
| 2691 |
|
|---|
| 2692 | /* Page should start on 'b', cursor unchanged */
|
|---|
| 2693 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2694 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2695 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2696 | PCUT_ASSERT_STR_EQUALS("b", list->page->caption);
|
|---|
| 2697 | PCUT_ASSERT_INT_EQUALS(2, (intptr_t)list->page->arg);
|
|---|
| 2698 | PCUT_ASSERT_INT_EQUALS(1, list->page_idx);
|
|---|
| 2699 |
|
|---|
| 2700 | /* Scroll to entry 3 (i.e. the end) */
|
|---|
| 2701 | ui_list_scroll_pos(list, 3);
|
|---|
| 2702 |
|
|---|
| 2703 | /* Page should now start at 'd', cursor unchanged */
|
|---|
| 2704 | PCUT_ASSERT_STR_EQUALS("a", list->cursor->caption);
|
|---|
| 2705 | PCUT_ASSERT_INT_EQUALS(1, (intptr_t)list->cursor->arg);
|
|---|
| 2706 | PCUT_ASSERT_INT_EQUALS(0, list->cursor_idx);
|
|---|
| 2707 | PCUT_ASSERT_STR_EQUALS("d", list->page->caption);
|
|---|
| 2708 | PCUT_ASSERT_INT_EQUALS(4, (intptr_t)list->page->arg);
|
|---|
| 2709 | PCUT_ASSERT_INT_EQUALS(3, list->page_idx);
|
|---|
| 2710 |
|
|---|
| 2711 | ui_list_destroy(list);
|
|---|
| 2712 | ui_window_destroy(window);
|
|---|
| 2713 | ui_destroy(ui);
|
|---|
| 2714 | }
|
|---|
| 2715 |
|
|---|
| 2716 | /** ui_list_activate_req() sends activation request */
|
|---|
| 2717 | PCUT_TEST(activate_req)
|
|---|
| 2718 | {
|
|---|
| 2719 | ui_t *ui;
|
|---|
| 2720 | ui_window_t *window;
|
|---|
| 2721 | ui_wnd_params_t params;
|
|---|
| 2722 | ui_list_t *list;
|
|---|
| 2723 | errno_t rc;
|
|---|
| 2724 | test_resp_t resp;
|
|---|
| 2725 |
|
|---|
| 2726 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2727 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2728 |
|
|---|
| 2729 | ui_wnd_params_init(¶ms);
|
|---|
| 2730 | params.caption = "Test";
|
|---|
| 2731 |
|
|---|
| 2732 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2733 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2734 |
|
|---|
| 2735 | rc = ui_list_create(window, true, &list);
|
|---|
| 2736 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2737 |
|
|---|
| 2738 | ui_list_set_cb(list, &test_cb, &resp);
|
|---|
| 2739 |
|
|---|
| 2740 | resp.activate_req = false;
|
|---|
| 2741 | resp.activate_req_list = NULL;
|
|---|
| 2742 |
|
|---|
| 2743 | ui_list_activate_req(list);
|
|---|
| 2744 | PCUT_ASSERT_TRUE(resp.activate_req);
|
|---|
| 2745 | PCUT_ASSERT_EQUALS(list, resp.activate_req_list);
|
|---|
| 2746 |
|
|---|
| 2747 | ui_list_destroy(list);
|
|---|
| 2748 | ui_window_destroy(window);
|
|---|
| 2749 | ui_destroy(ui);
|
|---|
| 2750 | }
|
|---|
| 2751 |
|
|---|
| 2752 | /** ui_list_selected() runs selected callback */
|
|---|
| 2753 | PCUT_TEST(selected)
|
|---|
| 2754 | {
|
|---|
| 2755 | ui_t *ui;
|
|---|
| 2756 | ui_window_t *window;
|
|---|
| 2757 | ui_wnd_params_t params;
|
|---|
| 2758 | ui_list_t *list;
|
|---|
| 2759 | ui_list_entry_attr_t attr;
|
|---|
| 2760 | ui_list_entry_t *entry;
|
|---|
| 2761 | errno_t rc;
|
|---|
| 2762 | test_resp_t resp;
|
|---|
| 2763 |
|
|---|
| 2764 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2765 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2766 |
|
|---|
| 2767 | ui_wnd_params_init(¶ms);
|
|---|
| 2768 | params.caption = "Test";
|
|---|
| 2769 |
|
|---|
| 2770 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2771 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2772 |
|
|---|
| 2773 | rc = ui_list_create(window, true, &list);
|
|---|
| 2774 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2775 |
|
|---|
| 2776 | ui_list_set_cb(list, &test_cb, &resp);
|
|---|
| 2777 |
|
|---|
| 2778 | ui_list_entry_attr_init(&attr);
|
|---|
| 2779 | attr.caption = "Hello";
|
|---|
| 2780 | attr.arg = &resp;
|
|---|
| 2781 |
|
|---|
| 2782 | rc = ui_list_entry_append(list, &attr, &entry);
|
|---|
| 2783 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2784 |
|
|---|
| 2785 | resp.selected = false;
|
|---|
| 2786 | resp.selected_entry = NULL;
|
|---|
| 2787 |
|
|---|
| 2788 | ui_list_selected(entry);
|
|---|
| 2789 | PCUT_ASSERT_TRUE(resp.selected);
|
|---|
| 2790 | PCUT_ASSERT_EQUALS(entry, resp.selected_entry);
|
|---|
| 2791 |
|
|---|
| 2792 | ui_list_destroy(list);
|
|---|
| 2793 | ui_window_destroy(window);
|
|---|
| 2794 | ui_destroy(ui);
|
|---|
| 2795 | }
|
|---|
| 2796 |
|
|---|
| 2797 | /** ui_list_entry_ptr_cmp compares two indirectly referenced entries */
|
|---|
| 2798 | PCUT_TEST(entry_ptr_cmp)
|
|---|
| 2799 | {
|
|---|
| 2800 | ui_t *ui;
|
|---|
| 2801 | ui_window_t *window;
|
|---|
| 2802 | ui_wnd_params_t params;
|
|---|
| 2803 | ui_list_t *list;
|
|---|
| 2804 | ui_list_entry_t *a, *b;
|
|---|
| 2805 | ui_list_entry_attr_t attr;
|
|---|
| 2806 | test_resp_t resp;
|
|---|
| 2807 | int rel;
|
|---|
| 2808 | errno_t rc;
|
|---|
| 2809 |
|
|---|
| 2810 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2811 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2812 |
|
|---|
| 2813 | ui_wnd_params_init(¶ms);
|
|---|
| 2814 | params.caption = "Test";
|
|---|
| 2815 |
|
|---|
| 2816 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2817 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2818 |
|
|---|
| 2819 | rc = ui_list_create(window, true, &list);
|
|---|
| 2820 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2821 |
|
|---|
| 2822 | ui_list_set_cb(list, &test_cb, &resp);
|
|---|
| 2823 |
|
|---|
| 2824 | ui_list_entry_attr_init(&attr);
|
|---|
| 2825 |
|
|---|
| 2826 | attr.caption = "a";
|
|---|
| 2827 | attr.arg = (void *)2;
|
|---|
| 2828 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2829 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2830 |
|
|---|
| 2831 | attr.caption = "b";
|
|---|
| 2832 | attr.arg = (void *)1;
|
|---|
| 2833 | rc = ui_list_entry_append(list, &attr, NULL);
|
|---|
| 2834 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2835 |
|
|---|
| 2836 | a = ui_list_first(list);
|
|---|
| 2837 | PCUT_ASSERT_NOT_NULL(a);
|
|---|
| 2838 | b = ui_list_next(a);
|
|---|
| 2839 | PCUT_ASSERT_NOT_NULL(b);
|
|---|
| 2840 |
|
|---|
| 2841 | /* a < b */
|
|---|
| 2842 | rel = ui_list_entry_ptr_cmp(&a, &b);
|
|---|
| 2843 | PCUT_ASSERT_TRUE(rel < 0);
|
|---|
| 2844 |
|
|---|
| 2845 | /* b > a */
|
|---|
| 2846 | rel = ui_list_entry_ptr_cmp(&b, &a);
|
|---|
| 2847 | PCUT_ASSERT_TRUE(rel > 0);
|
|---|
| 2848 |
|
|---|
| 2849 | /* a == a */
|
|---|
| 2850 | rel = ui_list_entry_ptr_cmp(&a, &a);
|
|---|
| 2851 | PCUT_ASSERT_INT_EQUALS(0, rel);
|
|---|
| 2852 |
|
|---|
| 2853 | ui_list_destroy(list);
|
|---|
| 2854 | ui_window_destroy(window);
|
|---|
| 2855 | ui_destroy(ui);
|
|---|
| 2856 | }
|
|---|
| 2857 |
|
|---|
| 2858 | /** ui_list_entry_get_idx() returns entry index */
|
|---|
| 2859 | PCUT_TEST(entry_get_idx)
|
|---|
| 2860 | {
|
|---|
| 2861 | ui_t *ui;
|
|---|
| 2862 | ui_window_t *window;
|
|---|
| 2863 | ui_wnd_params_t params;
|
|---|
| 2864 | ui_list_t *list;
|
|---|
| 2865 | ui_list_entry_t *a, *b;
|
|---|
| 2866 | ui_list_entry_attr_t attr;
|
|---|
| 2867 | test_resp_t resp;
|
|---|
| 2868 | errno_t rc;
|
|---|
| 2869 |
|
|---|
| 2870 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 2871 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2872 |
|
|---|
| 2873 | ui_wnd_params_init(¶ms);
|
|---|
| 2874 | params.caption = "Test";
|
|---|
| 2875 |
|
|---|
| 2876 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 2877 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2878 |
|
|---|
| 2879 | rc = ui_list_create(window, true, &list);
|
|---|
| 2880 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2881 |
|
|---|
| 2882 | ui_list_set_cb(list, &test_cb, &resp);
|
|---|
| 2883 |
|
|---|
| 2884 | ui_list_entry_attr_init(&attr);
|
|---|
| 2885 |
|
|---|
| 2886 | attr.caption = "a";
|
|---|
| 2887 | attr.arg = (void *)2;
|
|---|
| 2888 | rc = ui_list_entry_append(list, &attr, &a);
|
|---|
| 2889 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2890 |
|
|---|
| 2891 | attr.caption = "b";
|
|---|
| 2892 | attr.arg = (void *)1;
|
|---|
| 2893 | rc = ui_list_entry_append(list, &attr, &b);
|
|---|
| 2894 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 2895 |
|
|---|
| 2896 | PCUT_ASSERT_INT_EQUALS(0, ui_list_entry_get_idx(a));
|
|---|
| 2897 | PCUT_ASSERT_INT_EQUALS(1, ui_list_entry_get_idx(b));
|
|---|
| 2898 |
|
|---|
| 2899 | ui_list_destroy(list);
|
|---|
| 2900 | ui_window_destroy(window);
|
|---|
| 2901 | ui_destroy(ui);
|
|---|
| 2902 | }
|
|---|
| 2903 |
|
|---|
| 2904 | static void test_list_activate_req(ui_list_t *list, void *arg)
|
|---|
| 2905 | {
|
|---|
| 2906 | test_resp_t *resp = (test_resp_t *)arg;
|
|---|
| 2907 |
|
|---|
| 2908 | resp->activate_req = true;
|
|---|
| 2909 | resp->activate_req_list = list;
|
|---|
| 2910 | }
|
|---|
| 2911 |
|
|---|
| 2912 | static void test_list_selected(ui_list_entry_t *entry, void *arg)
|
|---|
| 2913 | {
|
|---|
| 2914 | test_resp_t *resp = (test_resp_t *)arg;
|
|---|
| 2915 |
|
|---|
| 2916 | resp->selected = true;
|
|---|
| 2917 | resp->selected_entry = entry;
|
|---|
| 2918 | }
|
|---|
| 2919 |
|
|---|
| 2920 | static int test_list_compare(ui_list_entry_t *a, ui_list_entry_t *b)
|
|---|
| 2921 | {
|
|---|
| 2922 | return str_cmp(a->caption, b->caption);
|
|---|
| 2923 | }
|
|---|
| 2924 |
|
|---|
| 2925 | PCUT_EXPORT(list);
|
|---|