source: mainline/uspace/lib/ui/test/menuentry.c@ 1aa0e38

Last change on this file since 1aa0e38 was 1aa0e38, checked in by Jiri Svoboda <jiri@…>, 4 years ago

UI menu unit tests

  • Property mode set to 100644
File size: 15.1 KB
Line 
1/*
2 * Copyright (c) 2021 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/control.h>
35#include <ui/menu.h>
36#include <ui/menubar.h>
37#include <ui/menuentry.h>
38#include <ui/resource.h>
39#include <ui/ui.h>
40#include "../private/dummygc.h"
41#include "../private/menuentry.h"
42
43PCUT_INIT;
44
45PCUT_TEST_SUITE(menuentry);
46
47typedef struct {
48 bool activated;
49} test_resp_t;
50
51static void test_entry_cb(ui_menu_entry_t *, void *);
52
53/** Create and destroy menu bar */
54PCUT_TEST(create_destroy)
55{
56 ui_menu_bar_t *mbar = NULL;
57 errno_t rc;
58
59 rc = ui_menu_bar_create(NULL, &mbar);
60 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
61 PCUT_ASSERT_NOT_NULL(mbar);
62
63 ui_menu_bar_destroy(mbar);
64}
65
66/** ui_menu_bar_destroy() can take NULL argument (no-op) */
67PCUT_TEST(destroy_null)
68{
69 ui_menu_bar_destroy(NULL);
70}
71
72/** ui_menu_entry_set_cb() .. */
73PCUT_TEST(set_cb)
74{
75 dummy_gc_t *dgc;
76 gfx_context_t *gc;
77 ui_resource_t *resource = NULL;
78 ui_menu_bar_t *mbar = NULL;
79 ui_menu_t *menu = NULL;
80 ui_menu_entry_t *mentry = NULL;
81 test_resp_t resp;
82 errno_t rc;
83
84 rc = dummygc_create(&dgc);
85 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
86
87 gc = dummygc_get_ctx(dgc);
88
89 rc = ui_resource_create(gc, false, &resource);
90 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
91 PCUT_ASSERT_NOT_NULL(resource);
92
93 rc = ui_menu_bar_create(resource, &mbar);
94 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
95 PCUT_ASSERT_NOT_NULL(mbar);
96
97 rc = ui_menu_create(mbar, "Test", &menu);
98 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
99 PCUT_ASSERT_NOT_NULL(menu);
100
101 rc = ui_menu_entry_create(menu, "Foo", &mentry);
102 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
103 PCUT_ASSERT_NOT_NULL(mentry);
104
105 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
106
107 resp.activated = false;
108 ui_menu_entry_cb(mentry);
109 PCUT_ASSERT_TRUE(resp.activated);
110
111 ui_menu_bar_destroy(mbar);
112 ui_resource_destroy(resource);
113 dummygc_destroy(dgc);
114}
115
116/** ui_menu_entry_first() / ui_menu_entry_next() iterate over entries */
117PCUT_TEST(first_next)
118{
119 dummy_gc_t *dgc;
120 gfx_context_t *gc;
121 ui_resource_t *resource = NULL;
122 ui_menu_bar_t *mbar = NULL;
123 ui_menu_t *menu = NULL;
124 ui_menu_entry_t *entry1 = NULL;
125 ui_menu_entry_t *entry2 = NULL;
126 ui_menu_entry_t *e;
127 errno_t rc;
128
129 rc = dummygc_create(&dgc);
130 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
131
132 gc = dummygc_get_ctx(dgc);
133
134 rc = ui_resource_create(gc, false, &resource);
135 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
136 PCUT_ASSERT_NOT_NULL(resource);
137
138 rc = ui_menu_bar_create(resource, &mbar);
139 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
140 PCUT_ASSERT_NOT_NULL(mbar);
141
142 rc = ui_menu_create(mbar, "Test", &menu);
143 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
144 PCUT_ASSERT_NOT_NULL(menu);
145
146 rc = ui_menu_entry_create(menu, "Foo", &entry1);
147 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
148 PCUT_ASSERT_NOT_NULL(entry1);
149
150 rc = ui_menu_entry_create(menu, "Bar", &entry2);
151 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
152 PCUT_ASSERT_NOT_NULL(entry2);
153
154 e = ui_menu_entry_first(menu);
155 PCUT_ASSERT_EQUALS(entry1, e);
156
157 e = ui_menu_entry_next(e);
158 PCUT_ASSERT_EQUALS(entry2, e);
159
160 e = ui_menu_entry_next(e);
161 PCUT_ASSERT_NULL(e);
162
163 ui_menu_bar_destroy(mbar);
164 ui_resource_destroy(resource);
165 dummygc_destroy(dgc);
166}
167
168/** ui_menu_entry_width() / ui_menu_entry_height() */
169PCUT_TEST(width_height)
170{
171 dummy_gc_t *dgc;
172 gfx_context_t *gc;
173 ui_resource_t *resource = NULL;
174 ui_menu_bar_t *mbar = NULL;
175 ui_menu_t *menu = NULL;
176 ui_menu_entry_t *mentry = NULL;
177 gfx_coord_t width;
178 gfx_coord_t height;
179 errno_t rc;
180
181 rc = dummygc_create(&dgc);
182 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
183
184 gc = dummygc_get_ctx(dgc);
185
186 rc = ui_resource_create(gc, false, &resource);
187 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
188 PCUT_ASSERT_NOT_NULL(resource);
189
190 rc = ui_menu_bar_create(resource, &mbar);
191 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
192 PCUT_ASSERT_NOT_NULL(mbar);
193
194 rc = ui_menu_create(mbar, "Test", &menu);
195 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
196 PCUT_ASSERT_NOT_NULL(menu);
197
198 rc = ui_menu_entry_create(menu, "X", &mentry);
199 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
200 PCUT_ASSERT_NOT_NULL(mentry);
201
202 width = ui_menu_entry_width(mentry);
203 PCUT_ASSERT_INT_EQUALS(11 + 8, width);
204
205 height = ui_menu_entry_height(mentry);
206 PCUT_ASSERT_INT_EQUALS(13 + 8, height);
207
208 ui_menu_bar_destroy(mbar);
209 ui_resource_destroy(resource);
210 dummygc_destroy(dgc);
211}
212
213/** Paint menu entry */
214PCUT_TEST(paint)
215{
216 dummy_gc_t *dgc;
217 gfx_context_t *gc;
218 ui_resource_t *resource = NULL;
219 ui_menu_bar_t *mbar = NULL;
220 ui_menu_t *menu = NULL;
221 ui_menu_entry_t *mentry = NULL;
222 gfx_coord2_t pos;
223 errno_t rc;
224
225 rc = dummygc_create(&dgc);
226 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
227
228 gc = dummygc_get_ctx(dgc);
229
230 rc = ui_resource_create(gc, false, &resource);
231 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
232 PCUT_ASSERT_NOT_NULL(resource);
233
234 rc = ui_menu_bar_create(resource, &mbar);
235 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
236 PCUT_ASSERT_NOT_NULL(mbar);
237
238 rc = ui_menu_create(mbar, "Test", &menu);
239 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
240 PCUT_ASSERT_NOT_NULL(menu);
241
242 rc = ui_menu_entry_create(menu, "Foo", &mentry);
243 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
244 PCUT_ASSERT_NOT_NULL(mentry);
245
246 pos.x = 0;
247 pos.y = 0;
248 rc = ui_menu_entry_paint(mentry, &pos);
249 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
250
251 ui_menu_bar_destroy(mbar);
252 ui_resource_destroy(resource);
253 dummygc_destroy(dgc);
254}
255
256/** Press and release activates menu entry */
257PCUT_TEST(press_release)
258{
259 dummy_gc_t *dgc;
260 gfx_context_t *gc;
261 ui_resource_t *resource = NULL;
262 ui_menu_bar_t *mbar = NULL;
263 ui_menu_t *menu = NULL;
264 ui_menu_entry_t *mentry = NULL;
265 gfx_coord2_t pos;
266 test_resp_t resp;
267 errno_t rc;
268
269 rc = dummygc_create(&dgc);
270 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
271
272 gc = dummygc_get_ctx(dgc);
273
274 rc = ui_resource_create(gc, false, &resource);
275 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
276 PCUT_ASSERT_NOT_NULL(resource);
277
278 rc = ui_menu_bar_create(resource, &mbar);
279 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
280 PCUT_ASSERT_NOT_NULL(mbar);
281
282 rc = ui_menu_create(mbar, "Test", &menu);
283 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
284 PCUT_ASSERT_NOT_NULL(menu);
285
286 rc = ui_menu_entry_create(menu, "X", &mentry);
287 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
288 PCUT_ASSERT_NOT_NULL(mentry);
289
290 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
291 resp.activated = false;
292
293 pos.x = 0;
294 pos.y = 0;
295 ui_menu_entry_press(mentry, &pos);
296 PCUT_ASSERT_TRUE(mentry->inside);
297 PCUT_ASSERT_TRUE(mentry->held);
298 PCUT_ASSERT_FALSE(resp.activated);
299
300 ui_menu_entry_release(mentry);
301 PCUT_ASSERT_FALSE(mentry->held);
302 PCUT_ASSERT_TRUE(resp.activated);
303
304 ui_menu_bar_destroy(mbar);
305 ui_resource_destroy(resource);
306 dummygc_destroy(dgc);
307}
308
309/** Press, leave and release does not activate entry */
310PCUT_TEST(press_leave_release)
311{
312 dummy_gc_t *dgc;
313 gfx_context_t *gc;
314 ui_resource_t *resource = NULL;
315 ui_menu_bar_t *mbar = NULL;
316 ui_menu_t *menu = NULL;
317 ui_menu_entry_t *mentry = NULL;
318 gfx_coord2_t pos;
319 test_resp_t resp;
320 errno_t rc;
321
322 rc = dummygc_create(&dgc);
323 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
324
325 gc = dummygc_get_ctx(dgc);
326
327 rc = ui_resource_create(gc, false, &resource);
328 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
329 PCUT_ASSERT_NOT_NULL(resource);
330
331 rc = ui_menu_bar_create(resource, &mbar);
332 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
333 PCUT_ASSERT_NOT_NULL(mbar);
334
335 rc = ui_menu_create(mbar, "Test", &menu);
336 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
337 PCUT_ASSERT_NOT_NULL(menu);
338
339 rc = ui_menu_entry_create(menu, "X", &mentry);
340 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
341 PCUT_ASSERT_NOT_NULL(mentry);
342
343 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
344 resp.activated = false;
345
346 pos.x = 0;
347 pos.y = 0;
348 ui_menu_entry_press(mentry, &pos);
349 PCUT_ASSERT_TRUE(mentry->inside);
350 PCUT_ASSERT_TRUE(mentry->held);
351 PCUT_ASSERT_FALSE(resp.activated);
352
353 ui_menu_entry_leave(mentry, &pos);
354 PCUT_ASSERT_FALSE(mentry->inside);
355 PCUT_ASSERT_TRUE(mentry->held);
356 PCUT_ASSERT_FALSE(resp.activated);
357
358 ui_menu_entry_release(mentry);
359 PCUT_ASSERT_FALSE(mentry->held);
360 PCUT_ASSERT_FALSE(resp.activated);
361
362 ui_menu_bar_destroy(mbar);
363 ui_resource_destroy(resource);
364 dummygc_destroy(dgc);
365}
366
367/** Press, leave, enter and release activates menu entry */
368PCUT_TEST(press_leave_enter_release)
369{
370 dummy_gc_t *dgc;
371 gfx_context_t *gc;
372 ui_resource_t *resource = NULL;
373 ui_menu_bar_t *mbar = NULL;
374 ui_menu_t *menu = NULL;
375 ui_menu_entry_t *mentry = NULL;
376 gfx_coord2_t pos;
377 test_resp_t resp;
378 errno_t rc;
379
380 rc = dummygc_create(&dgc);
381 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
382
383 gc = dummygc_get_ctx(dgc);
384
385 rc = ui_resource_create(gc, false, &resource);
386 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
387 PCUT_ASSERT_NOT_NULL(resource);
388
389 rc = ui_menu_bar_create(resource, &mbar);
390 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
391 PCUT_ASSERT_NOT_NULL(mbar);
392
393 rc = ui_menu_create(mbar, "Test", &menu);
394 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
395 PCUT_ASSERT_NOT_NULL(menu);
396
397 rc = ui_menu_entry_create(menu, "X", &mentry);
398 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
399 PCUT_ASSERT_NOT_NULL(mentry);
400
401 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
402 resp.activated = false;
403
404 pos.x = 0;
405 pos.y = 0;
406 ui_menu_entry_press(mentry, &pos);
407 PCUT_ASSERT_TRUE(mentry->inside);
408 PCUT_ASSERT_TRUE(mentry->held);
409 PCUT_ASSERT_FALSE(resp.activated);
410
411 ui_menu_entry_leave(mentry, &pos);
412 PCUT_ASSERT_FALSE(mentry->inside);
413 PCUT_ASSERT_TRUE(mentry->held);
414 PCUT_ASSERT_FALSE(resp.activated);
415
416 ui_menu_entry_enter(mentry, &pos);
417 PCUT_ASSERT_TRUE(mentry->inside);
418 PCUT_ASSERT_TRUE(mentry->held);
419 PCUT_ASSERT_FALSE(resp.activated);
420
421 ui_menu_entry_release(mentry);
422 PCUT_ASSERT_FALSE(mentry->held);
423 PCUT_ASSERT_TRUE(resp.activated);
424
425 ui_menu_bar_destroy(mbar);
426 ui_resource_destroy(resource);
427 dummygc_destroy(dgc);
428}
429
430/** Press event inside menu entry */
431PCUT_TEST(pos_press_inside)
432{
433 dummy_gc_t *dgc;
434 gfx_context_t *gc;
435 ui_resource_t *resource = NULL;
436 ui_menu_bar_t *mbar = NULL;
437 ui_menu_t *menu = NULL;
438 ui_menu_entry_t *mentry = NULL;
439 gfx_coord2_t pos;
440 pos_event_t event;
441 errno_t rc;
442
443 rc = dummygc_create(&dgc);
444 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
445
446 gc = dummygc_get_ctx(dgc);
447
448 rc = ui_resource_create(gc, false, &resource);
449 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
450 PCUT_ASSERT_NOT_NULL(resource);
451
452 rc = ui_menu_bar_create(resource, &mbar);
453 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
454 PCUT_ASSERT_NOT_NULL(mbar);
455
456 rc = ui_menu_create(mbar, "Test", &menu);
457 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
458 PCUT_ASSERT_NOT_NULL(menu);
459
460 rc = ui_menu_entry_create(menu, "X", &mentry);
461 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
462 PCUT_ASSERT_NOT_NULL(mentry);
463
464 pos.x = 0;
465 pos.y = 0;
466
467 event.type = POS_PRESS;
468 event.hpos = 4;
469 event.vpos = 4;
470
471 ui_menu_entry_pos_event(mentry, &pos, &event);
472 PCUT_ASSERT_TRUE(mentry->inside);
473 PCUT_ASSERT_TRUE(mentry->held);
474
475 ui_menu_bar_destroy(mbar);
476 ui_resource_destroy(resource);
477 dummygc_destroy(dgc);
478}
479
480/** Press event outside menu entry */
481PCUT_TEST(pos_press_outside)
482{
483 dummy_gc_t *dgc;
484 gfx_context_t *gc;
485 ui_resource_t *resource = NULL;
486 ui_menu_bar_t *mbar = NULL;
487 ui_menu_t *menu = NULL;
488 ui_menu_entry_t *mentry = NULL;
489 gfx_coord2_t pos;
490 pos_event_t event;
491 errno_t rc;
492
493 rc = dummygc_create(&dgc);
494 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
495
496 gc = dummygc_get_ctx(dgc);
497
498 rc = ui_resource_create(gc, false, &resource);
499 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
500 PCUT_ASSERT_NOT_NULL(resource);
501
502 rc = ui_menu_bar_create(resource, &mbar);
503 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
504 PCUT_ASSERT_NOT_NULL(mbar);
505
506 rc = ui_menu_create(mbar, "Test", &menu);
507 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
508 PCUT_ASSERT_NOT_NULL(menu);
509
510 rc = ui_menu_entry_create(menu, "X", &mentry);
511 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
512 PCUT_ASSERT_NOT_NULL(mentry);
513
514 pos.x = 0;
515 pos.y = 0;
516
517 event.type = POS_PRESS;
518 event.hpos = 20;
519 event.vpos = 20;
520
521 ui_menu_entry_pos_event(mentry, &pos, &event);
522 PCUT_ASSERT_FALSE(mentry->inside);
523 PCUT_ASSERT_FALSE(mentry->held);
524
525 ui_menu_bar_destroy(mbar);
526 ui_resource_destroy(resource);
527 dummygc_destroy(dgc);
528}
529
530/** Position event moving out of menu entry */
531PCUT_TEST(pos_move_out)
532{
533 dummy_gc_t *dgc;
534 gfx_context_t *gc;
535 ui_resource_t *resource = NULL;
536 ui_menu_bar_t *mbar = NULL;
537 ui_menu_t *menu = NULL;
538 ui_menu_entry_t *mentry = NULL;
539 gfx_coord2_t pos;
540 pos_event_t event;
541 errno_t rc;
542
543 rc = dummygc_create(&dgc);
544 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
545
546 gc = dummygc_get_ctx(dgc);
547
548 rc = ui_resource_create(gc, false, &resource);
549 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
550 PCUT_ASSERT_NOT_NULL(resource);
551
552 rc = ui_menu_bar_create(resource, &mbar);
553 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
554 PCUT_ASSERT_NOT_NULL(mbar);
555
556 rc = ui_menu_create(mbar, "Test", &menu);
557 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
558 PCUT_ASSERT_NOT_NULL(menu);
559
560 rc = ui_menu_entry_create(menu, "X", &mentry);
561 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
562 PCUT_ASSERT_NOT_NULL(mentry);
563
564 pos.x = 0;
565 pos.y = 0;
566 ui_menu_entry_press(mentry, &pos);
567 PCUT_ASSERT_TRUE(mentry->inside);
568 PCUT_ASSERT_TRUE(mentry->held);
569
570 event.type = POS_UPDATE;
571 event.hpos = 20;
572 event.vpos = 20;
573
574 ui_menu_entry_pos_event(mentry, &pos, &event);
575 PCUT_ASSERT_FALSE(mentry->inside);
576 PCUT_ASSERT_TRUE(mentry->held);
577
578 ui_menu_bar_destroy(mbar);
579 ui_resource_destroy(resource);
580 dummygc_destroy(dgc);
581}
582
583/** Position event moving inside menu entry */
584PCUT_TEST(pos_move_in)
585{
586 dummy_gc_t *dgc;
587 gfx_context_t *gc;
588 ui_resource_t *resource = NULL;
589 ui_menu_bar_t *mbar = NULL;
590 ui_menu_t *menu = NULL;
591 ui_menu_entry_t *mentry = NULL;
592 gfx_coord2_t pos;
593 pos_event_t event;
594 errno_t rc;
595
596 rc = dummygc_create(&dgc);
597 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
598
599 gc = dummygc_get_ctx(dgc);
600
601 rc = ui_resource_create(gc, false, &resource);
602 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
603 PCUT_ASSERT_NOT_NULL(resource);
604
605 rc = ui_menu_bar_create(resource, &mbar);
606 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
607 PCUT_ASSERT_NOT_NULL(mbar);
608
609 rc = ui_menu_create(mbar, "Test", &menu);
610 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
611 PCUT_ASSERT_NOT_NULL(menu);
612
613 rc = ui_menu_entry_create(menu, "X", &mentry);
614 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
615 PCUT_ASSERT_NOT_NULL(mentry);
616
617 event.type = POS_UPDATE;
618 event.hpos = 4;
619 event.vpos = 4;
620
621 pos.x = 0;
622 pos.y = 0;
623
624 ui_menu_entry_pos_event(mentry, &pos, &event);
625 PCUT_ASSERT_TRUE(mentry->inside);
626 PCUT_ASSERT_FALSE(mentry->held);
627
628 ui_menu_bar_destroy(mbar);
629 ui_resource_destroy(resource);
630 dummygc_destroy(dgc);
631}
632
633static void test_entry_cb(ui_menu_entry_t *mentry, void *arg)
634{
635 test_resp_t *resp = (test_resp_t *) arg;
636
637 resp->activated = true;
638}
639
640PCUT_EXPORT(menuentry);
Note: See TracBrowser for help on using the repository browser.