Changeset 0e80e40 in mainline for uspace/app/nav/test/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (2 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9f7e9bb
Parents:
61784ed
git-author:
Jiri Svoboda <jiri@…> (2021-10-07 17:17:36)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Read and display directory contents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/test/panel.c

    r61784ed r0e80e40  
    2929#include <errno.h>
    3030#include <pcut/pcut.h>
     31#include <stdio.h>
     32#include <vfs/vfs.h>
    3133#include "../panel.h"
    3234
     
    194196}
    195197
     198/** panel_clear_entries() removes all entries from panel */
     199PCUT_TEST(clear_entries)
     200{
     201        panel_t *panel;
     202        errno_t rc;
     203
     204        rc = panel_create(NULL, &panel);
     205        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     206
     207        rc = panel_entry_append(panel, "a", 1);
     208        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     209
     210        rc = panel_entry_append(panel, "b", 2);
     211        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     212
     213        PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));
     214
     215        panel_clear_entries(panel);
     216        PCUT_ASSERT_INT_EQUALS(0, list_count(&panel->entries));
     217
     218        panel_destroy(panel);
     219}
     220
     221/** panel_read_dir() reads the contents of a directory */
     222PCUT_TEST(read_dir)
     223{
     224        panel_t *panel;
     225        panel_entry_t *entry;
     226        char buf[L_tmpnam];
     227        char *fname;
     228        char *p;
     229        errno_t rc;
     230        FILE *f;
     231        int rv;
     232
     233        /* Create name for temporary directory */
     234        p = tmpnam(buf);
     235        PCUT_ASSERT_NOT_NULL(p);
     236
     237        /* Create temporary directory */
     238        rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
     239        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     240
     241        rv = asprintf(&fname, "%s/%s", p, "a");
     242        PCUT_ASSERT_TRUE(rv >= 0);
     243
     244        f = fopen(fname, "wb");
     245        PCUT_ASSERT_NOT_NULL(f);
     246
     247        rv = fprintf(f, "X");
     248        PCUT_ASSERT_TRUE(rv >= 0);
     249
     250        rv = fclose(f);
     251        PCUT_ASSERT_INT_EQUALS(0, rv);
     252
     253        rc = panel_create(NULL, &panel);
     254        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     255
     256        rc = panel_read_dir(panel, p);
     257        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     258
     259        PCUT_ASSERT_INT_EQUALS(1, list_count(&panel->entries));
     260
     261        entry = panel_first(panel);
     262        PCUT_ASSERT_NOT_NULL(entry);
     263        PCUT_ASSERT_STR_EQUALS("a", entry->name);
     264        // PCUT_ASSERT_INT_EQUALS(1, entry->size);
     265
     266        panel_destroy(panel);
     267
     268        rv = remove(fname);
     269        PCUT_ASSERT_INT_EQUALS(0, rv);
     270
     271        rv = remove(p);
     272        PCUT_ASSERT_INT_EQUALS(0, rv);
     273        free(fname);
     274}
     275
    196276/** panel_first() returns valid entry or @c NULL as appropriate */
    197277PCUT_TEST(first)
Note: See TracChangeset for help on using the changeset viewer.