Changeset 08d5f8b in mainline for uspace/app/nav/test/menu.c
- Timestamp:
- 2021-10-19T20:54:17Z (2 years ago)
- Children:
- 2651dc5
- Parents:
- bdb2a72f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/test/menu.c
rbdb2a72f r08d5f8b 29 29 #include <errno.h> 30 30 #include <pcut/pcut.h> 31 #include <stdbool.h> 31 32 #include "../menu.h" 32 33 … … 34 35 35 36 PCUT_TEST_SUITE(menu); 37 38 static void test_menu_file_open(void *); 39 static void test_menu_file_exit(void *); 40 41 static nav_menu_cb_t dummy_cb; 42 static nav_menu_cb_t test_cb = { 43 .file_open = test_menu_file_open, 44 .file_exit = test_menu_file_exit 45 }; 46 47 /** Test response */ 48 typedef struct { 49 bool file_open; 50 bool file_exit; 51 } test_resp_t; 36 52 37 53 /** Create and destroy menu. */ … … 61 77 } 62 78 79 /** nav_menu_set_cb() */ 80 PCUT_TEST(set_cb) 81 { 82 ui_t *ui; 83 ui_window_t *window; 84 ui_wnd_params_t params; 85 nav_menu_t *menu; 86 int foo; 87 errno_t rc; 88 89 rc = ui_create_disp(NULL, &ui); 90 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 91 92 ui_wnd_params_init(¶ms); 93 params.caption = "Test"; 94 95 rc = ui_window_create(ui, ¶ms, &window); 96 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 97 98 rc = nav_menu_create(window, &menu); 99 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 100 101 nav_menu_set_cb(menu, &test_cb, &foo); 102 PCUT_ASSERT_EQUALS(&test_cb, menu->cb); 103 PCUT_ASSERT_EQUALS(&foo, menu->cb_arg); 104 105 nav_menu_destroy(menu); 106 ui_window_destroy(window); 107 ui_destroy(ui); 108 } 109 110 /** File / Open callback */ 111 PCUT_TEST(file_open) 112 { 113 ui_t *ui; 114 ui_window_t *window; 115 ui_wnd_params_t params; 116 nav_menu_t *menu; 117 test_resp_t resp; 118 errno_t rc; 119 120 rc = ui_create_disp(NULL, &ui); 121 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 122 123 ui_wnd_params_init(¶ms); 124 params.caption = "Test"; 125 126 rc = ui_window_create(ui, ¶ms, &window); 127 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 128 129 rc = nav_menu_create(window, &menu); 130 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 131 132 /* Call back with no callbacks set */ 133 nav_menu_file_open(NULL, menu); 134 135 /* Call back with dummy callbacks set */ 136 nav_menu_set_cb(menu, &dummy_cb, &resp); 137 nav_menu_file_open(NULL, menu); 138 139 /* Call back with test callbacks set */ 140 resp.file_open = false; 141 nav_menu_set_cb(menu, &test_cb, &resp); 142 nav_menu_file_open(NULL, menu); 143 PCUT_ASSERT_TRUE(resp.file_open); 144 145 nav_menu_destroy(menu); 146 ui_window_destroy(window); 147 ui_destroy(ui); 148 } 149 150 /** Testing File / Open callback */ 151 static void test_menu_file_open(void *arg) 152 { 153 test_resp_t *resp = (test_resp_t *)arg; 154 155 resp->file_open = true; 156 } 157 158 /** Testing File / Exit callback */ 159 static void test_menu_file_exit(void *arg) 160 { 161 test_resp_t *resp = (test_resp_t *)arg; 162 163 resp->file_exit = true; 164 } 165 63 166 PCUT_EXPORT(menu);
Note:
See TracChangeset
for help on using the changeset viewer.