summaryrefslogtreecommitdiff
path: root/src/geometry/geometry.test.c
blob: dec16e91054efbb064b13b3693414ec8dadd3447 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <string.h>

#include <kalmia.h>
#include "geometry.h"
#include "test/test.h"


LILY_FILE_BEGIN(geometry_suite)


LILY_TEST("fail to read non-float_array")
{
	struct kai_tag_t *t = kai_parse_string(
		"<non_float_array></non_float_array>"
	);

	struct ka_float_array_t arr;
	int result = kai_read_float_array(&arr, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("fail to read float_array without count attribute")
{
	struct kai_tag_t *t = kai_parse_string(
		"<float_array id=\"some id\">"
		"	blah blah internals"
		"</float_array>"
	);

	struct ka_float_array_t arr;
	int result = kai_read_float_array(&arr, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("read normal float_array")
{
	struct kai_tag_t *t = kai_parse_string(
		"<float_array count=\"3\" id=\"arr\">"
		"	-0.5 0.0 0.5"
		"</float_array>"
	);

	struct ka_float_array_t arr;
	int result = kai_read_float_array(&arr, t);
	REQUIRE_EQ(result, 0, "%d");
	kai_tag_destroy(t);

	REQUIRE_EQ(arr.count, 3, "%d");
	CHECK_EQS(arr.id, "arr");
	CHECK_EQ(arr.digits, 6, "%d");
	CHECK_EQ(arr.magnitude, 38, "%d");

	CHECK_EQF(arr.buf[0], -0.5, "%f");
	CHECK_EQF(arr.buf[1],  0.0, "%f");
	CHECK_EQF(arr.buf[2],  0.5, "%f");

	free(arr.id);
	free(arr.buf);
}
#include LILY_PUSH_TEST()


LILY_TEST("fail to read non-param tag")
{
	struct kai_tag_t *t = kai_parse_string(
		"<tag />"
	);

	struct ka_param_t param;
	int result = kai_read_param(&param, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("fail to read param tag with no specified type")
{
	struct kai_tag_t *t = kai_parse_string(
		"<param />"
	);

	struct ka_param_t param;
	int result = kai_read_param(&param, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("read param tag")
{
	struct kai_tag_t *t = kai_parse_string(
		"<param type=\"float\" name=\"x\" />"
	);

	struct ka_param_t param;
	int result = kai_read_param(&param, t);
	kai_tag_destroy(t);

	REQUIRE_EQ(result, 0, "%d");
	CHECK_EQS(param.name, "x");
	CHECK_EQ(param.sid, NULL, "%p");
	CHECK_EQS(param.type, "float");
	CHECK_EQ(param.semantic, NULL, "%p");
}
#include LILY_PUSH_TEST()


#define LILY_FILE_END
#include LILY_REGISTER_TESTS()