aboutsummaryrefslogtreecommitdiff
path: root/test/core.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-30 18:29:11 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-30 18:29:11 +0100
commitc37e1e28f4f62132777ba0140cc5832fe8bf9a7a (patch)
tree0a3b740bc9c98841211b8a427b0f45be5ee92549 /test/core.c
parentcad5a3c852c6cda635179986a5bdaeae47fa4baa (diff)
downloadd2tk-c37e1e28f4f62132777ba0140cc5832fe8bf9a7a.tar.xz
all: prototype image sprite.
Diffstat (limited to 'test/core.c')
-rw-r--r--test/core.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/test/core.c b/test/core.c
index e2b6e69..3200dd5 100644
--- a/test/core.c
+++ b/test/core.c
@@ -62,7 +62,8 @@ _d2tk_mock_post(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
}
static inline void
-_d2tk_mock_sprite_free(void *data, uintptr_t body __attribute__((unused)))
+_d2tk_mock_sprite_free(void *data, uint8_t type __attribute__((unused)),
+ uintptr_t body __attribute__((unused)))
{
d2tk_mock_ctx_t *ctx = data;
(void)ctx;
@@ -1023,6 +1024,63 @@ _test_text()
#undef TEXT_TEXT
#undef TEXT_ALIGN
+#define IMAGE_X 10
+#define IMAGE_Y 20
+#define IMAGE_W 30
+#define IMAGE_H 40
+#define IMAGE_PATH "./libre-sugar-skull.png"
+#define IMAGE_ALIGN D2TK_ALIGN_LEFT
+
+static void
+_check_image(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_image_t) + strlen(IMAGE_PATH));
+ assert(com->instr == D2TK_INSTR_IMAGE);
+ assert(com->body->image.x == IMAGE_X - CLIP_X);
+ assert(com->body->image.y == IMAGE_Y - CLIP_Y);
+ assert(com->body->image.w == IMAGE_W);
+ assert(com->body->image.h == IMAGE_H);
+ assert(strcmp(com->body->image.path , IMAGE_PATH) == 0);
+ assert(com->body->image.align == IMAGE_ALIGN);
+}
+
+static void
+_test_image()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_image
+ };
+
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, &ctx);
+ assert(core);
+
+ 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_image(core, &D2TK_RECT(IMAGE_X, IMAGE_Y, IMAGE_W, IMAGE_H),
+ strlen(IMAGE_PATH), IMAGE_PATH, IMAGE_ALIGN);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef IMAGE_X
+#undef IMAGE_Y
+#undef IMAGE_W
+#undef IMAGE_H
+#undef IMAGE_PATH
+#undef IMAGE_ALIGN
+
#define STROKE_WIDTH 2
static void
@@ -1095,6 +1153,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_font_size();
_test_font_face();
_test_text();
+ _test_image();
_test_stroke_width();
return EXIT_SUCCESS;