Changeset 3d10a2f in mainline


Ignore:
Timestamp:
2021-10-04T12:25:43Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cd981f2a, e0e1b3d
Parents:
6d172f6
git-author:
Jiri Svoboda <jiri@…> (2021-10-03 17:25:36)
git-committer:
Jiri Svoboda <jiri@…> (2021-10-04 12:25:43)
Message:

Null display spec for the benefit of unit testing

When testing something that takes a display specification as argument,
it is useful to be able to be able to specify dummy output (so far,
only ui_create_disp() could create a UI with dummy output.

Location:
uspace/lib/ui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/types/ui/ui.h

    r6d172f6 r3d10a2f  
    4646/** Use the default console service (argument to ui_create()) */
    4747#define UI_CONSOLE_DEFAULT "cons@"
     48/** Use dummy output (argument to ui_create()) */
     49#define UI_DISPLAY_NULL "null@"
    4850
    4951/** Window system */
     
    5456        ui_ws_display,
    5557        /** Console */
    56         ui_ws_console
     58        ui_ws_console,
     59        /** Dummy output */
     60        ui_ws_null
    5761} ui_winsys_t;
    5862
  • uspace/lib/ui/include/ui/window.h

    r6d172f6 r3d10a2f  
    5656extern ui_window_t *ui_window_get_active(ui_t *);
    5757extern errno_t ui_window_resize(ui_window_t *, gfx_rect_t *);
     58extern ui_t *ui_window_get_ui(ui_window_t *);
    5859extern ui_resource_t *ui_window_get_res(ui_window_t *);
    5960extern gfx_context_t *ui_window_get_gc(ui_window_t *);
  • uspace/lib/ui/src/ui.c

    r6d172f6 r3d10a2f  
    5555 *
    5656 * Output specification has the form <proto>@<service> where proto is
    57  * eiher 'disp' for display service or 'cons' for console. Service
    58  * is a location ID service name (e.g. hid/display).
     57 * eiher 'disp' for display service, 'cons' for console, 'null'
     58 * for dummy output. Service is a location ID service name (e.g. hid/display).
    5959 *
    6060 * @param ospec Output specification
     
    8282                } else if (str_lcmp(ospec, "cons@", str_length("cons@")) == 0) {
    8383                        *ws = ui_ws_console;
     84                } else if (str_lcmp(ospec, "null@", str_length("null@")) == 0) {
     85                        *ws = ui_ws_null;
    8486                } else {
    8587                        *ws = ui_ws_unknown;
     
    99101 *
    100102 * @param ospec Output specification or @c UI_DISPLAY_DEFAULT to use
    101  *              the default output
     103 *              the default display service, UI_CONSOLE_DEFAULT to use
     104 *              the default console service, UI_DISPLAY_NULL to use
     105 *              dummy output.
    102106 * @param rui Place to store pointer to new UI
    103107 * @return EOK on success or an error code
     
    161165
    162166                (void) ui_paint(ui);
     167        } else if (ws == ui_ws_null) {
     168                rc = ui_create_disp(NULL, &ui);
     169                if (rc != EOK)
     170                        return rc;
    163171        } else {
    164172                return EINVAL;
  • uspace/lib/ui/src/window.c

    r6d172f6 r3d10a2f  
    601601}
    602602
     603/** Get window's containing UI.
     604 *
     605 * @param window Window
     606 * @return Containing UI
     607 */
     608ui_t *ui_window_get_ui(ui_window_t *window)
     609{
     610        return window->ui;
     611}
     612
    603613/** Get UI resource from window.
    604614 *
  • uspace/lib/ui/test/window.c

    r6d172f6 r3d10a2f  
    258258}
    259259
     260/** ui_window_get_ui() returns containing UI */
     261PCUT_TEST(get_ui)
     262{
     263        errno_t rc;
     264        ui_t *ui = NULL;
     265        ui_t *rui;
     266        ui_wnd_params_t params;
     267        ui_window_t *window = NULL;
     268
     269        rc = ui_create_disp(NULL, &ui);
     270        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     271
     272        ui_wnd_params_init(&params);
     273        params.caption = "Hello";
     274
     275        rc = ui_window_create(ui, &params, &window);
     276        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     277        PCUT_ASSERT_NOT_NULL(window);
     278
     279        rui = ui_window_get_ui(window);
     280        PCUT_ASSERT_EQUALS(ui, rui);
     281
     282        ui_window_destroy(window);
     283        ui_destroy(ui);
     284}
     285
    260286/** ui_window_get_res/gc/rect() return valid objects */
    261287PCUT_TEST(get_res_gc_rect)
Note: See TracChangeset for help on using the changeset viewer.