Changeset aefdccd in mainline for uspace/lib/ui/test/filelist.c


Ignore:
Timestamp:
2025-10-20T06:14:54Z (7 weeks ago)
Author:
GitHub <noreply@…>
Parents:
adbd7e1 (diff), 3e41cc4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2025-10-20 06:14:54)
git-committer:
GitHub <noreply@…> (2025-10-20 06:14:54)
Message:

Merge branch 'HelenOS:master' into ticket/packet-capture

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/filelist.c

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    665665}
    666666
     667/** ui_file_list_refresh() */
     668PCUT_TEST(refresh)
     669{
     670        ui_t *ui;
     671        ui_window_t *window;
     672        ui_wnd_params_t params;
     673        ui_file_list_t *flist;
     674        ui_file_list_entry_t *entry;
     675        char buf[L_tmpnam];
     676        char *fname;
     677        char *p;
     678        errno_t rc;
     679        FILE *f;
     680        int rv;
     681
     682        /* Create name for temporary directory */
     683        p = tmpnam(buf);
     684        PCUT_ASSERT_NOT_NULL(p);
     685
     686        /* Create temporary directory */
     687        rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
     688        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     689
     690        rv = asprintf(&fname, "%s/%s", p, "a");
     691        PCUT_ASSERT_TRUE(rv >= 0);
     692
     693        f = fopen(fname, "wb");
     694        PCUT_ASSERT_NOT_NULL(f);
     695
     696        rv = fprintf(f, "X");
     697        PCUT_ASSERT_TRUE(rv >= 0);
     698
     699        rv = fclose(f);
     700        PCUT_ASSERT_INT_EQUALS(0, rv);
     701
     702        rc = ui_create_disp(NULL, &ui);
     703        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     704
     705        ui_wnd_params_init(&params);
     706        params.caption = "Test";
     707
     708        rc = ui_window_create(ui, &params, &window);
     709        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     710
     711        rc = ui_file_list_create(window, true, &flist);
     712        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     713
     714        rc = ui_file_list_read_dir(flist, p);
     715        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     716
     717        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
     718
     719        entry = ui_file_list_first(flist);
     720        PCUT_ASSERT_NOT_NULL(entry);
     721        PCUT_ASSERT_STR_EQUALS("..", entry->name);
     722
     723        entry = ui_file_list_next(entry);
     724        PCUT_ASSERT_NOT_NULL(entry);
     725        PCUT_ASSERT_STR_EQUALS("a", entry->name);
     726        PCUT_ASSERT_INT_EQUALS(1, entry->size);
     727
     728        rv = remove(fname);
     729        PCUT_ASSERT_INT_EQUALS(0, rv);
     730        free(fname);
     731
     732        rv = asprintf(&fname, "%s/%s", p, "b");
     733        PCUT_ASSERT_TRUE(rv >= 0);
     734
     735        f = fopen(fname, "wb");
     736        PCUT_ASSERT_NOT_NULL(f);
     737
     738        rv = fprintf(f, "X");
     739        PCUT_ASSERT_TRUE(rv >= 0);
     740
     741        rv = fclose(f);
     742        PCUT_ASSERT_INT_EQUALS(0, rv);
     743
     744        rc = ui_file_list_refresh(flist);
     745        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     746
     747        entry = ui_file_list_first(flist);
     748        PCUT_ASSERT_NOT_NULL(entry);
     749        PCUT_ASSERT_STR_EQUALS("..", entry->name);
     750
     751        entry = ui_file_list_next(entry);
     752        PCUT_ASSERT_NOT_NULL(entry);
     753        PCUT_ASSERT_STR_EQUALS("b", entry->name);
     754        PCUT_ASSERT_INT_EQUALS(1, entry->size);
     755
     756        rv = remove(fname);
     757        PCUT_ASSERT_INT_EQUALS(0, rv);
     758        free(fname);
     759
     760        rv = remove(p);
     761        PCUT_ASSERT_INT_EQUALS(0, rv);
     762
     763        ui_file_list_destroy(flist);
     764
     765        ui_window_destroy(window);
     766        ui_destroy(ui);
     767}
     768
    667769/** ui_file_list_list_compare compares two file list entries */
    668770PCUT_TEST(list_compare)
Note: See TracChangeset for help on using the changeset viewer.