Changes in uspace/lib/ui/test/window.c [cde067e:3d10a2f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/window.c
rcde067e r3d10a2f 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2021 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 *);51 47 static void test_window_close(ui_window_t *, void *); 52 static void test_window_focus(ui_window_t *, void * , unsigned);48 static void test_window_focus(ui_window_t *, void *); 53 49 static void test_window_kbd(ui_window_t *, void *, kbd_event_t *); 54 50 static errno_t test_window_paint(ui_window_t *, void *); 55 51 static void test_window_pos(ui_window_t *, void *, pos_event_t *); 56 static void test_window_unfocus(ui_window_t *, void *, unsigned); 57 static void test_window_resize(ui_window_t *, void *); 52 static void test_window_unfocus(ui_window_t *, void *); 58 53 59 54 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,64 55 .close = test_window_close, 65 56 .focus = test_window_focus, … … 67 58 .paint = test_window_paint, 68 59 .pos = test_window_pos, 69 .unfocus = test_window_unfocus, 70 .resize = test_window_resize 60 .unfocus = test_window_unfocus 71 61 }; 72 62 … … 76 66 static errno_t test_ctl_paint(void *); 77 67 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *); 78 static void test_ctl_unfocus(void * , unsigned);68 static void test_ctl_unfocus(void *); 79 69 80 70 static ui_control_ops_t test_ctl_ops = { … … 86 76 typedef struct { 87 77 errno_t rc; 88 bool sysmenu;89 sysarg_t sysmenu_idev_id;90 bool minimize;91 bool maximize;92 bool unmaximize;93 78 bool close; 94 79 bool focus; 95 unsigned focus_nfocus;96 80 bool kbd; 97 81 kbd_event_t kbd_event; … … 100 84 pos_event_t pos_event; 101 85 bool unfocus; 102 unsigned unfocus_nfocus;103 bool resize;104 86 } test_cb_resp_t; 105 87 … … 111 93 pos_event_t pos_event; 112 94 bool unfocus; 113 unsigned unfocus_nfocus;114 95 } test_ctl_resp_t; 115 96 … … 540 521 resp.unfocus = false; 541 522 542 ui_window_def_unfocus(window , 42);523 ui_window_def_unfocus(window); 543 524 PCUT_ASSERT_TRUE(resp.unfocus); 544 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);545 525 546 526 /* Need to remove first because we didn't implement the destructor */ 547 527 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);694 528 695 529 ui_window_destroy(window); … … 753 587 754 588 /* Focus callback with no callbacks set */ 755 ui_window_send_focus(window , 42);589 ui_window_send_focus(window); 756 590 757 591 /* Focus callback with focus callback not implemented */ 758 592 ui_window_set_cb(window, &dummy_window_cb, NULL); 759 ui_window_send_focus(window , 42);593 ui_window_send_focus(window); 760 594 761 595 /* Focus callback with real callback set */ 762 596 resp.focus = false; 763 597 ui_window_set_cb(window, &test_window_cb, &resp); 764 ui_window_send_focus(window , 42);598 ui_window_send_focus(window); 765 599 PCUT_ASSERT_TRUE(resp.focus); 766 PCUT_ASSERT_INT_EQUALS(42, resp.focus_nfocus);767 600 768 601 ui_window_destroy(window); … … 790 623 PCUT_ASSERT_NOT_NULL(window); 791 624 792 kbd_event.type = KEY_PRESS;625 kbd_event.type = POS_PRESS; 793 626 kbd_event.key = KC_X; 794 627 kbd_event.mods = 0; … … 922 755 923 756 /* Unfocus callback with no callbacks set */ 924 ui_window_send_unfocus(window , 42);757 ui_window_send_unfocus(window); 925 758 926 759 /* Unfocus callback with unfocus callback not implemented */ 927 760 ui_window_set_cb(window, &dummy_window_cb, NULL); 928 ui_window_send_unfocus(window , 42);761 ui_window_send_unfocus(window); 929 762 930 763 /* Unfocus callback with real callback set */ 931 764 resp.close = false; 932 765 ui_window_set_cb(window, &test_window_cb, &resp); 933 ui_window_send_unfocus(window , 42);766 ui_window_send_unfocus(window); 934 767 PCUT_ASSERT_TRUE(resp.unfocus); 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) 768 769 ui_window_destroy(window); 770 ui_destroy(ui); 771 } 772 773 static void test_window_close(ui_window_t *window, void *arg) 978 774 { 979 775 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 980 776 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) 777 resp->close = true; 778 } 779 780 static void test_window_focus(ui_window_t *window, void *arg) 986 781 { 987 782 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 988 783 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;1004 }1005 1006 static void test_window_close(ui_window_t *window, void *arg)1007 {1008 test_cb_resp_t *resp = (test_cb_resp_t *) arg;1009 1010 resp->close = true;1011 }1012 1013 static void test_window_focus(ui_window_t *window, void *arg, unsigned nfocus)1014 {1015 test_cb_resp_t *resp = (test_cb_resp_t *) arg;1016 1017 784 resp->focus = true; 1018 resp->focus_nfocus = nfocus;1019 785 } 1020 786 … … 1045 811 } 1046 812 1047 static void test_window_unfocus(ui_window_t *window, void *arg , unsigned nfocus)813 static void test_window_unfocus(ui_window_t *window, void *arg) 1048 814 { 1049 815 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1050 816 1051 817 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;1060 818 } 1061 819 … … 1078 836 } 1079 837 1080 static void test_ctl_unfocus(void *arg , unsigned nfocus)838 static void test_ctl_unfocus(void *arg) 1081 839 { 1082 840 test_ctl_resp_t *resp = (test_ctl_resp_t *) arg; 1083 841 1084 842 resp->unfocus = true; 1085 resp->unfocus_nfocus = nfocus;1086 843 } 1087 844
Note:
See TracChangeset
for help on using the changeset viewer.