aboutsummaryrefslogtreecommitdiff
path: root/test/core.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-02-19 19:19:15 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-02-19 19:19:15 +0100
commit121da85a5f40ed2d0bea409f564ceb836e2f2097 (patch)
treeb1299d1b84300cf21106b52537c3b1bf08ae1ef7 /test/core.c
parent78adbf8139b4bdb9ade2a4eea66fa60cb083399b (diff)
downloadd2tk-121da85a5f40ed2d0bea409f564ceb836e2f2097.tar.xz
test: put drivers into mock, add base skeleton.
Diffstat (limited to 'test/core.c')
-rw-r--r--test/core.c180
1 files changed, 1 insertions, 179 deletions
diff --git a/test/core.c b/test/core.c
index 6b9f68c..6fddb02 100644
--- a/test/core.c
+++ b/test/core.c
@@ -1,181 +1,11 @@
#include <inttypes.h>
#include <stdlib.h>
-#include <stdlib.h>
-#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <d2tk/core.h>
#include <d2tk/hash.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 {
- d2tk_check_t check;
-};
-
-#define DIM_W 640
-#define DIM_H 480
-
-#define CLIP_X 10
-#define CLIP_Y 10
-#define CLIP_W 100
-#define CLIP_H 100
-
-static inline void
-_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;
- assert(ctx);
-
- assert(core);
- assert(w == DIM_W);
- assert(h == DIM_H);
- assert(pass == 0);
-}
-
-static inline bool
-_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;
- assert(ctx);
-
- assert(core);
- assert(w == DIM_W);
- assert(h == DIM_H);
- assert(pass == 0);
-
- assert(d2tk_core_get_pixels(core));
-
- return false; // do NOT enter 3rd pass
-}
-
-static inline void
-_d2tk_mock_sprite_free(void *data, uint8_t type, uintptr_t body)
-{
- d2tk_mock_ctx_t *ctx = data;
- assert(ctx);
-
- assert(type == 1);
-
- uint32_t *dummy = (uint32_t *)body;
- assert(*dummy == 1234);
- free(dummy);
-}
-
-static inline void
-_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 __attribute__((unused)), unsigned pass)
-{
- d2tk_mock_ctx_t *ctx = data;
- assert(ctx);
-
- assert(core);
- assert(com);
- assert(xo == CLIP_X);
- assert(yo == CLIP_Y);
- assert(pass == 0);
-
- 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_CONST(com, bbox)
- {
- ctx->check(bbox, &body->clip);
- num += 1;
- }
- 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 __attribute__((unused)), unsigned pass)
-{
- d2tk_mock_ctx_t *ctx = data;
- assert(ctx);
-
- assert(core);
- assert(com);
- assert(xo == CLIP_X);
- assert(yo == CLIP_Y);
- assert(pass == 0);
-
- 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);
-
- if(*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_CONST(com, bbox)
- {
- ctx->check(bbox, &body->clip);
- num += 1;
- }
- assert(num == 1);
-}
-
-const d2tk_core_driver_t d2tk_mock_driver = {
- .new = NULL,
- .free = NULL,
- .pre = _d2tk_mock_pre,
- .process = _d2tk_mock_process,
- .post = _d2tk_mock_post,
- .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
-};
+#include "mock.h"
static void
_test_hash()
@@ -1405,14 +1235,6 @@ _test_triple()
d2tk_core_free(core);
}
-#undef CLIP_X
-#undef CLIP_Y
-#undef CLIP_W
-#undef CLIP_H
-
-#undef DIM_W
-#undef DIM_H
-
int
main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{