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