Changeset d284ce9 in mainline for uspace/lib/ui/test/window.c
- Timestamp:
- 2020-10-27T21:56:15Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f03d1308
- Parents:
- f7a90df
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/window.c
rf7a90df rd284ce9 27 27 */ 28 28 29 #include <gfx/context.h> 30 #include <gfx/coord.h> 31 #include <io/pos_event.h> 29 32 #include <mem.h> 30 33 #include <pcut/pcut.h> 31 34 #include <stdbool.h> 35 #include <ui/resource.h> 32 36 #include <ui/ui.h> 33 37 #include <ui/window.h> … … 38 42 PCUT_TEST_SUITE(window); 39 43 44 static void test_window_close(ui_window_t *, void *); 45 static void test_window_pos(ui_window_t *, void *, pos_event_t *); 46 47 static ui_window_cb_t test_window_cb = { 48 .close = test_window_close, 49 .pos = test_window_pos 50 }; 51 52 static ui_window_cb_t dummy_window_cb = { 53 }; 54 55 typedef struct { 56 bool close; 57 bool pos; 58 pos_event_t pos_event; 59 } test_cb_resp_t; 60 40 61 /** Create and destroy window */ 41 62 PCUT_TEST(create_destroy) … … 43 64 errno_t rc; 44 65 ui_t *ui = NULL; 45 ui_w indow_params_t params;46 ui_window_t *window = NULL; 47 48 rc = ui_create_disp(NULL, &ui); 49 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 50 51 ui_w indow_params_init(¶ms);66 ui_wnd_params_t params; 67 ui_window_t *window = NULL; 68 69 rc = ui_create_disp(NULL, &ui); 70 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 71 72 ui_wnd_params_init(¶ms); 52 73 params.caption = "Hello"; 53 74 … … 66 87 } 67 88 89 /** ui_window_get_res/gc/rect() return valid objects */ 90 PCUT_TEST(get_res_gc_rect) 91 { 92 errno_t rc; 93 ui_t *ui = NULL; 94 ui_wnd_params_t params; 95 ui_window_t *window = NULL; 96 ui_resource_t *res; 97 gfx_context_t *gc; 98 gfx_rect_t rect; 99 100 rc = ui_create_disp(NULL, &ui); 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 103 ui_wnd_params_init(¶ms); 104 params.caption = "Hello"; 105 106 rc = ui_window_create(ui, ¶ms, &window); 107 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 108 PCUT_ASSERT_NOT_NULL(window); 109 110 res = ui_window_get_res(window); 111 PCUT_ASSERT_NOT_NULL(res); 112 113 gc = ui_window_get_gc(window); 114 PCUT_ASSERT_NOT_NULL(gc); 115 116 ui_window_get_app_rect(window, &rect); 117 118 ui_window_destroy(window); 119 ui_destroy(ui); 120 } 121 122 /** ui_window_close() calls close callback set via ui_window_set_cb() */ 123 PCUT_TEST(close) 124 { 125 errno_t rc; 126 ui_t *ui = NULL; 127 ui_wnd_params_t params; 128 ui_window_t *window = NULL; 129 test_cb_resp_t resp; 130 131 rc = ui_create_disp(NULL, &ui); 132 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 133 134 ui_wnd_params_init(¶ms); 135 params.caption = "Hello"; 136 137 rc = ui_window_create(ui, ¶ms, &window); 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 PCUT_ASSERT_NOT_NULL(window); 140 141 /* Close callback with no callbacks set */ 142 ui_window_close(window); 143 144 /* Close callback with close callback not implemented */ 145 ui_window_set_cb(window, &dummy_window_cb, NULL); 146 ui_window_close(window); 147 148 /* Close callback with real callback set */ 149 resp.close = false; 150 ui_window_set_cb(window, &test_window_cb, &resp); 151 ui_window_close(window); 152 PCUT_ASSERT_TRUE(resp.close); 153 154 ui_window_destroy(window); 155 ui_destroy(ui); 156 } 157 158 /** ui_window_pos() calls pos callback set via ui_window_set_cb() */ 159 PCUT_TEST(pos) 160 { 161 errno_t rc; 162 ui_t *ui = NULL; 163 ui_wnd_params_t params; 164 ui_window_t *window = NULL; 165 pos_event_t pos_event; 166 test_cb_resp_t resp; 167 168 rc = ui_create_disp(NULL, &ui); 169 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 170 171 ui_wnd_params_init(¶ms); 172 params.caption = "Hello"; 173 174 rc = ui_window_create(ui, ¶ms, &window); 175 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 176 PCUT_ASSERT_NOT_NULL(window); 177 178 pos_event.pos_id = 1; 179 pos_event.type = POS_PRESS; 180 pos_event.btn_num = 2; 181 pos_event.hpos = 3; 182 pos_event.vpos = 4; 183 184 /* Pos callback with no callbacks set */ 185 ui_window_pos(window, &pos_event); 186 187 /* Pos callback with pos callback not implemented */ 188 ui_window_set_cb(window, &dummy_window_cb, NULL); 189 ui_window_pos(window, &pos_event); 190 191 /* Pos callback with real callback set */ 192 resp.pos = false; 193 ui_window_set_cb(window, &test_window_cb, &resp); 194 ui_window_pos(window, &pos_event); 195 PCUT_ASSERT_TRUE(resp.pos); 196 PCUT_ASSERT_INT_EQUALS(pos_event.pos_id, resp.pos_event.pos_id); 197 PCUT_ASSERT_EQUALS(pos_event.type, resp.pos_event.type); 198 PCUT_ASSERT_INT_EQUALS(pos_event.btn_num, resp.pos_event.btn_num); 199 PCUT_ASSERT_INT_EQUALS(pos_event.hpos, resp.pos_event.hpos); 200 PCUT_ASSERT_INT_EQUALS(pos_event.vpos, resp.pos_event.vpos); 201 202 ui_window_destroy(window); 203 ui_destroy(ui); 204 } 205 206 static void test_window_close(ui_window_t *window, void *arg) 207 { 208 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 209 210 resp->close = true; 211 } 212 213 static void test_window_pos(ui_window_t *window, void *arg, 214 pos_event_t *event) 215 { 216 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 217 218 resp->pos = true; 219 resp->pos_event = *event; 220 } 221 68 222 PCUT_EXPORT(window);
Note:
See TracChangeset
for help on using the changeset viewer.