Changeset d284ce9 in mainline
- Timestamp:
- 2020-10-27T21:56:15Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f03d1308
- Parents:
- f7a90df
- Location:
- uspace
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rf7a90df rd284ce9 33 33 */ 34 34 35 #include <display.h>36 35 #include <gfx/color.h> 37 36 #include <gfx/coord.h> 38 37 #include <gfx/render.h> 38 #include <io/pos_event.h> 39 39 #include <stdio.h> 40 40 #include <str.h> … … 43 43 #include <ui/pbutton.h> 44 44 #include <ui/resource.h> 45 #include <ui/ui.h> 45 46 #include <ui/wdecor.h> 47 #include <ui/window.h> 46 48 #include "uidemo.h" 47 49 48 static void wnd_close_event(void *); 49 static void wnd_focus_event(void *); 50 static void wnd_kbd_event(void *, kbd_event_t *); 51 static void wnd_pos_event(void *, pos_event_t *); 52 static void wnd_unfocus_event(void *); 53 54 static display_wnd_cb_t wnd_cb = { 55 .close_event = wnd_close_event, 56 .focus_event = wnd_focus_event, 57 .kbd_event = wnd_kbd_event, 58 .pos_event = wnd_pos_event, 59 .unfocus_event = wnd_unfocus_event 50 static void wnd_close(ui_window_t *, void *); 51 static void wnd_pos(ui_window_t *, void *, pos_event_t *pos); 52 53 static ui_window_cb_t window_cb = { 54 .close = wnd_close, 55 .pos = wnd_pos 60 56 }; 61 57 … … 66 62 }; 67 63 68 static void wd_close(ui_wdecor_t *, void *); 69 static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 70 71 static ui_wdecor_cb_t wdecor_cb = { 72 .close = wd_close, 73 .move = wd_move 74 }; 75 76 /** Print syntax. */ 77 static void print_syntax(void) 78 { 79 printf("Syntax: uidemo [-d <display>]\n"); 80 } 81 82 /** Handle window close event. */ 83 static void wnd_close_event(void *arg) 64 /** Window close button was clicked. 65 * 66 * @param window Window 67 * @param arg Argument (demo) 68 */ 69 static void wnd_close(ui_window_t *window, void *arg) 84 70 { 85 71 ui_demo_t *demo = (ui_demo_t *) arg; 86 72 87 demo->quit = true; 88 } 89 90 /** Handle window focus event. */ 91 static void wnd_focus_event(void *arg) 73 ui_quit(demo->ui); 74 } 75 76 /** Window position event. 77 * 78 * @param window Window 79 * @param arg Argument (demo) 80 */ 81 static void wnd_pos(ui_window_t *window, void *arg, pos_event_t *event) 92 82 { 93 83 ui_demo_t *demo = (ui_demo_t *) arg; 94 84 95 if (demo->wdecor != NULL) {96 ui_wdecor_set_active(demo->wdecor, true);97 ui_wdecor_paint(demo->wdecor);98 }99 }100 101 /** Handle window keyboard event */102 static void wnd_kbd_event(void *arg, kbd_event_t *event)103 {104 ui_demo_t *demo = (ui_demo_t *) arg;105 106 (void) demo;107 }108 109 /** Handle window position event */110 static void wnd_pos_event(void *arg, pos_event_t *event)111 {112 ui_demo_t *demo = (ui_demo_t *) arg;113 114 85 /* Make sure we don't process events until fully initialized */ 115 if (demo-> wdecor == NULL || demo->pb1 == NULL || demo->pb2 == NULL)86 if (demo->pb1 == NULL || demo->pb2 == NULL) 116 87 return; 117 88 118 ui_wdecor_pos_event(demo->wdecor, event);119 89 ui_pbutton_pos_event(demo->pb1, event); 120 90 ui_pbutton_pos_event(demo->pb2, event); 121 }122 123 /** Handle window unfocus event. */124 static void wnd_unfocus_event(void *arg)125 {126 ui_demo_t *demo = (ui_demo_t *) arg;127 128 if (demo->wdecor != NULL) {129 ui_wdecor_set_active(demo->wdecor, false);130 ui_wdecor_paint(demo->wdecor);131 }132 91 } 133 92 … … 155 114 } 156 115 157 /** Window decoration requested window closure.158 *159 * @param wdecor Window decoration160 * @param arg Argument (demo)161 */162 static void wd_close(ui_wdecor_t *wdecor, void *arg)163 {164 ui_demo_t *demo = (ui_demo_t *) arg;165 166 demo->quit = true;167 }168 169 /** Window decoration requested window move.170 *171 * @param wdecor Window decoration172 * @param arg Argument (demo)173 * @param pos Position where the title bar was pressed174 */175 static void wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)176 {177 ui_demo_t *demo = (ui_demo_t *) arg;178 179 (void) display_window_move_req(demo->dwindow, pos);180 }181 182 116 /** Run UI demo on display server. */ 183 static errno_t ui_demo_display(const char *display_svc) 184 { 185 display_t *display = NULL; 186 gfx_context_t *gc; 187 display_wnd_params_t params; 188 display_window_t *window = NULL; 189 ui_resource_t *ui_res; 117 static errno_t ui_demo(const char *display_spec) 118 { 119 ui_t *ui = NULL; 120 ui_wnd_params_t params; 121 ui_window_t *window = NULL; 190 122 ui_demo_t demo; 191 123 gfx_rect_t rect; 192 gfx_color_t *color = NULL; 124 gfx_rect_t app_rect; 125 gfx_color_t *color; 126 ui_resource_t *ui_res; 127 gfx_context_t *gc; 193 128 errno_t rc; 194 129 195 rc = display_open(display_svc, &display); 196 if (rc != EOK) { 197 printf("Error opening display.\n"); 198 return rc; 199 } 200 201 display_wnd_params_init(¶ms); 130 rc = ui_create(display_spec, &ui); 131 if (rc != EOK) { 132 printf("Error creating UI on display %s.\n", display_spec); 133 return rc; 134 } 135 136 ui_wnd_params_init(¶ms); 137 params.caption = "UI Demo"; 202 138 params.rect.p0.x = 0; 203 139 params.rect.p0.y = 0; … … 206 142 207 143 memset((void *) &demo, 0, sizeof(demo)); 208 209 rc = display_window_create(display, ¶ms, &wnd_cb, (void *) &demo, 210 144 demo.ui = ui; 145 146 rc = ui_window_create(ui, ¶ms, &window); 211 147 if (rc != EOK) { 212 148 printf("Error creating window.\n"); … … 214 150 } 215 151 216 demo.quit = false; 217 demo.dwindow = window; 218 219 rc = display_window_get_gc(window, &gc); 220 if (rc != EOK) { 221 printf("Error getting graphics context.\n"); 222 return rc; 223 } 152 ui_window_set_cb(window, &window_cb, (void *) &demo); 153 demo.window = window; 224 154 225 155 task_retval(0); 226 156 227 rc = ui_resource_create(gc, &ui_res); 228 if (rc != EOK) { 229 printf("Error creating UI.\n"); 230 return rc; 231 } 232 233 rc = ui_wdecor_create(ui_res, "UI Demo", &demo.wdecor); 234 if (rc != EOK) { 235 printf("Error creating window decoration.\n"); 236 return rc; 237 } 238 239 ui_wdecor_set_rect(demo.wdecor, ¶ms.rect); 240 ui_wdecor_set_cb(demo.wdecor, &wdecor_cb, (void *) &demo); 157 ui_res = ui_window_get_res(window); 158 gc = ui_window_get_gc(window); 159 ui_window_get_app_rect(window, &app_rect); 241 160 242 161 rc = ui_label_create(ui_res, "Hello there!", &demo.label); … … 295 214 } 296 215 297 rc = gfx_fill_rect(gc, & params.rect);216 rc = gfx_fill_rect(gc, &app_rect); 298 217 if (rc != EOK) { 299 218 printf("Error filling background.\n"); … … 301 220 } 302 221 303 gfx_color_delete(color);304 color = NULL;305 306 rc = ui_wdecor_paint(demo.wdecor);307 if (rc != EOK) {308 printf("Error painting window decoration.\n");309 return rc;310 }311 312 222 rc = ui_label_paint(demo.label); 313 223 if (rc != EOK) { … … 328 238 } 329 239 330 while (!demo.quit) { 331 fibril_usleep(100 * 1000); 332 } 333 334 ui_wdecor_destroy(demo.wdecor); 240 ui_run(ui); 241 335 242 ui_pbutton_destroy(demo.pb1); 336 243 ui_pbutton_destroy(demo.pb2); 337 244 338 rc = gfx_context_delete(gc); 339 if (rc != EOK) 340 return rc; 341 342 display_window_destroy(window); 343 display_close(display); 245 ui_window_destroy(window); 246 ui_destroy(ui); 344 247 345 248 return EOK; 346 249 } 347 250 251 static void print_syntax(void) 252 { 253 printf("Syntax: uidemo [-d <display-spec>]\n"); 254 } 255 348 256 int main(int argc, char *argv[]) 349 257 { 350 const char *display_s vc =DISPLAY_DEFAULT;258 const char *display_spec = UI_DISPLAY_DEFAULT; 351 259 errno_t rc; 352 260 int i; … … 362 270 } 363 271 364 display_s vc = argv[i++];272 display_spec = argv[i++]; 365 273 } else { 366 274 printf("Invalid option '%s'.\n", argv[i]); … … 375 283 } 376 284 377 rc = ui_demo _display(display_svc);285 rc = ui_demo(display_spec); 378 286 if (rc != EOK) 379 287 return 1; -
uspace/app/uidemo/uidemo.h
rf7a90df rd284ce9 40 40 #include <ui/label.h> 41 41 #include <ui/pbutton.h> 42 #include <ui/wdecor.h> 42 #include <ui/ui.h> 43 #include <ui/window.h> 43 44 44 45 /** User interface demo */ 45 46 typedef struct { 46 display_window_t *dwindow;47 ui_w decor_t *wdecor;47 ui_t *ui; 48 ui_window_t *window; 48 49 ui_label_t *label; 49 50 ui_pbutton_t *pb1; 50 51 ui_pbutton_t *pb2; 51 bool quit;52 52 } ui_demo_t; 53 53 -
uspace/lib/ui/include/types/ui/window.h
rf7a90df rd284ce9 37 37 #define _UI_TYPES_WINDOW_H 38 38 39 #include <io/pos_event.h> 40 39 41 struct ui_window; 40 42 typedef struct ui_window ui_window_t; … … 43 45 typedef struct { 44 46 /** Window rectangle */ 45 gfx_rect_t *rect;47 gfx_rect_t rect; 46 48 /** Window caption */ 47 49 const char *caption; 48 } ui_window_params_t; 50 } ui_wnd_params_t; 51 52 /** Window callbacks */ 53 typedef struct ui_window_cb { 54 void (*close)(ui_window_t *, void *); 55 void (*pos)(ui_window_t *, void *, pos_event_t *); 56 } ui_window_cb_t; 49 57 50 58 #endif -
uspace/lib/ui/include/ui/ui.h
rf7a90df rd284ce9 44 44 extern errno_t ui_create_disp(display_t *, ui_t **); 45 45 extern void ui_destroy(ui_t *); 46 extern void ui_quit(ui_t *); 47 extern void ui_run(ui_t *); 46 48 47 49 #endif -
uspace/lib/ui/include/ui/window.h
rf7a90df rd284ce9 38 38 39 39 #include <errno.h> 40 #include <gfx/context.h> 41 #include <gfx/coord.h> 40 42 #include <types/ui/ui.h> 43 #include <types/ui/resource.h> 41 44 #include <types/ui/window.h> 42 45 43 extern void ui_w indow_params_init(ui_window_params_t *);44 extern errno_t ui_window_create(ui_t *, ui_w indow_params_t *,46 extern void ui_wnd_params_init(ui_wnd_params_t *); 47 extern errno_t ui_window_create(ui_t *, ui_wnd_params_t *, 45 48 ui_window_t **); 49 extern void ui_window_set_cb(ui_window_t *, ui_window_cb_t *, void *); 46 50 extern void ui_window_destroy(ui_window_t *); 51 extern ui_resource_t *ui_window_get_res(ui_window_t *); 52 extern gfx_context_t *ui_window_get_gc(ui_window_t *); 53 extern void ui_window_get_app_rect(ui_window_t *, gfx_rect_t *); 47 54 48 55 #endif -
uspace/lib/ui/private/ui.h
rf7a90df rd284ce9 50 50 /** Output owned by UI, clean up when destroying UI */ 51 51 bool myoutput; 52 /** @c true if terminating */ 53 bool quit; 52 54 }; 53 55 -
uspace/lib/ui/private/window.h
rf7a90df rd284ce9 40 40 #include <display.h> 41 41 #include <gfx/context.h> 42 #include <io/pos_event.h> 42 43 43 44 /** Actual structure of window. … … 48 49 /** Containing user interface */ 49 50 struct ui *ui; 51 /** Callbacks */ 52 struct ui_window_cb *cb; 53 /** Callback argument */ 54 void *arg; 50 55 /** Display window */ 51 56 display_window_t *dwindow; … … 58 63 }; 59 64 65 extern void ui_window_close(ui_window_t *); 66 extern void ui_window_pos(ui_window_t *, pos_event_t *); 67 60 68 #endif 61 69 -
uspace/lib/ui/src/ui.c
rf7a90df rd284ce9 36 36 #include <display.h> 37 37 #include <errno.h> 38 #include <fibril.h> 38 39 #include <stdlib.h> 39 40 #include <ui/ui.h> … … 65 66 ui->display = display; 66 67 ui->myoutput = true; 68 *rui = ui; 67 69 return EOK; 68 70 } … … 101 103 } 102 104 105 /** Execute user interface. 106 * 107 * This function returns once the application starts the termination 108 * process by calling ui_quit(@a ui). 109 * 110 * @param ui User interface 111 */ 112 void ui_run(ui_t *ui) 113 { 114 while (!ui->quit) 115 fibril_usleep(100000); 116 } 117 118 /** Terminate user interface. 119 * 120 * Calling this function causes the user interface to terminate 121 * (i.e. exit from ui_run()). This would be typically called from 122 * an event handler. 123 * 124 * @param ui User interface 125 */ 126 void ui_quit(ui_t *ui) 127 { 128 ui->quit = true; 129 } 130 103 131 /** @} 104 132 */ -
uspace/lib/ui/src/wdecor.c
rf7a90df rd284ce9 226 226 * 227 227 * @param wdecor Window decoration 228 * @param pos Position where the title bar was pressed229 228 */ 230 229 void ui_wdecor_close(ui_wdecor_t *wdecor) -
uspace/lib/ui/src/window.c
rf7a90df rd284ce9 37 37 #include <errno.h> 38 38 #include <gfx/context.h> 39 #include <io/pos_event.h> 39 40 #include <mem.h> 40 41 #include <stdlib.h> … … 44 45 #include "../private/dummygc.h" 45 46 #include "../private/ui.h" 47 #include "../private/wdecor.h" 46 48 #include "../private/window.h" 49 50 static void dwnd_close_event(void *); 51 static void dwnd_focus_event(void *); 52 static void dwnd_kbd_event(void *, kbd_event_t *); 53 static void dwnd_pos_event(void *, pos_event_t *); 54 static void dwnd_unfocus_event(void *); 55 56 static display_wnd_cb_t dwnd_cb = { 57 .close_event = dwnd_close_event, 58 .focus_event = dwnd_focus_event, 59 .kbd_event = dwnd_kbd_event, 60 .pos_event = dwnd_pos_event, 61 .unfocus_event = dwnd_unfocus_event 62 }; 63 64 static void wd_close(ui_wdecor_t *, void *); 65 static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 66 67 static ui_wdecor_cb_t wdecor_cb = { 68 .close = wd_close, 69 .move = wd_move 70 }; 47 71 48 72 /** Initialize window parameters structure. … … 53 77 * @param params Window parameters structure 54 78 */ 55 void ui_w indow_params_init(ui_window_params_t *params)56 { 57 memset(params, 0, sizeof(ui_w indow_params_t));79 void ui_wnd_params_init(ui_wnd_params_t *params) 80 { 81 memset(params, 0, sizeof(ui_wnd_params_t)); 58 82 } 59 83 … … 65 89 * @return EOK on success or an error code 66 90 */ 67 errno_t ui_window_create(ui_t *ui, ui_w indow_params_t *params,91 errno_t ui_window_create(ui_t *ui, ui_wnd_params_t *params, 68 92 ui_window_t **rwindow) 69 93 { … … 82 106 83 107 display_wnd_params_init(&dparams); 108 dparams.rect = params->rect; 84 109 85 110 if (ui->display != NULL) { 86 rc = display_window_create(ui->display, &dparams, NULL, NULL,87 &dwindow);111 rc = display_window_create(ui->display, &dparams, &dwnd_cb, 112 (void *) window, &dwindow); 88 113 if (rc != EOK) 89 114 goto error; … … 108 133 if (rc != EOK) 109 134 goto error; 135 136 ui_wdecor_set_rect(wdecor, ¶ms->rect); 137 ui_wdecor_set_cb(wdecor, &wdecor_cb, (void *) window); 138 ui_wdecor_paint(wdecor); 110 139 111 140 window->ui = ui; … … 145 174 } 146 175 176 /** Set window callbacks. 177 * 178 * @param window Window 179 * @param cb Window decoration callbacks 180 * @param arg Callback argument 181 */ 182 void ui_window_set_cb(ui_window_t *window, ui_window_cb_t *cb, void *arg) 183 { 184 window->cb = cb; 185 window->arg = arg; 186 } 187 188 ui_resource_t *ui_window_get_res(ui_window_t *window) 189 { 190 return window->res; 191 } 192 193 gfx_context_t *ui_window_get_gc(ui_window_t *window) 194 { 195 return window->gc; 196 } 197 198 void ui_window_get_app_rect(ui_window_t *window, gfx_rect_t *rect) 199 { 200 ui_wdecor_geom_t geom; 201 202 ui_wdecor_get_geom(window->wdecor, &geom); 203 *rect = geom.app_area_rect; 204 } 205 206 /** Handle window close event. */ 207 static void dwnd_close_event(void *arg) 208 { 209 ui_window_t *window = (ui_window_t *) arg; 210 211 ui_window_close(window); 212 } 213 214 /** Handle window focus event. */ 215 static void dwnd_focus_event(void *arg) 216 { 217 ui_window_t *window = (ui_window_t *) arg; 218 219 if (window->wdecor != NULL) { 220 ui_wdecor_set_active(window->wdecor, true); 221 ui_wdecor_paint(window->wdecor); 222 } 223 } 224 225 /** Handle window keyboard event */ 226 static void dwnd_kbd_event(void *arg, kbd_event_t *kbd_event) 227 { 228 ui_window_t *window = (ui_window_t *) arg; 229 230 (void) window; 231 (void) kbd_event; 232 } 233 234 /** Handle window position event */ 235 static void dwnd_pos_event(void *arg, pos_event_t *event) 236 { 237 ui_window_t *window = (ui_window_t *) arg; 238 239 /* Make sure we don't process events until fully initialized */ 240 if (window->wdecor == NULL) 241 return; 242 243 ui_wdecor_pos_event(window->wdecor, event); 244 ui_window_pos(window, event); 245 } 246 247 /** Handle window unfocus event. */ 248 static void dwnd_unfocus_event(void *arg) 249 { 250 ui_window_t *window = (ui_window_t *) arg; 251 252 if (window->wdecor != NULL) { 253 ui_wdecor_set_active(window->wdecor, false); 254 ui_wdecor_paint(window->wdecor); 255 } 256 } 257 258 /** Window decoration requested window closure. 259 * 260 * @param wdecor Window decoration 261 * @param arg Argument (demo) 262 */ 263 static void wd_close(ui_wdecor_t *wdecor, void *arg) 264 { 265 ui_window_t *window = (ui_window_t *) arg; 266 267 ui_window_close(window); 268 } 269 270 /** Window decoration requested window move. 271 * 272 * @param wdecor Window decoration 273 * @param arg Argument (demo) 274 * @param pos Position where the title bar was pressed 275 */ 276 static void wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos) 277 { 278 ui_window_t *window = (ui_window_t *) arg; 279 280 (void) display_window_move_req(window->dwindow, pos); 281 } 282 283 /** Send window close event. 284 * 285 * @param window Window 286 */ 287 void ui_window_close(ui_window_t *window) 288 { 289 if (window->cb != NULL && window->cb->close != NULL) 290 window->cb->close(window, window->arg); 291 } 292 293 /** Send window position event. 294 * 295 * @param window Window 296 */ 297 void ui_window_pos(ui_window_t *window, pos_event_t *pos) 298 { 299 if (window->cb != NULL && window->cb->pos != NULL) 300 window->cb->pos(window, window->arg, pos); 301 } 302 147 303 /** @} 148 304 */ -
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.