1 | /*
|
---|
2 | * Copyright (c) 2023 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_clip_rect(void *, gfx_rect_t *);
|
---|
44 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
---|
45 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
---|
46 | static errno_t testgc_update(void *);
|
---|
47 | static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
|
---|
48 | gfx_bitmap_alloc_t *, void **);
|
---|
49 | static errno_t testgc_bitmap_destroy(void *);
|
---|
50 | static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
|
---|
51 | static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
|
---|
52 |
|
---|
53 | static gfx_context_ops_t ops = {
|
---|
54 | .set_clip_rect = testgc_set_clip_rect,
|
---|
55 | .set_color = testgc_set_color,
|
---|
56 | .fill_rect = testgc_fill_rect,
|
---|
57 | .update = testgc_update,
|
---|
58 | .bitmap_create = testgc_bitmap_create,
|
---|
59 | .bitmap_destroy = testgc_bitmap_destroy,
|
---|
60 | .bitmap_render = testgc_bitmap_render,
|
---|
61 | .bitmap_get_alloc = testgc_bitmap_get_alloc
|
---|
62 | };
|
---|
63 |
|
---|
64 | static void test_wdecor_sysmenu(ui_wdecor_t *, void *, sysarg_t);
|
---|
65 | static void test_wdecor_minimize(ui_wdecor_t *, void *);
|
---|
66 | static void test_wdecor_maximize(ui_wdecor_t *, void *);
|
---|
67 | static void test_wdecor_unmaximize(ui_wdecor_t *, void *);
|
---|
68 | static void test_wdecor_close(ui_wdecor_t *, void *);
|
---|
69 | static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *, sysarg_t);
|
---|
70 | static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
|
---|
71 | gfx_coord2_t *, sysarg_t);
|
---|
72 | static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
|
---|
73 |
|
---|
74 | static ui_wdecor_cb_t test_wdecor_cb = {
|
---|
75 | .sysmenu = test_wdecor_sysmenu,
|
---|
76 | .minimize = test_wdecor_minimize,
|
---|
77 | .maximize = test_wdecor_maximize,
|
---|
78 | .unmaximize = test_wdecor_unmaximize,
|
---|
79 | .close = test_wdecor_close,
|
---|
80 | .move = test_wdecor_move,
|
---|
81 | .resize = test_wdecor_resize,
|
---|
82 | .set_cursor = test_wdecor_set_cursor
|
---|
83 | };
|
---|
84 |
|
---|
85 | static ui_wdecor_cb_t dummy_wdecor_cb = {
|
---|
86 | };
|
---|
87 |
|
---|
88 | typedef struct {
|
---|
89 | bool bm_created;
|
---|
90 | bool bm_destroyed;
|
---|
91 | gfx_bitmap_params_t bm_params;
|
---|
92 | void *bm_pixels;
|
---|
93 | gfx_rect_t bm_srect;
|
---|
94 | gfx_coord2_t bm_offs;
|
---|
95 | bool bm_rendered;
|
---|
96 | bool bm_got_alloc;
|
---|
97 | } test_gc_t;
|
---|
98 |
|
---|
99 | typedef struct {
|
---|
100 | test_gc_t *tgc;
|
---|
101 | gfx_bitmap_alloc_t alloc;
|
---|
102 | bool myalloc;
|
---|
103 | } testgc_bitmap_t;
|
---|
104 |
|
---|
105 | typedef struct {
|
---|
106 | bool sysmenu;
|
---|
107 | bool minimize;
|
---|
108 | bool maximize;
|
---|
109 | bool unmaximize;
|
---|
110 | bool close;
|
---|
111 | bool move;
|
---|
112 | gfx_coord2_t pos;
|
---|
113 | sysarg_t pos_id;
|
---|
114 | sysarg_t idev_id;
|
---|
115 | bool resize;
|
---|
116 | ui_wdecor_rsztype_t rsztype;
|
---|
117 | bool set_cursor;
|
---|
118 | ui_stock_cursor_t cursor;
|
---|
119 | } test_cb_resp_t;
|
---|
120 |
|
---|
121 | /** Create and destroy button */
|
---|
122 | PCUT_TEST(create_destroy)
|
---|
123 | {
|
---|
124 | ui_wdecor_t *wdecor = NULL;
|
---|
125 | errno_t rc;
|
---|
126 |
|
---|
127 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
128 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
129 | PCUT_ASSERT_NOT_NULL(wdecor);
|
---|
130 |
|
---|
131 | ui_wdecor_destroy(wdecor);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /** ui_wdecor_destroy() can take NULL argument (no-op) */
|
---|
135 | PCUT_TEST(destroy_null)
|
---|
136 | {
|
---|
137 | ui_wdecor_destroy(NULL);
|
---|
138 | }
|
---|
139 |
|
---|
140 | /** Set window decoration rectangle sets internal field */
|
---|
141 | PCUT_TEST(set_rect)
|
---|
142 | {
|
---|
143 | gfx_context_t *gc = NULL;
|
---|
144 | test_gc_t tgc;
|
---|
145 | ui_resource_t *resource = NULL;
|
---|
146 | ui_wdecor_t *wdecor;
|
---|
147 | gfx_rect_t rect;
|
---|
148 | errno_t rc;
|
---|
149 |
|
---|
150 | memset(&tgc, 0, sizeof(tgc));
|
---|
151 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
153 |
|
---|
154 | rc = ui_resource_create(gc, false, &resource);
|
---|
155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
156 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
157 |
|
---|
158 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
159 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
160 |
|
---|
161 | rect.p0.x = 1;
|
---|
162 | rect.p0.y = 2;
|
---|
163 | rect.p1.x = 3;
|
---|
164 | rect.p1.y = 4;
|
---|
165 |
|
---|
166 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
167 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, wdecor->rect.p0.x);
|
---|
168 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, wdecor->rect.p0.y);
|
---|
169 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, wdecor->rect.p1.x);
|
---|
170 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, wdecor->rect.p1.y);
|
---|
171 |
|
---|
172 | ui_wdecor_destroy(wdecor);
|
---|
173 | ui_resource_destroy(resource);
|
---|
174 |
|
---|
175 | rc = gfx_context_delete(gc);
|
---|
176 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
177 | }
|
---|
178 |
|
---|
179 | /** Set window decoration active sets internal field */
|
---|
180 | PCUT_TEST(set_active)
|
---|
181 | {
|
---|
182 | ui_wdecor_t *wdecor;
|
---|
183 | errno_t rc;
|
---|
184 |
|
---|
185 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
186 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
187 |
|
---|
188 | PCUT_ASSERT_TRUE(wdecor->active);
|
---|
189 |
|
---|
190 | ui_wdecor_set_active(wdecor, false);
|
---|
191 | PCUT_ASSERT_FALSE(wdecor->active);
|
---|
192 |
|
---|
193 | ui_wdecor_set_active(wdecor, true);
|
---|
194 | PCUT_ASSERT_TRUE(wdecor->active);
|
---|
195 |
|
---|
196 | ui_wdecor_destroy(wdecor);
|
---|
197 | }
|
---|
198 |
|
---|
199 | /** Set window decoration maximized sets internal field */
|
---|
200 | PCUT_TEST(set_maximized)
|
---|
201 | {
|
---|
202 | ui_wdecor_t *wdecor;
|
---|
203 | errno_t rc;
|
---|
204 |
|
---|
205 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
206 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
207 |
|
---|
208 | PCUT_ASSERT_TRUE(wdecor->active);
|
---|
209 |
|
---|
210 | ui_wdecor_set_maximized(wdecor, false);
|
---|
211 | PCUT_ASSERT_FALSE(wdecor->maximized);
|
---|
212 |
|
---|
213 | ui_wdecor_set_maximized(wdecor, true);
|
---|
214 | PCUT_ASSERT_TRUE(wdecor->maximized);
|
---|
215 |
|
---|
216 | ui_wdecor_destroy(wdecor);
|
---|
217 | }
|
---|
218 |
|
---|
219 | /** Paint button */
|
---|
220 | PCUT_TEST(paint)
|
---|
221 | {
|
---|
222 | errno_t rc;
|
---|
223 | gfx_context_t *gc = NULL;
|
---|
224 | test_gc_t tgc;
|
---|
225 | ui_resource_t *resource = NULL;
|
---|
226 | ui_wdecor_t *wdecor;
|
---|
227 |
|
---|
228 | memset(&tgc, 0, sizeof(tgc));
|
---|
229 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
230 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
231 |
|
---|
232 | rc = ui_resource_create(gc, false, &resource);
|
---|
233 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
234 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
235 |
|
---|
236 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
237 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
238 |
|
---|
239 | rc = ui_wdecor_paint(wdecor);
|
---|
240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
241 |
|
---|
242 | ui_wdecor_destroy(wdecor);
|
---|
243 | ui_resource_destroy(resource);
|
---|
244 |
|
---|
245 | rc = gfx_context_delete(gc);
|
---|
246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
247 | }
|
---|
248 |
|
---|
249 | /** Test ui_wdecor_sysmenu() */
|
---|
250 | PCUT_TEST(sysmenu)
|
---|
251 | {
|
---|
252 | errno_t rc;
|
---|
253 | ui_wdecor_t *wdecor;
|
---|
254 | test_cb_resp_t resp;
|
---|
255 |
|
---|
256 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
257 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
258 |
|
---|
259 | /* Sysmenu callback with no callbacks set */
|
---|
260 | ui_wdecor_sysmenu(wdecor, 42);
|
---|
261 |
|
---|
262 | /* Sysmenu callback with sysmenu callback not implemented */
|
---|
263 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
264 | ui_wdecor_sysmenu(wdecor, 42);
|
---|
265 |
|
---|
266 | /* Sysmenu callback with real callback set */
|
---|
267 | resp.sysmenu = false;
|
---|
268 | resp.idev_id = 0;
|
---|
269 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
270 | ui_wdecor_sysmenu(wdecor, 42);
|
---|
271 | PCUT_ASSERT_TRUE(resp.sysmenu);
|
---|
272 | PCUT_ASSERT_INT_EQUALS(42, resp.idev_id);
|
---|
273 |
|
---|
274 | ui_wdecor_destroy(wdecor);
|
---|
275 | }
|
---|
276 |
|
---|
277 | /** Test ui_wdecor_minimize() */
|
---|
278 | PCUT_TEST(minimize)
|
---|
279 | {
|
---|
280 | errno_t rc;
|
---|
281 | ui_wdecor_t *wdecor;
|
---|
282 | test_cb_resp_t resp;
|
---|
283 |
|
---|
284 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
285 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
286 |
|
---|
287 | /* Minimize callback with no callbacks set */
|
---|
288 | ui_wdecor_minimize(wdecor);
|
---|
289 |
|
---|
290 | /* Minimize callback with minimize callback not implemented */
|
---|
291 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
292 | ui_wdecor_minimize(wdecor);
|
---|
293 |
|
---|
294 | /* Minimize callback with real callback set */
|
---|
295 | resp.minimize = false;
|
---|
296 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
297 | ui_wdecor_minimize(wdecor);
|
---|
298 | PCUT_ASSERT_TRUE(resp.minimize);
|
---|
299 |
|
---|
300 | ui_wdecor_destroy(wdecor);
|
---|
301 | }
|
---|
302 |
|
---|
303 | /** Test ui_wdecor_maximize() */
|
---|
304 | PCUT_TEST(maximize)
|
---|
305 | {
|
---|
306 | errno_t rc;
|
---|
307 | ui_wdecor_t *wdecor;
|
---|
308 | test_cb_resp_t resp;
|
---|
309 |
|
---|
310 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
311 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
312 |
|
---|
313 | /* Maximize callback with no callbacks set */
|
---|
314 | ui_wdecor_maximize(wdecor);
|
---|
315 |
|
---|
316 | /* Maxmimize callback with maximize callback not implemented */
|
---|
317 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
318 | ui_wdecor_maximize(wdecor);
|
---|
319 |
|
---|
320 | /* Maximize callback with real callback set */
|
---|
321 | resp.maximize = false;
|
---|
322 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
323 | ui_wdecor_maximize(wdecor);
|
---|
324 | PCUT_ASSERT_TRUE(resp.maximize);
|
---|
325 |
|
---|
326 | ui_wdecor_destroy(wdecor);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /** Test ui_wdecor_unmaximize() */
|
---|
330 | PCUT_TEST(unmaximize)
|
---|
331 | {
|
---|
332 | errno_t rc;
|
---|
333 | ui_wdecor_t *wdecor;
|
---|
334 | test_cb_resp_t resp;
|
---|
335 |
|
---|
336 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
337 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
338 |
|
---|
339 | /* Unmaximize callback with no callbacks set */
|
---|
340 | ui_wdecor_unmaximize(wdecor);
|
---|
341 |
|
---|
342 | /* Unmaximize callback with unmaximize callback not implemented */
|
---|
343 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
344 | ui_wdecor_unmaximize(wdecor);
|
---|
345 |
|
---|
346 | /* Unmaximize callback with real callback set */
|
---|
347 | resp.unmaximize = false;
|
---|
348 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
349 | ui_wdecor_unmaximize(wdecor);
|
---|
350 | PCUT_ASSERT_TRUE(resp.unmaximize);
|
---|
351 |
|
---|
352 | ui_wdecor_destroy(wdecor);
|
---|
353 | }
|
---|
354 |
|
---|
355 | /** Test ui_wdecor_close() */
|
---|
356 | PCUT_TEST(close)
|
---|
357 | {
|
---|
358 | errno_t rc;
|
---|
359 | ui_wdecor_t *wdecor;
|
---|
360 | test_cb_resp_t resp;
|
---|
361 |
|
---|
362 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
363 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
364 |
|
---|
365 | /* Close callback with no callbacks set */
|
---|
366 | ui_wdecor_close(wdecor);
|
---|
367 |
|
---|
368 | /* Close callback with close callback not implemented */
|
---|
369 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
370 | ui_wdecor_close(wdecor);
|
---|
371 |
|
---|
372 | /* Close callback with real callback set */
|
---|
373 | resp.close = false;
|
---|
374 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
375 | ui_wdecor_close(wdecor);
|
---|
376 | PCUT_ASSERT_TRUE(resp.close);
|
---|
377 |
|
---|
378 | ui_wdecor_destroy(wdecor);
|
---|
379 | }
|
---|
380 |
|
---|
381 | /** Test ui_wdecor_move() */
|
---|
382 | PCUT_TEST(move)
|
---|
383 | {
|
---|
384 | errno_t rc;
|
---|
385 | ui_wdecor_t *wdecor;
|
---|
386 | test_cb_resp_t resp;
|
---|
387 | gfx_coord2_t pos;
|
---|
388 | sysarg_t pos_id;
|
---|
389 |
|
---|
390 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
391 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
392 |
|
---|
393 | pos.x = 3;
|
---|
394 | pos.y = 4;
|
---|
395 | pos_id = 5;
|
---|
396 |
|
---|
397 | /* Move callback with no callbacks set */
|
---|
398 | ui_wdecor_move(wdecor, &pos, pos_id);
|
---|
399 |
|
---|
400 | /* Move callback with move callback not implemented */
|
---|
401 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
402 | ui_wdecor_move(wdecor, &pos, pos_id);
|
---|
403 |
|
---|
404 | /* Move callback with real callback set */
|
---|
405 | resp.move = false;
|
---|
406 | resp.pos.x = 0;
|
---|
407 | resp.pos.y = 0;
|
---|
408 | resp.pos_id = 0;
|
---|
409 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
410 | ui_wdecor_move(wdecor, &pos, pos_id);
|
---|
411 | PCUT_ASSERT_TRUE(resp.move);
|
---|
412 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
---|
413 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
---|
414 | PCUT_ASSERT_INT_EQUALS(pos_id, resp.pos_id);
|
---|
415 |
|
---|
416 | ui_wdecor_destroy(wdecor);
|
---|
417 | }
|
---|
418 |
|
---|
419 | /** Test ui_wdecor_resize() */
|
---|
420 | PCUT_TEST(resize)
|
---|
421 | {
|
---|
422 | errno_t rc;
|
---|
423 | ui_wdecor_t *wdecor;
|
---|
424 | test_cb_resp_t resp;
|
---|
425 | ui_wdecor_rsztype_t rsztype;
|
---|
426 | gfx_coord2_t pos;
|
---|
427 | sysarg_t pos_id;
|
---|
428 |
|
---|
429 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
430 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
431 |
|
---|
432 | rsztype = ui_wr_bottom;
|
---|
433 | pos.x = 3;
|
---|
434 | pos.y = 4;
|
---|
435 | pos_id = 5;
|
---|
436 |
|
---|
437 | /* Resize callback with no callbacks set */
|
---|
438 | ui_wdecor_resize(wdecor, rsztype, &pos, pos_id);
|
---|
439 |
|
---|
440 | /* Resize callback with move callback not implemented */
|
---|
441 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
442 | ui_wdecor_resize(wdecor, rsztype, &pos, pos_id);
|
---|
443 |
|
---|
444 | /* Resize callback with real callback set */
|
---|
445 | resp.resize = false;
|
---|
446 | resp.rsztype = ui_wr_none;
|
---|
447 | resp.pos.x = 0;
|
---|
448 | resp.pos.y = 0;
|
---|
449 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
450 | ui_wdecor_resize(wdecor, rsztype, &pos, pos_id);
|
---|
451 | PCUT_ASSERT_TRUE(resp.resize);
|
---|
452 | PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype);
|
---|
453 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
---|
454 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
---|
455 | PCUT_ASSERT_INT_EQUALS(pos_id, resp.pos_id);
|
---|
456 |
|
---|
457 | ui_wdecor_destroy(wdecor);
|
---|
458 | }
|
---|
459 |
|
---|
460 | /** Test ui_wdecor_set_cursor() */
|
---|
461 | PCUT_TEST(set_cursor)
|
---|
462 | {
|
---|
463 | errno_t rc;
|
---|
464 | ui_wdecor_t *wdecor;
|
---|
465 | test_cb_resp_t resp;
|
---|
466 | ui_stock_cursor_t cursor;
|
---|
467 |
|
---|
468 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
469 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
470 |
|
---|
471 | cursor = ui_curs_size_uldr;
|
---|
472 |
|
---|
473 | /* Set cursor callback with no callbacks set */
|
---|
474 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
475 |
|
---|
476 | /* Set cursor callback with move callback not implemented */
|
---|
477 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
478 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
479 |
|
---|
480 | /* Set cursor callback with real callback set */
|
---|
481 | resp.set_cursor = false;
|
---|
482 | resp.cursor = ui_curs_arrow;
|
---|
483 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
484 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
485 | PCUT_ASSERT_TRUE(resp.set_cursor);
|
---|
486 | PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor);
|
---|
487 |
|
---|
488 | ui_wdecor_destroy(wdecor);
|
---|
489 | }
|
---|
490 |
|
---|
491 | /** Clicking the close button generates close callback */
|
---|
492 | PCUT_TEST(close_btn_clicked)
|
---|
493 | {
|
---|
494 | gfx_context_t *gc = NULL;
|
---|
495 | test_gc_t tgc;
|
---|
496 | ui_resource_t *resource = NULL;
|
---|
497 | ui_wdecor_t *wdecor;
|
---|
498 | gfx_rect_t rect;
|
---|
499 | test_cb_resp_t resp;
|
---|
500 | errno_t rc;
|
---|
501 |
|
---|
502 | memset(&tgc, 0, sizeof(tgc));
|
---|
503 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
504 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
505 |
|
---|
506 | rc = ui_resource_create(gc, false, &resource);
|
---|
507 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
508 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
509 |
|
---|
510 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
511 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
512 |
|
---|
513 | rect.p0.x = 10;
|
---|
514 | rect.p0.y = 20;
|
---|
515 | rect.p1.x = 100;
|
---|
516 | rect.p1.y = 200;
|
---|
517 |
|
---|
518 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
519 |
|
---|
520 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
521 |
|
---|
522 | resp.close = false;
|
---|
523 |
|
---|
524 | ui_pbutton_clicked(wdecor->btn_close);
|
---|
525 | PCUT_ASSERT_TRUE(resp.close);
|
---|
526 |
|
---|
527 | ui_wdecor_destroy(wdecor);
|
---|
528 | ui_resource_destroy(resource);
|
---|
529 |
|
---|
530 | rc = gfx_context_delete(gc);
|
---|
531 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
532 | }
|
---|
533 |
|
---|
534 | /** Button press on title bar generates move callback */
|
---|
535 | PCUT_TEST(pos_event_move)
|
---|
536 | {
|
---|
537 | errno_t rc;
|
---|
538 | gfx_rect_t rect;
|
---|
539 | pos_event_t event;
|
---|
540 | gfx_context_t *gc = NULL;
|
---|
541 | test_gc_t tgc;
|
---|
542 | test_cb_resp_t resp;
|
---|
543 | ui_resource_t *resource = NULL;
|
---|
544 | ui_wdecor_t *wdecor;
|
---|
545 |
|
---|
546 | memset(&tgc, 0, sizeof(tgc));
|
---|
547 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
548 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
549 |
|
---|
550 | rc = ui_resource_create(gc, false, &resource);
|
---|
551 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
552 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
553 |
|
---|
554 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
555 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
556 |
|
---|
557 | rect.p0.x = 10;
|
---|
558 | rect.p0.y = 20;
|
---|
559 | rect.p1.x = 100;
|
---|
560 | rect.p1.y = 200;
|
---|
561 |
|
---|
562 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
563 |
|
---|
564 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
565 |
|
---|
566 | resp.move = false;
|
---|
567 | resp.pos.x = 0;
|
---|
568 | resp.pos.y = 0;
|
---|
569 |
|
---|
570 | event.type = POS_PRESS;
|
---|
571 | event.hpos = 50;
|
---|
572 | event.vpos = 25;
|
---|
573 | ui_wdecor_pos_event(wdecor, &event);
|
---|
574 |
|
---|
575 | PCUT_ASSERT_TRUE(resp.move);
|
---|
576 | PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos.x);
|
---|
577 | PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos.y);
|
---|
578 |
|
---|
579 | ui_wdecor_destroy(wdecor);
|
---|
580 | ui_resource_destroy(resource);
|
---|
581 |
|
---|
582 | rc = gfx_context_delete(gc);
|
---|
583 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
584 | }
|
---|
585 |
|
---|
586 | /** Pressing F9 generates sysmenu event */
|
---|
587 | PCUT_TEST(kbd_f9_sysmenu)
|
---|
588 | {
|
---|
589 | errno_t rc;
|
---|
590 | gfx_rect_t rect;
|
---|
591 | kbd_event_t event;
|
---|
592 | gfx_context_t *gc = NULL;
|
---|
593 | test_gc_t tgc;
|
---|
594 | test_cb_resp_t resp;
|
---|
595 | ui_resource_t *resource = NULL;
|
---|
596 | ui_wdecor_t *wdecor;
|
---|
597 |
|
---|
598 | memset(&tgc, 0, sizeof(tgc));
|
---|
599 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
600 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
601 |
|
---|
602 | rc = ui_resource_create(gc, false, &resource);
|
---|
603 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
604 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
605 |
|
---|
606 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
607 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
608 |
|
---|
609 | rect.p0.x = 10;
|
---|
610 | rect.p0.y = 20;
|
---|
611 | rect.p1.x = 100;
|
---|
612 | rect.p1.y = 200;
|
---|
613 |
|
---|
614 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
615 |
|
---|
616 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
617 |
|
---|
618 | resp.move = false;
|
---|
619 | resp.pos.x = 0;
|
---|
620 | resp.pos.y = 0;
|
---|
621 |
|
---|
622 | event.type = KEY_PRESS;
|
---|
623 | event.mods = 0;
|
---|
624 | event.key = KC_F9;
|
---|
625 | event.kbd_id = 42;
|
---|
626 | ui_wdecor_kbd_event(wdecor, &event);
|
---|
627 |
|
---|
628 | PCUT_ASSERT_TRUE(resp.sysmenu);
|
---|
629 | PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id);
|
---|
630 |
|
---|
631 | ui_wdecor_destroy(wdecor);
|
---|
632 | ui_resource_destroy(resource);
|
---|
633 |
|
---|
634 | rc = gfx_context_delete(gc);
|
---|
635 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
636 | }
|
---|
637 |
|
---|
638 | /** ui_wdecor_get_geom() with ui_wds_none produces the correct geometry */
|
---|
639 | PCUT_TEST(get_geom_none)
|
---|
640 | {
|
---|
641 | gfx_context_t *gc = NULL;
|
---|
642 | test_gc_t tgc;
|
---|
643 | ui_resource_t *resource = NULL;
|
---|
644 | ui_wdecor_t *wdecor;
|
---|
645 | gfx_rect_t rect;
|
---|
646 | ui_wdecor_geom_t geom;
|
---|
647 | errno_t rc;
|
---|
648 |
|
---|
649 | memset(&tgc, 0, sizeof(tgc));
|
---|
650 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
651 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
652 |
|
---|
653 | rc = ui_resource_create(gc, false, &resource);
|
---|
654 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
655 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
656 |
|
---|
657 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
658 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
659 |
|
---|
660 | rect.p0.x = 10;
|
---|
661 | rect.p0.y = 20;
|
---|
662 | rect.p1.x = 100;
|
---|
663 | rect.p1.y = 200;
|
---|
664 |
|
---|
665 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
666 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
667 |
|
---|
668 | PCUT_ASSERT_INT_EQUALS(10, geom.interior_rect.p0.x);
|
---|
669 | PCUT_ASSERT_INT_EQUALS(20, geom.interior_rect.p0.y);
|
---|
670 | PCUT_ASSERT_INT_EQUALS(100, geom.interior_rect.p1.x);
|
---|
671 | PCUT_ASSERT_INT_EQUALS(200, geom.interior_rect.p1.y);
|
---|
672 |
|
---|
673 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
---|
674 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
---|
675 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
---|
676 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
---|
677 |
|
---|
678 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
679 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
680 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
681 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
682 |
|
---|
683 | PCUT_ASSERT_INT_EQUALS(10, geom.app_area_rect.p0.x);
|
---|
684 | PCUT_ASSERT_INT_EQUALS(20, geom.app_area_rect.p0.y);
|
---|
685 | PCUT_ASSERT_INT_EQUALS(100, geom.app_area_rect.p1.x);
|
---|
686 | PCUT_ASSERT_INT_EQUALS(200, geom.app_area_rect.p1.y);
|
---|
687 |
|
---|
688 | ui_wdecor_destroy(wdecor);
|
---|
689 | ui_resource_destroy(resource);
|
---|
690 |
|
---|
691 | rc = gfx_context_delete(gc);
|
---|
692 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
693 | }
|
---|
694 |
|
---|
695 | /** ui_wdecor_get_geom() with ui_wds_frame produces the correct geometry */
|
---|
696 | PCUT_TEST(get_geom_frame)
|
---|
697 | {
|
---|
698 | gfx_context_t *gc = NULL;
|
---|
699 | test_gc_t tgc;
|
---|
700 | ui_resource_t *resource = NULL;
|
---|
701 | ui_wdecor_t *wdecor;
|
---|
702 | gfx_rect_t rect;
|
---|
703 | ui_wdecor_geom_t geom;
|
---|
704 | errno_t rc;
|
---|
705 |
|
---|
706 | memset(&tgc, 0, sizeof(tgc));
|
---|
707 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
708 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
709 |
|
---|
710 | rc = ui_resource_create(gc, false, &resource);
|
---|
711 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
712 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
713 |
|
---|
714 | rc = ui_wdecor_create(resource, "Hello", ui_wds_frame, &wdecor);
|
---|
715 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
716 |
|
---|
717 | rect.p0.x = 10;
|
---|
718 | rect.p0.y = 20;
|
---|
719 | rect.p1.x = 100;
|
---|
720 | rect.p1.y = 200;
|
---|
721 |
|
---|
722 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
723 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
724 |
|
---|
725 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
726 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
727 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
728 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
729 |
|
---|
730 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
---|
731 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
---|
732 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
---|
733 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
---|
734 |
|
---|
735 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
736 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
737 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
738 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
739 |
|
---|
740 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
741 | PCUT_ASSERT_INT_EQUALS(24, geom.app_area_rect.p0.y);
|
---|
742 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
743 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
744 |
|
---|
745 | ui_wdecor_destroy(wdecor);
|
---|
746 | ui_resource_destroy(resource);
|
---|
747 |
|
---|
748 | rc = gfx_context_delete(gc);
|
---|
749 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
750 | }
|
---|
751 |
|
---|
752 | /** ui_wdecor_get_geom() with ui_wds_frame | ui_wds_titlebar */
|
---|
753 | PCUT_TEST(get_geom_frame_titlebar)
|
---|
754 | {
|
---|
755 | gfx_context_t *gc = NULL;
|
---|
756 | test_gc_t tgc;
|
---|
757 | ui_resource_t *resource = NULL;
|
---|
758 | ui_wdecor_t *wdecor;
|
---|
759 | gfx_rect_t rect;
|
---|
760 | ui_wdecor_geom_t geom;
|
---|
761 | errno_t rc;
|
---|
762 |
|
---|
763 | memset(&tgc, 0, sizeof(tgc));
|
---|
764 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
765 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
766 |
|
---|
767 | rc = ui_resource_create(gc, false, &resource);
|
---|
768 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
769 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
770 |
|
---|
771 | rc = ui_wdecor_create(resource, "Hello", ui_wds_frame | ui_wds_titlebar,
|
---|
772 | &wdecor);
|
---|
773 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
774 |
|
---|
775 | rect.p0.x = 10;
|
---|
776 | rect.p0.y = 20;
|
---|
777 | rect.p1.x = 100;
|
---|
778 | rect.p1.y = 200;
|
---|
779 |
|
---|
780 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
781 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
782 |
|
---|
783 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
784 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
785 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
786 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
787 |
|
---|
788 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
---|
789 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
---|
790 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
---|
791 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
---|
792 |
|
---|
793 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
794 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
795 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
796 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
797 |
|
---|
798 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
799 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
---|
800 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
801 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
802 |
|
---|
803 | ui_wdecor_destroy(wdecor);
|
---|
804 | ui_resource_destroy(resource);
|
---|
805 |
|
---|
806 | rc = gfx_context_delete(gc);
|
---|
807 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
808 | }
|
---|
809 |
|
---|
810 | /** ui_wdecor_get_geom() with ui_wds_decorated produces the correct geometry */
|
---|
811 | PCUT_TEST(get_geom_decorated)
|
---|
812 | {
|
---|
813 | gfx_context_t *gc = NULL;
|
---|
814 | test_gc_t tgc;
|
---|
815 | ui_resource_t *resource = NULL;
|
---|
816 | ui_wdecor_t *wdecor;
|
---|
817 | gfx_rect_t rect;
|
---|
818 | ui_wdecor_geom_t geom;
|
---|
819 | errno_t rc;
|
---|
820 |
|
---|
821 | memset(&tgc, 0, sizeof(tgc));
|
---|
822 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
823 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
824 |
|
---|
825 | rc = ui_resource_create(gc, false, &resource);
|
---|
826 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
827 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
828 |
|
---|
829 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
830 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
831 |
|
---|
832 | rect.p0.x = 10;
|
---|
833 | rect.p0.y = 20;
|
---|
834 | rect.p1.x = 100;
|
---|
835 | rect.p1.y = 200;
|
---|
836 |
|
---|
837 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
838 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
839 |
|
---|
840 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
841 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
842 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
843 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
844 |
|
---|
845 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
---|
846 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
---|
847 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
---|
848 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
---|
849 |
|
---|
850 | PCUT_ASSERT_INT_EQUALS(75, geom.btn_close_rect.p0.x);
|
---|
851 | PCUT_ASSERT_INT_EQUALS(25, geom.btn_close_rect.p0.y);
|
---|
852 | PCUT_ASSERT_INT_EQUALS(95, geom.btn_close_rect.p1.x);
|
---|
853 | PCUT_ASSERT_INT_EQUALS(45, geom.btn_close_rect.p1.y);
|
---|
854 |
|
---|
855 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
856 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
---|
857 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
858 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
859 |
|
---|
860 | ui_wdecor_destroy(wdecor);
|
---|
861 | ui_resource_destroy(resource);
|
---|
862 |
|
---|
863 | rc = gfx_context_delete(gc);
|
---|
864 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
865 | }
|
---|
866 |
|
---|
867 | /** ui_wdecor_rect_from_app() correctly converts application to window rect */
|
---|
868 | PCUT_TEST(rect_from_app)
|
---|
869 | {
|
---|
870 | gfx_rect_t arect;
|
---|
871 | gfx_rect_t rect;
|
---|
872 |
|
---|
873 | arect.p0.x = 14;
|
---|
874 | arect.p0.y = 46;
|
---|
875 | arect.p1.x = 96;
|
---|
876 | arect.p1.y = 196;
|
---|
877 |
|
---|
878 | ui_wdecor_rect_from_app(ui_wds_none, &arect, &rect);
|
---|
879 |
|
---|
880 | PCUT_ASSERT_INT_EQUALS(14, rect.p0.x);
|
---|
881 | PCUT_ASSERT_INT_EQUALS(46, rect.p0.y);
|
---|
882 | PCUT_ASSERT_INT_EQUALS(96, rect.p1.x);
|
---|
883 | PCUT_ASSERT_INT_EQUALS(196, rect.p1.y);
|
---|
884 |
|
---|
885 | ui_wdecor_rect_from_app(ui_wds_frame, &arect, &rect);
|
---|
886 |
|
---|
887 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
---|
888 | PCUT_ASSERT_INT_EQUALS(42, rect.p0.y);
|
---|
889 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
---|
890 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
---|
891 |
|
---|
892 | ui_wdecor_rect_from_app(ui_wds_decorated, &arect, &rect);
|
---|
893 |
|
---|
894 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
---|
895 | PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
|
---|
896 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
---|
897 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
---|
898 |
|
---|
899 | }
|
---|
900 |
|
---|
901 | /** Test ui_wdecor_get_rsztype() */
|
---|
902 | PCUT_TEST(get_rsztype)
|
---|
903 | {
|
---|
904 | gfx_context_t *gc = NULL;
|
---|
905 | test_gc_t tgc;
|
---|
906 | ui_resource_t *resource = NULL;
|
---|
907 | ui_wdecor_t *wdecor;
|
---|
908 | gfx_rect_t rect;
|
---|
909 | ui_wdecor_rsztype_t rsztype;
|
---|
910 | gfx_coord2_t pos;
|
---|
911 | errno_t rc;
|
---|
912 |
|
---|
913 | memset(&tgc, 0, sizeof(tgc));
|
---|
914 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
915 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
916 |
|
---|
917 | rc = ui_resource_create(gc, false, &resource);
|
---|
918 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
919 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
920 |
|
---|
921 | rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor);
|
---|
922 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
923 |
|
---|
924 | rect.p0.x = 10;
|
---|
925 | rect.p0.y = 20;
|
---|
926 | rect.p1.x = 100;
|
---|
927 | rect.p1.y = 200;
|
---|
928 |
|
---|
929 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
930 |
|
---|
931 | /* Outside of the window */
|
---|
932 | pos.x = 0;
|
---|
933 | pos.y = -1;
|
---|
934 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
935 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
936 |
|
---|
937 | /* Middle of the window */
|
---|
938 | pos.x = 50;
|
---|
939 | pos.y = 100;
|
---|
940 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
941 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
942 |
|
---|
943 | /* Top-left corner, but not on edge */
|
---|
944 | pos.x = 20;
|
---|
945 | pos.y = 30;
|
---|
946 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
947 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
948 |
|
---|
949 | /* Top-left corner on top edge */
|
---|
950 | pos.x = 20;
|
---|
951 | pos.y = 20;
|
---|
952 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
953 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
---|
954 |
|
---|
955 | /* Top-left corner on left edge */
|
---|
956 | pos.x = 10;
|
---|
957 | pos.y = 30;
|
---|
958 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
959 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
---|
960 |
|
---|
961 | /* Top-right corner on top edge */
|
---|
962 | pos.x = 90;
|
---|
963 | pos.y = 20;
|
---|
964 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
965 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
---|
966 |
|
---|
967 | /* Top-right corner on right edge */
|
---|
968 | pos.x = 99;
|
---|
969 | pos.y = 30;
|
---|
970 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
971 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
---|
972 |
|
---|
973 | /* Top edge */
|
---|
974 | pos.x = 50;
|
---|
975 | pos.y = 20;
|
---|
976 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
977 | PCUT_ASSERT_EQUALS(ui_wr_top, rsztype);
|
---|
978 |
|
---|
979 | /* Bottom edge */
|
---|
980 | pos.x = 50;
|
---|
981 | pos.y = 199;
|
---|
982 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
983 | PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype);
|
---|
984 |
|
---|
985 | /* Left edge */
|
---|
986 | pos.x = 10;
|
---|
987 | pos.y = 100;
|
---|
988 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
989 | PCUT_ASSERT_EQUALS(ui_wr_left, rsztype);
|
---|
990 |
|
---|
991 | /* Right edge */
|
---|
992 | pos.x = 99;
|
---|
993 | pos.y = 100;
|
---|
994 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
995 | PCUT_ASSERT_EQUALS(ui_wr_right, rsztype);
|
---|
996 |
|
---|
997 | ui_wdecor_destroy(wdecor);
|
---|
998 |
|
---|
999 | /* Non-resizable window */
|
---|
1000 |
|
---|
1001 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
1002 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1003 |
|
---|
1004 | rect.p0.x = 10;
|
---|
1005 | rect.p0.y = 20;
|
---|
1006 | rect.p1.x = 100;
|
---|
1007 | rect.p1.y = 200;
|
---|
1008 |
|
---|
1009 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
1010 |
|
---|
1011 | pos.x = 10;
|
---|
1012 | pos.y = 20;
|
---|
1013 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1014 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
1015 |
|
---|
1016 | ui_wdecor_destroy(wdecor);
|
---|
1017 | ui_resource_destroy(resource);
|
---|
1018 |
|
---|
1019 | rc = gfx_context_delete(gc);
|
---|
1020 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | /** Test ui_wdecor_cursor_from_rsztype() */
|
---|
1024 | PCUT_TEST(cursor_from_rsztype)
|
---|
1025 | {
|
---|
1026 | PCUT_ASSERT_EQUALS(ui_curs_arrow,
|
---|
1027 | ui_wdecor_cursor_from_rsztype(ui_wr_none));
|
---|
1028 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
---|
1029 | ui_wdecor_cursor_from_rsztype(ui_wr_top));
|
---|
1030 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
---|
1031 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom));
|
---|
1032 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
---|
1033 | ui_wdecor_cursor_from_rsztype(ui_wr_left));
|
---|
1034 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
---|
1035 | ui_wdecor_cursor_from_rsztype(ui_wr_right));
|
---|
1036 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
---|
1037 | ui_wdecor_cursor_from_rsztype(ui_wr_top_left));
|
---|
1038 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
---|
1039 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right));
|
---|
1040 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
---|
1041 | ui_wdecor_cursor_from_rsztype(ui_wr_top_right));
|
---|
1042 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
---|
1043 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left));
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | /** Test ui_wdecor_frame_pos_event() */
|
---|
1047 | PCUT_TEST(frame_pos_event)
|
---|
1048 | {
|
---|
1049 | gfx_context_t *gc = NULL;
|
---|
1050 | test_gc_t tgc;
|
---|
1051 | ui_resource_t *resource = NULL;
|
---|
1052 | ui_wdecor_t *wdecor;
|
---|
1053 | gfx_rect_t rect;
|
---|
1054 | test_cb_resp_t resp;
|
---|
1055 | pos_event_t event;
|
---|
1056 | errno_t rc;
|
---|
1057 |
|
---|
1058 | memset(&tgc, 0, sizeof(tgc));
|
---|
1059 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
1060 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1061 |
|
---|
1062 | rc = ui_resource_create(gc, false, &resource);
|
---|
1063 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1064 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
1065 |
|
---|
1066 | rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor);
|
---|
1067 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1068 |
|
---|
1069 | rect.p0.x = 10;
|
---|
1070 | rect.p0.y = 20;
|
---|
1071 | rect.p1.x = 100;
|
---|
1072 | rect.p1.y = 200;
|
---|
1073 |
|
---|
1074 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
1075 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
1076 |
|
---|
1077 | /* Release on window border should do nothing */
|
---|
1078 | resp.resize = false;
|
---|
1079 | event.type = POS_RELEASE;
|
---|
1080 | event.hpos = 10;
|
---|
1081 | event.vpos = 10;
|
---|
1082 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
1083 | PCUT_ASSERT_FALSE(resp.resize);
|
---|
1084 |
|
---|
1085 | /* Press in the middle of the window should do nothing */
|
---|
1086 | resp.resize = false;
|
---|
1087 | event.type = POS_PRESS;
|
---|
1088 | event.hpos = 50;
|
---|
1089 | event.vpos = 100;
|
---|
1090 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
1091 | PCUT_ASSERT_FALSE(resp.resize);
|
---|
1092 |
|
---|
1093 | /* Press on window border should cause resize to be called */
|
---|
1094 | resp.resize = false;
|
---|
1095 | event.type = POS_PRESS;
|
---|
1096 | event.hpos = 10;
|
---|
1097 | event.vpos = 20;
|
---|
1098 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
1099 | PCUT_ASSERT_TRUE(resp.resize);
|
---|
1100 |
|
---|
1101 | ui_wdecor_destroy(wdecor);
|
---|
1102 | ui_resource_destroy(resource);
|
---|
1103 |
|
---|
1104 | rc = gfx_context_delete(gc);
|
---|
1105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
|
---|
1109 | {
|
---|
1110 | (void) arg;
|
---|
1111 | (void) rect;
|
---|
1112 | return EOK;
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
---|
1116 | {
|
---|
1117 | (void) arg;
|
---|
1118 | (void) color;
|
---|
1119 | return EOK;
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
1123 | {
|
---|
1124 | (void) arg;
|
---|
1125 | (void) rect;
|
---|
1126 | return EOK;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | static errno_t testgc_update(void *arg)
|
---|
1130 | {
|
---|
1131 | (void) arg;
|
---|
1132 | return EOK;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
---|
1136 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
---|
1137 | {
|
---|
1138 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
1139 | testgc_bitmap_t *tbm;
|
---|
1140 |
|
---|
1141 | tbm = calloc(1, sizeof(testgc_bitmap_t));
|
---|
1142 | if (tbm == NULL)
|
---|
1143 | return ENOMEM;
|
---|
1144 |
|
---|
1145 | if (alloc == NULL) {
|
---|
1146 | tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
|
---|
1147 | sizeof(uint32_t);
|
---|
1148 | tbm->alloc.off0 = 0;
|
---|
1149 | tbm->alloc.pixels = calloc(sizeof(uint32_t),
|
---|
1150 | (params->rect.p1.x - params->rect.p0.x) *
|
---|
1151 | (params->rect.p1.y - params->rect.p0.y));
|
---|
1152 | tbm->myalloc = true;
|
---|
1153 | if (tbm->alloc.pixels == NULL) {
|
---|
1154 | free(tbm);
|
---|
1155 | return ENOMEM;
|
---|
1156 | }
|
---|
1157 | } else {
|
---|
1158 | tbm->alloc = *alloc;
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | tbm->tgc = tgc;
|
---|
1162 | tgc->bm_created = true;
|
---|
1163 | tgc->bm_params = *params;
|
---|
1164 | tgc->bm_pixels = tbm->alloc.pixels;
|
---|
1165 | *rbm = (void *)tbm;
|
---|
1166 | return EOK;
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | static errno_t testgc_bitmap_destroy(void *bm)
|
---|
1170 | {
|
---|
1171 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
1172 | if (tbm->myalloc)
|
---|
1173 | free(tbm->alloc.pixels);
|
---|
1174 | tbm->tgc->bm_destroyed = true;
|
---|
1175 | free(tbm);
|
---|
1176 | return EOK;
|
---|
1177 | }
|
---|
1178 |
|
---|
1179 | static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
|
---|
1180 | gfx_coord2_t *offs)
|
---|
1181 | {
|
---|
1182 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
1183 | tbm->tgc->bm_rendered = true;
|
---|
1184 | tbm->tgc->bm_srect = *srect;
|
---|
1185 | tbm->tgc->bm_offs = *offs;
|
---|
1186 | return EOK;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
---|
1190 | {
|
---|
1191 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
1192 | *alloc = tbm->alloc;
|
---|
1193 | tbm->tgc->bm_got_alloc = true;
|
---|
1194 | return EOK;
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | static void test_wdecor_sysmenu(ui_wdecor_t *wdecor, void *arg,
|
---|
1198 | sysarg_t idev_id)
|
---|
1199 | {
|
---|
1200 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1201 |
|
---|
1202 | resp->sysmenu = true;
|
---|
1203 | resp->idev_id = idev_id;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | static void test_wdecor_minimize(ui_wdecor_t *wdecor, void *arg)
|
---|
1207 | {
|
---|
1208 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1209 |
|
---|
1210 | resp->minimize = true;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | static void test_wdecor_maximize(ui_wdecor_t *wdecor, void *arg)
|
---|
1214 | {
|
---|
1215 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1216 |
|
---|
1217 | resp->maximize = true;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | static void test_wdecor_unmaximize(ui_wdecor_t *wdecor, void *arg)
|
---|
1221 | {
|
---|
1222 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1223 |
|
---|
1224 | resp->unmaximize = true;
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
|
---|
1228 | {
|
---|
1229 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1230 |
|
---|
1231 | resp->close = true;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | static void test_wdecor_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos,
|
---|
1235 | sysarg_t pos_id)
|
---|
1236 | {
|
---|
1237 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1238 |
|
---|
1239 | resp->move = true;
|
---|
1240 | resp->pos = *pos;
|
---|
1241 | resp->pos_id = pos_id;
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg,
|
---|
1245 | ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos, sysarg_t pos_id)
|
---|
1246 | {
|
---|
1247 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1248 |
|
---|
1249 | resp->resize = true;
|
---|
1250 | resp->rsztype = rsztype;
|
---|
1251 | resp->pos = *pos;
|
---|
1252 | resp->pos_id = pos_id;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg,
|
---|
1256 | ui_stock_cursor_t cursor)
|
---|
1257 | {
|
---|
1258 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1259 |
|
---|
1260 | resp->set_cursor = true;
|
---|
1261 | resp->cursor = cursor;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | PCUT_EXPORT(wdecor);
|
---|