[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>
|
---|
| 36 | #include <vfs/vfs.h>
|
---|
| 37 | #include "../private/filelist.h"
|
---|
| 38 |
|
---|
| 39 | PCUT_INIT;
|
---|
| 40 |
|
---|
| 41 | PCUT_TEST_SUITE(file_list);
|
---|
| 42 |
|
---|
| 43 | /** Test response */
|
---|
| 44 | typedef struct {
|
---|
| 45 | bool activate_req;
|
---|
| 46 | ui_file_list_t *activate_req_file_list;
|
---|
| 47 |
|
---|
| 48 | bool selected;
|
---|
| 49 | ui_file_list_t *selected_file_list;
|
---|
| 50 | const char *selected_fname;
|
---|
| 51 | } test_resp_t;
|
---|
| 52 |
|
---|
| 53 | static void test_file_list_activate_req(ui_file_list_t *, void *);
|
---|
| 54 | static void test_file_list_selected(ui_file_list_t *, void *, const char *);
|
---|
| 55 |
|
---|
| 56 | static ui_file_list_cb_t test_cb = {
|
---|
| 57 | .activate_req = test_file_list_activate_req,
|
---|
| 58 | .selected = test_file_list_selected
|
---|
| 59 | };
|
---|
| 60 |
|
---|
| 61 | /** Create and destroy file list. */
|
---|
| 62 | PCUT_TEST(create_destroy)
|
---|
| 63 | {
|
---|
| 64 | ui_file_list_t *flist;
|
---|
| 65 | errno_t rc;
|
---|
| 66 |
|
---|
| 67 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 68 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 69 |
|
---|
| 70 | ui_file_list_destroy(flist);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /** ui_file_list_set_cb() sets callback */
|
---|
| 74 | PCUT_TEST(set_cb)
|
---|
| 75 | {
|
---|
| 76 | ui_file_list_t *flist;
|
---|
| 77 | errno_t rc;
|
---|
| 78 | test_resp_t resp;
|
---|
| 79 |
|
---|
| 80 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 81 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 82 |
|
---|
| 83 | ui_file_list_set_cb(flist, &test_cb, &resp);
|
---|
| 84 | PCUT_ASSERT_EQUALS(&test_cb, flist->cb);
|
---|
| 85 | PCUT_ASSERT_EQUALS(&resp, flist->cb_arg);
|
---|
| 86 |
|
---|
| 87 | ui_file_list_destroy(flist);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /** ui_file_list_entry_height() gives the correct height */
|
---|
| 91 | PCUT_TEST(entry_height)
|
---|
| 92 | {
|
---|
| 93 | // XXX
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /** Test ui_file_list_entry_paint() */
|
---|
| 97 | PCUT_TEST(entry_paint)
|
---|
| 98 | {
|
---|
| 99 | ui_t *ui;
|
---|
| 100 | ui_window_t *window;
|
---|
| 101 | ui_wnd_params_t params;
|
---|
| 102 | ui_file_list_t *flist;
|
---|
| 103 | ui_file_list_entry_attr_t attr;
|
---|
| 104 | errno_t rc;
|
---|
| 105 |
|
---|
| 106 | rc = ui_create_disp(NULL, &ui);
|
---|
| 107 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 108 |
|
---|
| 109 | ui_wnd_params_init(¶ms);
|
---|
| 110 | params.caption = "Test";
|
---|
| 111 |
|
---|
| 112 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 113 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 114 |
|
---|
| 115 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 116 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 117 |
|
---|
| 118 | ui_file_list_entry_attr_init(&attr);
|
---|
| 119 | attr.name = "a";
|
---|
| 120 | attr.size = 1;
|
---|
| 121 |
|
---|
| 122 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 123 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 124 |
|
---|
| 125 | rc = ui_file_list_entry_paint(ui_file_list_first(flist), 0);
|
---|
| 126 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 127 |
|
---|
| 128 | ui_file_list_destroy(flist);
|
---|
| 129 | ui_window_destroy(window);
|
---|
| 130 | ui_destroy(ui);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | /** Test ui_file_list_paint() */
|
---|
| 134 | PCUT_TEST(paint)
|
---|
| 135 | {
|
---|
| 136 | ui_t *ui;
|
---|
| 137 | ui_window_t *window;
|
---|
| 138 | ui_wnd_params_t params;
|
---|
| 139 | ui_file_list_t *flist;
|
---|
| 140 | errno_t rc;
|
---|
| 141 |
|
---|
| 142 | rc = ui_create_disp(NULL, &ui);
|
---|
| 143 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 144 |
|
---|
| 145 | ui_wnd_params_init(¶ms);
|
---|
| 146 | params.caption = "Test";
|
---|
| 147 |
|
---|
| 148 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 150 |
|
---|
| 151 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 153 |
|
---|
| 154 | rc = ui_file_list_paint(flist);
|
---|
| 155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 156 |
|
---|
| 157 | ui_file_list_destroy(flist);
|
---|
| 158 | ui_window_destroy(window);
|
---|
| 159 | ui_destroy(ui);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | /** ui_file_list_ctl() returns a valid UI control */
|
---|
| 163 | PCUT_TEST(ctl)
|
---|
| 164 | {
|
---|
| 165 | ui_file_list_t *flist;
|
---|
| 166 | ui_control_t *control;
|
---|
| 167 | errno_t rc;
|
---|
| 168 |
|
---|
| 169 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 170 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 171 |
|
---|
| 172 | control = ui_file_list_ctl(flist);
|
---|
| 173 | PCUT_ASSERT_NOT_NULL(control);
|
---|
| 174 |
|
---|
| 175 | ui_file_list_destroy(flist);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /** Test ui_file_list_kbd_event() */
|
---|
| 179 | PCUT_TEST(kbd_event)
|
---|
| 180 | {
|
---|
| 181 | ui_file_list_t *flist;
|
---|
| 182 | ui_evclaim_t claimed;
|
---|
| 183 | kbd_event_t event;
|
---|
| 184 | errno_t rc;
|
---|
| 185 |
|
---|
| 186 | /* Active file list should claim events */
|
---|
| 187 |
|
---|
| 188 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 189 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 190 |
|
---|
| 191 | event.type = KEY_PRESS;
|
---|
| 192 | event.key = KC_ESCAPE;
|
---|
| 193 | event.mods = 0;
|
---|
| 194 | event.c = '\0';
|
---|
| 195 |
|
---|
| 196 | claimed = ui_file_list_kbd_event(flist, &event);
|
---|
| 197 | PCUT_ASSERT_EQUALS(ui_claimed, claimed);
|
---|
| 198 |
|
---|
| 199 | ui_file_list_destroy(flist);
|
---|
| 200 |
|
---|
| 201 | /* Inactive file list should not claim events */
|
---|
| 202 |
|
---|
| 203 | rc = ui_file_list_create(NULL, false, &flist);
|
---|
| 204 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 205 |
|
---|
| 206 | event.type = KEY_PRESS;
|
---|
| 207 | event.key = KC_ESCAPE;
|
---|
| 208 | event.mods = 0;
|
---|
| 209 | event.c = '\0';
|
---|
| 210 |
|
---|
| 211 | claimed = ui_file_list_kbd_event(flist, &event);
|
---|
| 212 | PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
|
---|
| 213 |
|
---|
| 214 | ui_file_list_destroy(flist);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | /** Test ui_file_list_pos_event() */
|
---|
| 218 | PCUT_TEST(pos_event)
|
---|
| 219 | {
|
---|
| 220 | ui_t *ui;
|
---|
| 221 | ui_window_t *window;
|
---|
| 222 | ui_wnd_params_t params;
|
---|
| 223 | ui_file_list_t *flist;
|
---|
| 224 | ui_evclaim_t claimed;
|
---|
| 225 | pos_event_t event;
|
---|
| 226 | gfx_rect_t rect;
|
---|
| 227 | ui_file_list_entry_attr_t attr;
|
---|
| 228 | errno_t rc;
|
---|
| 229 |
|
---|
| 230 | rc = ui_create_disp(NULL, &ui);
|
---|
| 231 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 232 |
|
---|
| 233 | ui_wnd_params_init(¶ms);
|
---|
| 234 | params.caption = "Test";
|
---|
| 235 |
|
---|
| 236 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 237 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 238 |
|
---|
| 239 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 241 |
|
---|
| 242 | rect.p0.x = 10;
|
---|
| 243 | rect.p0.y = 20;
|
---|
| 244 | rect.p1.x = 30;
|
---|
| 245 | rect.p1.y = 220;
|
---|
| 246 |
|
---|
| 247 | ui_file_list_set_rect(flist, &rect);
|
---|
| 248 |
|
---|
| 249 | ui_file_list_entry_attr_init(&attr);
|
---|
| 250 | attr.name = "a";
|
---|
| 251 | attr.size = 1;
|
---|
| 252 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 253 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 254 |
|
---|
| 255 | attr.name = "b";
|
---|
| 256 | attr.size = 2;
|
---|
| 257 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 258 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 259 |
|
---|
| 260 | attr.name = "c";
|
---|
| 261 | attr.size = 3;
|
---|
| 262 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 263 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 264 |
|
---|
| 265 | flist->cursor = ui_file_list_first(flist);
|
---|
| 266 | flist->cursor_idx = 0;
|
---|
| 267 | flist->page = ui_file_list_first(flist);
|
---|
| 268 | flist->page_idx = 0;
|
---|
| 269 |
|
---|
| 270 | event.pos_id = 0;
|
---|
| 271 | event.type = POS_PRESS;
|
---|
| 272 | event.btn_num = 1;
|
---|
| 273 |
|
---|
| 274 | /* Clicking on the middle entry should select it */
|
---|
| 275 | event.hpos = 20;
|
---|
| 276 | event.vpos = 40;
|
---|
| 277 |
|
---|
| 278 | claimed = ui_file_list_pos_event(flist, &event);
|
---|
| 279 | PCUT_ASSERT_EQUALS(ui_claimed, claimed);
|
---|
| 280 |
|
---|
| 281 | PCUT_ASSERT_NOT_NULL(flist->cursor);
|
---|
| 282 | PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
|
---|
| 283 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
|
---|
| 284 |
|
---|
| 285 | /* Clicking on the top edge should do a page-up */
|
---|
| 286 | event.hpos = 20;
|
---|
| 287 | event.vpos = 20;
|
---|
| 288 | claimed = ui_file_list_pos_event(flist, &event);
|
---|
| 289 | PCUT_ASSERT_EQUALS(ui_claimed, claimed);
|
---|
| 290 |
|
---|
| 291 | PCUT_ASSERT_NOT_NULL(flist->cursor);
|
---|
| 292 | PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
|
---|
| 293 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
|
---|
| 294 |
|
---|
| 295 | ui_file_list_destroy(flist);
|
---|
| 296 | ui_window_destroy(window);
|
---|
| 297 | ui_destroy(ui);
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | /** ui_file_list_set_rect() sets internal field */
|
---|
| 301 | PCUT_TEST(set_rect)
|
---|
| 302 | {
|
---|
| 303 | ui_file_list_t *flist;
|
---|
| 304 | gfx_rect_t rect;
|
---|
| 305 | errno_t rc;
|
---|
| 306 |
|
---|
| 307 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 308 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 309 |
|
---|
| 310 | rect.p0.x = 1;
|
---|
| 311 | rect.p0.y = 2;
|
---|
| 312 | rect.p1.x = 3;
|
---|
| 313 | rect.p1.y = 4;
|
---|
| 314 |
|
---|
| 315 | ui_file_list_set_rect(flist, &rect);
|
---|
| 316 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, flist->rect.p0.x);
|
---|
| 317 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, flist->rect.p0.y);
|
---|
| 318 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, flist->rect.p1.x);
|
---|
| 319 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, flist->rect.p1.y);
|
---|
| 320 |
|
---|
| 321 | ui_file_list_destroy(flist);
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | /** ui_file_list_page_size() returns correct size */
|
---|
| 325 | PCUT_TEST(page_size)
|
---|
| 326 | {
|
---|
| 327 | ui_t *ui;
|
---|
| 328 | ui_window_t *window;
|
---|
| 329 | ui_wnd_params_t params;
|
---|
| 330 | ui_file_list_t *flist;
|
---|
| 331 | gfx_rect_t rect;
|
---|
| 332 | errno_t rc;
|
---|
| 333 |
|
---|
| 334 | rc = ui_create_disp(NULL, &ui);
|
---|
| 335 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 336 |
|
---|
| 337 | ui_wnd_params_init(¶ms);
|
---|
| 338 | params.caption = "Test";
|
---|
| 339 |
|
---|
| 340 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 341 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 342 |
|
---|
| 343 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 344 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 345 |
|
---|
| 346 | rect.p0.x = 10;
|
---|
| 347 | rect.p0.y = 20;
|
---|
| 348 | rect.p1.x = 30;
|
---|
| 349 | rect.p1.y = 220;
|
---|
| 350 |
|
---|
| 351 | ui_file_list_set_rect(flist, &rect);
|
---|
| 352 |
|
---|
| 353 | /* NOTE If page size changes, we have problems elsewhere in the tests */
|
---|
| 354 | PCUT_ASSERT_INT_EQUALS(11, ui_file_list_page_size(flist));
|
---|
| 355 |
|
---|
| 356 | ui_file_list_destroy(flist);
|
---|
| 357 | ui_window_destroy(window);
|
---|
| 358 | ui_destroy(ui);
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | /** ui_file_list_inside_rect() ... */
|
---|
| 362 | PCUT_TEST(inside_rect)
|
---|
| 363 | {
|
---|
| 364 | // XXX
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /** ui_file_list_is_active() returns file list activity state */
|
---|
| 368 | PCUT_TEST(is_active)
|
---|
| 369 | {
|
---|
| 370 | ui_file_list_t *flist;
|
---|
| 371 | errno_t rc;
|
---|
| 372 |
|
---|
| 373 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 374 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 375 | PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
|
---|
| 376 | ui_file_list_destroy(flist);
|
---|
| 377 |
|
---|
| 378 | rc = ui_file_list_create(NULL, false, &flist);
|
---|
| 379 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 380 | PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
|
---|
| 381 | ui_file_list_destroy(flist);
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | /** ui_file_list_activate() activates file list */
|
---|
| 385 | PCUT_TEST(activate)
|
---|
| 386 | {
|
---|
| 387 | ui_t *ui;
|
---|
| 388 | ui_window_t *window;
|
---|
| 389 | ui_wnd_params_t params;
|
---|
| 390 | ui_file_list_t *flist;
|
---|
| 391 | errno_t rc;
|
---|
| 392 |
|
---|
| 393 | rc = ui_create_disp(NULL, &ui);
|
---|
| 394 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 395 |
|
---|
| 396 | ui_wnd_params_init(¶ms);
|
---|
| 397 | params.caption = "Test";
|
---|
| 398 |
|
---|
| 399 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 400 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 401 |
|
---|
| 402 | rc = ui_file_list_create(window, false, &flist);
|
---|
| 403 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 404 |
|
---|
| 405 | PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
|
---|
| 406 | rc = ui_file_list_activate(flist);
|
---|
| 407 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 408 | PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
|
---|
| 409 |
|
---|
| 410 | ui_file_list_destroy(flist);
|
---|
| 411 | ui_window_destroy(window);
|
---|
| 412 | ui_destroy(ui);
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | /** ui_file_list_deactivate() deactivates file list */
|
---|
| 416 | PCUT_TEST(deactivate)
|
---|
| 417 | {
|
---|
| 418 | ui_t *ui;
|
---|
| 419 | ui_window_t *window;
|
---|
| 420 | ui_wnd_params_t params;
|
---|
| 421 | ui_file_list_t *flist;
|
---|
| 422 | errno_t rc;
|
---|
| 423 |
|
---|
| 424 | rc = ui_create_disp(NULL, &ui);
|
---|
| 425 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 426 |
|
---|
| 427 | ui_wnd_params_init(¶ms);
|
---|
| 428 | params.caption = "Test";
|
---|
| 429 |
|
---|
| 430 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 431 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 432 |
|
---|
| 433 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 434 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 435 |
|
---|
| 436 | PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
|
---|
| 437 | ui_file_list_deactivate(flist);
|
---|
| 438 | PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
|
---|
| 439 |
|
---|
| 440 | ui_file_list_destroy(flist);
|
---|
| 441 | ui_window_destroy(window);
|
---|
| 442 | ui_destroy(ui);
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | /** ui_file_list_entry_append() appends new entry */
|
---|
| 446 | PCUT_TEST(entry_append)
|
---|
| 447 | {
|
---|
| 448 | ui_file_list_t *flist;
|
---|
| 449 | ui_file_list_entry_attr_t attr;
|
---|
| 450 | errno_t rc;
|
---|
| 451 |
|
---|
| 452 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 453 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 454 |
|
---|
| 455 | ui_file_list_entry_attr_init(&attr);
|
---|
| 456 |
|
---|
| 457 | attr.name = "a";
|
---|
| 458 | attr.size = 1;
|
---|
| 459 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 460 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 461 |
|
---|
| 462 | PCUT_ASSERT_INT_EQUALS(1, list_count(&flist->entries));
|
---|
| 463 |
|
---|
| 464 | attr.name = "b";
|
---|
| 465 | attr.size = 2;
|
---|
| 466 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 467 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 468 |
|
---|
| 469 | PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
|
---|
| 470 |
|
---|
| 471 | ui_file_list_destroy(flist);
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | /** ui_file_list_entry_delete() deletes entry */
|
---|
| 475 | PCUT_TEST(entry_delete)
|
---|
| 476 | {
|
---|
| 477 | ui_file_list_t *flist;
|
---|
| 478 | ui_file_list_entry_t *entry;
|
---|
| 479 | ui_file_list_entry_attr_t attr;
|
---|
| 480 | errno_t rc;
|
---|
| 481 |
|
---|
| 482 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 483 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 484 |
|
---|
| 485 | attr.name = "a";
|
---|
| 486 | attr.size = 1;
|
---|
| 487 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 488 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 489 |
|
---|
| 490 | attr.name = "b";
|
---|
| 491 | attr.size = 2;
|
---|
| 492 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 493 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 494 |
|
---|
| 495 | PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
|
---|
| 496 |
|
---|
| 497 | entry = ui_file_list_first(flist);
|
---|
| 498 | ui_file_list_entry_delete(entry);
|
---|
| 499 |
|
---|
| 500 | PCUT_ASSERT_INT_EQUALS(1, list_count(&flist->entries));
|
---|
| 501 |
|
---|
| 502 | entry = ui_file_list_first(flist);
|
---|
| 503 | ui_file_list_entry_delete(entry);
|
---|
| 504 |
|
---|
| 505 | PCUT_ASSERT_INT_EQUALS(0, list_count(&flist->entries));
|
---|
| 506 |
|
---|
| 507 | ui_file_list_destroy(flist);
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | /** ui_file_list_clear_entries() removes all entries from file list */
|
---|
| 511 | PCUT_TEST(clear_entries)
|
---|
| 512 | {
|
---|
| 513 | ui_file_list_t *flist;
|
---|
| 514 | ui_file_list_entry_attr_t attr;
|
---|
| 515 | errno_t rc;
|
---|
| 516 |
|
---|
| 517 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 518 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 519 |
|
---|
| 520 | ui_file_list_entry_attr_init(&attr);
|
---|
| 521 | attr.name = "a";
|
---|
| 522 | attr.size = 1;
|
---|
| 523 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 524 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 525 |
|
---|
| 526 | attr.name = "a";
|
---|
| 527 | attr.size = 2;
|
---|
| 528 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 529 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 530 |
|
---|
| 531 | PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
|
---|
| 532 |
|
---|
| 533 | ui_file_list_clear_entries(flist);
|
---|
| 534 | PCUT_ASSERT_INT_EQUALS(0, list_count(&flist->entries));
|
---|
| 535 |
|
---|
| 536 | ui_file_list_destroy(flist);
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | /** ui_file_list_read_dir() reads the contents of a directory */
|
---|
| 540 | PCUT_TEST(read_dir)
|
---|
| 541 | {
|
---|
| 542 | ui_file_list_t *flist;
|
---|
| 543 | ui_file_list_entry_t *entry;
|
---|
| 544 | char buf[L_tmpnam];
|
---|
| 545 | char *fname;
|
---|
| 546 | char *p;
|
---|
| 547 | errno_t rc;
|
---|
| 548 | FILE *f;
|
---|
| 549 | int rv;
|
---|
| 550 |
|
---|
| 551 | /* Create name for temporary directory */
|
---|
| 552 | p = tmpnam(buf);
|
---|
| 553 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 554 |
|
---|
| 555 | /* Create temporary directory */
|
---|
| 556 | rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
|
---|
| 557 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 558 |
|
---|
| 559 | rv = asprintf(&fname, "%s/%s", p, "a");
|
---|
| 560 | PCUT_ASSERT_TRUE(rv >= 0);
|
---|
| 561 |
|
---|
| 562 | f = fopen(fname, "wb");
|
---|
| 563 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 564 |
|
---|
| 565 | rv = fprintf(f, "X");
|
---|
| 566 | PCUT_ASSERT_TRUE(rv >= 0);
|
---|
| 567 |
|
---|
| 568 | rv = fclose(f);
|
---|
| 569 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 570 |
|
---|
| 571 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 573 |
|
---|
| 574 | rc = ui_file_list_read_dir(flist, p);
|
---|
| 575 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 576 |
|
---|
| 577 | PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
|
---|
| 578 |
|
---|
| 579 | entry = ui_file_list_first(flist);
|
---|
| 580 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 581 | PCUT_ASSERT_STR_EQUALS("..", entry->name);
|
---|
| 582 |
|
---|
| 583 | entry = ui_file_list_next(entry);
|
---|
| 584 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 585 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 586 | PCUT_ASSERT_INT_EQUALS(1, entry->size);
|
---|
| 587 |
|
---|
| 588 | ui_file_list_destroy(flist);
|
---|
| 589 |
|
---|
| 590 | rv = remove(fname);
|
---|
| 591 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 592 |
|
---|
| 593 | rv = remove(p);
|
---|
| 594 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 595 |
|
---|
| 596 | free(fname);
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | /** When moving to parent directory from a subdir, we seek to the
|
---|
| 600 | * coresponding entry
|
---|
| 601 | */
|
---|
| 602 | PCUT_TEST(read_dir_up)
|
---|
| 603 | {
|
---|
| 604 | ui_t *ui;
|
---|
| 605 | ui_window_t *window;
|
---|
| 606 | ui_wnd_params_t params;
|
---|
| 607 | ui_file_list_t *flist;
|
---|
| 608 | char buf[L_tmpnam];
|
---|
| 609 | char *subdir_a;
|
---|
| 610 | char *subdir_b;
|
---|
| 611 | char *subdir_c;
|
---|
| 612 | char *p;
|
---|
| 613 | errno_t rc;
|
---|
| 614 | int rv;
|
---|
| 615 |
|
---|
| 616 | /* Create name for temporary directory */
|
---|
| 617 | p = tmpnam(buf);
|
---|
| 618 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 619 |
|
---|
| 620 | /* Create temporary directory */
|
---|
| 621 | rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
|
---|
| 622 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 623 |
|
---|
| 624 | /* Create some subdirectories */
|
---|
| 625 |
|
---|
| 626 | rv = asprintf(&subdir_a, "%s/%s", p, "a");
|
---|
| 627 | PCUT_ASSERT_TRUE(rv >= 0);
|
---|
| 628 | rc = vfs_link_path(subdir_a, KIND_DIRECTORY, NULL);
|
---|
| 629 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 630 |
|
---|
| 631 | rv = asprintf(&subdir_b, "%s/%s", p, "b");
|
---|
| 632 | PCUT_ASSERT_TRUE(rv >= 0);
|
---|
| 633 | rc = vfs_link_path(subdir_b, KIND_DIRECTORY, NULL);
|
---|
| 634 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 635 |
|
---|
| 636 | rv = asprintf(&subdir_c, "%s/%s", p, "c");
|
---|
| 637 | PCUT_ASSERT_TRUE(rv >= 0);
|
---|
| 638 | rc = vfs_link_path(subdir_c, KIND_DIRECTORY, NULL);
|
---|
| 639 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 640 |
|
---|
| 641 | rc = ui_create_disp(NULL, &ui);
|
---|
| 642 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 643 |
|
---|
| 644 | ui_wnd_params_init(¶ms);
|
---|
| 645 | params.caption = "Test";
|
---|
| 646 |
|
---|
| 647 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 648 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 649 |
|
---|
| 650 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 651 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 652 |
|
---|
| 653 | /* Start in subdirectory "b" */
|
---|
| 654 | rc = ui_file_list_read_dir(flist, subdir_b);
|
---|
| 655 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 656 |
|
---|
| 657 | /* Now go up (into p) */
|
---|
| 658 |
|
---|
| 659 | rc = ui_file_list_read_dir(flist, "..");
|
---|
| 660 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 661 |
|
---|
| 662 | PCUT_ASSERT_NOT_NULL(flist->cursor);
|
---|
| 663 | PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
|
---|
| 664 |
|
---|
| 665 | ui_file_list_destroy(flist);
|
---|
| 666 |
|
---|
| 667 | rv = remove(subdir_a);
|
---|
| 668 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 669 |
|
---|
| 670 | rv = remove(subdir_b);
|
---|
| 671 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 672 |
|
---|
| 673 | rv = remove(subdir_c);
|
---|
| 674 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 675 |
|
---|
| 676 | rv = remove(p);
|
---|
| 677 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 678 |
|
---|
| 679 | free(subdir_a);
|
---|
| 680 | free(subdir_b);
|
---|
| 681 | free(subdir_c);
|
---|
| 682 |
|
---|
| 683 | ui_window_destroy(window);
|
---|
| 684 | ui_destroy(ui);
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | /** ui_file_list_sort() sorts file list entries */
|
---|
| 688 | PCUT_TEST(sort)
|
---|
| 689 | {
|
---|
| 690 | ui_file_list_t *flist;
|
---|
| 691 | ui_file_list_entry_t *entry;
|
---|
| 692 | ui_file_list_entry_attr_t attr;
|
---|
| 693 | errno_t rc;
|
---|
| 694 |
|
---|
| 695 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 696 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 697 |
|
---|
| 698 | ui_file_list_entry_attr_init(&attr);
|
---|
| 699 |
|
---|
| 700 | attr.name = "b";
|
---|
| 701 | attr.size = 1;
|
---|
| 702 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 703 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 704 |
|
---|
| 705 | attr.name = "c";
|
---|
| 706 | attr.size = 3;
|
---|
| 707 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 708 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 709 |
|
---|
| 710 | attr.name = "a";
|
---|
| 711 | attr.size = 2;
|
---|
| 712 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 713 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 714 |
|
---|
| 715 | rc = ui_file_list_sort(flist);
|
---|
| 716 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 717 |
|
---|
| 718 | entry = ui_file_list_first(flist);
|
---|
| 719 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 720 | PCUT_ASSERT_INT_EQUALS(2, entry->size);
|
---|
| 721 |
|
---|
| 722 | entry = ui_file_list_next(entry);
|
---|
| 723 | PCUT_ASSERT_STR_EQUALS("b", entry->name);
|
---|
| 724 | PCUT_ASSERT_INT_EQUALS(1, entry->size);
|
---|
| 725 |
|
---|
| 726 | entry = ui_file_list_next(entry);
|
---|
| 727 | PCUT_ASSERT_STR_EQUALS("c", entry->name);
|
---|
| 728 | PCUT_ASSERT_INT_EQUALS(3, entry->size);
|
---|
| 729 |
|
---|
| 730 | ui_file_list_destroy(flist);
|
---|
| 731 | }
|
---|
| 732 |
|
---|
| 733 | /** ui_file_list_entry_ptr_cmp compares two indirectly referenced entries */
|
---|
| 734 | PCUT_TEST(entry_ptr_cmp)
|
---|
| 735 | {
|
---|
| 736 | ui_file_list_t *flist;
|
---|
| 737 | ui_file_list_entry_t *a, *b;
|
---|
| 738 | ui_file_list_entry_attr_t attr;
|
---|
| 739 | int rel;
|
---|
| 740 | errno_t rc;
|
---|
| 741 |
|
---|
| 742 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 743 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 744 |
|
---|
| 745 | ui_file_list_entry_attr_init(&attr);
|
---|
| 746 |
|
---|
| 747 | attr.name = "a";
|
---|
| 748 | attr.size = 2;
|
---|
| 749 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 750 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 751 |
|
---|
| 752 | attr.name = "b";
|
---|
| 753 | attr.size = 1;
|
---|
| 754 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 755 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 756 |
|
---|
| 757 | a = ui_file_list_first(flist);
|
---|
| 758 | PCUT_ASSERT_NOT_NULL(a);
|
---|
| 759 | b = ui_file_list_next(a);
|
---|
| 760 | PCUT_ASSERT_NOT_NULL(b);
|
---|
| 761 |
|
---|
| 762 | /* a < b */
|
---|
| 763 | rel = ui_file_list_entry_ptr_cmp(&a, &b);
|
---|
| 764 | PCUT_ASSERT_TRUE(rel < 0);
|
---|
| 765 |
|
---|
| 766 | /* b > a */
|
---|
| 767 | rel = ui_file_list_entry_ptr_cmp(&b, &a);
|
---|
| 768 | PCUT_ASSERT_TRUE(rel > 0);
|
---|
| 769 |
|
---|
| 770 | /* a == a */
|
---|
| 771 | rel = ui_file_list_entry_ptr_cmp(&a, &a);
|
---|
| 772 | PCUT_ASSERT_INT_EQUALS(0, rel);
|
---|
| 773 |
|
---|
| 774 | ui_file_list_destroy(flist);
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 | /** ui_file_list_first() returns valid entry or @c NULL as appropriate */
|
---|
| 778 | PCUT_TEST(first)
|
---|
| 779 | {
|
---|
| 780 | ui_file_list_t *flist;
|
---|
| 781 | ui_file_list_entry_t *entry;
|
---|
| 782 | ui_file_list_entry_attr_t attr;
|
---|
| 783 | errno_t rc;
|
---|
| 784 |
|
---|
| 785 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 786 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 787 |
|
---|
| 788 | ui_file_list_entry_attr_init(&attr);
|
---|
| 789 |
|
---|
| 790 | entry = ui_file_list_first(flist);
|
---|
| 791 | PCUT_ASSERT_NULL(entry);
|
---|
| 792 |
|
---|
| 793 | /* Add one entry */
|
---|
| 794 | attr.name = "a";
|
---|
| 795 | attr.size = 1;
|
---|
| 796 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 797 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 798 |
|
---|
| 799 | /* Now try getting it */
|
---|
| 800 | entry = ui_file_list_first(flist);
|
---|
| 801 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 802 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 803 | PCUT_ASSERT_INT_EQUALS(1, entry->size);
|
---|
| 804 |
|
---|
| 805 | /* Add another entry */
|
---|
| 806 | attr.name = "b";
|
---|
| 807 | attr.size = 2;
|
---|
| 808 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 809 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 810 |
|
---|
| 811 | /* We should still get the first entry */
|
---|
| 812 | entry = ui_file_list_first(flist);
|
---|
| 813 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 814 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 815 | PCUT_ASSERT_INT_EQUALS(1, entry->size);
|
---|
| 816 |
|
---|
| 817 | ui_file_list_destroy(flist);
|
---|
| 818 | }
|
---|
| 819 |
|
---|
| 820 | /** ui_file_list_last() returns valid entry or @c NULL as appropriate */
|
---|
| 821 | PCUT_TEST(last)
|
---|
| 822 | {
|
---|
| 823 | ui_file_list_t *flist;
|
---|
| 824 | ui_file_list_entry_t *entry;
|
---|
| 825 | ui_file_list_entry_attr_t attr;
|
---|
| 826 | errno_t rc;
|
---|
| 827 |
|
---|
| 828 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 829 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 830 |
|
---|
| 831 | ui_file_list_entry_attr_init(&attr);
|
---|
| 832 |
|
---|
| 833 | entry = ui_file_list_last(flist);
|
---|
| 834 | PCUT_ASSERT_NULL(entry);
|
---|
| 835 |
|
---|
| 836 | /* Add one entry */
|
---|
| 837 | attr.name = "a";
|
---|
| 838 | attr.size = 1;
|
---|
| 839 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 840 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 841 |
|
---|
| 842 | /* Now try getting it */
|
---|
| 843 | entry = ui_file_list_last(flist);
|
---|
| 844 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 845 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 846 | PCUT_ASSERT_INT_EQUALS(1, entry->size);
|
---|
| 847 |
|
---|
| 848 | /* Add another entry */
|
---|
| 849 | attr.name = "b";
|
---|
| 850 | attr.size = 2;
|
---|
| 851 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 852 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 853 |
|
---|
| 854 | /* We should get new entry now */
|
---|
| 855 | entry = ui_file_list_last(flist);
|
---|
| 856 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 857 | attr.name = "b";
|
---|
| 858 | attr.size = 2;
|
---|
| 859 | PCUT_ASSERT_STR_EQUALS("b", entry->name);
|
---|
| 860 | PCUT_ASSERT_INT_EQUALS(2, entry->size);
|
---|
| 861 |
|
---|
| 862 | ui_file_list_destroy(flist);
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | /** ui_file_list_next() returns the next entry or @c NULL as appropriate */
|
---|
| 866 | PCUT_TEST(next)
|
---|
| 867 | {
|
---|
| 868 | ui_file_list_t *flist;
|
---|
| 869 | ui_file_list_entry_t *entry;
|
---|
| 870 | ui_file_list_entry_attr_t attr;
|
---|
| 871 | errno_t rc;
|
---|
| 872 |
|
---|
| 873 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 874 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 875 |
|
---|
| 876 | ui_file_list_entry_attr_init(&attr);
|
---|
| 877 |
|
---|
| 878 | /* Add one entry */
|
---|
| 879 | attr.name = "a";
|
---|
| 880 | attr.size = 1;
|
---|
| 881 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 882 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 883 |
|
---|
| 884 | /* Now try getting its successor */
|
---|
| 885 | entry = ui_file_list_first(flist);
|
---|
| 886 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 887 |
|
---|
| 888 | entry = ui_file_list_next(entry);
|
---|
| 889 | PCUT_ASSERT_NULL(entry);
|
---|
| 890 |
|
---|
| 891 | /* Add another entry */
|
---|
| 892 | attr.name = "b";
|
---|
| 893 | attr.size = 2;
|
---|
| 894 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 895 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 896 |
|
---|
| 897 | /* Try getting the successor of first entry again */
|
---|
| 898 | entry = ui_file_list_first(flist);
|
---|
| 899 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 900 |
|
---|
| 901 | entry = ui_file_list_next(entry);
|
---|
| 902 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 903 | PCUT_ASSERT_STR_EQUALS("b", entry->name);
|
---|
| 904 | PCUT_ASSERT_INT_EQUALS(2, entry->size);
|
---|
| 905 |
|
---|
| 906 | ui_file_list_destroy(flist);
|
---|
| 907 | }
|
---|
| 908 |
|
---|
| 909 | /** ui_file_list_prev() returns the previous entry or @c NULL as appropriate */
|
---|
| 910 | PCUT_TEST(prev)
|
---|
| 911 | {
|
---|
| 912 | ui_file_list_t *flist;
|
---|
| 913 | ui_file_list_entry_t *entry;
|
---|
| 914 | ui_file_list_entry_attr_t attr;
|
---|
| 915 | errno_t rc;
|
---|
| 916 |
|
---|
| 917 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 918 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 919 |
|
---|
| 920 | ui_file_list_entry_attr_init(&attr);
|
---|
| 921 |
|
---|
| 922 | /* Add one entry */
|
---|
| 923 | attr.name = "a";
|
---|
| 924 | attr.size = 1;
|
---|
| 925 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 926 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 927 |
|
---|
| 928 | /* Now try getting its predecessor */
|
---|
| 929 | entry = ui_file_list_last(flist);
|
---|
| 930 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 931 |
|
---|
| 932 | entry = ui_file_list_prev(entry);
|
---|
| 933 | PCUT_ASSERT_NULL(entry);
|
---|
| 934 |
|
---|
| 935 | /* Add another entry */
|
---|
| 936 | attr.name = "b";
|
---|
| 937 | attr.size = 2;
|
---|
| 938 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 939 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 940 |
|
---|
| 941 | /* Try getting the predecessor of the new entry */
|
---|
| 942 | entry = ui_file_list_last(flist);
|
---|
| 943 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 944 |
|
---|
| 945 | entry = ui_file_list_prev(entry);
|
---|
| 946 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 947 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 948 | PCUT_ASSERT_INT_EQUALS(1, entry->size);
|
---|
| 949 |
|
---|
| 950 | ui_file_list_destroy(flist);
|
---|
| 951 | }
|
---|
| 952 |
|
---|
| 953 | /** ui_file_list_page_nth_entry() .. */
|
---|
| 954 | PCUT_TEST(page_nth_entry)
|
---|
| 955 | {
|
---|
| 956 | ui_t *ui;
|
---|
| 957 | ui_window_t *window;
|
---|
| 958 | ui_wnd_params_t params;
|
---|
| 959 | ui_file_list_t *flist;
|
---|
| 960 | ui_file_list_entry_t *entry;
|
---|
| 961 | ui_file_list_entry_attr_t attr;
|
---|
| 962 | gfx_rect_t rect;
|
---|
| 963 | size_t idx;
|
---|
| 964 | errno_t rc;
|
---|
| 965 |
|
---|
| 966 | rc = ui_create_disp(NULL, &ui);
|
---|
| 967 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 968 |
|
---|
| 969 | ui_wnd_params_init(¶ms);
|
---|
| 970 | params.caption = "Test";
|
---|
| 971 |
|
---|
| 972 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 973 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 974 |
|
---|
| 975 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 976 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 977 |
|
---|
| 978 | ui_file_list_entry_attr_init(&attr);
|
---|
| 979 |
|
---|
| 980 | /* Add some entries */
|
---|
| 981 | attr.name = "a";
|
---|
| 982 | attr.size = 1;
|
---|
| 983 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 984 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 985 |
|
---|
| 986 | attr.name = "b";
|
---|
| 987 | attr.size = 2;
|
---|
| 988 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 989 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 990 |
|
---|
| 991 | attr.name = "c";
|
---|
| 992 | attr.size = 3;
|
---|
| 993 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 994 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 995 |
|
---|
| 996 | flist->page = ui_file_list_next(ui_file_list_first(flist));
|
---|
| 997 | flist->page_idx = 1;
|
---|
| 998 |
|
---|
| 999 | rect.p0.x = 0;
|
---|
| 1000 | rect.p0.y = 0;
|
---|
| 1001 | rect.p1.x = 100;
|
---|
| 1002 | rect.p1.y = 100;
|
---|
| 1003 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1004 |
|
---|
| 1005 | entry = ui_file_list_page_nth_entry(flist, 0, &idx);
|
---|
[fdf55a3] | 1006 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
[11662bd] | 1007 | PCUT_ASSERT_STR_EQUALS("b", entry->name);
|
---|
| 1008 | PCUT_ASSERT_INT_EQUALS(1, idx);
|
---|
| 1009 |
|
---|
| 1010 | entry = ui_file_list_page_nth_entry(flist, 1, &idx);
|
---|
[fdf55a3] | 1011 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
[11662bd] | 1012 | PCUT_ASSERT_STR_EQUALS("c", entry->name);
|
---|
| 1013 | PCUT_ASSERT_INT_EQUALS(2, idx);
|
---|
| 1014 |
|
---|
| 1015 | entry = ui_file_list_page_nth_entry(flist, 2, &idx);
|
---|
[fdf55a3] | 1016 | PCUT_ASSERT_NULL(entry);
|
---|
[11662bd] | 1017 |
|
---|
| 1018 | ui_file_list_destroy(flist);
|
---|
| 1019 | ui_window_destroy(window);
|
---|
| 1020 | ui_destroy(ui);
|
---|
| 1021 | }
|
---|
| 1022 |
|
---|
| 1023 | /** ui_file_list_cursor_move() ... */
|
---|
| 1024 | PCUT_TEST(cursor_move)
|
---|
| 1025 | {
|
---|
| 1026 | }
|
---|
| 1027 |
|
---|
| 1028 | /** ui_file_list_cursor_up() moves cursor one entry up */
|
---|
| 1029 | PCUT_TEST(cursor_up)
|
---|
| 1030 | {
|
---|
| 1031 | ui_t *ui;
|
---|
| 1032 | ui_window_t *window;
|
---|
| 1033 | ui_wnd_params_t params;
|
---|
| 1034 | ui_file_list_t *flist;
|
---|
| 1035 | ui_file_list_entry_attr_t attr;
|
---|
| 1036 | gfx_rect_t rect;
|
---|
| 1037 | errno_t rc;
|
---|
| 1038 |
|
---|
| 1039 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1040 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1041 |
|
---|
| 1042 | ui_wnd_params_init(¶ms);
|
---|
| 1043 | params.caption = "Test";
|
---|
| 1044 |
|
---|
| 1045 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1046 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1047 |
|
---|
| 1048 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1049 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1050 |
|
---|
| 1051 | rect.p0.x = 0;
|
---|
| 1052 | rect.p0.y = 0;
|
---|
| 1053 | rect.p1.x = 10;
|
---|
| 1054 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
| 1055 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1056 |
|
---|
| 1057 | PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
|
---|
| 1058 |
|
---|
| 1059 | /* Add tree entries (more than page size, which is 2) */
|
---|
| 1060 |
|
---|
| 1061 | ui_file_list_entry_attr_init(&attr);
|
---|
| 1062 |
|
---|
| 1063 | attr.name = "a";
|
---|
| 1064 | attr.size = 1;
|
---|
| 1065 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1066 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1067 |
|
---|
| 1068 | attr.name = "b";
|
---|
| 1069 | attr.size = 2;
|
---|
| 1070 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1071 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1072 |
|
---|
| 1073 | attr.name = "c";
|
---|
| 1074 | attr.size = 3;
|
---|
| 1075 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1076 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1077 |
|
---|
| 1078 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
| 1079 | flist->cursor = ui_file_list_last(flist);
|
---|
| 1080 | flist->cursor_idx = 2;
|
---|
| 1081 | flist->page = ui_file_list_prev(flist->cursor);
|
---|
| 1082 | flist->page_idx = 1;
|
---|
| 1083 |
|
---|
| 1084 | /* Move cursor one entry up */
|
---|
| 1085 | ui_file_list_cursor_up(flist);
|
---|
| 1086 |
|
---|
| 1087 | /* Cursor and page start should now both be at the second entry */
|
---|
| 1088 | PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
|
---|
| 1089 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
|
---|
| 1090 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor_idx);
|
---|
| 1091 | PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
|
---|
| 1092 | PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
|
---|
| 1093 |
|
---|
| 1094 | /* Move cursor one entry up. This should scroll up. */
|
---|
| 1095 | ui_file_list_cursor_up(flist);
|
---|
| 1096 |
|
---|
| 1097 | /* Cursor and page start should now both be at the first entry */
|
---|
| 1098 | PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
|
---|
| 1099 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
|
---|
| 1100 | PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
|
---|
| 1101 | PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
|
---|
| 1102 | PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
|
---|
| 1103 |
|
---|
| 1104 | /* Moving further up should do nothing (we are at the top). */
|
---|
| 1105 | ui_file_list_cursor_up(flist);
|
---|
| 1106 |
|
---|
| 1107 | /* Cursor and page start should still be at the first entry */
|
---|
| 1108 | PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
|
---|
| 1109 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
|
---|
| 1110 | PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
|
---|
| 1111 | PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
|
---|
| 1112 | PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
|
---|
| 1113 |
|
---|
| 1114 | ui_file_list_destroy(flist);
|
---|
| 1115 | ui_window_destroy(window);
|
---|
| 1116 | ui_destroy(ui);
|
---|
| 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | /** ui_file_list_cursor_down() moves cursor one entry down */
|
---|
| 1120 | PCUT_TEST(cursor_down)
|
---|
| 1121 | {
|
---|
| 1122 | ui_t *ui;
|
---|
| 1123 | ui_window_t *window;
|
---|
| 1124 | ui_wnd_params_t params;
|
---|
| 1125 | ui_file_list_t *flist;
|
---|
| 1126 | ui_file_list_entry_attr_t attr;
|
---|
| 1127 | gfx_rect_t rect;
|
---|
| 1128 | errno_t rc;
|
---|
| 1129 |
|
---|
| 1130 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1131 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1132 |
|
---|
| 1133 | ui_wnd_params_init(¶ms);
|
---|
| 1134 | params.caption = "Test";
|
---|
| 1135 |
|
---|
| 1136 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1137 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1138 |
|
---|
| 1139 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1140 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1141 |
|
---|
| 1142 | rect.p0.x = 0;
|
---|
| 1143 | rect.p0.y = 0;
|
---|
| 1144 | rect.p1.x = 10;
|
---|
| 1145 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
| 1146 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1147 |
|
---|
| 1148 | PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
|
---|
| 1149 |
|
---|
| 1150 | /* Add tree entries (more than page size, which is 2) */
|
---|
| 1151 |
|
---|
| 1152 | ui_file_list_entry_attr_init(&attr);
|
---|
| 1153 |
|
---|
| 1154 | attr.name = "a";
|
---|
| 1155 | attr.size = 1;
|
---|
| 1156 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1157 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1158 |
|
---|
| 1159 | attr.name = "b";
|
---|
| 1160 | attr.size = 2;
|
---|
| 1161 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1162 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1163 |
|
---|
| 1164 | attr.name = "c";
|
---|
| 1165 | attr.size = 3;
|
---|
| 1166 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1167 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1168 |
|
---|
| 1169 | /* Cursor and page start to the first entry */
|
---|
| 1170 | flist->cursor = ui_file_list_first(flist);
|
---|
| 1171 | flist->cursor_idx = 0;
|
---|
| 1172 | flist->page = flist->cursor;
|
---|
| 1173 | flist->page_idx = 0;
|
---|
| 1174 |
|
---|
| 1175 | /* Move cursor one entry down */
|
---|
| 1176 | ui_file_list_cursor_down(flist);
|
---|
| 1177 |
|
---|
| 1178 | /* Cursor should now be at the second entry, page stays the same */
|
---|
| 1179 | PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
|
---|
| 1180 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
|
---|
| 1181 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor_idx);
|
---|
| 1182 | PCUT_ASSERT_EQUALS(ui_file_list_first(flist), flist->page);
|
---|
| 1183 | PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
|
---|
| 1184 |
|
---|
| 1185 | /* Move cursor one entry down. This should scroll down. */
|
---|
| 1186 | ui_file_list_cursor_down(flist);
|
---|
| 1187 |
|
---|
| 1188 | /* Cursor should now be at the third and page at the second entry. */
|
---|
| 1189 | PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
|
---|
| 1190 | PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
|
---|
| 1191 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
|
---|
| 1192 | PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
|
---|
| 1193 | PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
|
---|
| 1194 | PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
|
---|
| 1195 |
|
---|
| 1196 | /* Moving further down should do nothing (we are at the bottom). */
|
---|
| 1197 | ui_file_list_cursor_down(flist);
|
---|
| 1198 |
|
---|
| 1199 | /* Cursor should still be at the third and page at the second entry. */
|
---|
| 1200 | PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
|
---|
| 1201 | PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
|
---|
| 1202 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
|
---|
| 1203 | PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
|
---|
| 1204 | PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
|
---|
| 1205 | PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
|
---|
| 1206 |
|
---|
| 1207 | ui_file_list_destroy(flist);
|
---|
| 1208 | ui_window_destroy(window);
|
---|
| 1209 | ui_destroy(ui);
|
---|
| 1210 | }
|
---|
| 1211 |
|
---|
| 1212 | /** ui_file_list_cursor_top() moves cursor to the first entry */
|
---|
| 1213 | PCUT_TEST(cursor_top)
|
---|
| 1214 | {
|
---|
| 1215 | ui_t *ui;
|
---|
| 1216 | ui_window_t *window;
|
---|
| 1217 | ui_wnd_params_t params;
|
---|
| 1218 | ui_file_list_t *flist;
|
---|
| 1219 | ui_file_list_entry_attr_t attr;
|
---|
| 1220 | gfx_rect_t rect;
|
---|
| 1221 | errno_t rc;
|
---|
| 1222 |
|
---|
| 1223 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1224 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1225 |
|
---|
| 1226 | ui_wnd_params_init(¶ms);
|
---|
| 1227 | params.caption = "Test";
|
---|
| 1228 |
|
---|
| 1229 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1230 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1231 |
|
---|
| 1232 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1233 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1234 |
|
---|
| 1235 | rect.p0.x = 0;
|
---|
| 1236 | rect.p0.y = 0;
|
---|
| 1237 | rect.p1.x = 10;
|
---|
| 1238 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
| 1239 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1240 |
|
---|
| 1241 | PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
|
---|
| 1242 |
|
---|
| 1243 | /* Add tree entries (more than page size, which is 2) */
|
---|
| 1244 |
|
---|
| 1245 | ui_file_list_entry_attr_init(&attr);
|
---|
| 1246 |
|
---|
| 1247 | attr.name = "a";
|
---|
| 1248 | attr.size = 1;
|
---|
| 1249 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1250 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1251 |
|
---|
| 1252 | attr.name = "b";
|
---|
| 1253 | attr.size = 2;
|
---|
| 1254 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1255 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1256 |
|
---|
| 1257 | attr.name = "c";
|
---|
| 1258 | attr.size = 3;
|
---|
| 1259 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1260 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1261 |
|
---|
| 1262 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
| 1263 | flist->cursor = ui_file_list_last(flist);
|
---|
| 1264 | flist->cursor_idx = 2;
|
---|
| 1265 | flist->page = ui_file_list_prev(flist->cursor);
|
---|
| 1266 | flist->page_idx = 1;
|
---|
| 1267 |
|
---|
| 1268 | /* Move cursor to the top. This should scroll up. */
|
---|
| 1269 | ui_file_list_cursor_top(flist);
|
---|
| 1270 |
|
---|
| 1271 | /* Cursor and page start should now both be at the first entry */
|
---|
| 1272 | PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
|
---|
| 1273 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
|
---|
| 1274 | PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
|
---|
| 1275 | PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
|
---|
| 1276 | PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
|
---|
| 1277 |
|
---|
| 1278 | ui_file_list_destroy(flist);
|
---|
| 1279 | ui_window_destroy(window);
|
---|
| 1280 | ui_destroy(ui);
|
---|
| 1281 | }
|
---|
| 1282 |
|
---|
| 1283 | /** ui_file_list_cursor_bottom() moves cursor to the last entry */
|
---|
| 1284 | PCUT_TEST(cursor_bottom)
|
---|
| 1285 | {
|
---|
| 1286 | ui_t *ui;
|
---|
| 1287 | ui_window_t *window;
|
---|
| 1288 | ui_wnd_params_t params;
|
---|
| 1289 | ui_file_list_t *flist;
|
---|
| 1290 | ui_file_list_entry_attr_t attr;
|
---|
| 1291 | gfx_rect_t rect;
|
---|
| 1292 | errno_t rc;
|
---|
| 1293 |
|
---|
| 1294 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1295 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1296 |
|
---|
| 1297 | ui_wnd_params_init(¶ms);
|
---|
| 1298 | params.caption = "Test";
|
---|
| 1299 |
|
---|
| 1300 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1301 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1302 |
|
---|
| 1303 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1304 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1305 |
|
---|
| 1306 | rect.p0.x = 0;
|
---|
| 1307 | rect.p0.y = 0;
|
---|
| 1308 | rect.p1.x = 10;
|
---|
| 1309 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
| 1310 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1311 |
|
---|
| 1312 | PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
|
---|
| 1313 |
|
---|
| 1314 | /* Add tree entries (more than page size, which is 2) */
|
---|
| 1315 |
|
---|
| 1316 | ui_file_list_entry_attr_init(&attr);
|
---|
| 1317 |
|
---|
| 1318 | attr.name = "a";
|
---|
| 1319 | attr.size = 1;
|
---|
| 1320 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1321 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1322 |
|
---|
| 1323 | attr.name = "b";
|
---|
| 1324 | attr.size = 2;
|
---|
| 1325 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1326 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1327 |
|
---|
| 1328 | attr.name = "c";
|
---|
| 1329 | attr.size = 3;
|
---|
| 1330 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1331 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1332 |
|
---|
| 1333 | /* Cursor and page start to the first entry */
|
---|
| 1334 | flist->cursor = ui_file_list_first(flist);
|
---|
| 1335 | flist->cursor_idx = 0;
|
---|
| 1336 | flist->page = flist->cursor;
|
---|
| 1337 | flist->page_idx = 0;
|
---|
| 1338 |
|
---|
| 1339 | /* Move cursor to the bottom. This should scroll down. */
|
---|
| 1340 | ui_file_list_cursor_bottom(flist);
|
---|
| 1341 |
|
---|
| 1342 | /* Cursor should now be at the third and page at the second entry. */
|
---|
| 1343 | PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
|
---|
| 1344 | PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
|
---|
| 1345 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
|
---|
| 1346 | PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
|
---|
| 1347 | PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
|
---|
| 1348 | PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
|
---|
| 1349 |
|
---|
| 1350 | ui_file_list_destroy(flist);
|
---|
| 1351 | ui_window_destroy(window);
|
---|
| 1352 | ui_destroy(ui);
|
---|
| 1353 | }
|
---|
| 1354 |
|
---|
| 1355 | /** ui_file_list_page_up() moves one page up */
|
---|
| 1356 | PCUT_TEST(page_up)
|
---|
| 1357 | {
|
---|
| 1358 | ui_t *ui;
|
---|
| 1359 | ui_window_t *window;
|
---|
| 1360 | ui_wnd_params_t params;
|
---|
| 1361 | ui_file_list_t *flist;
|
---|
| 1362 | ui_file_list_entry_attr_t attr;
|
---|
| 1363 | gfx_rect_t rect;
|
---|
| 1364 | errno_t rc;
|
---|
| 1365 |
|
---|
| 1366 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1367 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1368 |
|
---|
| 1369 | ui_wnd_params_init(¶ms);
|
---|
| 1370 | params.caption = "Test";
|
---|
| 1371 |
|
---|
| 1372 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1373 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1374 |
|
---|
| 1375 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1376 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1377 |
|
---|
| 1378 | rect.p0.x = 0;
|
---|
| 1379 | rect.p0.y = 0;
|
---|
| 1380 | rect.p1.x = 10;
|
---|
| 1381 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
| 1382 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1383 |
|
---|
| 1384 | PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
|
---|
| 1385 |
|
---|
| 1386 | /* Add five entries (2 full pages, one partial) */
|
---|
| 1387 |
|
---|
| 1388 | ui_file_list_entry_attr_init(&attr);
|
---|
| 1389 |
|
---|
| 1390 | attr.name = "a";
|
---|
| 1391 | attr.size = 1;
|
---|
| 1392 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1393 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1394 |
|
---|
| 1395 | attr.name = "b";
|
---|
| 1396 | attr.size = 2;
|
---|
| 1397 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1398 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1399 |
|
---|
| 1400 | attr.name = "c";
|
---|
| 1401 | attr.size = 3;
|
---|
| 1402 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1403 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1404 |
|
---|
| 1405 | attr.name = "d";
|
---|
| 1406 | attr.size = 4;
|
---|
| 1407 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1408 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1409 |
|
---|
| 1410 | attr.name = "e";
|
---|
| 1411 | attr.size = 5;
|
---|
| 1412 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1413 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1414 |
|
---|
| 1415 | /* Cursor to the last entry and page start to the next-to-last entry */
|
---|
| 1416 | flist->cursor = ui_file_list_last(flist);
|
---|
| 1417 | flist->cursor_idx = 4;
|
---|
| 1418 | flist->page = ui_file_list_prev(flist->cursor);
|
---|
| 1419 | flist->page_idx = 3;
|
---|
| 1420 |
|
---|
| 1421 | /* Move one page up */
|
---|
| 1422 | ui_file_list_page_up(flist);
|
---|
| 1423 |
|
---|
| 1424 | /* Page should now start at second entry and cursor at third */
|
---|
| 1425 | PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
|
---|
| 1426 | PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
|
---|
| 1427 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
|
---|
| 1428 | PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
|
---|
| 1429 | PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
|
---|
| 1430 | PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
|
---|
| 1431 |
|
---|
| 1432 | /* Move one page up again. */
|
---|
| 1433 | ui_file_list_page_up(flist);
|
---|
| 1434 |
|
---|
| 1435 | /* Cursor and page start should now both be at the first entry */
|
---|
| 1436 | PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
|
---|
| 1437 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
|
---|
| 1438 | PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
|
---|
| 1439 | PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
|
---|
| 1440 | PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
|
---|
| 1441 |
|
---|
| 1442 | /* Moving further up should do nothing (we are at the top). */
|
---|
| 1443 | ui_file_list_page_up(flist);
|
---|
| 1444 |
|
---|
| 1445 | /* Cursor and page start should still be at the first entry */
|
---|
| 1446 | PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
|
---|
| 1447 | PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
|
---|
| 1448 | PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
|
---|
| 1449 | PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
|
---|
| 1450 | PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
|
---|
| 1451 |
|
---|
| 1452 | ui_file_list_destroy(flist);
|
---|
| 1453 | ui_window_destroy(window);
|
---|
| 1454 | ui_destroy(ui);
|
---|
| 1455 | }
|
---|
| 1456 |
|
---|
| 1457 | /** ui_file_list_page_up() moves one page down */
|
---|
| 1458 | PCUT_TEST(page_down)
|
---|
| 1459 | {
|
---|
| 1460 | ui_t *ui;
|
---|
| 1461 | ui_window_t *window;
|
---|
| 1462 | ui_wnd_params_t params;
|
---|
| 1463 | ui_file_list_t *flist;
|
---|
| 1464 | ui_file_list_entry_attr_t attr;
|
---|
| 1465 | gfx_rect_t rect;
|
---|
| 1466 | errno_t rc;
|
---|
| 1467 |
|
---|
| 1468 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1469 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1470 |
|
---|
| 1471 | ui_wnd_params_init(¶ms);
|
---|
| 1472 | params.caption = "Test";
|
---|
| 1473 |
|
---|
| 1474 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1475 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1476 |
|
---|
| 1477 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1478 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1479 |
|
---|
| 1480 | rect.p0.x = 0;
|
---|
| 1481 | rect.p0.y = 0;
|
---|
| 1482 | rect.p1.x = 10;
|
---|
| 1483 | rect.p1.y = 38; /* Assuming this makes page size 2 */
|
---|
| 1484 | ui_file_list_set_rect(flist, &rect);
|
---|
| 1485 |
|
---|
| 1486 | PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
|
---|
| 1487 |
|
---|
| 1488 | /* Add five entries (2 full pages, one partial) */
|
---|
| 1489 |
|
---|
| 1490 | ui_file_list_entry_attr_init(&attr);
|
---|
| 1491 |
|
---|
| 1492 | attr.name = "a";
|
---|
| 1493 | attr.size = 1;
|
---|
| 1494 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1495 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1496 |
|
---|
| 1497 | attr.name = "b";
|
---|
| 1498 | attr.size = 2;
|
---|
| 1499 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1500 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1501 |
|
---|
| 1502 | attr.name = "c";
|
---|
| 1503 | attr.size = 3;
|
---|
| 1504 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1505 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1506 |
|
---|
| 1507 | attr.name = "d";
|
---|
| 1508 | attr.size = 4;
|
---|
| 1509 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1510 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1511 |
|
---|
| 1512 | attr.name = "e";
|
---|
| 1513 | attr.size = 5;
|
---|
| 1514 | rc = ui_file_list_entry_append(flist, &attr);
|
---|
| 1515 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1516 |
|
---|
| 1517 | /* Cursor and page to the first entry */
|
---|
| 1518 | flist->cursor = ui_file_list_first(flist);
|
---|
| 1519 | flist->cursor_idx = 0;
|
---|
| 1520 | flist->page = flist->cursor;
|
---|
| 1521 | flist->page_idx = 0;
|
---|
| 1522 |
|
---|
| 1523 | /* Move one page down */
|
---|
| 1524 | ui_file_list_page_down(flist);
|
---|
| 1525 |
|
---|
| 1526 | /* Page and cursor should point to the third entry */
|
---|
| 1527 | PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
|
---|
| 1528 | PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
|
---|
| 1529 | PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
|
---|
| 1530 | PCUT_ASSERT_STR_EQUALS("c", flist->page->name);
|
---|
| 1531 | PCUT_ASSERT_INT_EQUALS(3, flist->page->size);
|
---|
| 1532 | PCUT_ASSERT_INT_EQUALS(2, flist->page_idx);
|
---|
| 1533 |
|
---|
| 1534 | /* Move one page down again. */
|
---|
| 1535 | ui_file_list_page_down(flist);
|
---|
| 1536 |
|
---|
| 1537 | /* Cursor should point to last and page to next-to-last entry */
|
---|
| 1538 | PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
|
---|
| 1539 | PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
|
---|
| 1540 | PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
|
---|
| 1541 | PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
|
---|
| 1542 | PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
|
---|
| 1543 | PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
|
---|
| 1544 |
|
---|
| 1545 | /* Moving further down should do nothing (we are at the bottom). */
|
---|
| 1546 | ui_file_list_page_down(flist);
|
---|
| 1547 |
|
---|
| 1548 | /* Cursor should still point to last and page to next-to-last entry */
|
---|
| 1549 | PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
|
---|
| 1550 | PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
|
---|
| 1551 | PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
|
---|
| 1552 | PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
|
---|
| 1553 | PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
|
---|
| 1554 | PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
|
---|
| 1555 |
|
---|
| 1556 | ui_file_list_destroy(flist);
|
---|
| 1557 | ui_window_destroy(window);
|
---|
| 1558 | ui_destroy(ui);
|
---|
| 1559 | }
|
---|
| 1560 |
|
---|
| 1561 | /** ui_file_list_open() opens a directory entry */
|
---|
| 1562 | PCUT_TEST(open)
|
---|
| 1563 | {
|
---|
| 1564 | ui_t *ui;
|
---|
| 1565 | ui_window_t *window;
|
---|
| 1566 | ui_wnd_params_t params;
|
---|
| 1567 | ui_file_list_t *flist;
|
---|
| 1568 | ui_file_list_entry_t *entry;
|
---|
| 1569 | char buf[L_tmpnam];
|
---|
| 1570 | char *sdname;
|
---|
| 1571 | char *p;
|
---|
| 1572 | errno_t rc;
|
---|
| 1573 | int rv;
|
---|
| 1574 |
|
---|
| 1575 | rc = ui_create_disp(NULL, &ui);
|
---|
| 1576 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1577 |
|
---|
| 1578 | ui_wnd_params_init(¶ms);
|
---|
| 1579 | params.caption = "Test";
|
---|
| 1580 |
|
---|
| 1581 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 1582 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1583 |
|
---|
| 1584 | /* Create name for temporary directory */
|
---|
| 1585 | p = tmpnam(buf);
|
---|
| 1586 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 1587 |
|
---|
| 1588 | /* Create temporary directory */
|
---|
| 1589 | rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
|
---|
| 1590 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1591 |
|
---|
| 1592 | rv = asprintf(&sdname, "%s/%s", p, "a");
|
---|
| 1593 | PCUT_ASSERT_TRUE(rv >= 0);
|
---|
| 1594 |
|
---|
| 1595 | /* Create sub-directory */
|
---|
| 1596 | rc = vfs_link_path(sdname, KIND_DIRECTORY, NULL);
|
---|
| 1597 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1598 |
|
---|
| 1599 | rc = ui_file_list_create(window, true, &flist);
|
---|
| 1600 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1601 |
|
---|
| 1602 | rc = ui_file_list_read_dir(flist, p);
|
---|
| 1603 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1604 | PCUT_ASSERT_STR_EQUALS(p, flist->dir);
|
---|
| 1605 |
|
---|
| 1606 | PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
|
---|
| 1607 |
|
---|
| 1608 | entry = ui_file_list_first(flist);
|
---|
| 1609 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 1610 | PCUT_ASSERT_STR_EQUALS("..", entry->name);
|
---|
| 1611 |
|
---|
| 1612 | entry = ui_file_list_next(entry);
|
---|
| 1613 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
| 1614 | PCUT_ASSERT_STR_EQUALS("a", entry->name);
|
---|
| 1615 | PCUT_ASSERT_TRUE(entry->isdir);
|
---|
| 1616 |
|
---|
| 1617 | rc = ui_file_list_open(flist, entry);
|
---|
| 1618 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1619 |
|
---|
| 1620 | PCUT_ASSERT_STR_EQUALS(sdname, flist->dir);
|
---|
| 1621 |
|
---|
| 1622 | ui_file_list_destroy(flist);
|
---|
| 1623 | ui_window_destroy(window);
|
---|
| 1624 | ui_destroy(ui);
|
---|
| 1625 |
|
---|
| 1626 | rv = remove(sdname);
|
---|
| 1627 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 1628 |
|
---|
| 1629 | rv = remove(p);
|
---|
| 1630 | PCUT_ASSERT_INT_EQUALS(0, rv);
|
---|
| 1631 |
|
---|
| 1632 | free(sdname);
|
---|
| 1633 | }
|
---|
| 1634 |
|
---|
| 1635 | PCUT_TEST(open_dir)
|
---|
| 1636 | {
|
---|
| 1637 | }
|
---|
| 1638 |
|
---|
| 1639 | PCUT_TEST(open_file)
|
---|
| 1640 | {
|
---|
| 1641 | }
|
---|
| 1642 |
|
---|
| 1643 | /** ui_file_list_activate_req() sends activation request */
|
---|
| 1644 | PCUT_TEST(activate_req)
|
---|
| 1645 | {
|
---|
| 1646 | ui_file_list_t *flist;
|
---|
| 1647 | errno_t rc;
|
---|
| 1648 | test_resp_t resp;
|
---|
| 1649 |
|
---|
| 1650 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 1651 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1652 |
|
---|
| 1653 | ui_file_list_set_cb(flist, &test_cb, &resp);
|
---|
| 1654 |
|
---|
| 1655 | resp.activate_req = false;
|
---|
| 1656 | resp.activate_req_file_list = NULL;
|
---|
| 1657 |
|
---|
| 1658 | ui_file_list_activate_req(flist);
|
---|
| 1659 | PCUT_ASSERT_TRUE(resp.activate_req);
|
---|
| 1660 | PCUT_ASSERT_EQUALS(flist, resp.activate_req_file_list);
|
---|
| 1661 |
|
---|
| 1662 | ui_file_list_destroy(flist);
|
---|
| 1663 | }
|
---|
| 1664 |
|
---|
| 1665 | /** ui_file_list_selected() runs selected callback */
|
---|
| 1666 | PCUT_TEST(selected)
|
---|
| 1667 | {
|
---|
| 1668 | ui_file_list_t *flist;
|
---|
| 1669 | errno_t rc;
|
---|
| 1670 | test_resp_t resp;
|
---|
| 1671 |
|
---|
| 1672 | rc = ui_file_list_create(NULL, true, &flist);
|
---|
| 1673 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 1674 |
|
---|
| 1675 | ui_file_list_set_cb(flist, &test_cb, &resp);
|
---|
| 1676 |
|
---|
| 1677 | resp.selected = false;
|
---|
| 1678 | resp.selected_file_list = NULL;
|
---|
| 1679 | resp.selected_fname = NULL;
|
---|
| 1680 |
|
---|
| 1681 | ui_file_list_selected(flist, "hello.txt");
|
---|
| 1682 | PCUT_ASSERT_TRUE(resp.selected);
|
---|
| 1683 | PCUT_ASSERT_EQUALS(flist, resp.selected_file_list);
|
---|
| 1684 | PCUT_ASSERT_STR_EQUALS("hello.txt", resp.selected_fname);
|
---|
| 1685 |
|
---|
| 1686 | ui_file_list_destroy(flist);
|
---|
| 1687 | }
|
---|
| 1688 |
|
---|
| 1689 | static void test_file_list_activate_req(ui_file_list_t *flist, void *arg)
|
---|
| 1690 | {
|
---|
| 1691 | test_resp_t *resp = (test_resp_t *)arg;
|
---|
| 1692 |
|
---|
| 1693 | resp->activate_req = true;
|
---|
| 1694 | resp->activate_req_file_list = flist;
|
---|
| 1695 | }
|
---|
| 1696 |
|
---|
| 1697 | static void test_file_list_selected(ui_file_list_t *flist, void *arg,
|
---|
| 1698 | const char *fname)
|
---|
| 1699 | {
|
---|
| 1700 | test_resp_t *resp = (test_resp_t *)arg;
|
---|
| 1701 |
|
---|
| 1702 | resp->selected = true;
|
---|
| 1703 | resp->selected_file_list = flist;
|
---|
| 1704 | resp->selected_fname = fname;
|
---|
| 1705 | }
|
---|
| 1706 |
|
---|
| 1707 | PCUT_EXPORT(file_list);
|
---|