Changeset 1eaead4 in mainline for uspace/lib/ui/test/control.c


Ignore:
Timestamp:
2023-02-07T16:11:53Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0366d09d
Parents:
7c5320c
Message:

Tab set control

This allows to expand the space available in a dialog window
using stacking, with individual tabs that can be activated
by clicking the handle.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/control.c

    r7c5320c r1eaead4  
    3333#include <pcut/pcut.h>
    3434#include <ui/control.h>
     35#include <ui/testctl.h>
    3536#include <stdbool.h>
    3637#include <types/ui/event.h>
     38#include "../private/testctl.h"
    3739
    3840PCUT_INIT;
    3941
    4042PCUT_TEST_SUITE(control);
    41 
    42 static void test_ctl_destroy(void *);
    43 static errno_t test_ctl_paint(void *);
    44 static ui_evclaim_t test_ctl_kbd_event(void *, kbd_event_t *);
    45 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    46 static void test_ctl_unfocus(void *, unsigned);
    47 
    48 static ui_control_ops_t test_ctl_ops = {
    49         .destroy = test_ctl_destroy,
    50         .paint = test_ctl_paint,
    51         .kbd_event = test_ctl_kbd_event,
    52         .pos_event = test_ctl_pos_event,
    53         .unfocus = test_ctl_unfocus
    54 };
    55 
    56 /** Test response */
    57 typedef struct {
    58         /** Claim to return */
    59         ui_evclaim_t claim;
    60         /** Result code to return */
    61         errno_t rc;
    62 
    63         /** @c true iff destroy was called */
    64         bool destroy;
    65 
    66         /** @c true iff paint was called */
    67         bool paint;
    68 
    69         /** @c true iff kbd_event was called */
    70         bool kbd;
    71         /** Keyboard event that was sent */
    72         kbd_event_t kevent;
    73 
    74         /** @c true iff pos_event was called */
    75         bool pos;
    76         /** Position event that was sent */
    77         pos_event_t pevent;
    78 
    79         /** @c true iff unfocus was called */
    80         bool unfocus;
    81         /** Number of remaining foci that was sent */
    82         unsigned unfocus_nfocus;
    83 } test_resp_t;
    8443
    8544/** Allocate and deallocate control */
     
    8948        errno_t rc;
    9049
    91         rc = ui_control_new(&test_ctl_ops, NULL, &control);
     50        rc = ui_control_new(&ui_test_ctl_ops, NULL, &control);
    9251        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    9352        PCUT_ASSERT_NOT_NULL(control);
     
    10564PCUT_TEST(destroy)
    10665{
    107         ui_control_t *control = NULL;
    108         test_resp_t resp;
     66        ui_test_ctl_t *testctl = NULL;
     67        ui_tc_resp_t resp;
    10968        errno_t rc;
    11069
    111         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     70        rc = ui_test_ctl_create(&resp, &testctl);
    11271        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    113         PCUT_ASSERT_NOT_NULL(control);
     72        PCUT_ASSERT_NOT_NULL(testctl);
    11473
    11574        resp.rc = EOK;
    11675        resp.destroy = false;
    11776
    118         ui_control_destroy(control);
     77        ui_control_destroy(ui_test_ctl_ctl(testctl));
    11978        PCUT_ASSERT_TRUE(resp.destroy);
    12079}
     
    12382PCUT_TEST(paint)
    12483{
    125         ui_control_t *control = NULL;
    126         test_resp_t resp;
     84        ui_test_ctl_t *testctl = NULL;
     85        ui_tc_resp_t resp;
    12786        errno_t rc;
    12887
    129         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     88        rc = ui_test_ctl_create(&resp, &testctl);
    13089        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    131         PCUT_ASSERT_NOT_NULL(control);
     90        PCUT_ASSERT_NOT_NULL(testctl);
    13291
    13392        resp.rc = EOK;
    13493        resp.paint = false;
    13594
    136         rc = ui_control_paint(control);
     95        rc = ui_control_paint(ui_test_ctl_ctl(testctl));
    13796        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
    13897        PCUT_ASSERT_TRUE(resp.paint);
     
    141100        resp.paint = false;
    142101
    143         rc = ui_control_paint(control);
     102        rc = ui_control_paint(ui_test_ctl_ctl(testctl));
    144103        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
    145104        PCUT_ASSERT_TRUE(resp.paint);
    146105
    147         ui_control_delete(control);
     106        ui_test_ctl_destroy(testctl);
    148107}
    149108
     
    151110PCUT_TEST(kbd_event)
    152111{
    153         ui_control_t *control = NULL;
    154         test_resp_t resp;
     112        ui_test_ctl_t *testctl = NULL;
     113        ui_tc_resp_t resp;
    155114        kbd_event_t event;
    156115        ui_evclaim_t claim;
    157116        errno_t rc;
    158117
    159         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     118        rc = ui_test_ctl_create(&resp, &testctl);
    160119        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    161         PCUT_ASSERT_NOT_NULL(control);
     120        PCUT_ASSERT_NOT_NULL(testctl);
    162121
    163122        resp.claim = ui_claimed;
     
    168127        event.c = '@';
    169128
    170         claim = ui_control_kbd_event(control, &event);
     129        claim = ui_control_kbd_event(ui_test_ctl_ctl(testctl), &event);
    171130        PCUT_ASSERT_EQUALS(resp.claim, claim);
    172131        PCUT_ASSERT_TRUE(resp.kbd);
     
    176135        PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c);
    177136
    178         ui_control_delete(control);
     137        ui_test_ctl_destroy(testctl);
    179138}
    180139
     
    182141PCUT_TEST(pos_event)
    183142{
    184         ui_control_t *control = NULL;
    185         test_resp_t resp;
     143        ui_test_ctl_t *testctl = NULL;
     144        ui_tc_resp_t resp;
    186145        pos_event_t event;
    187146        ui_evclaim_t claim;
    188147        errno_t rc;
    189148
    190         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     149        rc = ui_test_ctl_create(&resp, &testctl);
    191150        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    192         PCUT_ASSERT_NOT_NULL(control);
     151        PCUT_ASSERT_NOT_NULL(testctl);
    193152
    194153        resp.claim = ui_claimed;
     
    200159        event.vpos = 4;
    201160
    202         claim = ui_control_pos_event(control, &event);
     161        claim = ui_control_pos_event(ui_test_ctl_ctl(testctl), &event);
    203162        PCUT_ASSERT_EQUALS(resp.claim, claim);
    204163        PCUT_ASSERT_TRUE(resp.pos);
     
    209168        PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos);
    210169
    211         ui_control_delete(control);
     170        ui_test_ctl_destroy(testctl);
    212171}
    213172
     
    215174PCUT_TEST(unfocus)
    216175{
    217         ui_control_t *control = NULL;
    218         test_resp_t resp;
     176        ui_test_ctl_t *testctl = NULL;
     177        ui_tc_resp_t resp;
    219178        errno_t rc;
    220179
    221         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     180        rc = ui_test_ctl_create(&resp, &testctl);
    222181        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    223         PCUT_ASSERT_NOT_NULL(control);
     182        PCUT_ASSERT_NOT_NULL(testctl);
    224183
    225184        resp.unfocus = false;
    226185
    227         ui_control_unfocus(control, 42);
     186        ui_control_unfocus(ui_test_ctl_ctl(testctl), 42);
    228187        PCUT_ASSERT_TRUE(resp.unfocus);
    229188        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    230189
    231         ui_control_delete(control);
    232 }
    233 
    234 static void test_ctl_destroy(void *arg)
    235 {
    236         test_resp_t *resp = (test_resp_t *) arg;
    237 
    238         resp->destroy = true;
    239 }
    240 
    241 static errno_t test_ctl_paint(void *arg)
    242 {
    243         test_resp_t *resp = (test_resp_t *) arg;
    244 
    245         resp->paint = true;
    246         return resp->rc;
    247 }
    248 
    249 static ui_evclaim_t test_ctl_kbd_event(void *arg, kbd_event_t *event)
    250 {
    251         test_resp_t *resp = (test_resp_t *) arg;
    252 
    253         resp->kbd = true;
    254         resp->kevent = *event;
    255 
    256         return resp->claim;
    257 }
    258 
    259 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event)
    260 {
    261         test_resp_t *resp = (test_resp_t *) arg;
    262 
    263         resp->pos = true;
    264         resp->pevent = *event;
    265 
    266         return resp->claim;
    267 }
    268 
    269 static void test_ctl_unfocus(void *arg, unsigned nfocus)
    270 {
    271         test_resp_t *resp = (test_resp_t *) arg;
    272 
    273         resp->unfocus = true;
    274         resp->unfocus_nfocus = nfocus;
     190        ui_test_ctl_destroy(testctl);
    275191}
    276192
Note: See TracChangeset for help on using the changeset viewer.