Ignore:
File:
1 edited

Legend:

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

    r7481ee19 r1eaead4  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    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 *);
    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 } test_resp_t;
    8243
    8344/** Allocate and deallocate control */
     
    8748        errno_t rc;
    8849
    89         rc = ui_control_new(&test_ctl_ops, NULL, &control);
     50        rc = ui_control_new(&ui_test_ctl_ops, NULL, &control);
    9051        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    9152        PCUT_ASSERT_NOT_NULL(control);
     
    10364PCUT_TEST(destroy)
    10465{
    105         ui_control_t *control = NULL;
    106         test_resp_t resp;
     66        ui_test_ctl_t *testctl = NULL;
     67        ui_tc_resp_t resp;
    10768        errno_t rc;
    10869
    109         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     70        rc = ui_test_ctl_create(&resp, &testctl);
    11071        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    111         PCUT_ASSERT_NOT_NULL(control);
     72        PCUT_ASSERT_NOT_NULL(testctl);
    11273
    11374        resp.rc = EOK;
    11475        resp.destroy = false;
    11576
    116         ui_control_destroy(control);
     77        ui_control_destroy(ui_test_ctl_ctl(testctl));
    11778        PCUT_ASSERT_TRUE(resp.destroy);
    11879}
     
    12182PCUT_TEST(paint)
    12283{
    123         ui_control_t *control = NULL;
    124         test_resp_t resp;
     84        ui_test_ctl_t *testctl = NULL;
     85        ui_tc_resp_t resp;
    12586        errno_t rc;
    12687
    127         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     88        rc = ui_test_ctl_create(&resp, &testctl);
    12889        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    129         PCUT_ASSERT_NOT_NULL(control);
     90        PCUT_ASSERT_NOT_NULL(testctl);
    13091
    13192        resp.rc = EOK;
    13293        resp.paint = false;
    13394
    134         rc = ui_control_paint(control);
     95        rc = ui_control_paint(ui_test_ctl_ctl(testctl));
    13596        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
    13697        PCUT_ASSERT_TRUE(resp.paint);
     
    139100        resp.paint = false;
    140101
    141         rc = ui_control_paint(control);
     102        rc = ui_control_paint(ui_test_ctl_ctl(testctl));
    142103        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
    143104        PCUT_ASSERT_TRUE(resp.paint);
    144105
    145         ui_control_delete(control);
     106        ui_test_ctl_destroy(testctl);
    146107}
    147108
     
    149110PCUT_TEST(kbd_event)
    150111{
    151         ui_control_t *control = NULL;
    152         test_resp_t resp;
     112        ui_test_ctl_t *testctl = NULL;
     113        ui_tc_resp_t resp;
    153114        kbd_event_t event;
    154115        ui_evclaim_t claim;
    155116        errno_t rc;
    156117
    157         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     118        rc = ui_test_ctl_create(&resp, &testctl);
    158119        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    159         PCUT_ASSERT_NOT_NULL(control);
     120        PCUT_ASSERT_NOT_NULL(testctl);
    160121
    161122        resp.claim = ui_claimed;
     
    166127        event.c = '@';
    167128
    168         claim = ui_control_kbd_event(control, &event);
     129        claim = ui_control_kbd_event(ui_test_ctl_ctl(testctl), &event);
    169130        PCUT_ASSERT_EQUALS(resp.claim, claim);
    170131        PCUT_ASSERT_TRUE(resp.kbd);
     
    174135        PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c);
    175136
    176         ui_control_delete(control);
     137        ui_test_ctl_destroy(testctl);
    177138}
    178139
     
    180141PCUT_TEST(pos_event)
    181142{
    182         ui_control_t *control = NULL;
    183         test_resp_t resp;
     143        ui_test_ctl_t *testctl = NULL;
     144        ui_tc_resp_t resp;
    184145        pos_event_t event;
    185146        ui_evclaim_t claim;
    186147        errno_t rc;
    187148
    188         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     149        rc = ui_test_ctl_create(&resp, &testctl);
    189150        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    190         PCUT_ASSERT_NOT_NULL(control);
     151        PCUT_ASSERT_NOT_NULL(testctl);
    191152
    192153        resp.claim = ui_claimed;
     
    198159        event.vpos = 4;
    199160
    200         claim = ui_control_pos_event(control, &event);
     161        claim = ui_control_pos_event(ui_test_ctl_ctl(testctl), &event);
    201162        PCUT_ASSERT_EQUALS(resp.claim, claim);
    202163        PCUT_ASSERT_TRUE(resp.pos);
     
    207168        PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos);
    208169
    209         ui_control_delete(control);
     170        ui_test_ctl_destroy(testctl);
    210171}
    211172
     
    213174PCUT_TEST(unfocus)
    214175{
    215         ui_control_t *control = NULL;
    216         test_resp_t resp;
     176        ui_test_ctl_t *testctl = NULL;
     177        ui_tc_resp_t resp;
    217178        errno_t rc;
    218179
    219         rc = ui_control_new(&test_ctl_ops, &resp, &control);
     180        rc = ui_test_ctl_create(&resp, &testctl);
    220181        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    221         PCUT_ASSERT_NOT_NULL(control);
     182        PCUT_ASSERT_NOT_NULL(testctl);
    222183
    223184        resp.unfocus = false;
    224185
    225         ui_control_unfocus(control);
     186        ui_control_unfocus(ui_test_ctl_ctl(testctl), 42);
    226187        PCUT_ASSERT_TRUE(resp.unfocus);
     188        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    227189
    228         ui_control_delete(control);
    229 }
    230 
    231 static void test_ctl_destroy(void *arg)
    232 {
    233         test_resp_t *resp = (test_resp_t *) arg;
    234 
    235         resp->destroy = true;
    236 }
    237 
    238 static errno_t test_ctl_paint(void *arg)
    239 {
    240         test_resp_t *resp = (test_resp_t *) arg;
    241 
    242         resp->paint = true;
    243         return resp->rc;
    244 }
    245 
    246 static ui_evclaim_t test_ctl_kbd_event(void *arg, kbd_event_t *event)
    247 {
    248         test_resp_t *resp = (test_resp_t *) arg;
    249 
    250         resp->kbd = true;
    251         resp->kevent = *event;
    252 
    253         return resp->claim;
    254 }
    255 
    256 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event)
    257 {
    258         test_resp_t *resp = (test_resp_t *) arg;
    259 
    260         resp->pos = true;
    261         resp->pevent = *event;
    262 
    263         return resp->claim;
    264 }
    265 
    266 static void test_ctl_unfocus(void *arg)
    267 {
    268         test_resp_t *resp = (test_resp_t *) arg;
    269 
    270         resp->unfocus = true;
     190        ui_test_ctl_destroy(testctl);
    271191}
    272192
Note: See TracChangeset for help on using the changeset viewer.