Changeset 97d3d9d in mainline


Ignore:
Timestamp:
2023-04-20T18:43:15Z (15 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cdf5361
Parents:
37087c8
Message:

Start filling in unit tests for display-cfg

Location:
uspace/app/display-cfg
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/display-cfg/display-cfg.c

    r37087c8 r97d3d9d  
    3636#include <stdio.h>
    3737#include <stdlib.h>
    38 #include <str.h>
    3938#include <ui/fixed.h>
    4039#include <ui/resource.h>
     
    6968 * @return EOK on success or an error code
    7069 */
    71 static errno_t display_cfg_create(const char *display_spec,
    72     display_cfg_t **rdcfg)
     70errno_t display_cfg_create(const char *display_spec, display_cfg_t **rdcfg)
    7371{
    7472        ui_t *ui = NULL;
     
    179177 * @param dcfg Display configuration dialog
    180178 */
    181 static void display_cfg_destroy(display_cfg_t *dcfg)
     179void display_cfg_destroy(display_cfg_t *dcfg)
    182180{
    183181        ui_window_destroy(dcfg->window);
     
    185183}
    186184
    187 static void print_syntax(void)
    188 {
    189         printf("Syntax: display-cfg [-d <display-spec>]\n");
    190 }
    191 
    192 int main(int argc, char *argv[])
    193 {
    194         const char *display_spec = UI_ANY_DEFAULT;
    195         display_cfg_t *dcfg;
    196         errno_t rc;
    197         int i;
    198 
    199         i = 1;
    200         while (i < argc && argv[i][0] == '-') {
    201                 if (str_cmp(argv[i], "-d") == 0) {
    202                         ++i;
    203                         if (i >= argc) {
    204                                 printf("Argument missing.\n");
    205                                 print_syntax();
    206                                 return 1;
    207                         }
    208 
    209                         display_spec = argv[i++];
    210                 } else {
    211                         printf("Invalid option '%s'.\n", argv[i]);
    212                         print_syntax();
    213                         return 1;
    214                 }
    215         }
    216 
    217         if (i < argc) {
    218                 print_syntax();
    219                 return 1;
    220         }
    221 
    222         rc = display_cfg_create(display_spec, &dcfg);
    223         if (rc != EOK)
    224                 return 1;
    225 
    226         ui_run(dcfg->ui);
    227         display_cfg_destroy(dcfg);
    228 
    229         return 0;
    230 }
    231 
    232185/** @}
    233186 */
  • uspace/app/display-cfg/display-cfg.h

    r37087c8 r97d3d9d  
    3939#include "types/display-cfg.h"
    4040
     41extern errno_t display_cfg_create(const char *, display_cfg_t **);
     42extern void display_cfg_destroy(display_cfg_t *);
     43
    4144#endif
    4245
  • uspace/app/display-cfg/meson.build

    r37087c8 r97d3d9d  
    3030src = files(
    3131        'display-cfg.c',
     32        'main.c',
    3233        'seats.c'
    3334)
    3435
    3536test_src = files(
     37        'display-cfg.c',
     38        'seats.c',
    3639        'test/display-cfg.c',
    3740        'test/main.c',
  • uspace/app/display-cfg/seats.c

    r37087c8 r97d3d9d  
    441441        dcfg_devices_entry_t *dentry;
    442442
    443         ui_pbutton_destroy(seats->add_device);
    444         ui_pbutton_destroy(seats->remove_device);
    445 
    446         ui_label_destroy(seats->devices_label);
    447 
    448443        lentry = ui_list_first(seats->device_list);
    449444        while (lentry != NULL) {
     
    454449                lentry = ui_list_first(seats->device_list);
    455450        }
    456         ui_list_destroy(seats->device_list);
    457 
    458         ui_pbutton_destroy(seats->add_seat);
    459         ui_pbutton_destroy(seats->remove_seat);
    460451
    461452        lentry = ui_list_first(seats->seat_list);
     
    468459        }
    469460
    470         ui_label_destroy(seats->seats_label);
    471         ui_list_destroy(seats->seat_list);
    472         ui_fixed_destroy(seats->fixed);
     461        /* This will automatically destroy all controls in the tab */
     462        ui_tab_destroy(seats->tab);
    473463        free(seats);
    474464}
     
    482472 * @return EOK on success or an error code
    483473 */
    484 static errno_t dcfg_seats_insert(dcfg_seats_t *seats, const char *name,
     474errno_t dcfg_seats_insert(dcfg_seats_t *seats, const char *name,
    485475    sysarg_t seat_id, dcfg_seats_entry_t **rentry)
    486476{
     
    564554 * @return EOK on success or an error code
    565555 */
    566 static errno_t dcfg_devices_insert(dcfg_seats_t *seats, const char *name,
     556errno_t dcfg_devices_insert(dcfg_seats_t *seats, const char *name,
    567557    service_id_t svc_id)
    568558{
  • uspace/app/display-cfg/seats.h

    r37087c8 r97d3d9d  
    4242extern errno_t dcfg_seats_create(display_cfg_t *, dcfg_seats_t **);
    4343extern void dcfg_seats_destroy(dcfg_seats_t *);
     44extern errno_t dcfg_seats_insert(dcfg_seats_t *, const char *, sysarg_t,
     45    dcfg_seats_entry_t **);
     46extern errno_t dcfg_devices_insert(dcfg_seats_t *, const char *,
     47    service_id_t);
    4448
    4549#endif
  • uspace/app/display-cfg/test/display-cfg.c

    r37087c8 r97d3d9d  
    2929#include <errno.h>
    3030#include <pcut/pcut.h>
     31#include <ui/ui.h>
    3132#include "../display-cfg.h"
    3233
     
    3536PCUT_TEST_SUITE(display_cfg);
    3637
    37 //XXX TODO
     38/** Test display_cfg_create() and display_cfg_destroy() */
     39PCUT_TEST(create_destroy)
     40{
     41        display_cfg_t *dcfg;
     42        errno_t rc;
     43
     44        rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
     45        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     46
     47        display_cfg_destroy(dcfg);
     48}
    3849
    3950PCUT_EXPORT(display_cfg);
  • uspace/app/display-cfg/test/seats.c

    r37087c8 r97d3d9d  
    2929#include <errno.h>
    3030#include <pcut/pcut.h>
     31#include "../display-cfg.h"
    3132#include "../seats.h"
    3233
     
    3536PCUT_TEST_SUITE(seats);
    3637
    37 //XXX TODO
     38/** Test dcfg_seats_create() and dcfg_seats_destroy() */
     39PCUT_TEST(create_destroy)
     40{
     41        display_cfg_t *dcfg;
     42        dcfg_seats_t *seats;
     43        errno_t rc;
     44
     45        rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
     46        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     47
     48        rc = dcfg_seats_create(dcfg, &seats);
     49        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     50
     51        dcfg_seats_destroy(seats);
     52        display_cfg_destroy(dcfg);
     53}
     54
     55/** dcfg_seats_insert() inserts an entry into the seat list */
     56PCUT_TEST(seats_insert)
     57{
     58        display_cfg_t *dcfg;
     59        dcfg_seats_t *seats;
     60        dcfg_seats_entry_t *entry = NULL;
     61        errno_t rc;
     62
     63        rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
     64        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     65
     66        rc = dcfg_seats_create(dcfg, &seats);
     67        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     68
     69        rc = dcfg_seats_insert(seats, "Alice", 42, &entry);
     70        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     71        PCUT_ASSERT_NOT_NULL(entry);
     72
     73        PCUT_ASSERT_STR_EQUALS("Alice", entry->name);
     74        PCUT_ASSERT_INT_EQUALS(42, entry->seat_id);
     75
     76        dcfg_seats_destroy(seats);
     77        display_cfg_destroy(dcfg);
     78}
     79
     80//??? Requires us to create a test display config service
     81PCUT_TEST(seats_list_populate)
     82{
     83}
     84
     85/** dcfg_devices_insert() inserts an entry into the device list */
     86PCUT_TEST(devices_insert)
     87{
     88        display_cfg_t *dcfg;
     89        dcfg_seats_t *seats;
     90        ui_list_entry_t *lentry;
     91        dcfg_devices_entry_t *entry;
     92        errno_t rc;
     93
     94        rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
     95        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     96
     97        rc = dcfg_seats_create(dcfg, &seats);
     98        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     99
     100        rc = dcfg_devices_insert(seats, "mydevice", 42);
     101        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     102
     103        lentry = ui_list_first(seats->device_list);
     104        PCUT_ASSERT_NOT_NULL(lentry);
     105        entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry);
     106        PCUT_ASSERT_NOT_NULL(entry);
     107
     108        PCUT_ASSERT_STR_EQUALS("mydevice", entry->name);
     109        PCUT_ASSERT_INT_EQUALS(42, entry->svc_id);
     110
     111        dcfg_seats_destroy(seats);
     112        display_cfg_destroy(dcfg);
     113}
     114
     115PCUT_TEST(avail_devices_insert)
     116{
     117}
     118
     119PCUT_TEST(asgn_dev_list_populate)
     120{
     121}
     122
     123PCUT_TEST(avail_dev_list_populate)
     124{
     125}
     126
     127PCUT_TEST(seats_get_selected)
     128{
     129}
     130
     131PCUT_TEST(devices_get_selected)
     132{
     133}
     134
     135PCUT_TEST(seats_list_selected)
     136{
     137}
     138
     139PCUT_TEST(add_seat_clicked)
     140{
     141}
     142
     143PCUT_TEST(remove_seat_clicked)
     144{
     145}
     146
     147PCUT_TEST(add_seat_dialog_bok)
     148{
     149}
     150
     151PCUT_TEST(add_seat_dialog_bcancel)
     152{
     153}
     154
     155PCUT_TEST(add_seat_dialog_close)
     156{
     157}
     158
     159PCUT_TEST(add_device_clicked)
     160{
     161}
     162
     163PCUT_TEST(remove_device_clicked)
     164{
     165}
     166
     167PCUT_TEST(add_device_dialog_bok)
     168{
     169}
     170
     171PCUT_TEST(add_device_dialog_bcancel)
     172{
     173}
     174
     175PCUT_TEST(add_device_dialog_close)
     176{
     177}
    38178
    39179PCUT_EXPORT(seats);
Note: See TracChangeset for help on using the changeset viewer.