| 1 | /*
|
|---|
| 2 | * Copyright (c) 2020 Jiri Svoboda
|
|---|
| 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 |
|
|---|
| 29 | #include <gfx/context.h>
|
|---|
| 30 | #include <gfx/coord.h>
|
|---|
| 31 | #include <mem.h>
|
|---|
| 32 | #include <pcut/pcut.h>
|
|---|
| 33 | #include <stdbool.h>
|
|---|
| 34 | #include <ui/pbutton.h>
|
|---|
| 35 | #include <ui/resource.h>
|
|---|
| 36 | #include <ui/wdecor.h>
|
|---|
| 37 | #include "../private/wdecor.h"
|
|---|
| 38 |
|
|---|
| 39 | PCUT_INIT;
|
|---|
| 40 |
|
|---|
| 41 | PCUT_TEST_SUITE(wdecor);
|
|---|
| 42 |
|
|---|
| 43 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
|---|
| 44 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
|---|
| 45 | static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
|
|---|
| 46 | gfx_bitmap_alloc_t *, void **);
|
|---|
| 47 | static errno_t testgc_bitmap_destroy(void *);
|
|---|
| 48 | static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
|
|---|
| 49 | static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
|
|---|
| 50 |
|
|---|
| 51 | static gfx_context_ops_t ops = {
|
|---|
| 52 | .set_color = testgc_set_color,
|
|---|
| 53 | .fill_rect = testgc_fill_rect,
|
|---|
| 54 | .bitmap_create = testgc_bitmap_create,
|
|---|
| 55 | .bitmap_destroy = testgc_bitmap_destroy,
|
|---|
| 56 | .bitmap_render = testgc_bitmap_render,
|
|---|
| 57 | .bitmap_get_alloc = testgc_bitmap_get_alloc
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | static void test_wdecor_close(ui_wdecor_t *, void *);
|
|---|
| 61 | static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *);
|
|---|
| 62 | static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
|
|---|
| 63 | gfx_coord2_t *);
|
|---|
| 64 | static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
|
|---|
| 65 |
|
|---|
| 66 | static ui_wdecor_cb_t test_wdecor_cb = {
|
|---|
| 67 | .close = test_wdecor_close,
|
|---|
| 68 | .move = test_wdecor_move,
|
|---|
| 69 | .resize = test_wdecor_resize,
|
|---|
| 70 | .set_cursor = test_wdecor_set_cursor
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | static ui_wdecor_cb_t dummy_wdecor_cb = {
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 | typedef struct {
|
|---|
| 77 | bool bm_created;
|
|---|
| 78 | bool bm_destroyed;
|
|---|
| 79 | gfx_bitmap_params_t bm_params;
|
|---|
| 80 | void *bm_pixels;
|
|---|
| 81 | gfx_rect_t bm_srect;
|
|---|
| 82 | gfx_coord2_t bm_offs;
|
|---|
| 83 | bool bm_rendered;
|
|---|
| 84 | bool bm_got_alloc;
|
|---|
| 85 | } test_gc_t;
|
|---|
| 86 |
|
|---|
| 87 | typedef struct {
|
|---|
| 88 | test_gc_t *tgc;
|
|---|
| 89 | gfx_bitmap_alloc_t alloc;
|
|---|
| 90 | bool myalloc;
|
|---|
| 91 | } testgc_bitmap_t;
|
|---|
| 92 |
|
|---|
| 93 | typedef struct {
|
|---|
| 94 | bool close;
|
|---|
| 95 | bool move;
|
|---|
| 96 | gfx_coord2_t pos;
|
|---|
| 97 | bool resize;
|
|---|
| 98 | ui_wdecor_rsztype_t rsztype;
|
|---|
| 99 | bool set_cursor;
|
|---|
| 100 | ui_stock_cursor_t cursor;
|
|---|
| 101 | } test_cb_resp_t;
|
|---|
| 102 |
|
|---|
| 103 | /** Create and destroy button */
|
|---|
| 104 | PCUT_TEST(create_destroy)
|
|---|
| 105 | {
|
|---|
| 106 | ui_wdecor_t *wdecor = NULL;
|
|---|
| 107 | errno_t rc;
|
|---|
| 108 |
|
|---|
| 109 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 111 | PCUT_ASSERT_NOT_NULL(wdecor);
|
|---|
| 112 |
|
|---|
| 113 | ui_wdecor_destroy(wdecor);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /** ui_wdecor_destroy() can take NULL argument (no-op) */
|
|---|
| 117 | PCUT_TEST(destroy_null)
|
|---|
| 118 | {
|
|---|
| 119 | ui_wdecor_destroy(NULL);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /** Set window decoration rectangle sets internal field */
|
|---|
| 123 | PCUT_TEST(set_rect)
|
|---|
| 124 | {
|
|---|
| 125 | ui_wdecor_t *wdecor;
|
|---|
| 126 | gfx_rect_t rect;
|
|---|
| 127 | errno_t rc;
|
|---|
| 128 |
|
|---|
| 129 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 130 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 131 |
|
|---|
| 132 | rect.p0.x = 1;
|
|---|
| 133 | rect.p0.y = 2;
|
|---|
| 134 | rect.p1.x = 3;
|
|---|
| 135 | rect.p1.y = 4;
|
|---|
| 136 |
|
|---|
| 137 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 138 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, wdecor->rect.p0.x);
|
|---|
| 139 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, wdecor->rect.p0.y);
|
|---|
| 140 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, wdecor->rect.p1.x);
|
|---|
| 141 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, wdecor->rect.p1.y);
|
|---|
| 142 |
|
|---|
| 143 | ui_wdecor_destroy(wdecor);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | /** Set window decoration active sets internal field */
|
|---|
| 147 | PCUT_TEST(set_active)
|
|---|
| 148 | {
|
|---|
| 149 | ui_wdecor_t *wdecor;
|
|---|
| 150 | errno_t rc;
|
|---|
| 151 |
|
|---|
| 152 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 153 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 154 |
|
|---|
| 155 | PCUT_ASSERT_TRUE(wdecor->active);
|
|---|
| 156 |
|
|---|
| 157 | ui_wdecor_set_active(wdecor, false);
|
|---|
| 158 | PCUT_ASSERT_FALSE(wdecor->active);
|
|---|
| 159 |
|
|---|
| 160 | ui_wdecor_set_active(wdecor, true);
|
|---|
| 161 | PCUT_ASSERT_TRUE(wdecor->active);
|
|---|
| 162 |
|
|---|
| 163 | ui_wdecor_destroy(wdecor);
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /** Paint button */
|
|---|
| 167 | PCUT_TEST(paint)
|
|---|
| 168 | {
|
|---|
| 169 | errno_t rc;
|
|---|
| 170 | gfx_context_t *gc = NULL;
|
|---|
| 171 | test_gc_t tgc;
|
|---|
| 172 | ui_resource_t *resource = NULL;
|
|---|
| 173 | ui_wdecor_t *wdecor;
|
|---|
| 174 |
|
|---|
| 175 | memset(&tgc, 0, sizeof(tgc));
|
|---|
| 176 | rc = gfx_context_new(&ops, &tgc, &gc);
|
|---|
| 177 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 178 |
|
|---|
| 179 | rc = ui_resource_create(gc, false, &resource);
|
|---|
| 180 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 181 | PCUT_ASSERT_NOT_NULL(resource);
|
|---|
| 182 |
|
|---|
| 183 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
|---|
| 184 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 185 |
|
|---|
| 186 | rc = ui_wdecor_paint(wdecor);
|
|---|
| 187 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 188 |
|
|---|
| 189 | ui_wdecor_destroy(wdecor);
|
|---|
| 190 | ui_resource_destroy(resource);
|
|---|
| 191 |
|
|---|
| 192 | rc = gfx_context_delete(gc);
|
|---|
| 193 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | /** Test ui_wdecor_close() */
|
|---|
| 197 | PCUT_TEST(close)
|
|---|
| 198 | {
|
|---|
| 199 | errno_t rc;
|
|---|
| 200 | ui_wdecor_t *wdecor;
|
|---|
| 201 | test_cb_resp_t resp;
|
|---|
| 202 |
|
|---|
| 203 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 204 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 205 |
|
|---|
| 206 | /* Close callback with no callbacks set */
|
|---|
| 207 | ui_wdecor_close(wdecor);
|
|---|
| 208 |
|
|---|
| 209 | /* Close callback with close callback not implemented */
|
|---|
| 210 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
|---|
| 211 | ui_wdecor_close(wdecor);
|
|---|
| 212 |
|
|---|
| 213 | /* Close callback with real callback set */
|
|---|
| 214 | resp.close = false;
|
|---|
| 215 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
|---|
| 216 | ui_wdecor_close(wdecor);
|
|---|
| 217 | PCUT_ASSERT_TRUE(resp.close);
|
|---|
| 218 |
|
|---|
| 219 | ui_wdecor_destroy(wdecor);
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | /** Test ui_wdecor_move() */
|
|---|
| 223 | PCUT_TEST(move)
|
|---|
| 224 | {
|
|---|
| 225 | errno_t rc;
|
|---|
| 226 | ui_wdecor_t *wdecor;
|
|---|
| 227 | test_cb_resp_t resp;
|
|---|
| 228 | gfx_coord2_t pos;
|
|---|
| 229 |
|
|---|
| 230 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 231 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 232 |
|
|---|
| 233 | pos.x = 3;
|
|---|
| 234 | pos.y = 4;
|
|---|
| 235 |
|
|---|
| 236 | /* Move callback with no callbacks set */
|
|---|
| 237 | ui_wdecor_move(wdecor, &pos);
|
|---|
| 238 |
|
|---|
| 239 | /* Move callback with move callback not implemented */
|
|---|
| 240 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
|---|
| 241 | ui_wdecor_move(wdecor, &pos);
|
|---|
| 242 |
|
|---|
| 243 | /* Move callback with real callback set */
|
|---|
| 244 | resp.move = false;
|
|---|
| 245 | resp.pos.x = 0;
|
|---|
| 246 | resp.pos.y = 0;
|
|---|
| 247 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
|---|
| 248 | ui_wdecor_move(wdecor, &pos);
|
|---|
| 249 | PCUT_ASSERT_TRUE(resp.move);
|
|---|
| 250 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
|---|
| 251 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
|---|
| 252 |
|
|---|
| 253 | ui_wdecor_destroy(wdecor);
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | /** Test ui_wdecor_resize() */
|
|---|
| 257 | PCUT_TEST(resize)
|
|---|
| 258 | {
|
|---|
| 259 | errno_t rc;
|
|---|
| 260 | ui_wdecor_t *wdecor;
|
|---|
| 261 | test_cb_resp_t resp;
|
|---|
| 262 | ui_wdecor_rsztype_t rsztype;
|
|---|
| 263 | gfx_coord2_t pos;
|
|---|
| 264 |
|
|---|
| 265 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 266 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 267 |
|
|---|
| 268 | rsztype = ui_wr_bottom;
|
|---|
| 269 | pos.x = 3;
|
|---|
| 270 | pos.y = 4;
|
|---|
| 271 |
|
|---|
| 272 | /* Resize callback with no callbacks set */
|
|---|
| 273 | ui_wdecor_resize(wdecor, rsztype, &pos);
|
|---|
| 274 |
|
|---|
| 275 | /* Resize callback with move callback not implemented */
|
|---|
| 276 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
|---|
| 277 | ui_wdecor_resize(wdecor, rsztype, &pos);
|
|---|
| 278 |
|
|---|
| 279 | /* Resize callback with real callback set */
|
|---|
| 280 | resp.resize = false;
|
|---|
| 281 | resp.rsztype = ui_wr_none;
|
|---|
| 282 | resp.pos.x = 0;
|
|---|
| 283 | resp.pos.y = 0;
|
|---|
| 284 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
|---|
| 285 | ui_wdecor_resize(wdecor, rsztype, &pos);
|
|---|
| 286 | PCUT_ASSERT_TRUE(resp.resize);
|
|---|
| 287 | PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype);
|
|---|
| 288 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
|---|
| 289 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
|---|
| 290 |
|
|---|
| 291 | ui_wdecor_destroy(wdecor);
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | /** Test ui_wdecor_set_cursor() */
|
|---|
| 295 | PCUT_TEST(set_cursor)
|
|---|
| 296 | {
|
|---|
| 297 | errno_t rc;
|
|---|
| 298 | ui_wdecor_t *wdecor;
|
|---|
| 299 | test_cb_resp_t resp;
|
|---|
| 300 | ui_stock_cursor_t cursor;
|
|---|
| 301 |
|
|---|
| 302 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 303 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 304 |
|
|---|
| 305 | cursor = ui_curs_size_uldr;
|
|---|
| 306 |
|
|---|
| 307 | /* Set cursor callback with no callbacks set */
|
|---|
| 308 | ui_wdecor_set_cursor(wdecor, cursor);
|
|---|
| 309 |
|
|---|
| 310 | /* Set cursor callback with move callback not implemented */
|
|---|
| 311 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
|---|
| 312 | ui_wdecor_set_cursor(wdecor, cursor);
|
|---|
| 313 |
|
|---|
| 314 | /* Set cursor callback with real callback set */
|
|---|
| 315 | resp.set_cursor = false;
|
|---|
| 316 | resp.cursor = ui_curs_arrow;
|
|---|
| 317 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
|---|
| 318 | ui_wdecor_set_cursor(wdecor, cursor);
|
|---|
| 319 | PCUT_ASSERT_TRUE(resp.set_cursor);
|
|---|
| 320 | PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor);
|
|---|
| 321 |
|
|---|
| 322 | ui_wdecor_destroy(wdecor);
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | /** Clicking the close button generates close callback */
|
|---|
| 326 | PCUT_TEST(close_btn_clicked)
|
|---|
| 327 | {
|
|---|
| 328 | ui_wdecor_t *wdecor;
|
|---|
| 329 | gfx_rect_t rect;
|
|---|
| 330 | test_cb_resp_t resp;
|
|---|
| 331 | errno_t rc;
|
|---|
| 332 |
|
|---|
| 333 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 334 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 335 |
|
|---|
| 336 | rect.p0.x = 10;
|
|---|
| 337 | rect.p0.y = 20;
|
|---|
| 338 | rect.p1.x = 100;
|
|---|
| 339 | rect.p1.y = 200;
|
|---|
| 340 |
|
|---|
| 341 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 342 |
|
|---|
| 343 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
|---|
| 344 |
|
|---|
| 345 | resp.close = false;
|
|---|
| 346 |
|
|---|
| 347 | ui_pbutton_clicked(wdecor->btn_close);
|
|---|
| 348 | PCUT_ASSERT_TRUE(resp.close);
|
|---|
| 349 |
|
|---|
| 350 | ui_wdecor_destroy(wdecor);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | /** Button press on title bar generates move callback */
|
|---|
| 354 | PCUT_TEST(pos_event_move)
|
|---|
| 355 | {
|
|---|
| 356 | ui_wdecor_t *wdecor;
|
|---|
| 357 | gfx_rect_t rect;
|
|---|
| 358 | pos_event_t event;
|
|---|
| 359 | test_cb_resp_t resp;
|
|---|
| 360 | errno_t rc;
|
|---|
| 361 |
|
|---|
| 362 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_decorated, &wdecor);
|
|---|
| 363 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 364 |
|
|---|
| 365 | rect.p0.x = 10;
|
|---|
| 366 | rect.p0.y = 20;
|
|---|
| 367 | rect.p1.x = 100;
|
|---|
| 368 | rect.p1.y = 200;
|
|---|
| 369 |
|
|---|
| 370 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 371 |
|
|---|
| 372 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
|---|
| 373 |
|
|---|
| 374 | resp.move = false;
|
|---|
| 375 | resp.pos.x = 0;
|
|---|
| 376 | resp.pos.y = 0;
|
|---|
| 377 |
|
|---|
| 378 | event.type = POS_PRESS;
|
|---|
| 379 | event.hpos = 50;
|
|---|
| 380 | event.vpos = 25;
|
|---|
| 381 | ui_wdecor_pos_event(wdecor, &event);
|
|---|
| 382 |
|
|---|
| 383 | PCUT_ASSERT_TRUE(resp.move);
|
|---|
| 384 | PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos.x);
|
|---|
| 385 | PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos.y);
|
|---|
| 386 |
|
|---|
| 387 | ui_wdecor_destroy(wdecor);
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | /** ui_wdecor_get_geom() with ui_wds_none produces the correct geometry */
|
|---|
| 391 | PCUT_TEST(get_geom_none)
|
|---|
| 392 | {
|
|---|
| 393 | ui_wdecor_t *wdecor;
|
|---|
| 394 | gfx_rect_t rect;
|
|---|
| 395 | ui_wdecor_geom_t geom;
|
|---|
| 396 | errno_t rc;
|
|---|
| 397 |
|
|---|
| 398 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 399 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 400 |
|
|---|
| 401 | rect.p0.x = 10;
|
|---|
| 402 | rect.p0.y = 20;
|
|---|
| 403 | rect.p1.x = 100;
|
|---|
| 404 | rect.p1.y = 200;
|
|---|
| 405 |
|
|---|
| 406 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 407 | ui_wdecor_get_geom(wdecor, &geom);
|
|---|
| 408 |
|
|---|
| 409 | PCUT_ASSERT_INT_EQUALS(10, geom.interior_rect.p0.x);
|
|---|
| 410 | PCUT_ASSERT_INT_EQUALS(20, geom.interior_rect.p0.y);
|
|---|
| 411 | PCUT_ASSERT_INT_EQUALS(100, geom.interior_rect.p1.x);
|
|---|
| 412 | PCUT_ASSERT_INT_EQUALS(200, geom.interior_rect.p1.y);
|
|---|
| 413 |
|
|---|
| 414 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
|---|
| 415 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
|---|
| 416 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
|---|
| 417 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
|---|
| 418 |
|
|---|
| 419 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
|---|
| 420 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
|---|
| 421 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
|---|
| 422 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
|---|
| 423 |
|
|---|
| 424 | PCUT_ASSERT_INT_EQUALS(10, geom.app_area_rect.p0.x);
|
|---|
| 425 | PCUT_ASSERT_INT_EQUALS(20, geom.app_area_rect.p0.y);
|
|---|
| 426 | PCUT_ASSERT_INT_EQUALS(100, geom.app_area_rect.p1.x);
|
|---|
| 427 | PCUT_ASSERT_INT_EQUALS(200, geom.app_area_rect.p1.y);
|
|---|
| 428 |
|
|---|
| 429 | ui_wdecor_destroy(wdecor);
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | /** ui_wdecor_get_geom() with ui_wds_frame produces the correct geometry */
|
|---|
| 433 | PCUT_TEST(get_geom_frame)
|
|---|
| 434 | {
|
|---|
| 435 | ui_wdecor_t *wdecor;
|
|---|
| 436 | gfx_rect_t rect;
|
|---|
| 437 | ui_wdecor_geom_t geom;
|
|---|
| 438 | errno_t rc;
|
|---|
| 439 |
|
|---|
| 440 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_frame, &wdecor);
|
|---|
| 441 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 442 |
|
|---|
| 443 | rect.p0.x = 10;
|
|---|
| 444 | rect.p0.y = 20;
|
|---|
| 445 | rect.p1.x = 100;
|
|---|
| 446 | rect.p1.y = 200;
|
|---|
| 447 |
|
|---|
| 448 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 449 | ui_wdecor_get_geom(wdecor, &geom);
|
|---|
| 450 |
|
|---|
| 451 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
|---|
| 452 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
|---|
| 453 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
|---|
| 454 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
|---|
| 455 |
|
|---|
| 456 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
|---|
| 457 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
|---|
| 458 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
|---|
| 459 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
|---|
| 460 |
|
|---|
| 461 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
|---|
| 462 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
|---|
| 463 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
|---|
| 464 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
|---|
| 465 |
|
|---|
| 466 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
|---|
| 467 | PCUT_ASSERT_INT_EQUALS(24, geom.app_area_rect.p0.y);
|
|---|
| 468 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
|---|
| 469 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
|---|
| 470 |
|
|---|
| 471 | ui_wdecor_destroy(wdecor);
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | /** ui_wdecor_get_geom() with ui_wds_frame | ui_wds_titlebar */
|
|---|
| 475 | PCUT_TEST(get_geom_frame_titlebar)
|
|---|
| 476 | {
|
|---|
| 477 | ui_wdecor_t *wdecor;
|
|---|
| 478 | gfx_rect_t rect;
|
|---|
| 479 | ui_wdecor_geom_t geom;
|
|---|
| 480 | errno_t rc;
|
|---|
| 481 |
|
|---|
| 482 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_frame | ui_wds_titlebar,
|
|---|
| 483 | &wdecor);
|
|---|
| 484 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 485 |
|
|---|
| 486 | rect.p0.x = 10;
|
|---|
| 487 | rect.p0.y = 20;
|
|---|
| 488 | rect.p1.x = 100;
|
|---|
| 489 | rect.p1.y = 200;
|
|---|
| 490 |
|
|---|
| 491 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 492 | ui_wdecor_get_geom(wdecor, &geom);
|
|---|
| 493 |
|
|---|
| 494 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
|---|
| 495 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
|---|
| 496 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
|---|
| 497 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
|---|
| 498 |
|
|---|
| 499 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
|---|
| 500 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
|---|
| 501 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
|---|
| 502 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
|---|
| 503 |
|
|---|
| 504 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
|---|
| 505 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
|---|
| 506 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
|---|
| 507 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
|---|
| 508 |
|
|---|
| 509 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
|---|
| 510 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
|---|
| 511 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
|---|
| 512 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
|---|
| 513 |
|
|---|
| 514 | ui_wdecor_destroy(wdecor);
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | /** ui_wdecor_get_geom() with ui_wds_decorated produces the correct geometry */
|
|---|
| 518 | PCUT_TEST(get_geom_decorated)
|
|---|
| 519 | {
|
|---|
| 520 | ui_wdecor_t *wdecor;
|
|---|
| 521 | gfx_rect_t rect;
|
|---|
| 522 | ui_wdecor_geom_t geom;
|
|---|
| 523 | errno_t rc;
|
|---|
| 524 |
|
|---|
| 525 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_decorated, &wdecor);
|
|---|
| 526 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 527 |
|
|---|
| 528 | rect.p0.x = 10;
|
|---|
| 529 | rect.p0.y = 20;
|
|---|
| 530 | rect.p1.x = 100;
|
|---|
| 531 | rect.p1.y = 200;
|
|---|
| 532 |
|
|---|
| 533 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 534 | ui_wdecor_get_geom(wdecor, &geom);
|
|---|
| 535 |
|
|---|
| 536 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
|---|
| 537 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
|---|
| 538 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
|---|
| 539 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
|---|
| 540 |
|
|---|
| 541 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
|---|
| 542 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
|---|
| 543 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
|---|
| 544 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
|---|
| 545 |
|
|---|
| 546 | PCUT_ASSERT_INT_EQUALS(75, geom.btn_close_rect.p0.x);
|
|---|
| 547 | PCUT_ASSERT_INT_EQUALS(25, geom.btn_close_rect.p0.y);
|
|---|
| 548 | PCUT_ASSERT_INT_EQUALS(95, geom.btn_close_rect.p1.x);
|
|---|
| 549 | PCUT_ASSERT_INT_EQUALS(45, geom.btn_close_rect.p1.y);
|
|---|
| 550 |
|
|---|
| 551 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
|---|
| 552 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
|---|
| 553 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
|---|
| 554 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
|---|
| 555 |
|
|---|
| 556 | ui_wdecor_destroy(wdecor);
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | /** ui_wdecor_rect_from_app() correctly converts application to window rect */
|
|---|
| 560 | PCUT_TEST(rect_from_app)
|
|---|
| 561 | {
|
|---|
| 562 | gfx_rect_t arect;
|
|---|
| 563 | gfx_rect_t rect;
|
|---|
| 564 |
|
|---|
| 565 | arect.p0.x = 14;
|
|---|
| 566 | arect.p0.y = 46;
|
|---|
| 567 | arect.p1.x = 96;
|
|---|
| 568 | arect.p1.y = 196;
|
|---|
| 569 |
|
|---|
| 570 | ui_wdecor_rect_from_app(ui_wds_none, &arect, &rect);
|
|---|
| 571 |
|
|---|
| 572 | PCUT_ASSERT_INT_EQUALS(14, rect.p0.x);
|
|---|
| 573 | PCUT_ASSERT_INT_EQUALS(46, rect.p0.y);
|
|---|
| 574 | PCUT_ASSERT_INT_EQUALS(96, rect.p1.x);
|
|---|
| 575 | PCUT_ASSERT_INT_EQUALS(196, rect.p1.y);
|
|---|
| 576 |
|
|---|
| 577 | ui_wdecor_rect_from_app(ui_wds_frame, &arect, &rect);
|
|---|
| 578 |
|
|---|
| 579 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
|---|
| 580 | PCUT_ASSERT_INT_EQUALS(42, rect.p0.y);
|
|---|
| 581 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
|---|
| 582 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
|---|
| 583 |
|
|---|
| 584 | ui_wdecor_rect_from_app(ui_wds_decorated, &arect, &rect);
|
|---|
| 585 |
|
|---|
| 586 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
|---|
| 587 | PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
|
|---|
| 588 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
|---|
| 589 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
|---|
| 590 |
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | /** Test ui_wdecor_get_rsztype() */
|
|---|
| 594 | PCUT_TEST(get_rsztype)
|
|---|
| 595 | {
|
|---|
| 596 | ui_wdecor_t *wdecor;
|
|---|
| 597 | gfx_rect_t rect;
|
|---|
| 598 | ui_wdecor_rsztype_t rsztype;
|
|---|
| 599 | gfx_coord2_t pos;
|
|---|
| 600 | errno_t rc;
|
|---|
| 601 |
|
|---|
| 602 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
|
|---|
| 603 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 604 |
|
|---|
| 605 | rect.p0.x = 10;
|
|---|
| 606 | rect.p0.y = 20;
|
|---|
| 607 | rect.p1.x = 100;
|
|---|
| 608 | rect.p1.y = 200;
|
|---|
| 609 |
|
|---|
| 610 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 611 |
|
|---|
| 612 | /* Outside of the window */
|
|---|
| 613 | pos.x = 0;
|
|---|
| 614 | pos.y = -1;
|
|---|
| 615 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 616 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
|---|
| 617 |
|
|---|
| 618 | /* Middle of the window */
|
|---|
| 619 | pos.x = 50;
|
|---|
| 620 | pos.y = 100;
|
|---|
| 621 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 622 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
|---|
| 623 |
|
|---|
| 624 | /* Top-left corner, but not on edge */
|
|---|
| 625 | pos.x = 20;
|
|---|
| 626 | pos.y = 30;
|
|---|
| 627 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 628 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
|---|
| 629 |
|
|---|
| 630 | /* Top-left corner on top edge */
|
|---|
| 631 | pos.x = 20;
|
|---|
| 632 | pos.y = 20;
|
|---|
| 633 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 634 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
|---|
| 635 |
|
|---|
| 636 | /* Top-left corner on left edge */
|
|---|
| 637 | pos.x = 10;
|
|---|
| 638 | pos.y = 30;
|
|---|
| 639 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 640 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
|---|
| 641 |
|
|---|
| 642 | /* Top-right corner on top edge */
|
|---|
| 643 | pos.x = 90;
|
|---|
| 644 | pos.y = 20;
|
|---|
| 645 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 646 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
|---|
| 647 |
|
|---|
| 648 | /* Top-right corner on right edge */
|
|---|
| 649 | pos.x = 99;
|
|---|
| 650 | pos.y = 30;
|
|---|
| 651 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 652 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
|---|
| 653 |
|
|---|
| 654 | /* Top edge */
|
|---|
| 655 | pos.x = 50;
|
|---|
| 656 | pos.y = 20;
|
|---|
| 657 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 658 | PCUT_ASSERT_EQUALS(ui_wr_top, rsztype);
|
|---|
| 659 |
|
|---|
| 660 | /* Bottom edge */
|
|---|
| 661 | pos.x = 50;
|
|---|
| 662 | pos.y = 199;
|
|---|
| 663 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 664 | PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype);
|
|---|
| 665 |
|
|---|
| 666 | /* Left edge */
|
|---|
| 667 | pos.x = 10;
|
|---|
| 668 | pos.y = 100;
|
|---|
| 669 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 670 | PCUT_ASSERT_EQUALS(ui_wr_left, rsztype);
|
|---|
| 671 |
|
|---|
| 672 | /* Right edge */
|
|---|
| 673 | pos.x = 99;
|
|---|
| 674 | pos.y = 100;
|
|---|
| 675 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 676 | PCUT_ASSERT_EQUALS(ui_wr_right, rsztype);
|
|---|
| 677 |
|
|---|
| 678 | ui_wdecor_destroy(wdecor);
|
|---|
| 679 |
|
|---|
| 680 | /* Non-resizable window */
|
|---|
| 681 |
|
|---|
| 682 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
|---|
| 683 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 684 |
|
|---|
| 685 | rect.p0.x = 10;
|
|---|
| 686 | rect.p0.y = 20;
|
|---|
| 687 | rect.p1.x = 100;
|
|---|
| 688 | rect.p1.y = 200;
|
|---|
| 689 |
|
|---|
| 690 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 691 |
|
|---|
| 692 | pos.x = 10;
|
|---|
| 693 | pos.y = 20;
|
|---|
| 694 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
|---|
| 695 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
|---|
| 696 |
|
|---|
| 697 | ui_wdecor_destroy(wdecor);
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | /** Test ui_wdecor_cursor_from_rsztype() */
|
|---|
| 701 | PCUT_TEST(cursor_from_rsztype)
|
|---|
| 702 | {
|
|---|
| 703 | PCUT_ASSERT_EQUALS(ui_curs_arrow,
|
|---|
| 704 | ui_wdecor_cursor_from_rsztype(ui_wr_none));
|
|---|
| 705 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
|---|
| 706 | ui_wdecor_cursor_from_rsztype(ui_wr_top));
|
|---|
| 707 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
|---|
| 708 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom));
|
|---|
| 709 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
|---|
| 710 | ui_wdecor_cursor_from_rsztype(ui_wr_left));
|
|---|
| 711 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
|---|
| 712 | ui_wdecor_cursor_from_rsztype(ui_wr_right));
|
|---|
| 713 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
|---|
| 714 | ui_wdecor_cursor_from_rsztype(ui_wr_top_left));
|
|---|
| 715 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
|---|
| 716 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right));
|
|---|
| 717 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
|---|
| 718 | ui_wdecor_cursor_from_rsztype(ui_wr_top_right));
|
|---|
| 719 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
|---|
| 720 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left));
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | /** Test ui_wdecor_frame_pos_event() */
|
|---|
| 724 | PCUT_TEST(frame_pos_event)
|
|---|
| 725 | {
|
|---|
| 726 | ui_wdecor_t *wdecor;
|
|---|
| 727 | gfx_rect_t rect;
|
|---|
| 728 | test_cb_resp_t resp;
|
|---|
| 729 | pos_event_t event;
|
|---|
| 730 | errno_t rc;
|
|---|
| 731 |
|
|---|
| 732 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
|
|---|
| 733 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 734 |
|
|---|
| 735 | rect.p0.x = 10;
|
|---|
| 736 | rect.p0.y = 20;
|
|---|
| 737 | rect.p1.x = 100;
|
|---|
| 738 | rect.p1.y = 200;
|
|---|
| 739 |
|
|---|
| 740 | ui_wdecor_set_rect(wdecor, &rect);
|
|---|
| 741 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
|---|
| 742 |
|
|---|
| 743 | /* Release on window border should do nothing */
|
|---|
| 744 | resp.resize = false;
|
|---|
| 745 | event.type = POS_RELEASE;
|
|---|
| 746 | event.hpos = 10;
|
|---|
| 747 | event.vpos = 10;
|
|---|
| 748 | ui_wdecor_frame_pos_event(wdecor, &event);
|
|---|
| 749 | PCUT_ASSERT_FALSE(resp.resize);
|
|---|
| 750 |
|
|---|
| 751 | /* Press in the middle of the window should do nothing */
|
|---|
| 752 | resp.resize = false;
|
|---|
| 753 | event.type = POS_PRESS;
|
|---|
| 754 | event.hpos = 50;
|
|---|
| 755 | event.vpos = 100;
|
|---|
| 756 | ui_wdecor_frame_pos_event(wdecor, &event);
|
|---|
| 757 | PCUT_ASSERT_FALSE(resp.resize);
|
|---|
| 758 |
|
|---|
| 759 | /* Press on window border should cause resize to be called */
|
|---|
| 760 | resp.resize = false;
|
|---|
| 761 | event.type = POS_PRESS;
|
|---|
| 762 | event.hpos = 10;
|
|---|
| 763 | event.vpos = 20;
|
|---|
| 764 | ui_wdecor_frame_pos_event(wdecor, &event);
|
|---|
| 765 | PCUT_ASSERT_TRUE(resp.resize);
|
|---|
| 766 |
|
|---|
| 767 | ui_wdecor_destroy(wdecor);
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
|---|
| 771 | {
|
|---|
| 772 | (void) arg;
|
|---|
| 773 | (void) color;
|
|---|
| 774 | return EOK;
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
|---|
| 778 | {
|
|---|
| 779 | (void) arg;
|
|---|
| 780 | (void) rect;
|
|---|
| 781 | return EOK;
|
|---|
| 782 | }
|
|---|
| 783 |
|
|---|
| 784 | static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
|---|
| 785 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
|---|
| 786 | {
|
|---|
| 787 | test_gc_t *tgc = (test_gc_t *) arg;
|
|---|
| 788 | testgc_bitmap_t *tbm;
|
|---|
| 789 |
|
|---|
| 790 | tbm = calloc(1, sizeof(testgc_bitmap_t));
|
|---|
| 791 | if (tbm == NULL)
|
|---|
| 792 | return ENOMEM;
|
|---|
| 793 |
|
|---|
| 794 | if (alloc == NULL) {
|
|---|
| 795 | tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
|
|---|
| 796 | sizeof(uint32_t);
|
|---|
| 797 | tbm->alloc.off0 = 0;
|
|---|
| 798 | tbm->alloc.pixels = calloc(sizeof(uint32_t),
|
|---|
| 799 | (params->rect.p1.x - params->rect.p0.x) *
|
|---|
| 800 | (params->rect.p1.y - params->rect.p0.y));
|
|---|
| 801 | tbm->myalloc = true;
|
|---|
| 802 | if (tbm->alloc.pixels == NULL) {
|
|---|
| 803 | free(tbm);
|
|---|
| 804 | return ENOMEM;
|
|---|
| 805 | }
|
|---|
| 806 | } else {
|
|---|
| 807 | tbm->alloc = *alloc;
|
|---|
| 808 | }
|
|---|
| 809 |
|
|---|
| 810 | tbm->tgc = tgc;
|
|---|
| 811 | tgc->bm_created = true;
|
|---|
| 812 | tgc->bm_params = *params;
|
|---|
| 813 | tgc->bm_pixels = tbm->alloc.pixels;
|
|---|
| 814 | *rbm = (void *)tbm;
|
|---|
| 815 | return EOK;
|
|---|
| 816 | }
|
|---|
| 817 |
|
|---|
| 818 | static errno_t testgc_bitmap_destroy(void *bm)
|
|---|
| 819 | {
|
|---|
| 820 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
|---|
| 821 | if (tbm->myalloc)
|
|---|
| 822 | free(tbm->alloc.pixels);
|
|---|
| 823 | tbm->tgc->bm_destroyed = true;
|
|---|
| 824 | free(tbm);
|
|---|
| 825 | return EOK;
|
|---|
| 826 | }
|
|---|
| 827 |
|
|---|
| 828 | static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
|
|---|
| 829 | gfx_coord2_t *offs)
|
|---|
| 830 | {
|
|---|
| 831 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
|---|
| 832 | tbm->tgc->bm_rendered = true;
|
|---|
| 833 | tbm->tgc->bm_srect = *srect;
|
|---|
| 834 | tbm->tgc->bm_offs = *offs;
|
|---|
| 835 | return EOK;
|
|---|
| 836 | }
|
|---|
| 837 |
|
|---|
| 838 | static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
|---|
| 839 | {
|
|---|
| 840 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
|---|
| 841 | *alloc = tbm->alloc;
|
|---|
| 842 | tbm->tgc->bm_got_alloc = true;
|
|---|
| 843 | return EOK;
|
|---|
| 844 | }
|
|---|
| 845 |
|
|---|
| 846 | static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
|
|---|
| 847 | {
|
|---|
| 848 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
|---|
| 849 |
|
|---|
| 850 | resp->close = true;
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | static void test_wdecor_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
|
|---|
| 854 | {
|
|---|
| 855 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
|---|
| 856 |
|
|---|
| 857 | resp->move = true;
|
|---|
| 858 | resp->pos = *pos;
|
|---|
| 859 | }
|
|---|
| 860 |
|
|---|
| 861 | static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg,
|
|---|
| 862 | ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos)
|
|---|
| 863 | {
|
|---|
| 864 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
|---|
| 865 |
|
|---|
| 866 | resp->resize = true;
|
|---|
| 867 | resp->rsztype = rsztype;
|
|---|
| 868 | resp->pos = *pos;
|
|---|
| 869 | }
|
|---|
| 870 |
|
|---|
| 871 | static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg,
|
|---|
| 872 | ui_stock_cursor_t cursor)
|
|---|
| 873 | {
|
|---|
| 874 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
|---|
| 875 |
|
|---|
| 876 | resp->set_cursor = true;
|
|---|
| 877 | resp->cursor = cursor;
|
|---|
| 878 | }
|
|---|
| 879 |
|
|---|
| 880 | PCUT_EXPORT(wdecor);
|
|---|