Changeset 14cbf07 in mainline


Ignore:
Timestamp:
2023-05-15T16:19:52Z (12 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2b5628c, 8a4ceaa
Parents:
aace43d8
Message:

Fill in tests seats_list_populate and avail_devices_insert

Location:
uspace
Files:
9 edited

Legend:

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

    raace43d8 r14cbf07  
    6565 *
    6666 * @param display_spec Display specification
     67 * @param dcfg_svc Display configuration service name or DISPCFG_DEFAULT
    6768 * @param rdcfg Place to store pointer to new display configuration
    6869 * @return EOK on success or an error code
     
    8283                printf("Out of memory.\n");
    8384                return ENOMEM;
    84         }
    85 
    86         rc = dispcfg_open(DISPCFG_DEFAULT, NULL, NULL, &dcfg->dispcfg);
    87         if (rc != EOK) {
    88                 printf("Error opening display configuration service.\n");
    89                 goto error;
    9085        }
    9186
     
    150145        ui_window_add(window, ui_fixed_ctl(dcfg->fixed));
    151146
    152         rc = ui_window_paint(window);
    153         if (rc != EOK) {
    154                 printf("Error painting window.\n");
    155                 return rc;
    156         }
    157 
    158147        *rdcfg = dcfg;
    159148        return EOK;
     
    167156        if (dcfg->ui != NULL)
    168157                ui_destroy(ui);
     158        free(dcfg);
     159        return rc;
     160}
     161
     162/** Open display configuration service.
     163 *
     164 * @param dcfg Display configuration dialog
     165 * @param dcfg_svc Display configuration service name or DISPCFG_DEFAULT
     166 * @return EOK on success or an error code
     167 */
     168errno_t display_cfg_open(display_cfg_t *dcfg, const char *dcfg_svc)
     169{
     170        errno_t rc;
     171
     172        rc = dispcfg_open(dcfg_svc, NULL, NULL, &dcfg->dispcfg);
     173        if (rc != EOK) {
     174                printf("Error opening display configuration service.\n");
     175                goto error;
     176        }
     177
     178        return EOK;
     179error:
     180        return rc;
     181}
     182
     183/** Populate display configuration from isplay configuration service.
     184 *
     185 * @param dcfg Display configuration dialog
     186 * @return EOK on success or an error code
     187 */
     188errno_t display_cfg_populate(display_cfg_t *dcfg)
     189{
     190        errno_t rc;
     191
     192        rc = dcfg_seats_populate(dcfg->seats);
     193        if (rc != EOK)
     194                return rc;
     195
     196        rc = ui_window_paint(dcfg->window);
     197        if (rc != EOK) {
     198                printf("Error painting window.\n");
     199                return rc;
     200        }
     201
     202        return EOK;
     203}
     204
     205/** Destroy display configuration dialog.
     206 *
     207 * @param dcfg Display configuration dialog
     208 */
     209void display_cfg_destroy(display_cfg_t *dcfg)
     210{
    169211        if (dcfg->dispcfg != NULL)
    170212                dispcfg_close(dcfg->dispcfg);
    171         free(dcfg);
    172         return rc;
    173 }
    174 
    175 /** Destroy display configuration dialog.
    176  *
    177  * @param dcfg Display configuration dialog
    178  */
    179 void display_cfg_destroy(display_cfg_t *dcfg)
    180 {
    181213        ui_window_destroy(dcfg->window);
    182214        ui_destroy(dcfg->ui);
  • uspace/app/display-cfg/display-cfg.h

    raace43d8 r14cbf07  
    4040
    4141extern errno_t display_cfg_create(const char *, display_cfg_t **);
     42extern errno_t display_cfg_open(display_cfg_t *, const char *);
     43extern errno_t display_cfg_populate(display_cfg_t *);
    4244extern void display_cfg_destroy(display_cfg_t *);
    4345
  • uspace/app/display-cfg/main.c

    raace43d8 r14cbf07  
    7777                return 1;
    7878
     79        rc = display_cfg_open(dcfg, DISPCFG_DEFAULT);
     80        if (rc != EOK)
     81                return 1;
     82
     83        rc = display_cfg_populate(dcfg);
     84        if (rc != EOK)
     85                return 1;
     86
    7987        ui_run(dcfg->ui);
    8088        display_cfg_destroy(dcfg);
  • uspace/app/display-cfg/seats.c

    raace43d8 r14cbf07  
    5050#include "seats.h"
    5151
    52 static errno_t dcfg_seats_list_populate(dcfg_seats_t *);
    5352static errno_t dcfg_seats_asgn_dev_list_populate(dcfg_seats_t *);
    5453static errno_t dcfg_seats_avail_dev_list_populate(dcfg_seats_t *,
     
    118117        ui_resource_t *ui_res;
    119118        dcfg_seats_t *seats;
    120         dcfg_seats_entry_t *entry;
    121119        gfx_rect_t rect;
    122         char *caption = NULL;
    123         errno_t rc;
    124         int rv;
     120        errno_t rc;
    125121
    126122        ui_res = ui_window_get_res(dcfg->window);
     
    204200        ui_list_set_cb(seats->seat_list, &dcfg_seats_list_cb, (void *)seats);
    205201
    206         rc = dcfg_seats_list_populate(seats);
    207         if (rc != EOK)
    208                 goto error;
    209 
    210202        /* 'Add...' seat button */
    211203
     
    272264        /* 'Devices assigned to seat 'xxx':' label */
    273265
    274         entry = dcfg_seats_get_selected(seats);
    275         rv = asprintf(&caption, "Devices assigned to seat '%s':", entry->name);
    276         if (rv < 0) {
    277                 rc = ENOMEM;
    278                 goto error;
    279         }
    280 
    281         rc = ui_label_create(ui_res, caption, &seats->devices_label);
     266        rc = ui_label_create(ui_res, "Devices assigned to seat 'xxx':",
     267            &seats->devices_label);
    282268        if (rc != EOK) {
    283269                printf("Error creating label.\n");
    284270                goto error;
    285271        }
    286 
    287         free(caption);
    288         caption = NULL;
    289272
    290273        if (ui_resource_is_textmode(ui_res)) {
     
    400383        ui_tab_add(seats->tab, ui_fixed_ctl(seats->fixed));
    401384
    402         rc = dcfg_seats_asgn_dev_list_populate(seats);
    403         if (rc != EOK)
    404                 goto error;
    405 
    406385        *rseats = seats;
    407386        return EOK;
     
    411390        if (seats->add_device != NULL)
    412391                ui_pbutton_destroy(seats->add_device);
    413         if (caption != NULL)
    414                 free(caption);
    415392        if (seats->devices_label != NULL)
    416393                ui_label_destroy(seats->devices_label);
     
    431408}
    432409
     410/** Populate seats tab with display configuration service data
     411 *
     412 * @param dcfg Display configuration dialog
     413 * @param rseats Place to store pointer to new seat configuration tab
     414 * @return EOK on success or an error code
     415 */
     416errno_t dcfg_seats_populate(dcfg_seats_t *seats)
     417{
     418        dcfg_seats_entry_t *entry;
     419        errno_t rc;
     420
     421        printf("seats list populate\n");
     422        rc = dcfg_seats_list_populate(seats);
     423        if (rc != EOK)
     424                return rc;
     425
     426        /*
     427         * Update "Devices assigned to seat 'xxx'" label and populate
     428         * assigned devices list.
     429         */
     430        entry = dcfg_seats_get_selected(seats);
     431        dcfg_seats_list_selected(entry->lentry, (void *)entry);
     432        return EOK;
     433}
     434
    433435/** Destroy display configuration dialog.
    434436 *
     
    511513 * @return EOK on success or an error code
    512514 */
    513 static errno_t dcfg_seats_list_populate(dcfg_seats_t *seats)
     515errno_t dcfg_seats_list_populate(dcfg_seats_t *seats)
    514516{
    515517        size_t i;
     
    594596 * @return EOK on success or an error code
    595597 */
    596 static errno_t dcfg_avail_devices_insert(dcfg_seats_t *seats,
     598errno_t dcfg_avail_devices_insert(dcfg_seats_t *seats,
    597599    ui_select_dialog_t *dialog, const char *name, service_id_t svc_id)
    598600{
  • uspace/app/display-cfg/seats.h

    raace43d8 r14cbf07  
    4141
    4242extern errno_t dcfg_seats_create(display_cfg_t *, dcfg_seats_t **);
     43extern errno_t dcfg_seats_populate(dcfg_seats_t *);
    4344extern void dcfg_seats_destroy(dcfg_seats_t *);
    4445extern errno_t dcfg_seats_insert(dcfg_seats_t *, const char *, sysarg_t,
     
    4647extern errno_t dcfg_devices_insert(dcfg_seats_t *, const char *,
    4748    service_id_t);
     49extern errno_t dcfg_avail_devices_insert(dcfg_seats_t *seats,
     50    ui_select_dialog_t *dialog, const char *name, service_id_t svc_id);
     51extern errno_t dcfg_seats_list_populate(dcfg_seats_t *);
    4852
    4953#endif
  • uspace/app/display-cfg/test/seats.c

    raace43d8 r14cbf07  
    3232#include <errno.h>
    3333#include <pcut/pcut.h>
     34#include <str.h>
    3435#include <testdc.h>
    3536#include "../display-cfg.h"
     
    8586}
    8687
    87 //??? Requires us to create a test display config service
     88/** dcfg_seats_list_populate() populates seat list */
    8889PCUT_TEST(seats_list_populate)
    8990{
     91        display_cfg_t *dcfg;
     92        dcfg_seats_t *seats;
    9093        errno_t rc;
    9194        service_id_t sid;
    92         dispcfg_t *dispcfg = NULL;
    9395        test_response_t resp;
    9496
     
    102104        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    103105
    104         rc = dispcfg_open(test_dispcfg_svc, NULL, NULL, &dispcfg);
    105         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    106         PCUT_ASSERT_NOT_NULL(dispcfg);
    107 
    108         dispcfg_close(dispcfg);
    109         rc = loc_service_unregister(sid);
    110         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     106        rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
     107        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     108
     109        rc = display_cfg_open(dcfg, test_dispcfg_svc);
     110        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     111
     112        rc = dcfg_seats_create(dcfg, &seats);
     113        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     114
     115        /*
     116         * dcfg_seat_list_populate() calls dispcfg_get_seat_list()
     117         * and dispcfg_get_seat_info()
     118         */
     119        resp.rc = EOK;
     120        resp.get_seat_list_rlist = calloc(1, sizeof(dispcfg_seat_list_t));
     121        PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist);
     122        resp.get_seat_list_rlist->nseats = 1;
     123        resp.get_seat_list_rlist->seats = calloc(1, sizeof(sysarg_t));
     124        PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist->seats);
     125        resp.get_seat_list_rlist->seats[0] = 42;
     126
     127        resp.get_seat_info_rinfo = calloc(1, sizeof(dispcfg_seat_info_t));
     128        PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo);
     129        resp.get_seat_info_rinfo->name = str_dup("Alice");
     130        PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo->name);
     131
     132        rc = dcfg_seats_list_populate(seats);
     133        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     134
     135        dcfg_seats_destroy(seats);
     136        display_cfg_destroy(dcfg);
    111137}
    112138
     
    141167}
    142168
     169/** dcfg_avail_devices_insert() inserts entry into available devices list */
    143170PCUT_TEST(avail_devices_insert)
    144171{
     172        display_cfg_t *dcfg;
     173        dcfg_seats_t *seats;
     174        ui_list_entry_t *lentry;
     175        dcfg_devices_entry_t *entry;
     176        ui_select_dialog_t *dialog;
     177        ui_select_dialog_params_t sdparams;
     178        errno_t rc;
     179
     180        rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
     181        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     182
     183        rc = dcfg_seats_create(dcfg, &seats);
     184        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     185
     186        ui_select_dialog_params_init(&sdparams);
     187        sdparams.caption = "Dialog";
     188        sdparams.prompt = "Select";
     189
     190        rc = ui_select_dialog_create(seats->dcfg->ui, &sdparams, &dialog);
     191        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     192
     193        rc = dcfg_avail_devices_insert(seats, dialog, "mydevice", 42);
     194        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     195
     196        lentry = ui_list_first(ui_select_dialog_list(dialog));
     197        PCUT_ASSERT_NOT_NULL(lentry);
     198        entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry);
     199        PCUT_ASSERT_NOT_NULL(entry);
     200
     201        PCUT_ASSERT_STR_EQUALS("mydevice", entry->name);
     202        PCUT_ASSERT_INT_EQUALS(42, entry->svc_id);
     203
     204        ui_select_dialog_destroy(dialog);
     205        dcfg_seats_destroy(seats);
     206        display_cfg_destroy(dcfg);
    145207}
    146208
  • uspace/lib/ui/include/ui/selectdialog.h

    raace43d8 r14cbf07  
    5151    ui_list_entry_attr_t *);
    5252extern errno_t ui_select_dialog_paint(ui_select_dialog_t *);
     53extern ui_list_t *ui_select_dialog_list(ui_select_dialog_t *);
    5354
    5455#endif
  • uspace/lib/ui/src/selectdialog.c

    raace43d8 r14cbf07  
    329329}
    330330
     331/** Get the entry list from select dialog.
     332 *
     333 * @param dialog Select dialog
     334 * @return UI list
     335 */
     336ui_list_t *ui_select_dialog_list(ui_select_dialog_t *dialog)
     337{
     338        return dialog->list;
     339}
     340
    331341/** Select dialog window close handler.
    332342 *
  • uspace/lib/ui/test/selectdialog.c

    raace43d8 r14cbf07  
    310310}
    311311
     312/** ui_select_dialog_list() returns the UI list */
     313PCUT_TEST(list)
     314{
     315        errno_t rc;
     316        ui_t *ui = NULL;
     317        ui_select_dialog_params_t params;
     318        ui_select_dialog_t *dialog = NULL;
     319        ui_list_t *list;
     320        ui_list_entry_attr_t attr;
     321
     322        rc = ui_create_disp(NULL, &ui);
     323        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     324
     325        ui_select_dialog_params_init(&params);
     326        params.caption = "Select one";
     327        params.prompt = "Please select";
     328
     329        rc = ui_select_dialog_create(ui, &params, &dialog);
     330        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     331        PCUT_ASSERT_NOT_NULL(dialog);
     332
     333        list = ui_select_dialog_list(dialog);
     334        PCUT_ASSERT_NOT_NULL(list);
     335
     336        PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(list));
     337
     338        /* Add one entry */
     339        ui_list_entry_attr_init(&attr);
     340        attr.caption = "Entry";
     341        rc = ui_select_dialog_append(dialog, &attr);
     342        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     343
     344        PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(list));
     345
     346        ui_select_dialog_destroy(dialog);
     347        ui_destroy(ui);
     348}
     349
    312350static void test_dialog_bok(ui_select_dialog_t *dialog, void *arg,
    313351    void *earg)
Note: See TracChangeset for help on using the changeset viewer.