aboutsummaryrefslogtreecommitdiff
path: root/test/core.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-07-21 15:42:20 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-07-21 15:42:20 +0200
commita4985b5f57cfd116aa8fd480eb8f09b4db995674 (patch)
tree789771d7041942c1ac1cbc53e24c9ee8eb7f72bc /test/core.c
parent8d3a4dcf9c65b399b90be1746856be02120c0d85 (diff)
downloadd2tk-a4985b5f57cfd116aa8fd480eb8f09b4db995674.tar.xz
core/base: prototype custom widget.
Diffstat (limited to 'test/core.c')
-rw-r--r--test/core.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/core.c b/test/core.c
index 3a8ca81..7c5b45a 100644
--- a/test/core.c
+++ b/test/core.c
@@ -1230,6 +1230,74 @@ _test_bitmap()
#undef BITMAP_STRIDE
#undef BITMAP_ALIGN
+#define CUSTOM_X 10
+#define CUSTOM_Y 20
+#define CUSTOM_W 30
+#define CUSTOM_H 40
+#define CUSTOM_SIZE 0
+#define CUSTOM_DATA NULL
+
+static void
+_custom(void *ctx, uint32_t size, const void *data)
+{
+ assert(ctx == NULL);
+ assert(size == CUSTOM_SIZE);
+ assert(data == CUSTOM_DATA);
+}
+
+static void
+_check_custom(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);
+
+ assert(com->size == sizeof(d2tk_body_custom_t));
+ assert(com->instr == D2TK_INSTR_CUSTOM);
+ assert(com->body->custom.x == CUSTOM_X - CLIP_X);
+ assert(com->body->custom.y == CUSTOM_Y - CLIP_Y);
+ assert(com->body->custom.w == CUSTOM_W);
+ assert(com->body->custom.h == CUSTOM_H);
+ assert(com->body->custom.size == CUSTOM_SIZE);
+ assert(com->body->custom.data == CUSTOM_DATA);
+ assert(com->body->custom.custom == _custom);
+}
+
+static void
+_test_custom()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_custom
+ };
+
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, &ctx);
+ assert(core);
+
+ d2tk_core_set_dimensions(core, DIM_W, DIM_H);
+
+ d2tk_core_pre(core);
+ 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_custom(core, &D2TK_RECT(CUSTOM_X, CUSTOM_Y, CUSTOM_W, CUSTOM_H),
+ CUSTOM_SIZE, CUSTOM_DATA, _custom);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef CUSTOM_X
+#undef CUSTOM_Y
+#undef CUSTOM_W
+#undef CUSTOM_H
+#undef CUSTOM_SIZE
+#undef CUSTOM_DATA
+
#define STROKE_WIDTH 2
static void
@@ -1373,6 +1441,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_text();
_test_image();
_test_bitmap();
+ _test_custom();
_test_stroke_width();
_test_triple();