[f7a90df] | 1 | /*
|
---|
[2ab8ab3] | 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
[f7a90df] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[d284ce9] | 29 | #include <gfx/context.h>
|
---|
| 30 | #include <gfx/coord.h>
|
---|
[66a2becf] | 31 | #include <gfx/render.h>
|
---|
[f03d1308] | 32 | #include <io/kbd_event.h>
|
---|
[d284ce9] | 33 | #include <io/pos_event.h>
|
---|
[f7a90df] | 34 | #include <mem.h>
|
---|
| 35 | #include <pcut/pcut.h>
|
---|
| 36 | #include <stdbool.h>
|
---|
[b71c0fc] | 37 | #include <ui/control.h>
|
---|
[3583ffb] | 38 | #include <ui/resource.h>
|
---|
[f7a90df] | 39 | #include <ui/ui.h>
|
---|
| 40 | #include <ui/window.h>
|
---|
| 41 | #include "../private/window.h"
|
---|
| 42 |
|
---|
| 43 | PCUT_INIT;
|
---|
| 44 |
|
---|
| 45 | PCUT_TEST_SUITE(window);
|
---|
| 46 |
|
---|
[d284ce9] | 47 | static void test_window_close(ui_window_t *, void *);
|
---|
[f03d1308] | 48 | static void test_window_focus(ui_window_t *, void *);
|
---|
| 49 | static void test_window_kbd(ui_window_t *, void *, kbd_event_t *);
|
---|
[fa01c05] | 50 | static errno_t test_window_paint(ui_window_t *, void *);
|
---|
[d284ce9] | 51 | static void test_window_pos(ui_window_t *, void *, pos_event_t *);
|
---|
[f03d1308] | 52 | static void test_window_unfocus(ui_window_t *, void *);
|
---|
[d284ce9] | 53 |
|
---|
| 54 | static ui_window_cb_t test_window_cb = {
|
---|
| 55 | .close = test_window_close,
|
---|
[f03d1308] | 56 | .focus = test_window_focus,
|
---|
| 57 | .kbd = test_window_kbd,
|
---|
[fa01c05] | 58 | .paint = test_window_paint,
|
---|
[f03d1308] | 59 | .pos = test_window_pos,
|
---|
| 60 | .unfocus = test_window_unfocus
|
---|
[d284ce9] | 61 | };
|
---|
| 62 |
|
---|
| 63 | static ui_window_cb_t dummy_window_cb = {
|
---|
| 64 | };
|
---|
| 65 |
|
---|
[b71c0fc] | 66 | static errno_t test_ctl_paint(void *);
|
---|
| 67 | static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
|
---|
| 68 |
|
---|
| 69 | static ui_control_ops_t test_ctl_ops = {
|
---|
| 70 | .paint = test_ctl_paint,
|
---|
| 71 | .pos_event = test_ctl_pos_event
|
---|
| 72 | };
|
---|
| 73 |
|
---|
[d284ce9] | 74 | typedef struct {
|
---|
[fa01c05] | 75 | errno_t rc;
|
---|
[d284ce9] | 76 | bool close;
|
---|
[f03d1308] | 77 | bool focus;
|
---|
| 78 | bool kbd;
|
---|
| 79 | kbd_event_t kbd_event;
|
---|
[fa01c05] | 80 | bool paint;
|
---|
[d284ce9] | 81 | bool pos;
|
---|
| 82 | pos_event_t pos_event;
|
---|
[f03d1308] | 83 | bool unfocus;
|
---|
[d284ce9] | 84 | } test_cb_resp_t;
|
---|
| 85 |
|
---|
[b71c0fc] | 86 | typedef struct {
|
---|
| 87 | errno_t rc;
|
---|
| 88 | ui_evclaim_t claim;
|
---|
| 89 | bool paint;
|
---|
| 90 | bool pos;
|
---|
| 91 | pos_event_t pos_event;
|
---|
| 92 | } test_ctl_resp_t;
|
---|
| 93 |
|
---|
[f7a90df] | 94 | /** Create and destroy window */
|
---|
| 95 | PCUT_TEST(create_destroy)
|
---|
| 96 | {
|
---|
| 97 | errno_t rc;
|
---|
| 98 | ui_t *ui = NULL;
|
---|
[d284ce9] | 99 | ui_wnd_params_t params;
|
---|
[f7a90df] | 100 | ui_window_t *window = NULL;
|
---|
| 101 |
|
---|
| 102 | rc = ui_create_disp(NULL, &ui);
|
---|
| 103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 104 |
|
---|
[d284ce9] | 105 | ui_wnd_params_init(¶ms);
|
---|
[f7a90df] | 106 | params.caption = "Hello";
|
---|
| 107 |
|
---|
| 108 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 109 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 110 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 111 |
|
---|
| 112 | ui_window_destroy(window);
|
---|
| 113 | ui_destroy(ui);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /** ui_window_destroy() can take NULL argument (no-op) */
|
---|
| 117 | PCUT_TEST(destroy_null)
|
---|
| 118 | {
|
---|
| 119 | ui_window_destroy(NULL);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[b71c0fc] | 122 | /** ui_window_add()/ui_window_remove() ... */
|
---|
| 123 | PCUT_TEST(add_remove)
|
---|
| 124 | {
|
---|
| 125 | errno_t rc;
|
---|
| 126 | ui_t *ui = NULL;
|
---|
| 127 | ui_wnd_params_t params;
|
---|
| 128 | ui_window_t *window = NULL;
|
---|
| 129 | ui_control_t *control = NULL;
|
---|
| 130 | test_ctl_resp_t resp;
|
---|
| 131 |
|
---|
| 132 | rc = ui_create_disp(NULL, &ui);
|
---|
| 133 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 134 |
|
---|
| 135 | ui_wnd_params_init(¶ms);
|
---|
| 136 | params.caption = "Hello";
|
---|
| 137 |
|
---|
| 138 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 139 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 140 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 141 |
|
---|
| 142 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 143 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 144 |
|
---|
| 145 | /* Control not called since it hasn't been added yet */
|
---|
| 146 | resp.rc = ENOMEM;
|
---|
| 147 | resp.paint = false;
|
---|
| 148 | rc = ui_window_def_paint(window);
|
---|
| 149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 150 | PCUT_ASSERT_FALSE(resp.paint);
|
---|
| 151 |
|
---|
| 152 | ui_window_add(window, control);
|
---|
| 153 |
|
---|
| 154 | /* Now paint request should be delivered to control */
|
---|
| 155 | resp.rc = EOK;
|
---|
| 156 | resp.paint = false;
|
---|
| 157 | rc = ui_window_def_paint(window);
|
---|
| 158 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 159 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 160 |
|
---|
| 161 | ui_window_remove(window, control);
|
---|
| 162 |
|
---|
| 163 | /*
|
---|
| 164 | * After having removed the control the request should no longer
|
---|
| 165 | * be delivered to it.
|
---|
| 166 | */
|
---|
| 167 | resp.rc = ENOMEM;
|
---|
| 168 | resp.paint = false;
|
---|
| 169 | rc = ui_window_def_paint(window);
|
---|
| 170 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 171 | PCUT_ASSERT_FALSE(resp.paint);
|
---|
| 172 |
|
---|
| 173 | ui_window_destroy(window);
|
---|
| 174 | ui_destroy(ui);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[0576df9] | 177 | /** ui_window_resize */
|
---|
| 178 | PCUT_TEST(resize)
|
---|
| 179 | {
|
---|
| 180 | errno_t rc;
|
---|
| 181 | ui_t *ui = NULL;
|
---|
| 182 | ui_wnd_params_t params;
|
---|
| 183 | ui_window_t *window = NULL;
|
---|
| 184 | gfx_rect_t nrect;
|
---|
| 185 |
|
---|
| 186 | rc = ui_create_disp(NULL, &ui);
|
---|
| 187 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 188 |
|
---|
| 189 | ui_wnd_params_init(¶ms);
|
---|
| 190 | params.caption = "Hello";
|
---|
| 191 | params.rect.p0.x = 0;
|
---|
| 192 | params.rect.p0.y = 0;
|
---|
| 193 | params.rect.p1.x = 1;
|
---|
| 194 | params.rect.p1.y = 1;
|
---|
| 195 |
|
---|
| 196 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 197 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 198 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 199 |
|
---|
| 200 | nrect.p0.x = -1;
|
---|
| 201 | nrect.p0.y = -1;
|
---|
| 202 | nrect.p1.x = 2;
|
---|
| 203 | nrect.p1.y = 2;
|
---|
| 204 | rc = ui_window_resize(window, &nrect);
|
---|
| 205 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 206 |
|
---|
| 207 | ui_window_destroy(window);
|
---|
| 208 | ui_destroy(ui);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[3583ffb] | 211 | /** ui_window_get_res/gc/rect() return valid objects */
|
---|
| 212 | PCUT_TEST(get_res_gc_rect)
|
---|
[d284ce9] | 213 | {
|
---|
| 214 | errno_t rc;
|
---|
| 215 | ui_t *ui = NULL;
|
---|
| 216 | ui_wnd_params_t params;
|
---|
| 217 | ui_window_t *window = NULL;
|
---|
[3583ffb] | 218 | ui_resource_t *res;
|
---|
[d284ce9] | 219 | gfx_context_t *gc;
|
---|
| 220 | gfx_rect_t rect;
|
---|
| 221 |
|
---|
| 222 | rc = ui_create_disp(NULL, &ui);
|
---|
| 223 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 224 |
|
---|
| 225 | ui_wnd_params_init(¶ms);
|
---|
| 226 | params.caption = "Hello";
|
---|
| 227 |
|
---|
| 228 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 229 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 230 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 231 |
|
---|
[3583ffb] | 232 | res = ui_window_get_res(window);
|
---|
| 233 | PCUT_ASSERT_NOT_NULL(res);
|
---|
| 234 |
|
---|
[d284ce9] | 235 | gc = ui_window_get_gc(window);
|
---|
| 236 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
| 237 |
|
---|
| 238 | ui_window_get_app_rect(window, &rect);
|
---|
| 239 |
|
---|
| 240 | ui_window_destroy(window);
|
---|
| 241 | ui_destroy(ui);
|
---|
| 242 | }
|
---|
| 243 |
|
---|
[66a2becf] | 244 | /** ui_window_get_app_gc() return valid GC */
|
---|
| 245 | PCUT_TEST(get_app_gc)
|
---|
| 246 | {
|
---|
| 247 | errno_t rc;
|
---|
| 248 | ui_t *ui = NULL;
|
---|
| 249 | ui_wnd_params_t params;
|
---|
| 250 | ui_window_t *window = NULL;
|
---|
| 251 | gfx_context_t *gc;
|
---|
| 252 |
|
---|
| 253 | rc = ui_create_disp(NULL, &ui);
|
---|
| 254 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 255 |
|
---|
| 256 | ui_wnd_params_init(¶ms);
|
---|
| 257 | params.caption = "Hello";
|
---|
| 258 | params.rect.p0.x = 0;
|
---|
| 259 | params.rect.p0.y = 0;
|
---|
[2ab8ab3] | 260 | params.rect.p0.x = 100;
|
---|
| 261 | params.rect.p0.y = 100;
|
---|
[66a2becf] | 262 |
|
---|
| 263 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 264 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 265 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 266 |
|
---|
| 267 | rc = ui_window_get_app_gc(window, &gc);
|
---|
| 268 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 269 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
| 270 |
|
---|
| 271 | rc = gfx_fill_rect(gc, ¶ms.rect);
|
---|
| 272 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 273 |
|
---|
| 274 | ui_window_destroy(window);
|
---|
| 275 | ui_destroy(ui);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
[fa01c05] | 278 | /** Test ui_window_paint() */
|
---|
| 279 | PCUT_TEST(paint)
|
---|
| 280 | {
|
---|
| 281 | errno_t rc;
|
---|
| 282 | ui_t *ui = NULL;
|
---|
| 283 | ui_wnd_params_t params;
|
---|
| 284 | ui_window_t *window = NULL;
|
---|
| 285 |
|
---|
| 286 | rc = ui_create_disp(NULL, &ui);
|
---|
| 287 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 288 |
|
---|
| 289 | ui_wnd_params_init(¶ms);
|
---|
| 290 | params.caption = "Hello";
|
---|
| 291 |
|
---|
| 292 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 293 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 294 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 295 |
|
---|
| 296 | ui_window_paint(window);
|
---|
| 297 |
|
---|
| 298 | ui_window_destroy(window);
|
---|
| 299 | ui_destroy(ui);
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | /** Test ui_window_def_paint() */
|
---|
| 303 | PCUT_TEST(def_paint)
|
---|
| 304 | {
|
---|
| 305 | errno_t rc;
|
---|
| 306 | ui_t *ui = NULL;
|
---|
| 307 | ui_wnd_params_t params;
|
---|
| 308 | ui_window_t *window = NULL;
|
---|
[b71c0fc] | 309 | ui_control_t *control = NULL;
|
---|
| 310 | test_ctl_resp_t resp;
|
---|
[fa01c05] | 311 |
|
---|
| 312 | rc = ui_create_disp(NULL, &ui);
|
---|
| 313 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 314 |
|
---|
| 315 | ui_wnd_params_init(¶ms);
|
---|
| 316 | params.caption = "Hello";
|
---|
| 317 |
|
---|
| 318 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 319 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 320 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 321 |
|
---|
[b71c0fc] | 322 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 323 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 324 |
|
---|
| 325 | ui_window_add(window, control);
|
---|
| 326 |
|
---|
| 327 | resp.rc = EOK;
|
---|
| 328 | resp.paint = false;
|
---|
| 329 | rc = ui_window_def_paint(window);
|
---|
| 330 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 331 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 332 |
|
---|
| 333 | resp.rc = ENOMEM;
|
---|
| 334 | resp.paint = false;
|
---|
| 335 | rc = ui_window_def_paint(window);
|
---|
| 336 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 337 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 338 |
|
---|
| 339 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 340 |
|
---|
| 341 | /* Need to remove first because we didn't implement the destructor */
|
---|
| 342 | ui_window_remove(window, control);
|
---|
| 343 |
|
---|
| 344 | ui_window_destroy(window);
|
---|
| 345 | ui_destroy(ui);
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | /** ui_window_def_pos() delivers position event to control in window */
|
---|
| 349 | PCUT_TEST(def_pos)
|
---|
| 350 | {
|
---|
| 351 | errno_t rc;
|
---|
| 352 | ui_t *ui = NULL;
|
---|
| 353 | ui_wnd_params_t params;
|
---|
| 354 | ui_window_t *window = NULL;
|
---|
| 355 | ui_control_t *control = NULL;
|
---|
| 356 | test_ctl_resp_t resp;
|
---|
| 357 | pos_event_t event;
|
---|
| 358 |
|
---|
| 359 | rc = ui_create_disp(NULL, &ui);
|
---|
| 360 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 361 |
|
---|
| 362 | ui_wnd_params_init(¶ms);
|
---|
| 363 | params.caption = "Hello";
|
---|
| 364 |
|
---|
| 365 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 366 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 367 |
|
---|
| 368 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 369 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 370 |
|
---|
| 371 | ui_window_add(window, control);
|
---|
| 372 |
|
---|
| 373 | event.pos_id = 1;
|
---|
| 374 | event.type = POS_PRESS;
|
---|
| 375 | event.btn_num = 2;
|
---|
| 376 | event.hpos = 3;
|
---|
| 377 | event.vpos = 4;
|
---|
| 378 |
|
---|
| 379 | resp.pos = false;
|
---|
| 380 | resp.claim = ui_claimed;
|
---|
| 381 |
|
---|
| 382 | ui_window_def_pos(window, &event);
|
---|
| 383 |
|
---|
| 384 | PCUT_ASSERT_TRUE(resp.pos);
|
---|
| 385 | PCUT_ASSERT_INT_EQUALS(event.pos_id, resp.pos_event.pos_id);
|
---|
| 386 | PCUT_ASSERT_INT_EQUALS(event.type, resp.pos_event.type);
|
---|
| 387 | PCUT_ASSERT_INT_EQUALS(event.btn_num, resp.pos_event.btn_num);
|
---|
| 388 | PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos_event.hpos);
|
---|
| 389 | PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos_event.vpos);
|
---|
| 390 |
|
---|
| 391 | /* Need to remove first because we didn't implement the destructor */
|
---|
| 392 | ui_window_remove(window, control);
|
---|
[fa01c05] | 393 |
|
---|
| 394 | ui_window_destroy(window);
|
---|
| 395 | ui_destroy(ui);
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | /** ui_window_send_close() calls close callback set via ui_window_set_cb() */
|
---|
| 399 | PCUT_TEST(send_close)
|
---|
[d284ce9] | 400 | {
|
---|
| 401 | errno_t rc;
|
---|
| 402 | ui_t *ui = NULL;
|
---|
| 403 | ui_wnd_params_t params;
|
---|
| 404 | ui_window_t *window = NULL;
|
---|
| 405 | test_cb_resp_t resp;
|
---|
| 406 |
|
---|
| 407 | rc = ui_create_disp(NULL, &ui);
|
---|
| 408 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 409 |
|
---|
| 410 | ui_wnd_params_init(¶ms);
|
---|
| 411 | params.caption = "Hello";
|
---|
| 412 |
|
---|
| 413 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 414 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 415 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 416 |
|
---|
| 417 | /* Close callback with no callbacks set */
|
---|
[fa01c05] | 418 | ui_window_send_close(window);
|
---|
[d284ce9] | 419 |
|
---|
| 420 | /* Close callback with close callback not implemented */
|
---|
| 421 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 422 | ui_window_send_close(window);
|
---|
[d284ce9] | 423 |
|
---|
| 424 | /* Close callback with real callback set */
|
---|
| 425 | resp.close = false;
|
---|
| 426 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 427 | ui_window_send_close(window);
|
---|
[d284ce9] | 428 | PCUT_ASSERT_TRUE(resp.close);
|
---|
| 429 |
|
---|
| 430 | ui_window_destroy(window);
|
---|
| 431 | ui_destroy(ui);
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[fa01c05] | 434 | /** ui_window_send_focus() calls focus callback set via ui_window_set_cb() */
|
---|
| 435 | PCUT_TEST(send_focus)
|
---|
[f03d1308] | 436 | {
|
---|
| 437 | errno_t rc;
|
---|
| 438 | ui_t *ui = NULL;
|
---|
| 439 | ui_wnd_params_t params;
|
---|
| 440 | ui_window_t *window = NULL;
|
---|
| 441 | test_cb_resp_t resp;
|
---|
| 442 |
|
---|
| 443 | rc = ui_create_disp(NULL, &ui);
|
---|
| 444 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 445 |
|
---|
| 446 | ui_wnd_params_init(¶ms);
|
---|
| 447 | params.caption = "Hello";
|
---|
| 448 |
|
---|
| 449 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 450 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 451 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 452 |
|
---|
| 453 | /* Focus callback with no callbacks set */
|
---|
[fa01c05] | 454 | ui_window_send_focus(window);
|
---|
[f03d1308] | 455 |
|
---|
| 456 | /* Focus callback with focus callback not implemented */
|
---|
| 457 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 458 | ui_window_send_focus(window);
|
---|
[f03d1308] | 459 |
|
---|
| 460 | /* Focus callback with real callback set */
|
---|
[fa01c05] | 461 | resp.focus = false;
|
---|
[f03d1308] | 462 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 463 | ui_window_send_focus(window);
|
---|
[f03d1308] | 464 | PCUT_ASSERT_TRUE(resp.focus);
|
---|
| 465 |
|
---|
| 466 | ui_window_destroy(window);
|
---|
| 467 | ui_destroy(ui);
|
---|
| 468 | }
|
---|
| 469 |
|
---|
[fa01c05] | 470 | /** ui_window_send_kbd() calls kbd callback set via ui_window_set_cb() */
|
---|
| 471 | PCUT_TEST(send_kbd)
|
---|
[f03d1308] | 472 | {
|
---|
| 473 | errno_t rc;
|
---|
| 474 | ui_t *ui = NULL;
|
---|
| 475 | ui_wnd_params_t params;
|
---|
| 476 | ui_window_t *window = NULL;
|
---|
| 477 | kbd_event_t kbd_event;
|
---|
| 478 | test_cb_resp_t resp;
|
---|
| 479 |
|
---|
| 480 | rc = ui_create_disp(NULL, &ui);
|
---|
| 481 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 482 |
|
---|
| 483 | ui_wnd_params_init(¶ms);
|
---|
| 484 | params.caption = "Hello";
|
---|
| 485 |
|
---|
| 486 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 487 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 488 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 489 |
|
---|
| 490 | kbd_event.type = POS_PRESS;
|
---|
| 491 | kbd_event.key = KC_X;
|
---|
| 492 | kbd_event.mods = 0;
|
---|
| 493 | kbd_event.c = 'x';
|
---|
| 494 |
|
---|
| 495 | /* Kbd callback with no callbacks set */
|
---|
[fa01c05] | 496 | ui_window_send_kbd(window, &kbd_event);
|
---|
[f03d1308] | 497 |
|
---|
| 498 | /* Kbd callback with kbd callback not implemented */
|
---|
| 499 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 500 | ui_window_send_kbd(window, &kbd_event);
|
---|
[f03d1308] | 501 |
|
---|
| 502 | /* Kbd callback with real callback set */
|
---|
| 503 | resp.kbd = false;
|
---|
| 504 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 505 | ui_window_send_kbd(window, &kbd_event);
|
---|
[f03d1308] | 506 | PCUT_ASSERT_TRUE(resp.kbd);
|
---|
| 507 | PCUT_ASSERT_EQUALS(kbd_event.type, resp.kbd_event.type);
|
---|
| 508 | PCUT_ASSERT_INT_EQUALS(kbd_event.key, resp.kbd_event.key);
|
---|
| 509 | PCUT_ASSERT_INT_EQUALS(kbd_event.mods, resp.kbd_event.mods);
|
---|
| 510 | PCUT_ASSERT_INT_EQUALS(kbd_event.c, resp.kbd_event.c);
|
---|
| 511 |
|
---|
| 512 | ui_window_destroy(window);
|
---|
| 513 | ui_destroy(ui);
|
---|
| 514 | }
|
---|
| 515 |
|
---|
[fa01c05] | 516 | /** ui_window_send_paint() calls paint callback set via ui_window_set_cb() */
|
---|
| 517 | PCUT_TEST(send_paint)
|
---|
| 518 | {
|
---|
| 519 | errno_t rc;
|
---|
| 520 | ui_t *ui = NULL;
|
---|
| 521 | ui_wnd_params_t params;
|
---|
| 522 | ui_window_t *window = NULL;
|
---|
| 523 | test_cb_resp_t resp;
|
---|
| 524 |
|
---|
| 525 | rc = ui_create_disp(NULL, &ui);
|
---|
| 526 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 527 |
|
---|
| 528 | ui_wnd_params_init(¶ms);
|
---|
| 529 | params.caption = "Hello";
|
---|
| 530 |
|
---|
| 531 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 532 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 533 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 534 |
|
---|
| 535 | /* Paint callback with no callbacks set */
|
---|
| 536 | ui_window_send_paint(window);
|
---|
| 537 |
|
---|
| 538 | /* Paint callback with paint callback not implemented */
|
---|
| 539 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
| 540 | ui_window_send_paint(window);
|
---|
| 541 |
|
---|
| 542 | /* Paint callback with real callback set */
|
---|
| 543 | resp.paint = false;
|
---|
| 544 | resp.rc = EOK;
|
---|
| 545 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
| 546 | rc = ui_window_send_paint(window);
|
---|
| 547 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 548 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 549 |
|
---|
| 550 | ui_window_destroy(window);
|
---|
| 551 | ui_destroy(ui);
|
---|
| 552 | }
|
---|
| 553 |
|
---|
| 554 | /** ui_window_send_pos() calls pos callback set via ui_window_set_cb() */
|
---|
| 555 | PCUT_TEST(send_pos)
|
---|
[d284ce9] | 556 | {
|
---|
| 557 | errno_t rc;
|
---|
| 558 | ui_t *ui = NULL;
|
---|
| 559 | ui_wnd_params_t params;
|
---|
| 560 | ui_window_t *window = NULL;
|
---|
| 561 | pos_event_t pos_event;
|
---|
| 562 | test_cb_resp_t resp;
|
---|
| 563 |
|
---|
| 564 | rc = ui_create_disp(NULL, &ui);
|
---|
| 565 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 566 |
|
---|
| 567 | ui_wnd_params_init(¶ms);
|
---|
| 568 | params.caption = "Hello";
|
---|
| 569 |
|
---|
| 570 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 571 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 572 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 573 |
|
---|
| 574 | pos_event.pos_id = 1;
|
---|
| 575 | pos_event.type = POS_PRESS;
|
---|
| 576 | pos_event.btn_num = 2;
|
---|
| 577 | pos_event.hpos = 3;
|
---|
| 578 | pos_event.vpos = 4;
|
---|
| 579 |
|
---|
| 580 | /* Pos callback with no callbacks set */
|
---|
[fa01c05] | 581 | ui_window_send_pos(window, &pos_event);
|
---|
[d284ce9] | 582 |
|
---|
| 583 | /* Pos callback with pos callback not implemented */
|
---|
| 584 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 585 | ui_window_send_pos(window, &pos_event);
|
---|
[d284ce9] | 586 |
|
---|
| 587 | /* Pos callback with real callback set */
|
---|
| 588 | resp.pos = false;
|
---|
| 589 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 590 | ui_window_send_pos(window, &pos_event);
|
---|
[d284ce9] | 591 | PCUT_ASSERT_TRUE(resp.pos);
|
---|
| 592 | PCUT_ASSERT_INT_EQUALS(pos_event.pos_id, resp.pos_event.pos_id);
|
---|
| 593 | PCUT_ASSERT_EQUALS(pos_event.type, resp.pos_event.type);
|
---|
| 594 | PCUT_ASSERT_INT_EQUALS(pos_event.btn_num, resp.pos_event.btn_num);
|
---|
| 595 | PCUT_ASSERT_INT_EQUALS(pos_event.hpos, resp.pos_event.hpos);
|
---|
| 596 | PCUT_ASSERT_INT_EQUALS(pos_event.vpos, resp.pos_event.vpos);
|
---|
| 597 |
|
---|
| 598 | ui_window_destroy(window);
|
---|
| 599 | ui_destroy(ui);
|
---|
| 600 | }
|
---|
| 601 |
|
---|
[fa01c05] | 602 | /** ui_window_send_unfocus() calls unfocus callback set via ui_window_set_cb() */
|
---|
| 603 | PCUT_TEST(send_unfocus)
|
---|
[f03d1308] | 604 | {
|
---|
| 605 | errno_t rc;
|
---|
| 606 | ui_t *ui = NULL;
|
---|
| 607 | ui_wnd_params_t params;
|
---|
| 608 | ui_window_t *window = NULL;
|
---|
| 609 | test_cb_resp_t resp;
|
---|
| 610 |
|
---|
| 611 | rc = ui_create_disp(NULL, &ui);
|
---|
| 612 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 613 |
|
---|
| 614 | ui_wnd_params_init(¶ms);
|
---|
| 615 | params.caption = "Hello";
|
---|
| 616 |
|
---|
| 617 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 618 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 619 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 620 |
|
---|
| 621 | /* Unfocus callback with no callbacks set */
|
---|
[fa01c05] | 622 | ui_window_send_unfocus(window);
|
---|
[f03d1308] | 623 |
|
---|
| 624 | /* Unfocus callback with unfocus callback not implemented */
|
---|
| 625 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 626 | ui_window_send_unfocus(window);
|
---|
[f03d1308] | 627 |
|
---|
| 628 | /* Unfocus callback with real callback set */
|
---|
| 629 | resp.close = false;
|
---|
| 630 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 631 | ui_window_send_unfocus(window);
|
---|
[f03d1308] | 632 | PCUT_ASSERT_TRUE(resp.unfocus);
|
---|
| 633 |
|
---|
| 634 | ui_window_destroy(window);
|
---|
| 635 | ui_destroy(ui);
|
---|
| 636 | }
|
---|
| 637 |
|
---|
[d284ce9] | 638 | static void test_window_close(ui_window_t *window, void *arg)
|
---|
| 639 | {
|
---|
| 640 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 641 |
|
---|
| 642 | resp->close = true;
|
---|
| 643 | }
|
---|
| 644 |
|
---|
[f03d1308] | 645 | static void test_window_focus(ui_window_t *window, void *arg)
|
---|
| 646 | {
|
---|
| 647 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 648 |
|
---|
| 649 | resp->focus = true;
|
---|
| 650 | }
|
---|
| 651 |
|
---|
| 652 | static void test_window_kbd(ui_window_t *window, void *arg,
|
---|
| 653 | kbd_event_t *event)
|
---|
| 654 | {
|
---|
| 655 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 656 |
|
---|
| 657 | resp->kbd = true;
|
---|
| 658 | resp->kbd_event = *event;
|
---|
| 659 | }
|
---|
| 660 |
|
---|
[fa01c05] | 661 | static errno_t test_window_paint(ui_window_t *window, void *arg)
|
---|
| 662 | {
|
---|
| 663 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 664 |
|
---|
| 665 | resp->paint = true;
|
---|
| 666 | return resp->rc;
|
---|
| 667 | }
|
---|
| 668 |
|
---|
[d284ce9] | 669 | static void test_window_pos(ui_window_t *window, void *arg,
|
---|
| 670 | pos_event_t *event)
|
---|
| 671 | {
|
---|
| 672 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 673 |
|
---|
| 674 | resp->pos = true;
|
---|
| 675 | resp->pos_event = *event;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
[f03d1308] | 678 | static void test_window_unfocus(ui_window_t *window, void *arg)
|
---|
| 679 | {
|
---|
| 680 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 681 |
|
---|
| 682 | resp->unfocus = true;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
[b71c0fc] | 685 | static errno_t test_ctl_paint(void *arg)
|
---|
| 686 | {
|
---|
| 687 | test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
|
---|
| 688 |
|
---|
| 689 | resp->paint = true;
|
---|
| 690 | return resp->rc;
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event)
|
---|
| 694 | {
|
---|
| 695 | test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
|
---|
| 696 |
|
---|
| 697 | resp->pos = true;
|
---|
| 698 | resp->pos_event = *event;
|
---|
| 699 |
|
---|
| 700 | return resp->claim;
|
---|
| 701 | }
|
---|
| 702 |
|
---|
[f7a90df] | 703 | PCUT_EXPORT(window);
|
---|