[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 *);
|
---|
[62223ec] | 68 | static void test_ctl_unfocus(void *);
|
---|
[b71c0fc] | 69 |
|
---|
| 70 | static ui_control_ops_t test_ctl_ops = {
|
---|
| 71 | .paint = test_ctl_paint,
|
---|
[62223ec] | 72 | .pos_event = test_ctl_pos_event,
|
---|
| 73 | .unfocus = test_ctl_unfocus
|
---|
[b71c0fc] | 74 | };
|
---|
| 75 |
|
---|
[d284ce9] | 76 | typedef struct {
|
---|
[fa01c05] | 77 | errno_t rc;
|
---|
[d284ce9] | 78 | bool close;
|
---|
[f03d1308] | 79 | bool focus;
|
---|
| 80 | bool kbd;
|
---|
| 81 | kbd_event_t kbd_event;
|
---|
[fa01c05] | 82 | bool paint;
|
---|
[d284ce9] | 83 | bool pos;
|
---|
| 84 | pos_event_t pos_event;
|
---|
[f03d1308] | 85 | bool unfocus;
|
---|
[d284ce9] | 86 | } test_cb_resp_t;
|
---|
| 87 |
|
---|
[b71c0fc] | 88 | typedef struct {
|
---|
| 89 | errno_t rc;
|
---|
| 90 | ui_evclaim_t claim;
|
---|
| 91 | bool paint;
|
---|
| 92 | bool pos;
|
---|
| 93 | pos_event_t pos_event;
|
---|
[62223ec] | 94 | bool unfocus;
|
---|
[b71c0fc] | 95 | } test_ctl_resp_t;
|
---|
| 96 |
|
---|
[f7a90df] | 97 | /** Create and destroy window */
|
---|
| 98 | PCUT_TEST(create_destroy)
|
---|
| 99 | {
|
---|
| 100 | errno_t rc;
|
---|
| 101 | ui_t *ui = NULL;
|
---|
[d284ce9] | 102 | ui_wnd_params_t params;
|
---|
[f7a90df] | 103 | ui_window_t *window = NULL;
|
---|
| 104 |
|
---|
| 105 | rc = ui_create_disp(NULL, &ui);
|
---|
| 106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 107 |
|
---|
[d284ce9] | 108 | ui_wnd_params_init(¶ms);
|
---|
[f7a90df] | 109 | params.caption = "Hello";
|
---|
| 110 |
|
---|
| 111 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 112 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 113 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 114 |
|
---|
| 115 | ui_window_destroy(window);
|
---|
| 116 | ui_destroy(ui);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /** ui_window_destroy() can take NULL argument (no-op) */
|
---|
| 120 | PCUT_TEST(destroy_null)
|
---|
| 121 | {
|
---|
| 122 | ui_window_destroy(NULL);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[b71c0fc] | 125 | /** ui_window_add()/ui_window_remove() ... */
|
---|
| 126 | PCUT_TEST(add_remove)
|
---|
| 127 | {
|
---|
| 128 | errno_t rc;
|
---|
| 129 | ui_t *ui = NULL;
|
---|
| 130 | ui_wnd_params_t params;
|
---|
| 131 | ui_window_t *window = NULL;
|
---|
| 132 | ui_control_t *control = NULL;
|
---|
| 133 | test_ctl_resp_t resp;
|
---|
| 134 |
|
---|
| 135 | rc = ui_create_disp(NULL, &ui);
|
---|
| 136 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 137 |
|
---|
| 138 | ui_wnd_params_init(¶ms);
|
---|
| 139 | params.caption = "Hello";
|
---|
| 140 |
|
---|
| 141 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 142 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 143 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 144 |
|
---|
| 145 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 146 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 147 |
|
---|
| 148 | /* Control not called since it hasn't been added yet */
|
---|
| 149 | resp.rc = ENOMEM;
|
---|
| 150 | resp.paint = false;
|
---|
| 151 | rc = ui_window_def_paint(window);
|
---|
| 152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 153 | PCUT_ASSERT_FALSE(resp.paint);
|
---|
| 154 |
|
---|
| 155 | ui_window_add(window, control);
|
---|
| 156 |
|
---|
| 157 | /* Now paint request should be delivered to control */
|
---|
| 158 | resp.rc = EOK;
|
---|
| 159 | resp.paint = false;
|
---|
| 160 | rc = ui_window_def_paint(window);
|
---|
| 161 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 162 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 163 |
|
---|
| 164 | ui_window_remove(window, control);
|
---|
| 165 |
|
---|
| 166 | /*
|
---|
| 167 | * After having removed the control the request should no longer
|
---|
| 168 | * be delivered to it.
|
---|
| 169 | */
|
---|
| 170 | resp.rc = ENOMEM;
|
---|
| 171 | resp.paint = false;
|
---|
| 172 | rc = ui_window_def_paint(window);
|
---|
| 173 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 174 | PCUT_ASSERT_FALSE(resp.paint);
|
---|
| 175 |
|
---|
| 176 | ui_window_destroy(window);
|
---|
| 177 | ui_destroy(ui);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[252d03c] | 180 | /** ui_window_get_active */
|
---|
| 181 | PCUT_TEST(get_active)
|
---|
| 182 | {
|
---|
| 183 | errno_t rc;
|
---|
| 184 | ui_t *ui = NULL;
|
---|
| 185 | ui_wnd_params_t params;
|
---|
| 186 | ui_window_t *window1 = NULL;
|
---|
| 187 | ui_window_t *window2 = NULL;
|
---|
| 188 | ui_window_t *awnd;
|
---|
| 189 |
|
---|
| 190 | rc = ui_create_cons(NULL, &ui);
|
---|
| 191 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 192 |
|
---|
| 193 | awnd = ui_window_get_active(ui);
|
---|
| 194 | PCUT_ASSERT_NULL(awnd);
|
---|
| 195 |
|
---|
| 196 | ui_wnd_params_init(¶ms);
|
---|
| 197 | params.caption = "Hello";
|
---|
| 198 |
|
---|
| 199 | rc = ui_window_create(ui, ¶ms, &window1);
|
---|
| 200 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 201 | PCUT_ASSERT_NOT_NULL(window1);
|
---|
| 202 |
|
---|
| 203 | awnd = ui_window_get_active(ui);
|
---|
| 204 | PCUT_ASSERT_EQUALS(window1, awnd);
|
---|
| 205 |
|
---|
| 206 | rc = ui_window_create(ui, ¶ms, &window2);
|
---|
| 207 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 208 | PCUT_ASSERT_NOT_NULL(window2);
|
---|
| 209 |
|
---|
| 210 | awnd = ui_window_get_active(ui);
|
---|
| 211 | PCUT_ASSERT_EQUALS(window2, awnd);
|
---|
| 212 |
|
---|
| 213 | ui_window_destroy(window2);
|
---|
| 214 |
|
---|
| 215 | awnd = ui_window_get_active(ui);
|
---|
| 216 | PCUT_ASSERT_EQUALS(window1, awnd);
|
---|
| 217 |
|
---|
| 218 | ui_window_destroy(window1);
|
---|
| 219 |
|
---|
| 220 | awnd = ui_window_get_active(ui);
|
---|
| 221 | PCUT_ASSERT_NULL(awnd);
|
---|
| 222 |
|
---|
| 223 | ui_destroy(ui);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[0576df9] | 226 | /** ui_window_resize */
|
---|
| 227 | PCUT_TEST(resize)
|
---|
| 228 | {
|
---|
| 229 | errno_t rc;
|
---|
| 230 | ui_t *ui = NULL;
|
---|
| 231 | ui_wnd_params_t params;
|
---|
| 232 | ui_window_t *window = NULL;
|
---|
| 233 | gfx_rect_t nrect;
|
---|
| 234 |
|
---|
| 235 | rc = ui_create_disp(NULL, &ui);
|
---|
| 236 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 237 |
|
---|
| 238 | ui_wnd_params_init(¶ms);
|
---|
| 239 | params.caption = "Hello";
|
---|
| 240 | params.rect.p0.x = 0;
|
---|
| 241 | params.rect.p0.y = 0;
|
---|
| 242 | params.rect.p1.x = 1;
|
---|
| 243 | params.rect.p1.y = 1;
|
---|
| 244 |
|
---|
| 245 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 247 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 248 |
|
---|
| 249 | nrect.p0.x = -1;
|
---|
| 250 | nrect.p0.y = -1;
|
---|
| 251 | nrect.p1.x = 2;
|
---|
| 252 | nrect.p1.y = 2;
|
---|
| 253 | rc = ui_window_resize(window, &nrect);
|
---|
| 254 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 255 |
|
---|
| 256 | ui_window_destroy(window);
|
---|
| 257 | ui_destroy(ui);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
[3583ffb] | 260 | /** ui_window_get_res/gc/rect() return valid objects */
|
---|
| 261 | PCUT_TEST(get_res_gc_rect)
|
---|
[d284ce9] | 262 | {
|
---|
| 263 | errno_t rc;
|
---|
| 264 | ui_t *ui = NULL;
|
---|
| 265 | ui_wnd_params_t params;
|
---|
| 266 | ui_window_t *window = NULL;
|
---|
[3583ffb] | 267 | ui_resource_t *res;
|
---|
[d284ce9] | 268 | gfx_context_t *gc;
|
---|
| 269 | gfx_rect_t rect;
|
---|
| 270 |
|
---|
| 271 | rc = ui_create_disp(NULL, &ui);
|
---|
| 272 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 273 |
|
---|
| 274 | ui_wnd_params_init(¶ms);
|
---|
| 275 | params.caption = "Hello";
|
---|
| 276 |
|
---|
| 277 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 278 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 279 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 280 |
|
---|
[3583ffb] | 281 | res = ui_window_get_res(window);
|
---|
| 282 | PCUT_ASSERT_NOT_NULL(res);
|
---|
| 283 |
|
---|
[d284ce9] | 284 | gc = ui_window_get_gc(window);
|
---|
| 285 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
| 286 |
|
---|
| 287 | ui_window_get_app_rect(window, &rect);
|
---|
| 288 |
|
---|
| 289 | ui_window_destroy(window);
|
---|
| 290 | ui_destroy(ui);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[66a2becf] | 293 | /** ui_window_get_app_gc() return valid GC */
|
---|
| 294 | PCUT_TEST(get_app_gc)
|
---|
| 295 | {
|
---|
| 296 | errno_t rc;
|
---|
| 297 | ui_t *ui = NULL;
|
---|
| 298 | ui_wnd_params_t params;
|
---|
| 299 | ui_window_t *window = NULL;
|
---|
| 300 | gfx_context_t *gc;
|
---|
| 301 |
|
---|
| 302 | rc = ui_create_disp(NULL, &ui);
|
---|
| 303 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 304 |
|
---|
| 305 | ui_wnd_params_init(¶ms);
|
---|
| 306 | params.caption = "Hello";
|
---|
| 307 | params.rect.p0.x = 0;
|
---|
| 308 | params.rect.p0.y = 0;
|
---|
[2ab8ab3] | 309 | params.rect.p0.x = 100;
|
---|
| 310 | params.rect.p0.y = 100;
|
---|
[66a2becf] | 311 |
|
---|
| 312 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 313 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 314 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 315 |
|
---|
| 316 | rc = ui_window_get_app_gc(window, &gc);
|
---|
| 317 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 318 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
| 319 |
|
---|
| 320 | rc = gfx_fill_rect(gc, ¶ms.rect);
|
---|
| 321 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 322 |
|
---|
| 323 | ui_window_destroy(window);
|
---|
| 324 | ui_destroy(ui);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
[fa01c05] | 327 | /** Test ui_window_paint() */
|
---|
| 328 | PCUT_TEST(paint)
|
---|
| 329 | {
|
---|
| 330 | errno_t rc;
|
---|
| 331 | ui_t *ui = NULL;
|
---|
| 332 | ui_wnd_params_t params;
|
---|
| 333 | ui_window_t *window = NULL;
|
---|
| 334 |
|
---|
| 335 | rc = ui_create_disp(NULL, &ui);
|
---|
| 336 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 337 |
|
---|
| 338 | ui_wnd_params_init(¶ms);
|
---|
| 339 | params.caption = "Hello";
|
---|
| 340 |
|
---|
| 341 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 342 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 343 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 344 |
|
---|
| 345 | ui_window_paint(window);
|
---|
| 346 |
|
---|
| 347 | ui_window_destroy(window);
|
---|
| 348 | ui_destroy(ui);
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /** Test ui_window_def_paint() */
|
---|
| 352 | PCUT_TEST(def_paint)
|
---|
| 353 | {
|
---|
| 354 | errno_t rc;
|
---|
| 355 | ui_t *ui = NULL;
|
---|
| 356 | ui_wnd_params_t params;
|
---|
| 357 | ui_window_t *window = NULL;
|
---|
[b71c0fc] | 358 | ui_control_t *control = NULL;
|
---|
| 359 | test_ctl_resp_t resp;
|
---|
[fa01c05] | 360 |
|
---|
| 361 | rc = ui_create_disp(NULL, &ui);
|
---|
| 362 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 363 |
|
---|
| 364 | ui_wnd_params_init(¶ms);
|
---|
| 365 | params.caption = "Hello";
|
---|
| 366 |
|
---|
| 367 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 368 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 369 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 370 |
|
---|
[b71c0fc] | 371 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 372 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 373 |
|
---|
| 374 | ui_window_add(window, control);
|
---|
| 375 |
|
---|
| 376 | resp.rc = EOK;
|
---|
| 377 | resp.paint = false;
|
---|
| 378 | rc = ui_window_def_paint(window);
|
---|
| 379 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 380 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 381 |
|
---|
| 382 | resp.rc = ENOMEM;
|
---|
| 383 | resp.paint = false;
|
---|
| 384 | rc = ui_window_def_paint(window);
|
---|
| 385 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 386 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 387 |
|
---|
| 388 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 389 |
|
---|
| 390 | /* Need to remove first because we didn't implement the destructor */
|
---|
| 391 | ui_window_remove(window, control);
|
---|
| 392 |
|
---|
| 393 | ui_window_destroy(window);
|
---|
| 394 | ui_destroy(ui);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | /** ui_window_def_pos() delivers position event to control in window */
|
---|
| 398 | PCUT_TEST(def_pos)
|
---|
| 399 | {
|
---|
| 400 | errno_t rc;
|
---|
| 401 | ui_t *ui = NULL;
|
---|
| 402 | ui_wnd_params_t params;
|
---|
| 403 | ui_window_t *window = NULL;
|
---|
| 404 | ui_control_t *control = NULL;
|
---|
| 405 | test_ctl_resp_t resp;
|
---|
| 406 | pos_event_t event;
|
---|
| 407 |
|
---|
| 408 | rc = ui_create_disp(NULL, &ui);
|
---|
| 409 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 410 |
|
---|
| 411 | ui_wnd_params_init(¶ms);
|
---|
| 412 | params.caption = "Hello";
|
---|
| 413 |
|
---|
| 414 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 415 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 416 |
|
---|
| 417 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 418 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 419 |
|
---|
| 420 | ui_window_add(window, control);
|
---|
| 421 |
|
---|
| 422 | event.pos_id = 1;
|
---|
| 423 | event.type = POS_PRESS;
|
---|
| 424 | event.btn_num = 2;
|
---|
| 425 | event.hpos = 3;
|
---|
| 426 | event.vpos = 4;
|
---|
| 427 |
|
---|
| 428 | resp.pos = false;
|
---|
| 429 | resp.claim = ui_claimed;
|
---|
| 430 |
|
---|
| 431 | ui_window_def_pos(window, &event);
|
---|
| 432 |
|
---|
| 433 | PCUT_ASSERT_TRUE(resp.pos);
|
---|
| 434 | PCUT_ASSERT_INT_EQUALS(event.pos_id, resp.pos_event.pos_id);
|
---|
| 435 | PCUT_ASSERT_INT_EQUALS(event.type, resp.pos_event.type);
|
---|
| 436 | PCUT_ASSERT_INT_EQUALS(event.btn_num, resp.pos_event.btn_num);
|
---|
| 437 | PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos_event.hpos);
|
---|
| 438 | PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos_event.vpos);
|
---|
| 439 |
|
---|
| 440 | /* Need to remove first because we didn't implement the destructor */
|
---|
| 441 | ui_window_remove(window, control);
|
---|
[fa01c05] | 442 |
|
---|
| 443 | ui_window_destroy(window);
|
---|
| 444 | ui_destroy(ui);
|
---|
| 445 | }
|
---|
| 446 |
|
---|
[62223ec] | 447 | /** ui_window_def_unfocus() delivers unfocus event to control in window */
|
---|
| 448 | PCUT_TEST(def_unfocus)
|
---|
| 449 | {
|
---|
| 450 | errno_t rc;
|
---|
| 451 | ui_t *ui = NULL;
|
---|
| 452 | ui_wnd_params_t params;
|
---|
| 453 | ui_window_t *window = NULL;
|
---|
| 454 | ui_control_t *control = NULL;
|
---|
| 455 | test_ctl_resp_t resp;
|
---|
| 456 |
|
---|
| 457 | rc = ui_create_disp(NULL, &ui);
|
---|
| 458 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 459 |
|
---|
| 460 | ui_wnd_params_init(¶ms);
|
---|
| 461 | params.caption = "Hello";
|
---|
| 462 |
|
---|
| 463 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 464 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 465 |
|
---|
| 466 | rc = ui_control_new(&test_ctl_ops, &resp, &control);
|
---|
| 467 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 468 |
|
---|
| 469 | ui_window_add(window, control);
|
---|
| 470 |
|
---|
| 471 | resp.unfocus = false;
|
---|
| 472 |
|
---|
| 473 | ui_window_def_unfocus(window);
|
---|
| 474 | PCUT_ASSERT_TRUE(resp.unfocus);
|
---|
| 475 |
|
---|
| 476 | /* Need to remove first because we didn't implement the destructor */
|
---|
| 477 | ui_window_remove(window, control);
|
---|
| 478 |
|
---|
| 479 | ui_window_destroy(window);
|
---|
| 480 | ui_destroy(ui);
|
---|
| 481 | }
|
---|
| 482 |
|
---|
[fa01c05] | 483 | /** ui_window_send_close() calls close callback set via ui_window_set_cb() */
|
---|
| 484 | PCUT_TEST(send_close)
|
---|
[d284ce9] | 485 | {
|
---|
| 486 | errno_t rc;
|
---|
| 487 | ui_t *ui = NULL;
|
---|
| 488 | ui_wnd_params_t params;
|
---|
| 489 | ui_window_t *window = NULL;
|
---|
| 490 | test_cb_resp_t resp;
|
---|
| 491 |
|
---|
| 492 | rc = ui_create_disp(NULL, &ui);
|
---|
| 493 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 494 |
|
---|
| 495 | ui_wnd_params_init(¶ms);
|
---|
| 496 | params.caption = "Hello";
|
---|
| 497 |
|
---|
| 498 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 499 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 500 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 501 |
|
---|
| 502 | /* Close callback with no callbacks set */
|
---|
[fa01c05] | 503 | ui_window_send_close(window);
|
---|
[d284ce9] | 504 |
|
---|
| 505 | /* Close callback with close callback not implemented */
|
---|
| 506 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 507 | ui_window_send_close(window);
|
---|
[d284ce9] | 508 |
|
---|
| 509 | /* Close callback with real callback set */
|
---|
| 510 | resp.close = false;
|
---|
| 511 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 512 | ui_window_send_close(window);
|
---|
[d284ce9] | 513 | PCUT_ASSERT_TRUE(resp.close);
|
---|
| 514 |
|
---|
| 515 | ui_window_destroy(window);
|
---|
| 516 | ui_destroy(ui);
|
---|
| 517 | }
|
---|
| 518 |
|
---|
[fa01c05] | 519 | /** ui_window_send_focus() calls focus callback set via ui_window_set_cb() */
|
---|
| 520 | PCUT_TEST(send_focus)
|
---|
[f03d1308] | 521 | {
|
---|
| 522 | errno_t rc;
|
---|
| 523 | ui_t *ui = NULL;
|
---|
| 524 | ui_wnd_params_t params;
|
---|
| 525 | ui_window_t *window = NULL;
|
---|
| 526 | test_cb_resp_t resp;
|
---|
| 527 |
|
---|
| 528 | rc = ui_create_disp(NULL, &ui);
|
---|
| 529 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 530 |
|
---|
| 531 | ui_wnd_params_init(¶ms);
|
---|
| 532 | params.caption = "Hello";
|
---|
| 533 |
|
---|
| 534 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 535 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 536 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 537 |
|
---|
| 538 | /* Focus callback with no callbacks set */
|
---|
[fa01c05] | 539 | ui_window_send_focus(window);
|
---|
[f03d1308] | 540 |
|
---|
| 541 | /* Focus callback with focus callback not implemented */
|
---|
| 542 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 543 | ui_window_send_focus(window);
|
---|
[f03d1308] | 544 |
|
---|
| 545 | /* Focus callback with real callback set */
|
---|
[fa01c05] | 546 | resp.focus = false;
|
---|
[f03d1308] | 547 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 548 | ui_window_send_focus(window);
|
---|
[f03d1308] | 549 | PCUT_ASSERT_TRUE(resp.focus);
|
---|
| 550 |
|
---|
| 551 | ui_window_destroy(window);
|
---|
| 552 | ui_destroy(ui);
|
---|
| 553 | }
|
---|
| 554 |
|
---|
[fa01c05] | 555 | /** ui_window_send_kbd() calls kbd callback set via ui_window_set_cb() */
|
---|
| 556 | PCUT_TEST(send_kbd)
|
---|
[f03d1308] | 557 | {
|
---|
| 558 | errno_t rc;
|
---|
| 559 | ui_t *ui = NULL;
|
---|
| 560 | ui_wnd_params_t params;
|
---|
| 561 | ui_window_t *window = NULL;
|
---|
| 562 | kbd_event_t kbd_event;
|
---|
| 563 | test_cb_resp_t resp;
|
---|
| 564 |
|
---|
| 565 | rc = ui_create_disp(NULL, &ui);
|
---|
| 566 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 567 |
|
---|
| 568 | ui_wnd_params_init(¶ms);
|
---|
| 569 | params.caption = "Hello";
|
---|
| 570 |
|
---|
| 571 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 573 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 574 |
|
---|
| 575 | kbd_event.type = POS_PRESS;
|
---|
| 576 | kbd_event.key = KC_X;
|
---|
| 577 | kbd_event.mods = 0;
|
---|
| 578 | kbd_event.c = 'x';
|
---|
| 579 |
|
---|
| 580 | /* Kbd callback with no callbacks set */
|
---|
[fa01c05] | 581 | ui_window_send_kbd(window, &kbd_event);
|
---|
[f03d1308] | 582 |
|
---|
| 583 | /* Kbd callback with kbd callback not implemented */
|
---|
| 584 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 585 | ui_window_send_kbd(window, &kbd_event);
|
---|
[f03d1308] | 586 |
|
---|
| 587 | /* Kbd callback with real callback set */
|
---|
| 588 | resp.kbd = false;
|
---|
| 589 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 590 | ui_window_send_kbd(window, &kbd_event);
|
---|
[f03d1308] | 591 | PCUT_ASSERT_TRUE(resp.kbd);
|
---|
| 592 | PCUT_ASSERT_EQUALS(kbd_event.type, resp.kbd_event.type);
|
---|
| 593 | PCUT_ASSERT_INT_EQUALS(kbd_event.key, resp.kbd_event.key);
|
---|
| 594 | PCUT_ASSERT_INT_EQUALS(kbd_event.mods, resp.kbd_event.mods);
|
---|
| 595 | PCUT_ASSERT_INT_EQUALS(kbd_event.c, resp.kbd_event.c);
|
---|
| 596 |
|
---|
| 597 | ui_window_destroy(window);
|
---|
| 598 | ui_destroy(ui);
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[fa01c05] | 601 | /** ui_window_send_paint() calls paint callback set via ui_window_set_cb() */
|
---|
| 602 | PCUT_TEST(send_paint)
|
---|
| 603 | {
|
---|
| 604 | errno_t rc;
|
---|
| 605 | ui_t *ui = NULL;
|
---|
| 606 | ui_wnd_params_t params;
|
---|
| 607 | ui_window_t *window = NULL;
|
---|
| 608 | test_cb_resp_t resp;
|
---|
| 609 |
|
---|
| 610 | rc = ui_create_disp(NULL, &ui);
|
---|
| 611 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 612 |
|
---|
| 613 | ui_wnd_params_init(¶ms);
|
---|
| 614 | params.caption = "Hello";
|
---|
| 615 |
|
---|
| 616 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 617 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 618 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 619 |
|
---|
| 620 | /* Paint callback with no callbacks set */
|
---|
| 621 | ui_window_send_paint(window);
|
---|
| 622 |
|
---|
| 623 | /* Paint callback with paint callback not implemented */
|
---|
| 624 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
| 625 | ui_window_send_paint(window);
|
---|
| 626 |
|
---|
| 627 | /* Paint callback with real callback set */
|
---|
| 628 | resp.paint = false;
|
---|
| 629 | resp.rc = EOK;
|
---|
| 630 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
| 631 | rc = ui_window_send_paint(window);
|
---|
| 632 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 633 | PCUT_ASSERT_TRUE(resp.paint);
|
---|
| 634 |
|
---|
| 635 | ui_window_destroy(window);
|
---|
| 636 | ui_destroy(ui);
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 | /** ui_window_send_pos() calls pos callback set via ui_window_set_cb() */
|
---|
| 640 | PCUT_TEST(send_pos)
|
---|
[d284ce9] | 641 | {
|
---|
| 642 | errno_t rc;
|
---|
| 643 | ui_t *ui = NULL;
|
---|
| 644 | ui_wnd_params_t params;
|
---|
| 645 | ui_window_t *window = NULL;
|
---|
| 646 | pos_event_t pos_event;
|
---|
| 647 | test_cb_resp_t resp;
|
---|
| 648 |
|
---|
| 649 | rc = ui_create_disp(NULL, &ui);
|
---|
| 650 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 651 |
|
---|
| 652 | ui_wnd_params_init(¶ms);
|
---|
| 653 | params.caption = "Hello";
|
---|
| 654 |
|
---|
| 655 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 656 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 657 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 658 |
|
---|
| 659 | pos_event.pos_id = 1;
|
---|
| 660 | pos_event.type = POS_PRESS;
|
---|
| 661 | pos_event.btn_num = 2;
|
---|
| 662 | pos_event.hpos = 3;
|
---|
| 663 | pos_event.vpos = 4;
|
---|
| 664 |
|
---|
| 665 | /* Pos callback with no callbacks set */
|
---|
[fa01c05] | 666 | ui_window_send_pos(window, &pos_event);
|
---|
[d284ce9] | 667 |
|
---|
| 668 | /* Pos callback with pos callback not implemented */
|
---|
| 669 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 670 | ui_window_send_pos(window, &pos_event);
|
---|
[d284ce9] | 671 |
|
---|
| 672 | /* Pos callback with real callback set */
|
---|
| 673 | resp.pos = false;
|
---|
| 674 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 675 | ui_window_send_pos(window, &pos_event);
|
---|
[d284ce9] | 676 | PCUT_ASSERT_TRUE(resp.pos);
|
---|
| 677 | PCUT_ASSERT_INT_EQUALS(pos_event.pos_id, resp.pos_event.pos_id);
|
---|
| 678 | PCUT_ASSERT_EQUALS(pos_event.type, resp.pos_event.type);
|
---|
| 679 | PCUT_ASSERT_INT_EQUALS(pos_event.btn_num, resp.pos_event.btn_num);
|
---|
| 680 | PCUT_ASSERT_INT_EQUALS(pos_event.hpos, resp.pos_event.hpos);
|
---|
| 681 | PCUT_ASSERT_INT_EQUALS(pos_event.vpos, resp.pos_event.vpos);
|
---|
| 682 |
|
---|
| 683 | ui_window_destroy(window);
|
---|
| 684 | ui_destroy(ui);
|
---|
| 685 | }
|
---|
| 686 |
|
---|
[fa01c05] | 687 | /** ui_window_send_unfocus() calls unfocus callback set via ui_window_set_cb() */
|
---|
| 688 | PCUT_TEST(send_unfocus)
|
---|
[f03d1308] | 689 | {
|
---|
| 690 | errno_t rc;
|
---|
| 691 | ui_t *ui = NULL;
|
---|
| 692 | ui_wnd_params_t params;
|
---|
| 693 | ui_window_t *window = NULL;
|
---|
| 694 | test_cb_resp_t resp;
|
---|
| 695 |
|
---|
| 696 | rc = ui_create_disp(NULL, &ui);
|
---|
| 697 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 698 |
|
---|
| 699 | ui_wnd_params_init(¶ms);
|
---|
| 700 | params.caption = "Hello";
|
---|
| 701 |
|
---|
| 702 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 703 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 704 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 705 |
|
---|
| 706 | /* Unfocus callback with no callbacks set */
|
---|
[fa01c05] | 707 | ui_window_send_unfocus(window);
|
---|
[f03d1308] | 708 |
|
---|
| 709 | /* Unfocus callback with unfocus callback not implemented */
|
---|
| 710 | ui_window_set_cb(window, &dummy_window_cb, NULL);
|
---|
[fa01c05] | 711 | ui_window_send_unfocus(window);
|
---|
[f03d1308] | 712 |
|
---|
| 713 | /* Unfocus callback with real callback set */
|
---|
| 714 | resp.close = false;
|
---|
| 715 | ui_window_set_cb(window, &test_window_cb, &resp);
|
---|
[fa01c05] | 716 | ui_window_send_unfocus(window);
|
---|
[f03d1308] | 717 | PCUT_ASSERT_TRUE(resp.unfocus);
|
---|
| 718 |
|
---|
| 719 | ui_window_destroy(window);
|
---|
| 720 | ui_destroy(ui);
|
---|
| 721 | }
|
---|
| 722 |
|
---|
[d284ce9] | 723 | static void test_window_close(ui_window_t *window, void *arg)
|
---|
| 724 | {
|
---|
| 725 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 726 |
|
---|
| 727 | resp->close = true;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
[f03d1308] | 730 | static void test_window_focus(ui_window_t *window, void *arg)
|
---|
| 731 | {
|
---|
| 732 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 733 |
|
---|
| 734 | resp->focus = true;
|
---|
| 735 | }
|
---|
| 736 |
|
---|
| 737 | static void test_window_kbd(ui_window_t *window, void *arg,
|
---|
| 738 | kbd_event_t *event)
|
---|
| 739 | {
|
---|
| 740 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 741 |
|
---|
| 742 | resp->kbd = true;
|
---|
| 743 | resp->kbd_event = *event;
|
---|
| 744 | }
|
---|
| 745 |
|
---|
[fa01c05] | 746 | static errno_t test_window_paint(ui_window_t *window, void *arg)
|
---|
| 747 | {
|
---|
| 748 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 749 |
|
---|
| 750 | resp->paint = true;
|
---|
| 751 | return resp->rc;
|
---|
| 752 | }
|
---|
| 753 |
|
---|
[d284ce9] | 754 | static void test_window_pos(ui_window_t *window, void *arg,
|
---|
| 755 | pos_event_t *event)
|
---|
| 756 | {
|
---|
| 757 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 758 |
|
---|
| 759 | resp->pos = true;
|
---|
| 760 | resp->pos_event = *event;
|
---|
| 761 | }
|
---|
| 762 |
|
---|
[f03d1308] | 763 | static void test_window_unfocus(ui_window_t *window, void *arg)
|
---|
| 764 | {
|
---|
| 765 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
| 766 |
|
---|
| 767 | resp->unfocus = true;
|
---|
| 768 | }
|
---|
| 769 |
|
---|
[b71c0fc] | 770 | static errno_t test_ctl_paint(void *arg)
|
---|
| 771 | {
|
---|
| 772 | test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
|
---|
| 773 |
|
---|
| 774 | resp->paint = true;
|
---|
| 775 | return resp->rc;
|
---|
| 776 | }
|
---|
| 777 |
|
---|
| 778 | static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event)
|
---|
| 779 | {
|
---|
| 780 | test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
|
---|
| 781 |
|
---|
| 782 | resp->pos = true;
|
---|
| 783 | resp->pos_event = *event;
|
---|
| 784 |
|
---|
| 785 | return resp->claim;
|
---|
| 786 | }
|
---|
| 787 |
|
---|
[62223ec] | 788 | static void test_ctl_unfocus(void *arg)
|
---|
| 789 | {
|
---|
| 790 | test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
|
---|
| 791 |
|
---|
| 792 | resp->unfocus = true;
|
---|
| 793 | }
|
---|
| 794 |
|
---|
[f7a90df] | 795 | PCUT_EXPORT(window);
|
---|