aboutsummaryrefslogtreecommitdiff
path: root/test/core.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-28 12:55:56 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2018-12-28 12:55:56 +0100
commit710567ac319d07f154b85a9fcab68f11fd119141 (patch)
tree4f674461f1d359ef50e71ba332db55b112c8a9c6 /test/core.c
parente6f0a99a97117bc302870be7b3f9e25b347df2f9 (diff)
downloadd2tk-710567ac319d07f154b85a9fcab68f11fd119141.tar.xz
test: add skeleton.
Diffstat (limited to 'test/core.c')
-rw-r--r--test/core.c176
1 files changed, 176 insertions, 0 deletions
diff --git a/test/core.c b/test/core.c
new file mode 100644
index 0000000..0d578bd
--- /dev/null
+++ b/test/core.c
@@ -0,0 +1,176 @@
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <d2tk/core.h>
+#include "src/core_internal.h"
+
+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;
+ unsigned pass;
+ } pre;
+ struct {
+ d2tk_core_t *core;
+ d2tk_coord_t w;
+ d2tk_coord_t h;
+ unsigned pass;
+ } post;
+ struct {
+ d2tk_core_t *core;
+ const d2tk_com_t *com;
+ d2tk_coord_t xo;
+ d2tk_coord_t yo;
+ const d2tk_clip_t *clip;
+ unsigned pass;
+ } process;
+};
+
+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,
+ unsigned pass)
+{
+ d2tk_mock_ctx_t *ctx = data;
+
+ ctx->pre.core = core;
+ ctx->pre.w = w;
+ ctx->pre.h = h;
+ ctx->pre.pass = pass;
+}
+
+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;
+
+ ctx->post.core = core;
+ ctx->post.w = w;
+ ctx->post.h = h;
+ ctx->post.pass = pass;
+
+ return false; // do NOT enter 3rd pass
+}
+
+static inline void
+d2tk_mock_sprite_free(void *data, uintptr_t body __attribute__((unused)))
+{
+ d2tk_mock_ctx_t *ctx = data;
+ (void)ctx;
+ //FIXME
+}
+
+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, unsigned pass)
+{
+ d2tk_mock_ctx_t *ctx = data;
+
+ ctx->process.core = core;
+ ctx->process.com = com;
+ ctx->process.xo = xo;
+ ctx->process.yo = yo;
+ ctx->process.clip = clip;
+ ctx->process.pass = pass;
+}
+
+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
+};
+
+static void
+_test_rect()
+{
+ d2tk_rect_t dst;
+
+ // initialization
+ const d2tk_rect_t src = D2TK_RECT(1, 2, 3, 4);
+ assert(src.x == 1);
+ assert(src.y == 2);
+ assert(src.w == 3);
+ assert(src.h == 4);
+
+ // shrink on x-axis
+ memset(&dst, 0x0, sizeof(dst));
+ d2tk_rect_shrink_x(&dst, &src, 1);
+ assert(dst.x == 1 + 1);
+ assert(dst.y == 2);
+ assert(dst.w == 3 - 2*1);
+ assert(dst.h == 4);
+
+ // shrink on y-axis
+ memset(&dst, 0x0, sizeof(dst));
+ d2tk_rect_shrink_y(&dst, &src, 1);
+ assert(dst.x == 1);
+ assert(dst.y == 2 + 1);
+ assert(dst.w == 3);
+ assert(dst.h == 4 - 2*1);
+
+ // shrink on x/y-axes
+ memset(&dst, 0x0, sizeof(dst));
+ d2tk_rect_shrink(&dst, &src, 1);
+ assert(dst.x == 1 + 1);
+ assert(dst.y == 2 + 1);
+ assert(dst.w == 3 - 2*1);
+ assert(dst.h == 4 - 2*1);
+}
+
+static void
+_test_move_to()
+{
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, NULL);
+ assert(core);
+
+ d2tk_core_pre(core);
+ d2tk_core_move_to(core, 10, 20);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+int
+main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
+{
+ _test_rect();
+ _test_move_to();
+
+ return EXIT_SUCCESS;
+}