Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 1aa0e38 in mainline


Ignore:
Timestamp:
2021-04-09T22:01:35Z (6 months ago)
Author:
Jiri Svoboda <jiri@…>
Children:
6de45af0
Parents:
f5a6e25
Message:

UI menu unit tests

Location:
uspace/lib/ui
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/meson.build

    rf5a6e25 r1aa0e38  
    5757        'test/label.c',
    5858        'test/main.c',
     59        'test/menu.c',
     60        'test/menubar.c',
     61        'test/menuentry.c',
    5962        'test/paint.c',
    6063        'test/pbutton.c',
  • uspace/lib/ui/private/menu.h

    rf5a6e25 r1aa0e38  
    3939
    4040#include <adt/list.h>
     41#include <gfx/coord.h>
    4142#include <stdbool.h>
     43#include <types/ui/menu.h>
    4244
    4345/** Actual structure of menu.
  • uspace/lib/ui/private/menubar.h

    rf5a6e25 r1aa0e38  
    4040#include <adt/list.h>
    4141#include <gfx/coord.h>
     42#include <types/ui/menu.h>
    4243#include <types/ui/menubar.h>
    4344
  • uspace/lib/ui/private/menuentry.h

    rf5a6e25 r1aa0e38  
    7676extern void ui_menu_entry_get_geom(ui_menu_entry_t *, gfx_coord2_t *,
    7777    ui_menu_entry_geom_t *);
     78extern void ui_menu_entry_cb(ui_menu_entry_t *);
    7879
    7980#endif
  • uspace/lib/ui/src/menuentry.c

    rf5a6e25 r1aa0e38  
    286286
    287287                /* Call back */
    288                 if (mentry->cb != NULL)
    289                         mentry->cb(mentry, mentry->arg);
    290         }
     288                ui_menu_entry_cb(mentry);
     289        }
     290}
     291
     292/** Call menu entry callback.
     293 *
     294 * @param mentry Menu entry
     295 */
     296void ui_menu_entry_cb(ui_menu_entry_t *mentry)
     297{
     298        if (mentry->cb != NULL)
     299                mentry->cb(mentry, mentry->arg);
    291300}
    292301
  • uspace/lib/ui/test/image.c

    rf5a6e25 r1aa0e38  
    4343PCUT_TEST_SUITE(image);
    4444
    45 typedef struct {
    46         bool clicked;
    47 } test_cb_resp_t;
    48 
    4945/** Create and destroy image */
    5046PCUT_TEST(create_destroy)
  • uspace/lib/ui/test/main.c

    rf5a6e25 r1aa0e38  
    3737PCUT_IMPORT(image);
    3838PCUT_IMPORT(label);
     39PCUT_IMPORT(menu);
     40PCUT_IMPORT(menubar);
     41PCUT_IMPORT(menuentry);
    3942PCUT_IMPORT(paint);
    4043PCUT_IMPORT(pbutton);
  • uspace/lib/ui/test/resource.c

    rf5a6e25 r1aa0e38  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4444static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    4545
     46static void test_expose(void *);
     47
    4648static gfx_context_ops_t ops = {
    4749        .bitmap_create = testgc_bitmap_create,
     
    6870} testgc_bitmap_t;
    6971
     72typedef struct {
     73        bool expose;
     74} test_resp_t;
     75
    7076/** Create and destroy UI resource */
    7177PCUT_TEST(create_destroy)
     
    97103{
    98104        ui_resource_destroy(NULL);
     105}
     106
     107/** ui_resource_set_expose_cb() / ui_resource_expose() */
     108PCUT_TEST(set_expose_cb_expose)
     109{
     110        errno_t rc;
     111        gfx_context_t *gc = NULL;
     112        test_gc_t tgc;
     113        ui_resource_t *resource = NULL;
     114        test_resp_t resp;
     115
     116        memset(&tgc, 0, sizeof(tgc));
     117        rc = gfx_context_new(&ops, &tgc, &gc);
     118        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     119
     120        rc = ui_resource_create(gc, false, &resource);
     121        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     122        PCUT_ASSERT_NOT_NULL(resource);
     123
     124        ui_resource_set_expose_cb(resource, test_expose, &resp);
     125
     126        resp.expose = false;
     127        ui_resource_expose(resource);
     128        PCUT_ASSERT_TRUE(resp.expose);
     129
     130        ui_resource_destroy(resource);
     131
     132        rc = gfx_context_delete(gc);
     133        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    99134}
    100135
     
    161196}
    162197
     198static void test_expose(void *arg)
     199{
     200        test_resp_t *resp = (test_resp_t *) arg;
     201
     202        resp->expose = true;
     203}
     204
    163205PCUT_EXPORT(resource);
Note: See TracChangeset for help on using the changeset viewer.