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