Changeset 2ab8ab3 in mainline for uspace/lib/memgfx/test/memgfx.c
- Timestamp:
- 2021-02-16T18:12:05Z (3 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68a552f
- Parents:
- ef734b7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/memgfx/test/memgfx.c
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 PCUT_TEST_SUITE(memgfx); 43 43 44 static void test_update_rect(void *arg, gfx_rect_t *rect); 44 static void test_invalidate_rect(void *arg, gfx_rect_t *rect); 45 static void test_update(void *arg); 45 46 46 47 typedef struct { 48 /** True if invalidate was called */ 49 bool invalidate_called; 50 /** Invalidate rectangle */ 51 gfx_rect_t inv_rect; 47 52 /** True if update was called */ 48 53 bool update_called; 49 /** Update rectangle */ 50 gfx_rect_t rect; 51 } test_update_t; 54 } test_resp_t; 52 55 53 56 /** Test creating and deleting a memory GC */ … … 69 72 PCUT_ASSERT_NOT_NULL(alloc.pixels); 70 73 71 rc = mem_gc_create(&rect, &alloc, NULL, NULL, &mgc);74 rc = mem_gc_create(&rect, &alloc, NULL, NULL, NULL, &mgc); 72 75 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 73 76 … … 89 92 pixel_t pixel; 90 93 pixel_t expected; 91 test_ update_t update;94 test_resp_t resp; 92 95 errno_t rc; 93 96 … … 103 106 PCUT_ASSERT_NOT_NULL(alloc.pixels); 104 107 105 rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc); 108 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 109 test_update, &resp, &mgc); 106 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 107 111 … … 122 126 frect.p1.y = 5; 123 127 124 memset(& update, 0, sizeof(update));128 memset(&resp, 0, sizeof(resp)); 125 129 126 130 rc = gfx_fill_rect(gc, &frect); … … 141 145 } 142 146 143 /* Check that the update rect is equal to the filled rect */144 PCUT_ASSERT_TRUE( update.update_called);145 PCUT_ASSERT_INT_EQUALS(frect.p0.x, update.rect.p0.x);146 PCUT_ASSERT_INT_EQUALS(frect.p0.y, update.rect.p0.y);147 PCUT_ASSERT_INT_EQUALS(frect.p1.x, update.rect.p1.x);148 PCUT_ASSERT_INT_EQUALS(frect.p1.y, update.rect.p1.y);147 /* Check that the invalidate rect is equal to the filled rect */ 148 PCUT_ASSERT_TRUE(resp.invalidate_called); 149 PCUT_ASSERT_INT_EQUALS(frect.p0.x, resp.inv_rect.p0.x); 150 PCUT_ASSERT_INT_EQUALS(frect.p0.y, resp.inv_rect.p0.y); 151 PCUT_ASSERT_INT_EQUALS(frect.p1.x, resp.inv_rect.p1.x); 152 PCUT_ASSERT_INT_EQUALS(frect.p1.y, resp.inv_rect.p1.y); 149 153 150 154 /* TODO: Check clipping once memgc can support pitch != width etc. */ … … 169 173 pixel_t pixel; 170 174 pixel_t expected; 171 test_ update_t update;175 test_resp_t resp; 172 176 errno_t rc; 173 177 … … 183 187 PCUT_ASSERT_NOT_NULL(alloc.pixels); 184 188 185 rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc); 189 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 190 test_update, &resp, &mgc); 186 191 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 187 192 … … 191 196 /* Create bitmap */ 192 197 198 gfx_bitmap_params_init(¶ms); 193 199 params.rect.p0.x = 0; 194 200 params.rect.p0.y = 0; … … 219 225 dpmap.data = alloc.pixels; 220 226 221 memset(& update, 0, sizeof(update));227 memset(&resp, 0, sizeof(resp)); 222 228 223 229 /* Render the bitmap */ … … 237 243 } 238 244 239 /* Check that the update rect is equal to the filled rect */240 PCUT_ASSERT_TRUE( update.update_called);241 PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, update.rect.p0.x);242 PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, update.rect.p0.y);243 PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, update.rect.p1.x);244 PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, update.rect.p1.y);245 /* Check that the invalidate rect is equal to the filled rect */ 246 PCUT_ASSERT_TRUE(resp.invalidate_called); 247 PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, resp.inv_rect.p0.x); 248 PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, resp.inv_rect.p0.y); 249 PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, resp.inv_rect.p1.x); 250 PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, resp.inv_rect.p1.y); 245 251 246 252 /* TODO: Check clipping once memgc can support pitch != width etc. */ … … 250 256 } 251 257 252 /** Called by memory GC when a rectangle is updated. */ 253 static void test_update_rect(void *arg, gfx_rect_t *rect) 254 { 255 test_update_t *update = (test_update_t *)arg; 256 257 update->update_called = true; 258 update->rect = *rect; 258 /** Test gfx_update() on a memory GC */ 259 PCUT_TEST(gfx_update) 260 { 261 mem_gc_t *mgc; 262 gfx_rect_t rect; 263 gfx_bitmap_alloc_t alloc; 264 gfx_context_t *gc; 265 test_resp_t resp; 266 errno_t rc; 267 268 /* Bounding rectangle for memory GC */ 269 rect.p0.x = 0; 270 rect.p0.y = 0; 271 rect.p1.x = 10; 272 rect.p1.y = 10; 273 274 alloc.pitch = (rect.p1.x - rect.p0.x) * sizeof(uint32_t); 275 alloc.off0 = 0; 276 alloc.pixels = calloc(1, alloc.pitch * (rect.p1.y - rect.p0.y)); 277 PCUT_ASSERT_NOT_NULL(alloc.pixels); 278 279 rc = mem_gc_create(&rect, &alloc, test_invalidate_rect, 280 test_update, &resp, &mgc); 281 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 282 283 gc = mem_gc_get_ctx(mgc); 284 PCUT_ASSERT_NOT_NULL(gc); 285 286 memset(&resp, 0, sizeof(resp)); 287 PCUT_ASSERT_FALSE(resp.update_called); 288 289 gfx_update(gc); 290 PCUT_ASSERT_TRUE(resp.update_called); 291 292 mem_gc_delete(mgc); 293 free(alloc.pixels); 294 } 295 296 /** Called by memory GC when a rectangle is modified. */ 297 static void test_invalidate_rect(void *arg, gfx_rect_t *rect) 298 { 299 test_resp_t *resp = (test_resp_t *)arg; 300 301 resp->invalidate_called = true; 302 resp->inv_rect = *rect; 303 } 304 305 /** Called by memory GC when update is called. */ 306 static void test_update(void *arg) 307 { 308 test_resp_t *resp = (test_resp_t *)arg; 309 310 resp->update_called = true; 259 311 } 260 312
Note:
See TracChangeset
for help on using the changeset viewer.