diff --git a/.gitignore b/.gitignore index de38718..96858dc 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,6 @@ cscope.* test/*.trs test/test_* *.log -test-* \ No newline at end of file +test-* +test/.libs/* +test/tests diff --git a/makefile.am b/makefile.am index d491a17..4ae93a1 100644 --- a/makefile.am +++ b/makefile.am @@ -26,11 +26,11 @@ checkLDFLAGS = -L./.libs \ checkCFLAGS = -I./test/lib/cmocka/include \ -I./include -check_PROGRAMS = test/test_mat4 +check_PROGRAMS = test/tests TESTS = $(check_PROGRAMS) -test_test_mat4_LDFLAGS = $(checkLDFLAGS) -test_test_mat4_CFLAGS = $(checkCFLAGS) +test_tests_LDFLAGS = $(checkLDFLAGS) +test_tests_CFLAGS = $(checkCFLAGS) cglmdir=$(includedir)/cglm cglm_HEADERS = include/cglm-version.h \ @@ -78,7 +78,10 @@ libcglm_la_SOURCES=\ src/cglm-mat3.c \ src/cglm-mat.c -test_test_mat4_SOURCES=test/src/test_mat4.c +test_tests_SOURCES=\ + test/src/test_common.c \ + test/src/test_main.c \ + test/src/test_mat4.c all-local: sh ./post-build.sh diff --git a/test/src/test_common.c b/test/src/test_common.c new file mode 100644 index 0000000..43aa423 --- /dev/null +++ b/test/src/test_common.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * MIT License (MIT), http://opensource.org/licenses/MIT + */ + +#include "test_common.h" +#include + +void +test_rand_mat4(mat4 dest) { + int i, j; + + srand((unsigned int)time(NULL)); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + dest[i][j] = drand48(); + } + } +} + +void +test_assert_mat4_eq(mat4 m1, mat4 m2) { + int i, j, k; + +#define m 4 +#define n 4 + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + for (k = 0; k < m; k++) + assert_true(fabsf(m1[i][j] - m2[i][j]) <= FLT_EPSILON); + } + } +#undef m +#undef n +} + diff --git a/test/src/test_common.h b/test/src/test_common.h index 71e5962..fee9395 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -14,27 +14,18 @@ #include #include #include +#include +#include +#include +#include #include #include -#define precision 0.00001f - -static void test_rand_mat4(mat4 dest); -static void -test_rand_mat4(mat4 dest) { - int i, j; - - srand((unsigned int)time(NULL)); - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - dest[i][j] = drand48(); - } - } -} +test_assert_mat4_eq(mat4 m1, mat4 m2); #endif /* test_common_h */ diff --git a/test/src/test_main.c b/test/src/test_main.c new file mode 100644 index 0000000..4578997 --- /dev/null +++ b/test/src/test_main.c @@ -0,0 +1,19 @@ +/* + * Copyright (c), Recep Aslantas. + * MIT License (MIT), http://opensource.org/licenses/MIT + */ + +#include "test_common.h" +#include "test_tests.h" + +int +main(int argc, const char * argv[]) { + const struct CMUnitTest tests[] = { + /* mat4 */ + cmocka_unit_test(test_mat4), + }; + + return cmocka_run_group_tests(tests, + NULL, + NULL); +} diff --git a/test/src/test_mat4.c b/test/src/test_mat4.c index e6a7947..a026058 100644 --- a/test/src/test_mat4.c +++ b/test/src/test_mat4.c @@ -5,18 +5,13 @@ * Full license can be found in the LICENSE file */ -#include -#include -#include -#include - #include "test_common.h" #define m 4 #define n 4 void -test_mat4_mul(void **state) { +test_mat4(void **state) { mat4 m1 = GLM_MAT4_IDENTITY_INIT; mat4 m2 = GLM_MAT4_IDENTITY_INIT; mat4 m3; @@ -48,30 +43,9 @@ test_mat4_mul(void **state) { } } - for (i = 0; i < m; i++) { - for (j = 0; j < n; j++) { - for (k = 0; k < m; k++) - assert_true(fabsf(m3[i][j] - m4[i][j]) <= FLT_EPSILON); - } - } + test_assert_mat4_eq(m3, m4); /* test pre compiled */ glmc_mat4_mul(m1, m2, m3); - for (i = 0; i < m; i++) { - for (j = 0; j < n; j++) { - for (k = 0; k < m; k++) - assert_true(fabsf(m3[i][j] - m4[i][j]) <= FLT_EPSILON); - } - } -} - -int -main(int argc, const char * argv[]) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_mat4_mul) - }; - - return cmocka_run_group_tests(tests, - NULL, - NULL); + test_assert_mat4_eq(m3, m4); } diff --git a/test/src/test_tests.h b/test/src/test_tests.h new file mode 100644 index 0000000..7e8fe20 --- /dev/null +++ b/test/src/test_tests.h @@ -0,0 +1,12 @@ +/* + * Copyright (c), Recep Aslantas. + * MIT License (MIT), http://opensource.org/licenses/MIT + */ + +#ifndef test_tests_h +#define test_tests_h + +/* mat4 */ +void test_mat4(void **state); + +#endif /* test_tests_h */