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