Changes in uspace/lib/ui/test/window.c [db3895d:cde067e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/window.c
rdb3895d rcde067e 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 PCUT_TEST_SUITE(window); 46 46 47 static void test_window_sysmenu(ui_window_t *, void *, sysarg_t); 48 static void test_window_minimize(ui_window_t *, void *); 49 static void test_window_maximize(ui_window_t *, void *); 50 static void test_window_unmaximize(ui_window_t *, void *); 47 51 static void test_window_close(ui_window_t *, void *); 48 static void test_window_focus(ui_window_t *, void * );52 static void test_window_focus(ui_window_t *, void *, unsigned); 49 53 static void test_window_kbd(ui_window_t *, void *, kbd_event_t *); 50 54 static errno_t test_window_paint(ui_window_t *, void *); 51 55 static void test_window_pos(ui_window_t *, void *, pos_event_t *); 52 static void test_window_unfocus(ui_window_t *, void *); 56 static void test_window_unfocus(ui_window_t *, void *, unsigned); 57 static void test_window_resize(ui_window_t *, void *); 53 58 54 59 static ui_window_cb_t test_window_cb = { 60 .sysmenu = test_window_sysmenu, 61 .minimize = test_window_minimize, 62 .maximize = test_window_maximize, 63 .unmaximize = test_window_unmaximize, 55 64 .close = test_window_close, 56 65 .focus = test_window_focus, … … 58 67 .paint = test_window_paint, 59 68 .pos = test_window_pos, 60 .unfocus = test_window_unfocus 69 .unfocus = test_window_unfocus, 70 .resize = test_window_resize 61 71 }; 62 72 … … 66 76 static errno_t test_ctl_paint(void *); 67 77 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *); 68 static void test_ctl_unfocus(void * );78 static void test_ctl_unfocus(void *, unsigned); 69 79 70 80 static ui_control_ops_t test_ctl_ops = { … … 76 86 typedef struct { 77 87 errno_t rc; 88 bool sysmenu; 89 sysarg_t sysmenu_idev_id; 90 bool minimize; 91 bool maximize; 92 bool unmaximize; 78 93 bool close; 79 94 bool focus; 95 unsigned focus_nfocus; 80 96 bool kbd; 81 97 kbd_event_t kbd_event; … … 84 100 pos_event_t pos_event; 85 101 bool unfocus; 102 unsigned unfocus_nfocus; 103 bool resize; 86 104 } test_cb_resp_t; 87 105 … … 93 111 pos_event_t pos_event; 94 112 bool unfocus; 113 unsigned unfocus_nfocus; 95 114 } test_ctl_resp_t; 96 115 … … 258 277 } 259 278 279 /** ui_window_get_ui() returns containing UI */ 280 PCUT_TEST(get_ui) 281 { 282 errno_t rc; 283 ui_t *ui = NULL; 284 ui_t *rui; 285 ui_wnd_params_t params; 286 ui_window_t *window = NULL; 287 288 rc = ui_create_disp(NULL, &ui); 289 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 290 291 ui_wnd_params_init(¶ms); 292 params.caption = "Hello"; 293 294 rc = ui_window_create(ui, ¶ms, &window); 295 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 296 PCUT_ASSERT_NOT_NULL(window); 297 298 rui = ui_window_get_ui(window); 299 PCUT_ASSERT_EQUALS(ui, rui); 300 301 ui_window_destroy(window); 302 ui_destroy(ui); 303 } 304 260 305 /** ui_window_get_res/gc/rect() return valid objects */ 261 306 PCUT_TEST(get_res_gc_rect) … … 495 540 resp.unfocus = false; 496 541 497 ui_window_def_unfocus(window );542 ui_window_def_unfocus(window, 42); 498 543 PCUT_ASSERT_TRUE(resp.unfocus); 544 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus); 499 545 500 546 /* Need to remove first because we didn't implement the destructor */ 501 547 ui_window_remove(window, control); 548 549 ui_window_destroy(window); 550 ui_destroy(ui); 551 } 552 553 /** ui_window_send_sysmenu() calls sysmenu callback set via ui_window_set_cb() */ 554 PCUT_TEST(send_sysmenu) 555 { 556 errno_t rc; 557 ui_t *ui = NULL; 558 ui_wnd_params_t params; 559 ui_window_t *window = NULL; 560 test_cb_resp_t resp; 561 562 rc = ui_create_disp(NULL, &ui); 563 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 564 565 ui_wnd_params_init(¶ms); 566 params.caption = "Hello"; 567 568 rc = ui_window_create(ui, ¶ms, &window); 569 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 570 PCUT_ASSERT_NOT_NULL(window); 571 572 /* Sysmenu callback with no callbacks set */ 573 ui_window_send_sysmenu(window, 42); 574 575 /* Sysmenu callback with sysmenu callback not implemented */ 576 ui_window_set_cb(window, &dummy_window_cb, NULL); 577 ui_window_send_sysmenu(window, 42); 578 579 /* Sysmenu callback with real callback set */ 580 resp.sysmenu = false; 581 resp.sysmenu_idev_id = 0; 582 ui_window_set_cb(window, &test_window_cb, &resp); 583 ui_window_send_sysmenu(window, 42); 584 PCUT_ASSERT_TRUE(resp.sysmenu); 585 PCUT_ASSERT_INT_EQUALS(42, resp.sysmenu_idev_id); 586 587 ui_window_destroy(window); 588 ui_destroy(ui); 589 } 590 591 /** ui_window_send_minimize() calls minimize callback set via ui_window_set_cb() */ 592 PCUT_TEST(send_minimize) 593 { 594 errno_t rc; 595 ui_t *ui = NULL; 596 ui_wnd_params_t params; 597 ui_window_t *window = NULL; 598 test_cb_resp_t resp; 599 600 rc = ui_create_disp(NULL, &ui); 601 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 602 603 ui_wnd_params_init(¶ms); 604 params.caption = "Hello"; 605 606 rc = ui_window_create(ui, ¶ms, &window); 607 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 608 PCUT_ASSERT_NOT_NULL(window); 609 610 /* Minimize callback with no callbacks set */ 611 ui_window_send_minimize(window); 612 613 /* Minimize callback with minimize callback not implemented */ 614 ui_window_set_cb(window, &dummy_window_cb, NULL); 615 ui_window_send_minimize(window); 616 617 /* Minimize callback with real callback set */ 618 resp.minimize = false; 619 ui_window_set_cb(window, &test_window_cb, &resp); 620 ui_window_send_minimize(window); 621 PCUT_ASSERT_TRUE(resp.minimize); 622 623 ui_window_destroy(window); 624 ui_destroy(ui); 625 } 626 627 /** ui_window_send_maximize() calls maximize callback set via ui_window_set_cb() */ 628 PCUT_TEST(send_maximize) 629 { 630 errno_t rc; 631 ui_t *ui = NULL; 632 ui_wnd_params_t params; 633 ui_window_t *window = NULL; 634 test_cb_resp_t resp; 635 636 rc = ui_create_disp(NULL, &ui); 637 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 638 639 ui_wnd_params_init(¶ms); 640 params.caption = "Hello"; 641 642 rc = ui_window_create(ui, ¶ms, &window); 643 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 644 PCUT_ASSERT_NOT_NULL(window); 645 646 /* Maximize callback with no callbacks set */ 647 ui_window_send_maximize(window); 648 649 /* Maximize callback with maximize callback not implemented */ 650 ui_window_set_cb(window, &dummy_window_cb, NULL); 651 ui_window_send_maximize(window); 652 653 /* Maximize callback with real callback set */ 654 resp.maximize = false; 655 ui_window_set_cb(window, &test_window_cb, &resp); 656 ui_window_send_maximize(window); 657 PCUT_ASSERT_TRUE(resp.maximize); 658 659 ui_window_destroy(window); 660 ui_destroy(ui); 661 } 662 663 /** ui_window_send_unmaximize() calls unmaximize callback set via ui_window_set_cb() */ 664 PCUT_TEST(send_unmaximize) 665 { 666 errno_t rc; 667 ui_t *ui = NULL; 668 ui_wnd_params_t params; 669 ui_window_t *window = NULL; 670 test_cb_resp_t resp; 671 672 rc = ui_create_disp(NULL, &ui); 673 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 674 675 ui_wnd_params_init(¶ms); 676 params.caption = "Hello"; 677 678 rc = ui_window_create(ui, ¶ms, &window); 679 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 680 PCUT_ASSERT_NOT_NULL(window); 681 682 /* Unmaximize callback with no callbacks set */ 683 ui_window_send_unmaximize(window); 684 685 /* Unmaximize callback with unmaximize callback not implemented */ 686 ui_window_set_cb(window, &dummy_window_cb, NULL); 687 ui_window_send_unmaximize(window); 688 689 /* Unmaximize callback with real callback set */ 690 resp.unmaximize = false; 691 ui_window_set_cb(window, &test_window_cb, &resp); 692 ui_window_send_unmaximize(window); 693 PCUT_ASSERT_TRUE(resp.unmaximize); 502 694 503 695 ui_window_destroy(window); … … 561 753 562 754 /* Focus callback with no callbacks set */ 563 ui_window_send_focus(window );755 ui_window_send_focus(window, 42); 564 756 565 757 /* Focus callback with focus callback not implemented */ 566 758 ui_window_set_cb(window, &dummy_window_cb, NULL); 567 ui_window_send_focus(window );759 ui_window_send_focus(window, 42); 568 760 569 761 /* Focus callback with real callback set */ 570 762 resp.focus = false; 571 763 ui_window_set_cb(window, &test_window_cb, &resp); 572 ui_window_send_focus(window );764 ui_window_send_focus(window, 42); 573 765 PCUT_ASSERT_TRUE(resp.focus); 766 PCUT_ASSERT_INT_EQUALS(42, resp.focus_nfocus); 574 767 575 768 ui_window_destroy(window); … … 597 790 PCUT_ASSERT_NOT_NULL(window); 598 791 599 kbd_event.type = POS_PRESS;792 kbd_event.type = KEY_PRESS; 600 793 kbd_event.key = KC_X; 601 794 kbd_event.mods = 0; … … 729 922 730 923 /* Unfocus callback with no callbacks set */ 731 ui_window_send_unfocus(window );924 ui_window_send_unfocus(window, 42); 732 925 733 926 /* Unfocus callback with unfocus callback not implemented */ 734 927 ui_window_set_cb(window, &dummy_window_cb, NULL); 735 ui_window_send_unfocus(window );928 ui_window_send_unfocus(window, 42); 736 929 737 930 /* Unfocus callback with real callback set */ 738 931 resp.close = false; 739 932 ui_window_set_cb(window, &test_window_cb, &resp); 740 ui_window_send_unfocus(window );933 ui_window_send_unfocus(window, 42); 741 934 PCUT_ASSERT_TRUE(resp.unfocus); 742 743 ui_window_destroy(window); 744 ui_destroy(ui); 935 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus); 936 937 ui_window_destroy(window); 938 ui_destroy(ui); 939 } 940 941 /** ui_window_send_resize() calls resize callback set via ui_window_set_cb() */ 942 PCUT_TEST(send_resize) 943 { 944 errno_t rc; 945 ui_t *ui = NULL; 946 ui_wnd_params_t params; 947 ui_window_t *window = NULL; 948 test_cb_resp_t resp; 949 950 rc = ui_create_disp(NULL, &ui); 951 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 952 953 ui_wnd_params_init(¶ms); 954 params.caption = "Hello"; 955 956 rc = ui_window_create(ui, ¶ms, &window); 957 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 958 PCUT_ASSERT_NOT_NULL(window); 959 960 /* Resize callback with no callbacks set */ 961 ui_window_send_resize(window); 962 963 /* Resize callback with resize callback not implemented */ 964 ui_window_set_cb(window, &dummy_window_cb, NULL); 965 ui_window_send_resize(window); 966 967 /* Resize callback with real callback set */ 968 resp.close = false; 969 ui_window_set_cb(window, &test_window_cb, &resp); 970 ui_window_send_resize(window); 971 PCUT_ASSERT_TRUE(resp.resize); 972 973 ui_window_destroy(window); 974 ui_destroy(ui); 975 } 976 977 static void test_window_sysmenu(ui_window_t *window, void *arg, sysarg_t idev_id) 978 { 979 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 980 981 resp->sysmenu = true; 982 resp->sysmenu_idev_id = idev_id; 983 } 984 985 static void test_window_minimize(ui_window_t *window, void *arg) 986 { 987 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 988 989 resp->minimize = true; 990 } 991 992 static void test_window_maximize(ui_window_t *window, void *arg) 993 { 994 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 995 996 resp->maximize = true; 997 } 998 999 static void test_window_unmaximize(ui_window_t *window, void *arg) 1000 { 1001 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1002 1003 resp->unmaximize = true; 745 1004 } 746 1005 … … 752 1011 } 753 1012 754 static void test_window_focus(ui_window_t *window, void *arg )1013 static void test_window_focus(ui_window_t *window, void *arg, unsigned nfocus) 755 1014 { 756 1015 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 757 1016 758 1017 resp->focus = true; 1018 resp->focus_nfocus = nfocus; 759 1019 } 760 1020 … … 785 1045 } 786 1046 787 static void test_window_unfocus(ui_window_t *window, void *arg )1047 static void test_window_unfocus(ui_window_t *window, void *arg, unsigned nfocus) 788 1048 { 789 1049 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 790 1050 791 1051 resp->unfocus = true; 1052 resp->unfocus_nfocus = nfocus; 1053 } 1054 1055 static void test_window_resize(ui_window_t *window, void *arg) 1056 { 1057 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1058 1059 resp->resize = true; 792 1060 } 793 1061 … … 810 1078 } 811 1079 812 static void test_ctl_unfocus(void *arg )1080 static void test_ctl_unfocus(void *arg, unsigned nfocus) 813 1081 { 814 1082 test_ctl_resp_t *resp = (test_ctl_resp_t *) arg; 815 1083 816 1084 resp->unfocus = true; 1085 resp->unfocus_nfocus = nfocus; 817 1086 } 818 1087
Note:
See TracChangeset
for help on using the changeset viewer.