mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 01:00:46 +00:00
re-organise test structure
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -52,3 +52,5 @@ test/*.trs
|
|||||||
test/test_*
|
test/test_*
|
||||||
*.log
|
*.log
|
||||||
test-*
|
test-*
|
||||||
|
test/.libs/*
|
||||||
|
test/tests
|
||||||
|
11
makefile.am
11
makefile.am
@@ -26,11 +26,11 @@ checkLDFLAGS = -L./.libs \
|
|||||||
checkCFLAGS = -I./test/lib/cmocka/include \
|
checkCFLAGS = -I./test/lib/cmocka/include \
|
||||||
-I./include
|
-I./include
|
||||||
|
|
||||||
check_PROGRAMS = test/test_mat4
|
check_PROGRAMS = test/tests
|
||||||
TESTS = $(check_PROGRAMS)
|
TESTS = $(check_PROGRAMS)
|
||||||
|
|
||||||
test_test_mat4_LDFLAGS = $(checkLDFLAGS)
|
test_tests_LDFLAGS = $(checkLDFLAGS)
|
||||||
test_test_mat4_CFLAGS = $(checkCFLAGS)
|
test_tests_CFLAGS = $(checkCFLAGS)
|
||||||
|
|
||||||
cglmdir=$(includedir)/cglm
|
cglmdir=$(includedir)/cglm
|
||||||
cglm_HEADERS = include/cglm-version.h \
|
cglm_HEADERS = include/cglm-version.h \
|
||||||
@@ -78,7 +78,10 @@ libcglm_la_SOURCES=\
|
|||||||
src/cglm-mat3.c \
|
src/cglm-mat3.c \
|
||||||
src/cglm-mat.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:
|
all-local:
|
||||||
sh ./post-build.sh
|
sh ./post-build.sh
|
||||||
|
36
test/src/test_common.c
Normal file
36
test/src/test_common.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "test_common.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
@@ -14,27 +14,18 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <cmocka.h>
|
#include <cmocka.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <cglm.h>
|
#include <cglm.h>
|
||||||
#include <cglm-call.h>
|
#include <cglm-call.h>
|
||||||
|
|
||||||
#define precision 0.00001f
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
void
|
||||||
test_rand_mat4(mat4 dest);
|
test_rand_mat4(mat4 dest);
|
||||||
|
|
||||||
static
|
|
||||||
void
|
void
|
||||||
test_rand_mat4(mat4 dest) {
|
test_assert_mat4_eq(mat4 m1, mat4 m2);
|
||||||
int i, j;
|
|
||||||
|
|
||||||
srand((unsigned int)time(NULL));
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
for (j = 0; j < 4; j++) {
|
|
||||||
dest[i][j] = drand48();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* test_common_h */
|
#endif /* test_common_h */
|
||||||
|
19
test/src/test_main.c
Normal file
19
test/src/test_main.c
Normal file
@@ -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);
|
||||||
|
}
|
@@ -5,18 +5,13 @@
|
|||||||
* Full license can be found in the LICENSE file
|
* Full license can be found in the LICENSE file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <float.h>
|
|
||||||
|
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
|
||||||
#define m 4
|
#define m 4
|
||||||
#define n 4
|
#define n 4
|
||||||
|
|
||||||
void
|
void
|
||||||
test_mat4_mul(void **state) {
|
test_mat4(void **state) {
|
||||||
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||||
mat4 m3;
|
mat4 m3;
|
||||||
@@ -48,30 +43,9 @@ test_mat4_mul(void **state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
test_assert_mat4_eq(m3, m4);
|
||||||
for (j = 0; j < n; j++) {
|
|
||||||
for (k = 0; k < m; k++)
|
|
||||||
assert_true(fabsf(m3[i][j] - m4[i][j]) <= FLT_EPSILON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* test pre compiled */
|
/* test pre compiled */
|
||||||
glmc_mat4_mul(m1, m2, m3);
|
glmc_mat4_mul(m1, m2, m3);
|
||||||
for (i = 0; i < m; i++) {
|
test_assert_mat4_eq(m3, m4);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
12
test/src/test_tests.h
Normal file
12
test/src/test_tests.h
Normal file
@@ -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 */
|
Reference in New Issue
Block a user