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