Changeset 4912dd59 in mainline for uspace/srv/hid/display/test/cursor.c
- Timestamp:
- 2020-05-19T10:21:12Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4c4d6142
- Parents:
- 4d8002d
- git-author:
- Jiri Svoboda <jiri@…> (2020-05-18 18:17:47)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-05-19 10:21:12)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/test/cursor.c
r4d8002d r4912dd59 28 28 29 29 #include <errno.h> 30 #include <gfx/context.h> 31 #include <stdbool.h> 30 32 #include <pcut/pcut.h> 31 33 32 34 #include "../cursor.h" 33 35 #include "../cursimg.h" 36 #include "../ddev.h" 34 37 #include "../display.h" 38 #include "../display.h" 35 39 36 40 PCUT_INIT; 37 41 38 42 PCUT_TEST_SUITE(cursor); 43 44 static errno_t dummy_bitmap_create(void *, gfx_bitmap_params_t *, 45 gfx_bitmap_alloc_t *, void **); 46 static errno_t dummy_bitmap_destroy(void *); 47 static errno_t dummy_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 48 static errno_t dummy_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 49 50 static gfx_context_ops_t dummy_ops = { 51 .bitmap_create = dummy_bitmap_create, 52 .bitmap_destroy = dummy_bitmap_destroy, 53 .bitmap_render = dummy_bitmap_render, 54 .bitmap_get_alloc = dummy_bitmap_get_alloc 55 }; 56 57 58 typedef struct { 59 bool render_called; 60 } test_response_t; 61 62 typedef struct { 63 test_response_t *resp; 64 gfx_bitmap_alloc_t alloc; 65 } dummy_bitmap_t; 39 66 40 67 /** Test ds_cursor_create(), ds_cursor_destroy(). */ … … 59 86 PCUT_TEST(cursor_paint) 60 87 { 88 gfx_context_t *gc; 61 89 ds_display_t *disp; 62 90 ds_cursor_t *cursor; 91 ds_ddev_t *ddev; 92 ddev_info_t ddinfo; 93 gfx_coord2_t pos; 94 test_response_t resp; 63 95 errno_t rc; 64 96 65 rc = ds_display_create(NULL, &disp); 97 rc = gfx_context_new(&dummy_ops, &resp, &gc); 98 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 99 100 rc = ds_display_create(gc, &disp); 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 103 ddev_info_init(&ddinfo); 104 105 rc = ds_ddev_create(disp, NULL, &ddinfo, NULL, 0, gc, &ddev); 66 106 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 67 107 … … 70 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 71 111 112 resp.render_called = false; 113 114 pos.x = 0; 115 pos.y = 0; 116 ds_cursor_paint(cursor, &pos); 117 118 PCUT_ASSERT_TRUE(resp.render_called); 119 72 120 ds_cursor_destroy(cursor); 73 121 ds_display_destroy(disp); … … 79 127 ds_display_t *disp; 80 128 ds_cursor_t *cursor; 129 gfx_coord2_t pos1, pos2; 130 gfx_rect_t rect1, rect2; 81 131 errno_t rc; 82 132 … … 88 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 89 139 140 pos1.x = 10; 141 pos1.y = 11; 142 143 pos2.x = 22; 144 pos2.y = 23; 145 146 ds_cursor_get_rect(cursor, &pos1, &rect1); 147 ds_cursor_get_rect(cursor, &pos2, &rect2); 148 149 PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect1)); 150 PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect2)); 151 152 PCUT_ASSERT_INT_EQUALS(pos2.x - pos1.x, rect2.p0.x - rect1.p0.x); 153 PCUT_ASSERT_INT_EQUALS(pos2.y - pos1.y, rect2.p0.y - rect1.p0.y); 154 PCUT_ASSERT_INT_EQUALS(pos2.x - pos1.x, rect2.p1.x - rect1.p1.x); 155 PCUT_ASSERT_INT_EQUALS(pos2.y - pos1.y, rect2.p1.y - rect1.p1.y); 156 90 157 ds_cursor_destroy(cursor); 91 158 ds_display_destroy(disp); 92 159 } 93 160 161 static errno_t dummy_bitmap_create(void *arg, gfx_bitmap_params_t *params, 162 gfx_bitmap_alloc_t *alloc, void **rbm) 163 { 164 test_response_t *resp = (test_response_t *) arg; 165 dummy_bitmap_t *bm; 166 gfx_coord2_t dims; 167 168 gfx_rect_dims(¶ms->rect, &dims); 169 bm = calloc(1, sizeof(dummy_bitmap_t)); 170 if (bm == NULL) 171 return ENOMEM; 172 173 bm->resp = resp; 174 bm->alloc.pitch = dims.x * sizeof(uint32_t); 175 bm->alloc.off0 = 0; 176 177 bm->alloc.pixels = malloc(bm->alloc.pitch * dims.y * sizeof(uint32_t)); 178 if (bm->alloc.pixels == NULL) { 179 free(bm); 180 return ENOMEM; 181 } 182 183 *rbm = (void *) bm; 184 return EOK; 185 } 186 187 static errno_t dummy_bitmap_destroy(void *arg) 188 { 189 dummy_bitmap_t *bm = (dummy_bitmap_t *) arg; 190 191 free(bm); 192 return EOK; 193 } 194 195 static errno_t dummy_bitmap_render(void *arg, gfx_rect_t *rect, 196 gfx_coord2_t *dpos) 197 { 198 dummy_bitmap_t *bm = (dummy_bitmap_t *) arg; 199 200 bm->resp->render_called = true; 201 return EOK; 202 } 203 204 static errno_t dummy_bitmap_get_alloc(void *arg, gfx_bitmap_alloc_t *alloc) 205 { 206 dummy_bitmap_t *bm = (dummy_bitmap_t *) arg; 207 208 *alloc = bm->alloc; 209 return EOK; 210 } 211 212 94 213 PCUT_EXPORT(cursor);
Note:
See TracChangeset
for help on using the changeset viewer.