diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2019-01-04 10:21:30 +0100 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2019-01-04 10:21:30 +0100 |
commit | 47ab785f8de77a1c656079ac8cb4ca99d8fd8655 (patch) | |
tree | cd307a0a6ad24af380273d846cd09e5776dd0b39 /test/core.c | |
parent | 463ecfe1c5056bac32d852ad0dde96345aa58d75 (diff) | |
download | d2tk-47ab785f8de77a1c656079ac8cb4ca99d8fd8655.tar.xz |
test: increase coverage for widget dis/appearance.
Diffstat (limited to 'test/core.c')
-rw-r--r-- | test/core.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/core.c b/test/core.c index a25c44c..ff2775a 100644 --- a/test/core.c +++ b/test/core.c @@ -123,6 +123,51 @@ _d2tk_mock_process(void *data, d2tk_core_t *core, const d2tk_com_t *com, assert(num == 1); } +static inline void +_d2tk_mock_process_triple(void *data, d2tk_core_t *core, const d2tk_com_t *com, + d2tk_coord_t xo, d2tk_coord_t yo, const d2tk_clip_t *clip, unsigned pass) +{ + d2tk_mock_ctx_t *ctx = data; + assert(ctx); + + ctx->process.core = core; + ctx->process.com = com; + ctx->process.xo = xo; + ctx->process.yo = yo; + ctx->process.clip = clip; + ctx->process.pass = pass; + + assert(com->instr == D2TK_INSTR_BBOX); + + const d2tk_body_bbox_t *body = &com->body->bbox; + //assert(body->dirty == false); + assert(body->cached == true); + assert(body->hash != 0x0); //FIXME + + uintptr_t *sprite = d2tk_core_get_sprite(core, body->hash, 1); + assert(sprite); + assert(*sprite == 0); + + uint32_t *dummy = calloc(1, sizeof(uint32_t)); + assert(dummy); + *dummy = 1234; + + *sprite = (uintptr_t)dummy; + + assert(sprite == d2tk_core_get_sprite(core, body->hash, 1)); + assert(sprite != d2tk_core_get_sprite(core, body->hash, 0)); + assert(sprite != d2tk_core_get_sprite(core, ~body->hash, 1)); + assert(sprite != d2tk_core_get_sprite(core, ~body->hash, 0)); + + unsigned num = 0; + D2TK_COM_FOREACH(com, bbox) + { + ctx->check(bbox, &body->clip); + num += 1; + } + assert(num == 1); +} + const d2tk_core_driver_t d2tk_mock_driver = { .new = NULL, .free = NULL, @@ -132,6 +177,15 @@ const d2tk_core_driver_t d2tk_mock_driver = { .sprite_free = _d2tk_mock_sprite_free }; +const d2tk_core_driver_t d2tk_mock_driver_triple = { + .new = NULL, + .free = NULL, + .pre = _d2tk_mock_pre, + .process = _d2tk_mock_process_triple, + .post = _d2tk_mock_post, + .sprite_free = _d2tk_mock_sprite_free +}; + static void _test_rect_shrink() { @@ -1270,6 +1324,74 @@ _test_stroke_width() #undef STROKE_WIDTH +static void +_check_triple(const d2tk_com_t *com, const d2tk_clip_t *clip) +{ + assert(clip->x0 == CLIP_X); + assert(clip->y0 == CLIP_Y); + assert(clip->x1 == CLIP_X + CLIP_W); + assert(clip->y1 == CLIP_Y + CLIP_H); + assert(clip->w == CLIP_W); + assert(clip->h == CLIP_H); + + (void)com; //FIXME +} + +static void +_test_triple() +{ + d2tk_mock_ctx_t ctx = { + .check = _check_triple + }; + + d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver_triple, &ctx); + assert(core); + + d2tk_core_set_dimensions(core, DIM_W, DIM_H); + + for(unsigned i = 0; i < 3; i++) + { + d2tk_core_pre(core); + + if(i != 0) + { + const ssize_t ref = d2tk_core_bbox_push(core, true, + &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H)); + assert(ref >= 0); + + d2tk_core_rect(core, &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H)); + + d2tk_core_bbox_pop(core, ref); + } + + if(i != 1) + { + const ssize_t ref = d2tk_core_bbox_push(core, true, + &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H)); + assert(ref >= 0); + + d2tk_core_rect(core, &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W/2, CLIP_H)); + + d2tk_core_bbox_pop(core, ref); + } + + if(i != 2) + { + const ssize_t ref = d2tk_core_bbox_push(core, true, + &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H)); + assert(ref >= 0); + + d2tk_core_rect(core, &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H/2)); + + d2tk_core_bbox_pop(core, ref); + } + + d2tk_core_post(core); + } + + d2tk_core_free(core); +} + #undef CLIP_X #undef CLIP_Y #undef CLIP_W @@ -1309,5 +1431,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused))) _test_image(); _test_stroke_width(); + _test_triple(); + return EXIT_SUCCESS; } |