diff options
author | sanine <sanine.not@pm.me> | 2022-11-27 00:43:18 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-11-27 00:43:18 -0600 |
commit | c42d9264aed8da3a057719cab7390fa55904bda6 (patch) | |
tree | be60812077cefca105769f6e841ddfdf3d0fe25e /src/transform.test.c | |
parent | 29f9921b919497be4d652ce963c8afbb2c1cd1e7 (diff) |
add rotation parsing
Diffstat (limited to 'src/transform.test.c')
-rw-r--r-- | src/transform.test.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/transform.test.c b/src/transform.test.c index e9982f6..f0cd06f 100644 --- a/src/transform.test.c +++ b/src/transform.test.c @@ -7,16 +7,27 @@ void parse_matrix_fail_nonmatrix(); void parse_identity(); +void parse_rotate_fail(); +void parse_rotate(); + +void parse_translate_fail(); +void parse_translate(); + void suite_transform() { lily_run_test(parse_matrix_fail_nonmatrix); lily_run_test(parse_identity); + lily_run_test(parse_rotate_fail); + lily_run_test(parse_rotate); + lily_run_test(parse_translate_fail); + lily_run_test(parse_translate); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +/* ======== matrix ======== */ void parse_matrix_fail_nonmatrix() { char str[128]; @@ -69,3 +80,107 @@ void parse_identity() lily_assert_float_equal(mat[14], 0.0f, 1e-3); lily_assert_float_equal(mat[15], 1.0f, 1e-3); } + + +/* ======== rotate ======== */ +void parse_rotate_fail() +{ + char str[128]; + strncpy(str, "<non></non>", 128); + ezxml_t tag = ezxml_parse_str(str, strlen(str)); + + ka_matrix_t mat; + int rc = kai_parse_rotate(&mat, tag); + lily_assert_true(rc != 0); + + ezxml_free(tag); +} + + +void parse_rotate() +{ + char str[512]; + strncpy( + str, + "<rotate>\n" + " 0 1 0 90.0\n" + "</rotate>", + 512 + ); + ezxml_t tag = ezxml_parse_str(str, strlen(str)); + + ka_matrix_t mat; + mat[0] = 100; + int rc = kai_parse_rotate(&mat, tag); + lily_assert_true(rc == 0); + ezxml_free(tag); + + lily_assert_float_equal(mat[0], 0.0f, 1e-3); + lily_assert_float_equal(mat[1], 0.0f, 1e-3); + lily_assert_float_equal(mat[2], 1.0f, 1e-3); + lily_assert_float_equal(mat[3], 0.0f, 1e-3); + lily_assert_float_equal(mat[4], 0.0f, 1e-3); + lily_assert_float_equal(mat[5], 1.0f, 1e-3); + lily_assert_float_equal(mat[6], 0.0f, 1e-3); + lily_assert_float_equal(mat[7], 0.0f, 1e-3); + lily_assert_float_equal(mat[8], -1.0f, 1e-3); + lily_assert_float_equal(mat[9], 0.0f, 1e-3); + lily_assert_float_equal(mat[10], 0.0f, 1e-3); + lily_assert_float_equal(mat[11], 0.0f, 1e-3); + lily_assert_float_equal(mat[12], 0.0f, 1e-3); + lily_assert_float_equal(mat[13], 0.0f, 1e-3); + lily_assert_float_equal(mat[14], 0.0f, 1e-3); + lily_assert_float_equal(mat[15], 1.0f, 1e-3); +} + + +/* ======== translate ======== */ +void parse_translate_fail() +{ + char str[128]; + strncpy(str, "<non></non>", 128); + ezxml_t tag = ezxml_parse_str(str, strlen(str)); + + ka_matrix_t mat; + int rc = kai_parse_translate(&mat, tag); + lily_assert_true(rc != 0); + + ezxml_free(tag); +} + + +void parse_translate() +{ + char str[512]; + strncpy( + str, + "<translate>\n" + " 10 5 -1\n" + "</translate>", + 512 + ); + ezxml_t tag = ezxml_parse_str(str, strlen(str)); + + ka_matrix_t mat; + mat[0] = 100; + int rc = kai_parse_translate(&mat, tag); + lily_assert_true(rc == 0); + ezxml_free(tag); + + lily_assert_float_equal(mat[0], 1.0f, 1e-3); + lily_assert_float_equal(mat[1], 0.0f, 1e-3); + lily_assert_float_equal(mat[2], 0.0f, 1e-3); + lily_assert_float_equal(mat[3], 10.0f, 1e-3); + lily_assert_float_equal(mat[4], 0.0f, 1e-3); + lily_assert_float_equal(mat[5], 1.0f, 1e-3); + lily_assert_float_equal(mat[6], 0.0f, 1e-3); + lily_assert_float_equal(mat[7], 5.0f, 1e-3); + lily_assert_float_equal(mat[8], 0.0f, 1e-3); + lily_assert_float_equal(mat[9], 0.0f, 1e-3); + lily_assert_float_equal(mat[10], 1.0f, 1e-3); + lily_assert_float_equal(mat[11],-1.0f, 1e-3); + lily_assert_float_equal(mat[12], 0.0f, 1e-3); + lily_assert_float_equal(mat[13], 0.0f, 1e-3); + lily_assert_float_equal(mat[14], 0.0f, 1e-3); + lily_assert_float_equal(mat[15], 1.0f, 1e-3); +} |