aboutsummaryrefslogtreecommitdiff
path: root/test/core.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-28 17:08:04 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-28 17:08:04 +0100
commitaedd88f129d9ace9bdce4b22cdd2fabc76044013 (patch)
tree7895a4d3af30d84f648d2ad9c40eedab3de8e3a6 /test/core.c
parent6918f13aaf5eb228a5ce33f60a13c2031e23aa64 (diff)
downloadd2tk-aedd88f129d9ace9bdce4b22cdd2fabc76044013.tar.xz
test: move_to, line_to, rect, rounded_rect.
Diffstat (limited to 'test/core.c')
-rw-r--r--test/core.c266
1 files changed, 224 insertions, 42 deletions
diff --git a/test/core.c b/test/core.c
index 0d578bd..616870e 100644
--- a/test/core.c
+++ b/test/core.c
@@ -1,20 +1,18 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <d2tk/core.h>
#include "src/core_internal.h"
+typedef void (*d2tk_check_t)(const d2tk_com_t *com, const d2tk_clip_t *clip);
typedef struct _d2tk_mock_ctx_t d2tk_mock_ctx_t;
struct _d2tk_mock_ctx_t {
struct {
- const char *bundle_path;
- void *pctx;
- } init;
- struct {
d2tk_core_t *core;
d2tk_coord_t w;
d2tk_coord_t h;
@@ -34,34 +32,11 @@ struct _d2tk_mock_ctx_t {
const d2tk_clip_t *clip;
unsigned pass;
} process;
+ d2tk_check_t check;
};
-static void
-d2tk_mock_free(void *data)
-{
- d2tk_mock_ctx_t *ctx = data;
-
- free(ctx);
-}
-
-static void *
-d2tk_mock_new(const char *bundle_path, void *pctx)
-{
- d2tk_mock_ctx_t *ctx = calloc(1, sizeof(d2tk_mock_ctx_t));
-
- if(!ctx)
- {
- return NULL;
- }
-
- ctx->init.bundle_path = bundle_path;
- ctx->init.pctx = pctx;
-
- return ctx;
-}
-
static inline void
-d2tk_mock_pre(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
+_d2tk_mock_pre(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
unsigned pass)
{
d2tk_mock_ctx_t *ctx = data;
@@ -73,7 +48,7 @@ d2tk_mock_pre(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
}
static inline bool
-d2tk_mock_post(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
+_d2tk_mock_post(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
unsigned pass)
{
d2tk_mock_ctx_t *ctx = data;
@@ -87,7 +62,7 @@ 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, uintptr_t body __attribute__((unused)))
{
d2tk_mock_ctx_t *ctx = data;
(void)ctx;
@@ -95,7 +70,7 @@ d2tk_mock_sprite_free(void *data, uintptr_t body __attribute__((unused)))
}
static inline void
-d2tk_mock_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
+_d2tk_mock_process(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;
@@ -106,19 +81,31 @@ d2tk_mock_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
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 == true);
+ assert(body->cached == true);
+ assert(body->hash != 0x0); //FIXME
+
+ D2TK_COM_FOREACH(com, bbox)
+ {
+ ctx->check(bbox, &body->clip);
+ }
}
const d2tk_core_driver_t d2tk_mock_driver = {
- .new = d2tk_mock_new,
- .free = d2tk_mock_free,
- .pre = d2tk_mock_pre,
- .process = d2tk_mock_process,
- .post = d2tk_mock_post,
- .sprite_free = d2tk_mock_sprite_free
+ .new = NULL,
+ .free = NULL,
+ .pre = _d2tk_mock_pre,
+ .process = _d2tk_mock_process,
+ .post = _d2tk_mock_post,
+ .sprite_free = _d2tk_mock_sprite_free
};
static void
-_test_rect()
+_test_rect_shrink()
{
d2tk_rect_t dst;
@@ -154,23 +141,218 @@ _test_rect()
assert(dst.h == 4 - 2*1);
}
+#define CLIP_X 10
+#define CLIP_Y 10
+#define CLIP_W 100
+#define CLIP_H 100
+
+#define MOVE_TO_X 10
+#define MOVE_TO_Y 20
+
+static void
+_check_move_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_move_to_t));
+ assert(com->instr == D2TK_INSTR_MOVE_TO);
+ assert(com->body->move_to.x == MOVE_TO_X - CLIP_X);
+ assert(com->body->move_to.y == MOVE_TO_Y - CLIP_Y);
+}
+
static void
_test_move_to()
{
- d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, NULL);
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_move_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_move_to(core, MOVE_TO_X, MOVE_TO_Y);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef MOVE_TO_X
+#undef MOVE_TO_Y
+
+#define LINE_TO_X 10
+#define LINE_TO_Y 20
+
+static void
+_check_line_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_line_to_t));
+ assert(com->instr == D2TK_INSTR_LINE_TO);
+ assert(com->body->line_to.x == LINE_TO_X - CLIP_X);
+ assert(com->body->line_to.y == LINE_TO_Y - CLIP_Y);
+}
+
+static void
+_test_line_to()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_line_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_line_to(core, LINE_TO_X, LINE_TO_Y);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef LINE_TO_X
+#undef LINE_TO_Y
+
+#define RECT_X 10
+#define RECT_Y 20
+#define RECT_W 30
+#define RECT_H 40
+
+static void
+_check_rect(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_rect_t));
+ assert(com->instr == D2TK_INSTR_RECT);
+ assert(com->body->rect.x == RECT_X - CLIP_X);
+ assert(com->body->rect.y == RECT_Y - CLIP_Y);
+ assert(com->body->rect.w == RECT_W);
+ assert(com->body->rect.h == RECT_H);
+}
+
+static void
+_test_rect()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_rect
+ };
+
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, &ctx);
assert(core);
d2tk_core_pre(core);
- d2tk_core_move_to(core, 10, 20);
+ 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(RECT_X, RECT_Y, RECT_W, RECT_H));
+
+ d2tk_core_bbox_pop(core, ref);
d2tk_core_post(core);
d2tk_core_free(core);
}
+#undef RECT_X
+#undef RECT_Y
+#undef RECT_W
+#undef RECT_H
+
+#define ROUNDED_RECT_X 10
+#define ROUNDED_RECT_Y 20
+#define ROUNDED_RECT_W 30
+#define ROUNDED_RECT_H 40
+#define ROUNDED_RECT_R 5
+
+static void
+_check_rounded_rect(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_rounded_rect_t));
+ assert(com->instr == D2TK_INSTR_ROUNDED_RECT);
+ assert(com->body->rounded_rect.x == ROUNDED_RECT_X - CLIP_X);
+ assert(com->body->rounded_rect.y == ROUNDED_RECT_Y - CLIP_Y);
+ assert(com->body->rounded_rect.w == ROUNDED_RECT_W);
+ assert(com->body->rounded_rect.h == ROUNDED_RECT_H);
+ assert(com->body->rounded_rect.r == ROUNDED_RECT_R);
+}
+
+static void
+_test_rounded_rect()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_rounded_rect
+ };
+
+ 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_rounded_rect(core,
+ &D2TK_RECT(ROUNDED_RECT_X, ROUNDED_RECT_Y, ROUNDED_RECT_W, ROUNDED_RECT_H),
+ ROUNDED_RECT_R);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef ROUNDED_RECT_X
+#undef ROUNDED_RECT_Y
+#undef ROUNDED_RECT_W
+#undef ROUNDED_RECT_H
+#undef ROUNDED_RECT_R
+
+#undef CLIP_X
+#undef CLIP_Y
+#undef CLIP_W
+#undef CLIP_H
+
int
main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{
- _test_rect();
+ _test_rect_shrink();
+
_test_move_to();
+ _test_line_to();
+ _test_rect();
+ _test_rounded_rect();
return EXIT_SUCCESS;
}