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 window decoration */
|
---|
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 | /** Setting system menu handle as active/inactive */
|
---|
220 | PCUT_TEST(sysmenu_hdl_set_active)
|
---|
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_decorated, &wdecor);
|
---|
237 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
238 |
|
---|
239 | PCUT_ASSERT_FALSE(wdecor->sysmenu_hdl_active);
|
---|
240 | ui_wdecor_sysmenu_hdl_set_active(wdecor, true);
|
---|
241 | PCUT_ASSERT_TRUE(wdecor->sysmenu_hdl_active);
|
---|
242 | ui_wdecor_sysmenu_hdl_set_active(wdecor, false);
|
---|
243 | PCUT_ASSERT_FALSE(wdecor->sysmenu_hdl_active);
|
---|
244 |
|
---|
245 | ui_wdecor_destroy(wdecor);
|
---|
246 | ui_resource_destroy(resource);
|
---|
247 |
|
---|
248 | rc = gfx_context_delete(gc);
|
---|
249 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
250 | }
|
---|
251 |
|
---|
252 | /** Paint system menu handle */
|
---|
253 | PCUT_TEST(sysmenu_hdl_paint)
|
---|
254 | {
|
---|
255 | errno_t rc;
|
---|
256 | gfx_context_t *gc = NULL;
|
---|
257 | test_gc_t tgc;
|
---|
258 | ui_resource_t *resource = NULL;
|
---|
259 | ui_wdecor_t *wdecor;
|
---|
260 | ui_wdecor_geom_t geom;
|
---|
261 |
|
---|
262 | memset(&tgc, 0, sizeof(tgc));
|
---|
263 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
264 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
265 |
|
---|
266 | rc = ui_resource_create(gc, false, &resource);
|
---|
267 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
268 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
269 |
|
---|
270 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
271 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
272 |
|
---|
273 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
274 | rc = ui_wdecor_sysmenu_hdl_paint(wdecor, &geom.sysmenu_hdl_rect);
|
---|
275 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
276 |
|
---|
277 | ui_wdecor_destroy(wdecor);
|
---|
278 | ui_resource_destroy(resource);
|
---|
279 |
|
---|
280 | rc = gfx_context_delete(gc);
|
---|
281 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
282 | }
|
---|
283 |
|
---|
284 | /** Paint window decoration */
|
---|
285 | PCUT_TEST(paint)
|
---|
286 | {
|
---|
287 | errno_t rc;
|
---|
288 | gfx_context_t *gc = NULL;
|
---|
289 | test_gc_t tgc;
|
---|
290 | ui_resource_t *resource = NULL;
|
---|
291 | ui_wdecor_t *wdecor;
|
---|
292 |
|
---|
293 | memset(&tgc, 0, sizeof(tgc));
|
---|
294 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
295 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
296 |
|
---|
297 | rc = ui_resource_create(gc, false, &resource);
|
---|
298 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
299 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
300 |
|
---|
301 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
302 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
303 |
|
---|
304 | rc = ui_wdecor_paint(wdecor);
|
---|
305 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
306 |
|
---|
307 | ui_wdecor_destroy(wdecor);
|
---|
308 | ui_resource_destroy(resource);
|
---|
309 |
|
---|
310 | rc = gfx_context_delete(gc);
|
---|
311 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
312 | }
|
---|
313 |
|
---|
314 | /** Test ui_wdecor_sysmenu() */
|
---|
315 | PCUT_TEST(sysmenu)
|
---|
316 | {
|
---|
317 | errno_t rc;
|
---|
318 | ui_wdecor_t *wdecor;
|
---|
319 | test_cb_resp_t resp;
|
---|
320 |
|
---|
321 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
322 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
323 |
|
---|
324 | /* Sysmenu callback with no callbacks set */
|
---|
325 | ui_wdecor_sysmenu(wdecor, 42);
|
---|
326 |
|
---|
327 | /* Sysmenu callback with sysmenu callback not implemented */
|
---|
328 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
329 | ui_wdecor_sysmenu(wdecor, 42);
|
---|
330 |
|
---|
331 | /* Sysmenu callback with real callback set */
|
---|
332 | resp.sysmenu = false;
|
---|
333 | resp.idev_id = 0;
|
---|
334 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
335 | ui_wdecor_sysmenu(wdecor, 42);
|
---|
336 | PCUT_ASSERT_TRUE(resp.sysmenu);
|
---|
337 | PCUT_ASSERT_INT_EQUALS(42, resp.idev_id);
|
---|
338 |
|
---|
339 | ui_wdecor_destroy(wdecor);
|
---|
340 | }
|
---|
341 |
|
---|
342 | /** Test ui_wdecor_minimize() */
|
---|
343 | PCUT_TEST(minimize)
|
---|
344 | {
|
---|
345 | errno_t rc;
|
---|
346 | ui_wdecor_t *wdecor;
|
---|
347 | test_cb_resp_t resp;
|
---|
348 |
|
---|
349 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
350 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
351 |
|
---|
352 | /* Minimize callback with no callbacks set */
|
---|
353 | ui_wdecor_minimize(wdecor);
|
---|
354 |
|
---|
355 | /* Minimize callback with minimize callback not implemented */
|
---|
356 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
357 | ui_wdecor_minimize(wdecor);
|
---|
358 |
|
---|
359 | /* Minimize callback with real callback set */
|
---|
360 | resp.minimize = false;
|
---|
361 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
362 | ui_wdecor_minimize(wdecor);
|
---|
363 | PCUT_ASSERT_TRUE(resp.minimize);
|
---|
364 |
|
---|
365 | ui_wdecor_destroy(wdecor);
|
---|
366 | }
|
---|
367 |
|
---|
368 | /** Test ui_wdecor_maximize() */
|
---|
369 | PCUT_TEST(maximize)
|
---|
370 | {
|
---|
371 | errno_t rc;
|
---|
372 | ui_wdecor_t *wdecor;
|
---|
373 | test_cb_resp_t resp;
|
---|
374 |
|
---|
375 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
376 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
377 |
|
---|
378 | /* Maximize callback with no callbacks set */
|
---|
379 | ui_wdecor_maximize(wdecor);
|
---|
380 |
|
---|
381 | /* Maxmimize callback with maximize callback not implemented */
|
---|
382 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
383 | ui_wdecor_maximize(wdecor);
|
---|
384 |
|
---|
385 | /* Maximize callback with real callback set */
|
---|
386 | resp.maximize = false;
|
---|
387 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
388 | ui_wdecor_maximize(wdecor);
|
---|
389 | PCUT_ASSERT_TRUE(resp.maximize);
|
---|
390 |
|
---|
391 | ui_wdecor_destroy(wdecor);
|
---|
392 | }
|
---|
393 |
|
---|
394 | /** Test ui_wdecor_unmaximize() */
|
---|
395 | PCUT_TEST(unmaximize)
|
---|
396 | {
|
---|
397 | errno_t rc;
|
---|
398 | ui_wdecor_t *wdecor;
|
---|
399 | test_cb_resp_t resp;
|
---|
400 |
|
---|
401 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
402 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
403 |
|
---|
404 | /* Unmaximize callback with no callbacks set */
|
---|
405 | ui_wdecor_unmaximize(wdecor);
|
---|
406 |
|
---|
407 | /* Unmaximize callback with unmaximize callback not implemented */
|
---|
408 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
409 | ui_wdecor_unmaximize(wdecor);
|
---|
410 |
|
---|
411 | /* Unmaximize callback with real callback set */
|
---|
412 | resp.unmaximize = false;
|
---|
413 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
414 | ui_wdecor_unmaximize(wdecor);
|
---|
415 | PCUT_ASSERT_TRUE(resp.unmaximize);
|
---|
416 |
|
---|
417 | ui_wdecor_destroy(wdecor);
|
---|
418 | }
|
---|
419 |
|
---|
420 | /** Test ui_wdecor_close() */
|
---|
421 | PCUT_TEST(close)
|
---|
422 | {
|
---|
423 | errno_t rc;
|
---|
424 | ui_wdecor_t *wdecor;
|
---|
425 | test_cb_resp_t resp;
|
---|
426 |
|
---|
427 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
428 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
429 |
|
---|
430 | /* Close callback with no callbacks set */
|
---|
431 | ui_wdecor_close(wdecor);
|
---|
432 |
|
---|
433 | /* Close callback with close callback not implemented */
|
---|
434 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
435 | ui_wdecor_close(wdecor);
|
---|
436 |
|
---|
437 | /* Close callback with real callback set */
|
---|
438 | resp.close = false;
|
---|
439 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
440 | ui_wdecor_close(wdecor);
|
---|
441 | PCUT_ASSERT_TRUE(resp.close);
|
---|
442 |
|
---|
443 | ui_wdecor_destroy(wdecor);
|
---|
444 | }
|
---|
445 |
|
---|
446 | /** Test ui_wdecor_move() */
|
---|
447 | PCUT_TEST(move)
|
---|
448 | {
|
---|
449 | errno_t rc;
|
---|
450 | ui_wdecor_t *wdecor;
|
---|
451 | test_cb_resp_t resp;
|
---|
452 | gfx_coord2_t pos;
|
---|
453 | sysarg_t pos_id;
|
---|
454 |
|
---|
455 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
456 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
457 |
|
---|
458 | pos.x = 3;
|
---|
459 | pos.y = 4;
|
---|
460 | pos_id = 5;
|
---|
461 |
|
---|
462 | /* Move callback with no callbacks set */
|
---|
463 | ui_wdecor_move(wdecor, &pos, pos_id);
|
---|
464 |
|
---|
465 | /* Move callback with move callback not implemented */
|
---|
466 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
467 | ui_wdecor_move(wdecor, &pos, pos_id);
|
---|
468 |
|
---|
469 | /* Move callback with real callback set */
|
---|
470 | resp.move = false;
|
---|
471 | resp.pos.x = 0;
|
---|
472 | resp.pos.y = 0;
|
---|
473 | resp.pos_id = 0;
|
---|
474 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
475 | ui_wdecor_move(wdecor, &pos, pos_id);
|
---|
476 | PCUT_ASSERT_TRUE(resp.move);
|
---|
477 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
---|
478 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
---|
479 | PCUT_ASSERT_INT_EQUALS(pos_id, resp.pos_id);
|
---|
480 |
|
---|
481 | ui_wdecor_destroy(wdecor);
|
---|
482 | }
|
---|
483 |
|
---|
484 | /** Test ui_wdecor_resize() */
|
---|
485 | PCUT_TEST(resize)
|
---|
486 | {
|
---|
487 | errno_t rc;
|
---|
488 | ui_wdecor_t *wdecor;
|
---|
489 | test_cb_resp_t resp;
|
---|
490 | ui_wdecor_rsztype_t rsztype;
|
---|
491 | gfx_coord2_t pos;
|
---|
492 | sysarg_t pos_id;
|
---|
493 |
|
---|
494 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
495 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
496 |
|
---|
497 | rsztype = ui_wr_bottom;
|
---|
498 | pos.x = 3;
|
---|
499 | pos.y = 4;
|
---|
500 | pos_id = 5;
|
---|
501 |
|
---|
502 | /* Resize callback with no callbacks set */
|
---|
503 | ui_wdecor_resize(wdecor, rsztype, &pos, pos_id);
|
---|
504 |
|
---|
505 | /* Resize callback with move callback not implemented */
|
---|
506 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
507 | ui_wdecor_resize(wdecor, rsztype, &pos, pos_id);
|
---|
508 |
|
---|
509 | /* Resize callback with real callback set */
|
---|
510 | resp.resize = false;
|
---|
511 | resp.rsztype = ui_wr_none;
|
---|
512 | resp.pos.x = 0;
|
---|
513 | resp.pos.y = 0;
|
---|
514 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
515 | ui_wdecor_resize(wdecor, rsztype, &pos, pos_id);
|
---|
516 | PCUT_ASSERT_TRUE(resp.resize);
|
---|
517 | PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype);
|
---|
518 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
---|
519 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
---|
520 | PCUT_ASSERT_INT_EQUALS(pos_id, resp.pos_id);
|
---|
521 |
|
---|
522 | ui_wdecor_destroy(wdecor);
|
---|
523 | }
|
---|
524 |
|
---|
525 | /** Test ui_wdecor_set_cursor() */
|
---|
526 | PCUT_TEST(set_cursor)
|
---|
527 | {
|
---|
528 | errno_t rc;
|
---|
529 | ui_wdecor_t *wdecor;
|
---|
530 | test_cb_resp_t resp;
|
---|
531 | ui_stock_cursor_t cursor;
|
---|
532 |
|
---|
533 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | cursor = ui_curs_size_uldr;
|
---|
537 |
|
---|
538 | /* Set cursor callback with no callbacks set */
|
---|
539 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
540 |
|
---|
541 | /* Set cursor callback with move callback not implemented */
|
---|
542 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
543 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
544 |
|
---|
545 | /* Set cursor callback with real callback set */
|
---|
546 | resp.set_cursor = false;
|
---|
547 | resp.cursor = ui_curs_arrow;
|
---|
548 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
549 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
550 | PCUT_ASSERT_TRUE(resp.set_cursor);
|
---|
551 | PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor);
|
---|
552 |
|
---|
553 | ui_wdecor_destroy(wdecor);
|
---|
554 | }
|
---|
555 |
|
---|
556 | /** Clicking the close button generates close callback */
|
---|
557 | PCUT_TEST(close_btn_clicked)
|
---|
558 | {
|
---|
559 | gfx_context_t *gc = NULL;
|
---|
560 | test_gc_t tgc;
|
---|
561 | ui_resource_t *resource = NULL;
|
---|
562 | ui_wdecor_t *wdecor;
|
---|
563 | gfx_rect_t rect;
|
---|
564 | test_cb_resp_t resp;
|
---|
565 | errno_t rc;
|
---|
566 |
|
---|
567 | memset(&tgc, 0, sizeof(tgc));
|
---|
568 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
569 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
570 |
|
---|
571 | rc = ui_resource_create(gc, false, &resource);
|
---|
572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
573 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
574 |
|
---|
575 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
576 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
577 |
|
---|
578 | rect.p0.x = 10;
|
---|
579 | rect.p0.y = 20;
|
---|
580 | rect.p1.x = 100;
|
---|
581 | rect.p1.y = 200;
|
---|
582 |
|
---|
583 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
584 |
|
---|
585 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
586 |
|
---|
587 | resp.close = false;
|
---|
588 |
|
---|
589 | ui_pbutton_clicked(wdecor->btn_close);
|
---|
590 | PCUT_ASSERT_TRUE(resp.close);
|
---|
591 |
|
---|
592 | ui_wdecor_destroy(wdecor);
|
---|
593 | ui_resource_destroy(resource);
|
---|
594 |
|
---|
595 | rc = gfx_context_delete(gc);
|
---|
596 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
597 | }
|
---|
598 |
|
---|
599 | /** Button press on title bar generates move callback */
|
---|
600 | PCUT_TEST(pos_event_move)
|
---|
601 | {
|
---|
602 | errno_t rc;
|
---|
603 | gfx_rect_t rect;
|
---|
604 | pos_event_t event;
|
---|
605 | gfx_context_t *gc = NULL;
|
---|
606 | test_gc_t tgc;
|
---|
607 | test_cb_resp_t resp;
|
---|
608 | ui_resource_t *resource = NULL;
|
---|
609 | ui_wdecor_t *wdecor;
|
---|
610 |
|
---|
611 | memset(&tgc, 0, sizeof(tgc));
|
---|
612 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
613 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
614 |
|
---|
615 | rc = ui_resource_create(gc, false, &resource);
|
---|
616 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
617 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
618 |
|
---|
619 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
620 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
621 |
|
---|
622 | rect.p0.x = 10;
|
---|
623 | rect.p0.y = 20;
|
---|
624 | rect.p1.x = 100;
|
---|
625 | rect.p1.y = 200;
|
---|
626 |
|
---|
627 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
628 |
|
---|
629 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
630 |
|
---|
631 | resp.move = false;
|
---|
632 | resp.pos.x = 0;
|
---|
633 | resp.pos.y = 0;
|
---|
634 |
|
---|
635 | event.type = POS_PRESS;
|
---|
636 | event.hpos = 50;
|
---|
637 | event.vpos = 25;
|
---|
638 | ui_wdecor_pos_event(wdecor, &event);
|
---|
639 |
|
---|
640 | PCUT_ASSERT_TRUE(resp.move);
|
---|
641 | PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos.x);
|
---|
642 | PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos.y);
|
---|
643 |
|
---|
644 | ui_wdecor_destroy(wdecor);
|
---|
645 | ui_resource_destroy(resource);
|
---|
646 |
|
---|
647 | rc = gfx_context_delete(gc);
|
---|
648 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
649 | }
|
---|
650 |
|
---|
651 | /** Pressing F9 generates sysmenu event */
|
---|
652 | PCUT_TEST(kbd_f9_sysmenu)
|
---|
653 | {
|
---|
654 | errno_t rc;
|
---|
655 | gfx_rect_t rect;
|
---|
656 | kbd_event_t event;
|
---|
657 | gfx_context_t *gc = NULL;
|
---|
658 | test_gc_t tgc;
|
---|
659 | test_cb_resp_t resp;
|
---|
660 | ui_resource_t *resource = NULL;
|
---|
661 | ui_wdecor_t *wdecor;
|
---|
662 |
|
---|
663 | memset(&tgc, 0, sizeof(tgc));
|
---|
664 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
665 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
666 |
|
---|
667 | rc = ui_resource_create(gc, false, &resource);
|
---|
668 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
669 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
670 |
|
---|
671 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
672 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
673 |
|
---|
674 | rect.p0.x = 10;
|
---|
675 | rect.p0.y = 20;
|
---|
676 | rect.p1.x = 100;
|
---|
677 | rect.p1.y = 200;
|
---|
678 |
|
---|
679 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
680 |
|
---|
681 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
682 |
|
---|
683 | resp.move = false;
|
---|
684 | resp.pos.x = 0;
|
---|
685 | resp.pos.y = 0;
|
---|
686 |
|
---|
687 | event.type = KEY_PRESS;
|
---|
688 | event.mods = 0;
|
---|
689 | event.key = KC_F9;
|
---|
690 | event.kbd_id = 42;
|
---|
691 | ui_wdecor_kbd_event(wdecor, &event);
|
---|
692 |
|
---|
693 | PCUT_ASSERT_TRUE(resp.sysmenu);
|
---|
694 | PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id);
|
---|
695 |
|
---|
696 | ui_wdecor_destroy(wdecor);
|
---|
697 | ui_resource_destroy(resource);
|
---|
698 |
|
---|
699 | rc = gfx_context_delete(gc);
|
---|
700 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
701 | }
|
---|
702 |
|
---|
703 | /** ui_wdecor_get_geom() with ui_wds_none produces the correct geometry */
|
---|
704 | PCUT_TEST(get_geom_none)
|
---|
705 | {
|
---|
706 | gfx_context_t *gc = NULL;
|
---|
707 | test_gc_t tgc;
|
---|
708 | ui_resource_t *resource = NULL;
|
---|
709 | ui_wdecor_t *wdecor;
|
---|
710 | gfx_rect_t rect;
|
---|
711 | ui_wdecor_geom_t geom;
|
---|
712 | errno_t rc;
|
---|
713 |
|
---|
714 | memset(&tgc, 0, sizeof(tgc));
|
---|
715 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
716 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
717 |
|
---|
718 | rc = ui_resource_create(gc, false, &resource);
|
---|
719 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
720 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
721 |
|
---|
722 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
723 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
724 |
|
---|
725 | rect.p0.x = 10;
|
---|
726 | rect.p0.y = 20;
|
---|
727 | rect.p1.x = 100;
|
---|
728 | rect.p1.y = 200;
|
---|
729 |
|
---|
730 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
731 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
732 |
|
---|
733 | PCUT_ASSERT_INT_EQUALS(10, geom.interior_rect.p0.x);
|
---|
734 | PCUT_ASSERT_INT_EQUALS(20, geom.interior_rect.p0.y);
|
---|
735 | PCUT_ASSERT_INT_EQUALS(100, geom.interior_rect.p1.x);
|
---|
736 | PCUT_ASSERT_INT_EQUALS(200, geom.interior_rect.p1.y);
|
---|
737 |
|
---|
738 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
---|
739 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
---|
740 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
---|
741 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
---|
742 |
|
---|
743 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p0.x);
|
---|
744 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p0.y);
|
---|
745 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p1.x);
|
---|
746 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p1.y);
|
---|
747 |
|
---|
748 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p0.x);
|
---|
749 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p0.y);
|
---|
750 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p1.x);
|
---|
751 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p1.y);
|
---|
752 |
|
---|
753 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p0.x);
|
---|
754 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p0.y);
|
---|
755 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p1.x);
|
---|
756 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p1.y);
|
---|
757 |
|
---|
758 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.x);
|
---|
759 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.y);
|
---|
760 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.x);
|
---|
761 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.y);
|
---|
762 |
|
---|
763 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
764 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
765 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
766 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
767 |
|
---|
768 | PCUT_ASSERT_INT_EQUALS(10, geom.app_area_rect.p0.x);
|
---|
769 | PCUT_ASSERT_INT_EQUALS(20, geom.app_area_rect.p0.y);
|
---|
770 | PCUT_ASSERT_INT_EQUALS(100, geom.app_area_rect.p1.x);
|
---|
771 | PCUT_ASSERT_INT_EQUALS(200, geom.app_area_rect.p1.y);
|
---|
772 |
|
---|
773 | ui_wdecor_destroy(wdecor);
|
---|
774 | ui_resource_destroy(resource);
|
---|
775 |
|
---|
776 | rc = gfx_context_delete(gc);
|
---|
777 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
778 | }
|
---|
779 |
|
---|
780 | /** ui_wdecor_get_geom() with ui_wds_frame produces the correct geometry */
|
---|
781 | PCUT_TEST(get_geom_frame)
|
---|
782 | {
|
---|
783 | gfx_context_t *gc = NULL;
|
---|
784 | test_gc_t tgc;
|
---|
785 | ui_resource_t *resource = NULL;
|
---|
786 | ui_wdecor_t *wdecor;
|
---|
787 | gfx_rect_t rect;
|
---|
788 | ui_wdecor_geom_t geom;
|
---|
789 | errno_t rc;
|
---|
790 |
|
---|
791 | memset(&tgc, 0, sizeof(tgc));
|
---|
792 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
793 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
794 |
|
---|
795 | rc = ui_resource_create(gc, false, &resource);
|
---|
796 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
797 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
798 |
|
---|
799 | rc = ui_wdecor_create(resource, "Hello", ui_wds_frame, &wdecor);
|
---|
800 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
801 |
|
---|
802 | rect.p0.x = 10;
|
---|
803 | rect.p0.y = 20;
|
---|
804 | rect.p1.x = 100;
|
---|
805 | rect.p1.y = 200;
|
---|
806 |
|
---|
807 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
808 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
809 |
|
---|
810 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
811 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
812 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
813 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
814 |
|
---|
815 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
---|
816 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
---|
817 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
---|
818 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
---|
819 |
|
---|
820 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p0.x);
|
---|
821 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p0.y);
|
---|
822 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p1.x);
|
---|
823 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p1.y);
|
---|
824 |
|
---|
825 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p0.x);
|
---|
826 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p0.y);
|
---|
827 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p1.x);
|
---|
828 | PCUT_ASSERT_INT_EQUALS(0, geom.caption_rect.p1.y);
|
---|
829 |
|
---|
830 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p0.x);
|
---|
831 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p0.y);
|
---|
832 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p1.x);
|
---|
833 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p1.y);
|
---|
834 |
|
---|
835 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.x);
|
---|
836 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.y);
|
---|
837 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.x);
|
---|
838 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.y);
|
---|
839 |
|
---|
840 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
841 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
842 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
843 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
844 |
|
---|
845 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
846 | PCUT_ASSERT_INT_EQUALS(24, geom.app_area_rect.p0.y);
|
---|
847 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
848 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
849 |
|
---|
850 | ui_wdecor_destroy(wdecor);
|
---|
851 | ui_resource_destroy(resource);
|
---|
852 |
|
---|
853 | rc = gfx_context_delete(gc);
|
---|
854 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
855 | }
|
---|
856 |
|
---|
857 | /** ui_wdecor_get_geom() with ui_wds_frame | ui_wds_titlebar */
|
---|
858 | PCUT_TEST(get_geom_frame_titlebar)
|
---|
859 | {
|
---|
860 | gfx_context_t *gc = NULL;
|
---|
861 | test_gc_t tgc;
|
---|
862 | ui_resource_t *resource = NULL;
|
---|
863 | ui_wdecor_t *wdecor;
|
---|
864 | gfx_rect_t rect;
|
---|
865 | ui_wdecor_geom_t geom;
|
---|
866 | errno_t rc;
|
---|
867 |
|
---|
868 | memset(&tgc, 0, sizeof(tgc));
|
---|
869 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
870 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
871 |
|
---|
872 | rc = ui_resource_create(gc, false, &resource);
|
---|
873 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
874 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
875 |
|
---|
876 | rc = ui_wdecor_create(resource, "Hello", ui_wds_frame | ui_wds_titlebar,
|
---|
877 | &wdecor);
|
---|
878 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
879 |
|
---|
880 | rect.p0.x = 10;
|
---|
881 | rect.p0.y = 20;
|
---|
882 | rect.p1.x = 100;
|
---|
883 | rect.p1.y = 200;
|
---|
884 |
|
---|
885 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
886 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
887 |
|
---|
888 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
889 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
890 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
891 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
892 |
|
---|
893 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
---|
894 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
---|
895 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
---|
896 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
---|
897 |
|
---|
898 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p0.x);
|
---|
899 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p0.y);
|
---|
900 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p1.x);
|
---|
901 | PCUT_ASSERT_INT_EQUALS(0, geom.sysmenu_hdl_rect.p1.y);
|
---|
902 |
|
---|
903 | PCUT_ASSERT_INT_EQUALS(18, geom.caption_rect.p0.x);
|
---|
904 | PCUT_ASSERT_INT_EQUALS(24, geom.caption_rect.p0.y);
|
---|
905 | PCUT_ASSERT_INT_EQUALS(91, geom.caption_rect.p1.x);
|
---|
906 | PCUT_ASSERT_INT_EQUALS(46, geom.caption_rect.p1.y);
|
---|
907 |
|
---|
908 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p0.x);
|
---|
909 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p0.y);
|
---|
910 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p1.x);
|
---|
911 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_min_rect.p1.y);
|
---|
912 |
|
---|
913 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.x);
|
---|
914 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.y);
|
---|
915 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.x);
|
---|
916 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.y);
|
---|
917 |
|
---|
918 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
919 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
920 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
921 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
922 |
|
---|
923 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
924 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
---|
925 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
926 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
927 |
|
---|
928 | ui_wdecor_destroy(wdecor);
|
---|
929 | ui_resource_destroy(resource);
|
---|
930 |
|
---|
931 | rc = gfx_context_delete(gc);
|
---|
932 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
933 | }
|
---|
934 |
|
---|
935 | /** ui_wdecor_get_geom() with ui_wds_decorated produces the correct geometry */
|
---|
936 | PCUT_TEST(get_geom_decorated)
|
---|
937 | {
|
---|
938 | gfx_context_t *gc = NULL;
|
---|
939 | test_gc_t tgc;
|
---|
940 | ui_resource_t *resource = NULL;
|
---|
941 | ui_wdecor_t *wdecor;
|
---|
942 | gfx_rect_t rect;
|
---|
943 | ui_wdecor_geom_t geom;
|
---|
944 | errno_t rc;
|
---|
945 |
|
---|
946 | memset(&tgc, 0, sizeof(tgc));
|
---|
947 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
948 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
949 |
|
---|
950 | rc = ui_resource_create(gc, false, &resource);
|
---|
951 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
952 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
953 |
|
---|
954 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
955 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
956 |
|
---|
957 | rect.p0.x = 10;
|
---|
958 | rect.p0.y = 20;
|
---|
959 | rect.p1.x = 100;
|
---|
960 | rect.p1.y = 200;
|
---|
961 |
|
---|
962 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
963 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
964 |
|
---|
965 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
966 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
967 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
968 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
969 |
|
---|
970 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
---|
971 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
---|
972 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
---|
973 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
---|
974 |
|
---|
975 | PCUT_ASSERT_INT_EQUALS(15, geom.sysmenu_hdl_rect.p0.x);
|
---|
976 | PCUT_ASSERT_INT_EQUALS(25, geom.sysmenu_hdl_rect.p0.y);
|
---|
977 | PCUT_ASSERT_INT_EQUALS(35, geom.sysmenu_hdl_rect.p1.x);
|
---|
978 | PCUT_ASSERT_INT_EQUALS(45, geom.sysmenu_hdl_rect.p1.y);
|
---|
979 |
|
---|
980 | PCUT_ASSERT_INT_EQUALS(38, geom.caption_rect.p0.x);
|
---|
981 | PCUT_ASSERT_INT_EQUALS(24, geom.caption_rect.p0.y);
|
---|
982 | PCUT_ASSERT_INT_EQUALS(51, geom.caption_rect.p1.x);
|
---|
983 | PCUT_ASSERT_INT_EQUALS(46, geom.caption_rect.p1.y);
|
---|
984 |
|
---|
985 | PCUT_ASSERT_INT_EQUALS(55, geom.btn_min_rect.p0.x);
|
---|
986 | PCUT_ASSERT_INT_EQUALS(25, geom.btn_min_rect.p0.y);
|
---|
987 | PCUT_ASSERT_INT_EQUALS(75, geom.btn_min_rect.p1.x);
|
---|
988 | PCUT_ASSERT_INT_EQUALS(45, geom.btn_min_rect.p1.y);
|
---|
989 |
|
---|
990 | /* Maximize button is not in ui_wds_decorated */
|
---|
991 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.x);
|
---|
992 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p0.y);
|
---|
993 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.x);
|
---|
994 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_max_rect.p1.y);
|
---|
995 |
|
---|
996 | PCUT_ASSERT_INT_EQUALS(75, geom.btn_close_rect.p0.x);
|
---|
997 | PCUT_ASSERT_INT_EQUALS(25, geom.btn_close_rect.p0.y);
|
---|
998 | PCUT_ASSERT_INT_EQUALS(95, geom.btn_close_rect.p1.x);
|
---|
999 | PCUT_ASSERT_INT_EQUALS(45, geom.btn_close_rect.p1.y);
|
---|
1000 |
|
---|
1001 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
1002 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
---|
1003 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
1004 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
1005 |
|
---|
1006 | ui_wdecor_destroy(wdecor);
|
---|
1007 | ui_resource_destroy(resource);
|
---|
1008 |
|
---|
1009 | rc = gfx_context_delete(gc);
|
---|
1010 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | /** ui_wdecor_rect_from_app() correctly converts application to window rect */
|
---|
1014 | PCUT_TEST(rect_from_app)
|
---|
1015 | {
|
---|
1016 | gfx_rect_t arect;
|
---|
1017 | gfx_rect_t rect;
|
---|
1018 |
|
---|
1019 | arect.p0.x = 14;
|
---|
1020 | arect.p0.y = 46;
|
---|
1021 | arect.p1.x = 96;
|
---|
1022 | arect.p1.y = 196;
|
---|
1023 |
|
---|
1024 | ui_wdecor_rect_from_app(ui_wds_none, &arect, &rect);
|
---|
1025 |
|
---|
1026 | PCUT_ASSERT_INT_EQUALS(14, rect.p0.x);
|
---|
1027 | PCUT_ASSERT_INT_EQUALS(46, rect.p0.y);
|
---|
1028 | PCUT_ASSERT_INT_EQUALS(96, rect.p1.x);
|
---|
1029 | PCUT_ASSERT_INT_EQUALS(196, rect.p1.y);
|
---|
1030 |
|
---|
1031 | ui_wdecor_rect_from_app(ui_wds_frame, &arect, &rect);
|
---|
1032 |
|
---|
1033 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
---|
1034 | PCUT_ASSERT_INT_EQUALS(42, rect.p0.y);
|
---|
1035 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
---|
1036 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
---|
1037 |
|
---|
1038 | ui_wdecor_rect_from_app(ui_wds_decorated, &arect, &rect);
|
---|
1039 |
|
---|
1040 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
---|
1041 | PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
|
---|
1042 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
---|
1043 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
---|
1044 |
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | /** Test ui_wdecor_get_rsztype() */
|
---|
1048 | PCUT_TEST(get_rsztype)
|
---|
1049 | {
|
---|
1050 | gfx_context_t *gc = NULL;
|
---|
1051 | test_gc_t tgc;
|
---|
1052 | ui_resource_t *resource = NULL;
|
---|
1053 | ui_wdecor_t *wdecor;
|
---|
1054 | gfx_rect_t rect;
|
---|
1055 | ui_wdecor_rsztype_t rsztype;
|
---|
1056 | gfx_coord2_t pos;
|
---|
1057 | errno_t rc;
|
---|
1058 |
|
---|
1059 | memset(&tgc, 0, sizeof(tgc));
|
---|
1060 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
1061 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1062 |
|
---|
1063 | rc = ui_resource_create(gc, false, &resource);
|
---|
1064 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1065 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
1066 |
|
---|
1067 | rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor);
|
---|
1068 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1069 |
|
---|
1070 | rect.p0.x = 10;
|
---|
1071 | rect.p0.y = 20;
|
---|
1072 | rect.p1.x = 100;
|
---|
1073 | rect.p1.y = 200;
|
---|
1074 |
|
---|
1075 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
1076 |
|
---|
1077 | /* Outside of the window */
|
---|
1078 | pos.x = 0;
|
---|
1079 | pos.y = -1;
|
---|
1080 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1081 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
1082 |
|
---|
1083 | /* Middle of the window */
|
---|
1084 | pos.x = 50;
|
---|
1085 | pos.y = 100;
|
---|
1086 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1087 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
1088 |
|
---|
1089 | /* Top-left corner, but not on edge */
|
---|
1090 | pos.x = 20;
|
---|
1091 | pos.y = 30;
|
---|
1092 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1093 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
1094 |
|
---|
1095 | /* Top-left corner on top edge */
|
---|
1096 | pos.x = 20;
|
---|
1097 | pos.y = 20;
|
---|
1098 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1099 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
---|
1100 |
|
---|
1101 | /* Top-left corner on left edge */
|
---|
1102 | pos.x = 10;
|
---|
1103 | pos.y = 30;
|
---|
1104 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1105 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
---|
1106 |
|
---|
1107 | /* Top-right corner on top edge */
|
---|
1108 | pos.x = 90;
|
---|
1109 | pos.y = 20;
|
---|
1110 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1111 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
---|
1112 |
|
---|
1113 | /* Top-right corner on right edge */
|
---|
1114 | pos.x = 99;
|
---|
1115 | pos.y = 30;
|
---|
1116 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1117 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
---|
1118 |
|
---|
1119 | /* Top edge */
|
---|
1120 | pos.x = 50;
|
---|
1121 | pos.y = 20;
|
---|
1122 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1123 | PCUT_ASSERT_EQUALS(ui_wr_top, rsztype);
|
---|
1124 |
|
---|
1125 | /* Bottom edge */
|
---|
1126 | pos.x = 50;
|
---|
1127 | pos.y = 199;
|
---|
1128 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1129 | PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype);
|
---|
1130 |
|
---|
1131 | /* Left edge */
|
---|
1132 | pos.x = 10;
|
---|
1133 | pos.y = 100;
|
---|
1134 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1135 | PCUT_ASSERT_EQUALS(ui_wr_left, rsztype);
|
---|
1136 |
|
---|
1137 | /* Right edge */
|
---|
1138 | pos.x = 99;
|
---|
1139 | pos.y = 100;
|
---|
1140 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1141 | PCUT_ASSERT_EQUALS(ui_wr_right, rsztype);
|
---|
1142 |
|
---|
1143 | ui_wdecor_destroy(wdecor);
|
---|
1144 |
|
---|
1145 | /* Non-resizable window */
|
---|
1146 |
|
---|
1147 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
1148 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1149 |
|
---|
1150 | rect.p0.x = 10;
|
---|
1151 | rect.p0.y = 20;
|
---|
1152 | rect.p1.x = 100;
|
---|
1153 | rect.p1.y = 200;
|
---|
1154 |
|
---|
1155 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
1156 |
|
---|
1157 | pos.x = 10;
|
---|
1158 | pos.y = 20;
|
---|
1159 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
1160 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
1161 |
|
---|
1162 | ui_wdecor_destroy(wdecor);
|
---|
1163 | ui_resource_destroy(resource);
|
---|
1164 |
|
---|
1165 | rc = gfx_context_delete(gc);
|
---|
1166 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | /** Test ui_wdecor_cursor_from_rsztype() */
|
---|
1170 | PCUT_TEST(cursor_from_rsztype)
|
---|
1171 | {
|
---|
1172 | PCUT_ASSERT_EQUALS(ui_curs_arrow,
|
---|
1173 | ui_wdecor_cursor_from_rsztype(ui_wr_none));
|
---|
1174 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
---|
1175 | ui_wdecor_cursor_from_rsztype(ui_wr_top));
|
---|
1176 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
---|
1177 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom));
|
---|
1178 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
---|
1179 | ui_wdecor_cursor_from_rsztype(ui_wr_left));
|
---|
1180 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
---|
1181 | ui_wdecor_cursor_from_rsztype(ui_wr_right));
|
---|
1182 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
---|
1183 | ui_wdecor_cursor_from_rsztype(ui_wr_top_left));
|
---|
1184 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
---|
1185 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right));
|
---|
1186 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
---|
1187 | ui_wdecor_cursor_from_rsztype(ui_wr_top_right));
|
---|
1188 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
---|
1189 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left));
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | /** Test ui_wdecor_frame_pos_event() */
|
---|
1193 | PCUT_TEST(frame_pos_event)
|
---|
1194 | {
|
---|
1195 | gfx_context_t *gc = NULL;
|
---|
1196 | test_gc_t tgc;
|
---|
1197 | ui_resource_t *resource = NULL;
|
---|
1198 | ui_wdecor_t *wdecor;
|
---|
1199 | gfx_rect_t rect;
|
---|
1200 | test_cb_resp_t resp;
|
---|
1201 | pos_event_t event;
|
---|
1202 | errno_t rc;
|
---|
1203 |
|
---|
1204 | memset(&tgc, 0, sizeof(tgc));
|
---|
1205 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
1206 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1207 |
|
---|
1208 | rc = ui_resource_create(gc, false, &resource);
|
---|
1209 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1210 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
1211 |
|
---|
1212 | rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor);
|
---|
1213 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1214 |
|
---|
1215 | rect.p0.x = 10;
|
---|
1216 | rect.p0.y = 20;
|
---|
1217 | rect.p1.x = 100;
|
---|
1218 | rect.p1.y = 200;
|
---|
1219 |
|
---|
1220 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
1221 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
1222 |
|
---|
1223 | /* Release on window border should do nothing */
|
---|
1224 | resp.resize = false;
|
---|
1225 | event.type = POS_RELEASE;
|
---|
1226 | event.hpos = 10;
|
---|
1227 | event.vpos = 10;
|
---|
1228 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
1229 | PCUT_ASSERT_FALSE(resp.resize);
|
---|
1230 |
|
---|
1231 | /* Press in the middle of the window should do nothing */
|
---|
1232 | resp.resize = false;
|
---|
1233 | event.type = POS_PRESS;
|
---|
1234 | event.hpos = 50;
|
---|
1235 | event.vpos = 100;
|
---|
1236 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
1237 | PCUT_ASSERT_FALSE(resp.resize);
|
---|
1238 |
|
---|
1239 | /* Press on window border should cause resize to be called */
|
---|
1240 | resp.resize = false;
|
---|
1241 | event.type = POS_PRESS;
|
---|
1242 | event.hpos = 10;
|
---|
1243 | event.vpos = 20;
|
---|
1244 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
1245 | PCUT_ASSERT_TRUE(resp.resize);
|
---|
1246 |
|
---|
1247 | ui_wdecor_destroy(wdecor);
|
---|
1248 | ui_resource_destroy(resource);
|
---|
1249 |
|
---|
1250 | rc = gfx_context_delete(gc);
|
---|
1251 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
|
---|
1255 | {
|
---|
1256 | (void) arg;
|
---|
1257 | (void) rect;
|
---|
1258 | return EOK;
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
---|
1262 | {
|
---|
1263 | (void) arg;
|
---|
1264 | (void) color;
|
---|
1265 | return EOK;
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
1269 | {
|
---|
1270 | (void) arg;
|
---|
1271 | (void) rect;
|
---|
1272 | return EOK;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | static errno_t testgc_update(void *arg)
|
---|
1276 | {
|
---|
1277 | (void) arg;
|
---|
1278 | return EOK;
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
---|
1282 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
---|
1283 | {
|
---|
1284 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
1285 | testgc_bitmap_t *tbm;
|
---|
1286 |
|
---|
1287 | tbm = calloc(1, sizeof(testgc_bitmap_t));
|
---|
1288 | if (tbm == NULL)
|
---|
1289 | return ENOMEM;
|
---|
1290 |
|
---|
1291 | if (alloc == NULL) {
|
---|
1292 | tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
|
---|
1293 | sizeof(uint32_t);
|
---|
1294 | tbm->alloc.off0 = 0;
|
---|
1295 | tbm->alloc.pixels = calloc(sizeof(uint32_t),
|
---|
1296 | (params->rect.p1.x - params->rect.p0.x) *
|
---|
1297 | (params->rect.p1.y - params->rect.p0.y));
|
---|
1298 | tbm->myalloc = true;
|
---|
1299 | if (tbm->alloc.pixels == NULL) {
|
---|
1300 | free(tbm);
|
---|
1301 | return ENOMEM;
|
---|
1302 | }
|
---|
1303 | } else {
|
---|
1304 | tbm->alloc = *alloc;
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | tbm->tgc = tgc;
|
---|
1308 | tgc->bm_created = true;
|
---|
1309 | tgc->bm_params = *params;
|
---|
1310 | tgc->bm_pixels = tbm->alloc.pixels;
|
---|
1311 | *rbm = (void *)tbm;
|
---|
1312 | return EOK;
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | static errno_t testgc_bitmap_destroy(void *bm)
|
---|
1316 | {
|
---|
1317 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
1318 | if (tbm->myalloc)
|
---|
1319 | free(tbm->alloc.pixels);
|
---|
1320 | tbm->tgc->bm_destroyed = true;
|
---|
1321 | free(tbm);
|
---|
1322 | return EOK;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
|
---|
1326 | gfx_coord2_t *offs)
|
---|
1327 | {
|
---|
1328 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
1329 | tbm->tgc->bm_rendered = true;
|
---|
1330 | tbm->tgc->bm_srect = *srect;
|
---|
1331 | tbm->tgc->bm_offs = *offs;
|
---|
1332 | return EOK;
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
---|
1336 | {
|
---|
1337 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
1338 | *alloc = tbm->alloc;
|
---|
1339 | tbm->tgc->bm_got_alloc = true;
|
---|
1340 | return EOK;
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | static void test_wdecor_sysmenu(ui_wdecor_t *wdecor, void *arg,
|
---|
1344 | sysarg_t idev_id)
|
---|
1345 | {
|
---|
1346 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1347 |
|
---|
1348 | resp->sysmenu = true;
|
---|
1349 | resp->idev_id = idev_id;
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | static void test_wdecor_minimize(ui_wdecor_t *wdecor, void *arg)
|
---|
1353 | {
|
---|
1354 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1355 |
|
---|
1356 | resp->minimize = true;
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | static void test_wdecor_maximize(ui_wdecor_t *wdecor, void *arg)
|
---|
1360 | {
|
---|
1361 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1362 |
|
---|
1363 | resp->maximize = true;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | static void test_wdecor_unmaximize(ui_wdecor_t *wdecor, void *arg)
|
---|
1367 | {
|
---|
1368 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1369 |
|
---|
1370 | resp->unmaximize = true;
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
|
---|
1374 | {
|
---|
1375 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1376 |
|
---|
1377 | resp->close = true;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | static void test_wdecor_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos,
|
---|
1381 | sysarg_t pos_id)
|
---|
1382 | {
|
---|
1383 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1384 |
|
---|
1385 | resp->move = true;
|
---|
1386 | resp->pos = *pos;
|
---|
1387 | resp->pos_id = pos_id;
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 | static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg,
|
---|
1391 | ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos, sysarg_t pos_id)
|
---|
1392 | {
|
---|
1393 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1394 |
|
---|
1395 | resp->resize = true;
|
---|
1396 | resp->rsztype = rsztype;
|
---|
1397 | resp->pos = *pos;
|
---|
1398 | resp->pos_id = pos_id;
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg,
|
---|
1402 | ui_stock_cursor_t cursor)
|
---|
1403 | {
|
---|
1404 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
1405 |
|
---|
1406 | resp->set_cursor = true;
|
---|
1407 | resp->cursor = cursor;
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | PCUT_EXPORT(wdecor);
|
---|