aboutsummaryrefslogtreecommitdiff
path: root/test/core.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-29 15:39:17 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-29 15:39:17 +0100
commitcad5a3c852c6cda635179986a5bdaeae47fa4baa (patch)
treecf7e22229a99f3d9c1e0d6d228e85cfb8fb909fe /test/core.c
parentaedd88f129d9ace9bdce4b22cdd2fabc76044013 (diff)
downloadd2tk-cad5a3c852c6cda635179986a5bdaeae47fa4baa.tar.xz
test: add remaining core functions.
Diffstat (limited to 'test/core.c')
-rw-r--r--test/core.c743
1 files changed, 743 insertions, 0 deletions
diff --git a/test/core.c b/test/core.c
index 616870e..e2b6e69 100644
--- a/test/core.c
+++ b/test/core.c
@@ -89,10 +89,13 @@ _d2tk_mock_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
assert(body->cached == true);
assert(body->hash != 0x0); //FIXME
+ 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 = {
@@ -141,6 +144,54 @@ _test_rect_shrink()
assert(dst.h == 4 - 2*1);
}
+#define DIM_W 640
+#define DIM_H 480
+
+static void
+_test_dimensions()
+{
+ d2tk_coord_t w;
+ d2tk_coord_t h;
+
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, NULL);
+ assert(core);
+
+ d2tk_core_set_dimensions(core, DIM_W, DIM_H);
+
+ w = 0;
+ h = 0;
+ d2tk_core_get_dimensions(core, &w, &h);
+ assert(w == DIM_W);
+ assert(h == DIM_H);
+
+ w = 0;
+ h = 0;
+ d2tk_core_get_dimensions(core, NULL, NULL);
+ assert(w == 0);
+ assert(h == 0);
+
+ d2tk_core_free(core);
+}
+
+#undef DIM_W
+#undef DIM_H
+
+#define BG_COLOR 0x222222ff
+
+static void
+_test_bg_color()
+{
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, NULL);
+ assert(core);
+
+ d2tk_core_set_bg_color(core, BG_COLOR);
+ assert(BG_COLOR == d2tk_core_get_bg_color(core));
+
+ d2tk_core_free(core);
+}
+
+#undef BG_COLOR
+
#define CLIP_X 10
#define CLIP_Y 10
#define CLIP_W 100
@@ -339,6 +390,680 @@ _test_rounded_rect()
#undef ROUNDED_RECT_H
#undef ROUNDED_RECT_R
+#define ARC_X 10
+#define ARC_Y 20
+#define ARC_R 5
+#define ARC_A 30
+#define ARC_B 60
+
+static void
+_check_arc(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_arc_t));
+ assert(com->instr == D2TK_INSTR_ARC);
+ assert(com->body->arc.x == ARC_X - CLIP_X);
+ assert(com->body->arc.y == ARC_Y - CLIP_Y);
+ assert(com->body->arc.r == ARC_R);
+ assert(com->body->arc.a == ARC_A);
+ assert(com->body->arc.b == ARC_B);
+}
+
+static void
+_test_arc()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_arc
+ };
+
+ 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_arc(core, ARC_X, ARC_Y, ARC_R, ARC_A, ARC_B);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef ARC_X
+#undef ARC_Y
+#undef ARC_R
+#undef ARC_A
+#undef ARC_B
+
+#define CURVE_TO_X1 10
+#define CURVE_TO_Y1 10
+#define CURVE_TO_X2 20
+#define CURVE_TO_Y2 20
+#define CURVE_TO_X3 30
+#define CURVE_TO_Y3 30
+
+static void
+_check_curve_to(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_curve_to_t));
+ assert(com->instr == D2TK_INSTR_CURVE_TO);
+ assert(com->body->curve_to.x1 == CURVE_TO_X1 - CLIP_X);
+ assert(com->body->curve_to.y1 == CURVE_TO_Y1 - CLIP_Y);
+ assert(com->body->curve_to.x2 == CURVE_TO_X2 - CLIP_X);
+ assert(com->body->curve_to.y2 == CURVE_TO_Y2 - CLIP_Y);
+ assert(com->body->curve_to.x3 == CURVE_TO_X3 - CLIP_X);
+ assert(com->body->curve_to.y3 == CURVE_TO_Y3 - CLIP_Y);
+}
+
+static void
+_test_curve_to()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_curve_to
+ };
+
+ 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_curve_to(core, CURVE_TO_X1, CURVE_TO_Y1, CURVE_TO_X2, CURVE_TO_Y2,
+ CURVE_TO_X3, CURVE_TO_Y3);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef CURVE_TO_X1
+#undef CURVE_TO_Y1
+#undef CURVE_TO_X2
+#undef CURVE_TO_Y2
+#undef CURVE_TO_X3
+#undef CURVE_TO_Y3
+
+#define COLOR_RGBA 0xff00ff00
+
+static void
+_check_color(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_color_t));
+ assert(com->instr == D2TK_INSTR_COLOR);
+ assert(com->body->color.rgba == COLOR_RGBA);
+}
+
+static void
+_test_color()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_color
+ };
+
+ 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_color(core, COLOR_RGBA);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef COLOR_RGBA
+
+static void
+_check_stroke(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 == 0);
+ assert(com->instr == D2TK_INSTR_STROKE);
+}
+
+static void
+_test_stroke()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_stroke
+ };
+
+ 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_stroke(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+static void
+_check_fill(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 == 0);
+ assert(com->instr == D2TK_INSTR_FILL);
+}
+
+static void
+_test_fill()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_fill
+ };
+
+ 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_fill(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+static void
+_check_save(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 == 0);
+ assert(com->instr == D2TK_INSTR_SAVE);
+}
+
+static void
+_test_save()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_save
+ };
+
+ 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_save(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+static void
+_check_restore(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 == 0);
+ assert(com->instr == D2TK_INSTR_RESTORE);
+}
+
+static void
+_test_restore()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_restore
+ };
+
+ 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_restore(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#define ROTATE_DEG 45
+
+static void
+_check_rotate(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_rotate_t));
+ assert(com->instr == D2TK_INSTR_ROTATE);
+ assert(com->body->rotate.deg == ROTATE_DEG);
+}
+
+static void
+_test_rotate()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_rotate
+ };
+
+ 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_rotate(core, ROTATE_DEG);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef ROTATE_DEG
+
+static void
+_check_begin_path(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 == 0);
+ assert(com->instr == D2TK_INSTR_BEGIN_PATH);
+}
+
+static void
+_test_begin_path()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_begin_path
+ };
+
+ 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_begin_path(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+static void
+_check_close_path(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 == 0);
+ assert(com->instr == D2TK_INSTR_CLOSE_PATH);
+}
+
+static void
+_test_close_path()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_close_path
+ };
+
+ 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_close_path(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#define SCISSOR_X 10
+#define SCISSOR_Y 20
+#define SCISSOR_W 30
+#define SCISSOR_H 40
+
+static void
+_check_scissor(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_scissor_t));
+ assert(com->instr == D2TK_INSTR_SCISSOR);
+ assert(com->body->scissor.x == SCISSOR_X - CLIP_X);
+ assert(com->body->scissor.y == SCISSOR_Y - CLIP_Y);
+ assert(com->body->scissor.w == SCISSOR_W);
+ assert(com->body->scissor.h == SCISSOR_H);
+}
+
+static void
+_test_scissor()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_scissor
+ };
+
+ 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_scissor(core, &D2TK_RECT(SCISSOR_X, SCISSOR_Y, SCISSOR_W, SCISSOR_H));
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef SCISSOR_X
+#undef SCISSOR_Y
+#undef SCISSOR_W
+#undef SCISSOR_H
+
+static void
+_check_reset_scissor(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 == 0);
+ assert(com->instr == D2TK_INSTR_RESET_SCISSOR);
+}
+
+static void
+_test_reset_scissor()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_reset_scissor
+ };
+
+ 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_reset_scissor(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#define FONT_SIZE 11
+
+static void
+_check_font_size(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_font_size_t));
+ assert(com->instr == D2TK_INSTR_FONT_SIZE);
+ assert(com->body->font_size.size == FONT_SIZE);
+}
+
+static void
+_test_font_size()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_font_size
+ };
+
+ 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_font_size(core, FONT_SIZE);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef FONT_SIZE
+
+#define FONT_FACE "Monospace"
+
+static void
+_check_font_face(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_font_face_t) + strlen(FONT_FACE));
+ assert(com->instr == D2TK_INSTR_FONT_FACE);
+ assert(strcmp(com->body->font_face.face, FONT_FACE) == 0);
+}
+
+static void
+_test_font_face()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_font_face
+ };
+
+ 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_font_face(core, strlen(FONT_FACE), FONT_FACE);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef FONT_FACE
+
+#define TEXT_X 10
+#define TEXT_Y 20
+#define TEXT_W 30
+#define TEXT_H 40
+#define TEXT_TEXT "Text"
+#define TEXT_ALIGN D2TK_ALIGN_LEFT
+
+static void
+_check_text(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_text_t) + strlen(TEXT_TEXT));
+ assert(com->instr == D2TK_INSTR_TEXT);
+ assert(com->body->text.x == TEXT_X - CLIP_X);
+ assert(com->body->text.y == TEXT_Y - CLIP_Y);
+ assert(com->body->text.w == TEXT_W);
+ assert(com->body->text.h == TEXT_H);
+ assert(strcmp(com->body->text.text, TEXT_TEXT) == 0);
+ assert(com->body->text.align == TEXT_ALIGN);
+}
+
+static void
+_test_text()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_text
+ };
+
+ 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_text(core, &D2TK_RECT(TEXT_X, TEXT_Y, TEXT_W, TEXT_H),
+ strlen(TEXT_TEXT), TEXT_TEXT, TEXT_ALIGN);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef TEXT_X
+#undef TEXT_Y
+#undef TEXT_W
+#undef TEXT_H
+#undef TEXT_TEXT
+#undef TEXT_ALIGN
+
+#define STROKE_WIDTH 2
+
+static void
+_check_stroke_width(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_stroke_width_t));
+ assert(com->instr == D2TK_INSTR_STROKE_WIDTH);
+ assert(com->body->stroke_width.width == STROKE_WIDTH);
+}
+
+static void
+_test_stroke_width()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_stroke_width
+ };
+
+ 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_stroke_width(core, STROKE_WIDTH);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef STROKE_WIDTH
+
#undef CLIP_X
#undef CLIP_Y
#undef CLIP_W
@@ -348,11 +1073,29 @@ int
main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{
_test_rect_shrink();
+ _test_dimensions();
+ _test_bg_color();
_test_move_to();
_test_line_to();
_test_rect();
_test_rounded_rect();
+ _test_arc();
+ _test_curve_to();
+ _test_color();
+ _test_stroke();
+ _test_fill();
+ _test_save();
+ _test_restore();
+ _test_rotate();
+ _test_begin_path();
+ _test_close_path();
+ _test_scissor();
+ _test_reset_scissor();
+ _test_font_size();
+ _test_font_face();
+ _test_text();
+ _test_stroke_width();
return EXIT_SUCCESS;
}