summaryrefslogtreecommitdiff
path: root/src/geometry/geometry.test.c
blob: d918ffa35116b518de1e3787d7d474a767966af1 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#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");

	kai_release_float_array(arr);
}
#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");

	kai_release_param(param);
}
#include LILY_PUSH_TEST()


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

	struct ka_accessor_t accessor;
	int result = kai_read_accessor(&accessor, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("fail to read accessor tag with no specified count or source")
{
	struct kai_tag_t *t = kai_parse_string(
		"<accessor />"
	);

	struct ka_accessor_t accessor;
	int result = kai_read_accessor(&accessor, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("parse accessor")
{
	struct kai_tag_t *t = kai_parse_string(
		"<accessor source=\"some id\" count=\"6\" stride=\"3\">"
		"	<param type=\"float\" name=\"x\" />"
		"	<param type=\"float\" name=\"y\" />"
		"	<param type=\"float\" name=\"z\" />"
		"</accessor>"
	);

	struct ka_accessor_t acc;
	int result = kai_read_accessor(&acc, t);
	kai_tag_destroy(t);

	CHECK_EQ(result, 0, "%d");
	CHECK_EQ(acc.count, 6, "%d");
	CHECK_EQ(acc.offset, 0, "%d");
	CHECK_EQS(acc.source, "some id");
	CHECK_EQ(acc.stride, 3, "%d");

	REQUIRE_EQ(acc.param_count, 3, "%d");
	CHECK_EQS(acc.param[0].name, "x");
	CHECK_EQS(acc.param[1].name, "y");
	CHECK_EQS(acc.param[2].name, "z");

	kai_release_accessor(acc);
}
#include LILY_PUSH_TEST()


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

	struct ka_source_t source;
	int result = kai_read_source(&source, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


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

	struct ka_source_t source;
	int result = kai_read_source(&source, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("read source correctly")
{
	struct kai_tag_t *t = kai_parse_string(
		"<source id=\"source\">"
		"	<float_array count=\"1\">0.0</float_array>"
		"	<technique_common>"
		"		<accessor count=\"1\" source=\"xxx\">"
		"			<param type=\"float\" />"
		"		</accessor>"
		"	</technique_common>"
		"</source>"
	);

	struct ka_source_t source;
	int result = kai_read_source(&source, t);
	kai_tag_destroy(t);

	CHECK_EQ(result, 0, "%d");
	REQUIRE_EQS(source.id, "source");
	CHECK_EQS(source.name, NULL);

	CHECK_EQ(source.float_array.count, 1, "%d");
	CHECK_EQS(source.accessor.source, "xxx");

	kai_release_source(source);
}
#include LILY_PUSH_TEST()


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

	struct ka_input_t input_unshared;
	int result = kai_read_input_unshared(&input_unshared, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("fail to read input (unshared) tag with no specified semantic or source")
{
	struct kai_tag_t *t = kai_parse_string(
		"<input />"
	);

	struct ka_input_t input_unshared;
	int result = kai_read_input_unshared(&input_unshared, t);
	CHECK_EQ(result, -1, "%d");
	kai_tag_destroy(t);

	t = kai_parse_string(
		"<input semantic=\"xxx\" />"
	);
	result = kai_read_input_unshared(&input_unshared, t);
	CHECK_EQ(result, -1, "%d");
	kai_tag_destroy(t);

	t = kai_parse_string(
		"<input source=\"xxx\" />"
	);
	result = kai_read_input_unshared(&input_unshared, t);
	CHECK_EQ(result, -1, "%d");
	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("read input (unshared)")
{
	struct kai_tag_t *t = kai_parse_string(
		"<input semantic=\"xxx\" source=\"yyy\" />"
	);

	struct ka_input_t input_unshared;
	int result = kai_read_input_unshared(&input_unshared, t);
	kai_tag_destroy(t);

	CHECK_EQ(result, 0, "%d");
	CHECK_EQ(input_unshared.shared, false, "%d");
	CHECK_EQS(input_unshared.semantic, "xxx");
	CHECK_EQS(input_unshared.source, "yyy");

	kai_release_input(input_unshared);
}
#include LILY_PUSH_TEST()


LILY_TEST("fail to read input (shared) with no offset")
{
	struct kai_tag_t *t = kai_parse_string(
		"<input semantic=\"xxx\" source=\"yyy\" />"
	);

	struct ka_input_t input_shared;
	int result = kai_read_input_shared(&input_shared, t);
	kai_tag_destroy(t);
	kai_release_input(input_shared);

	CHECK_EQ(result, -1, "%d");
}
#include LILY_PUSH_TEST()


LILY_TEST("read input (shared)")
{
	struct kai_tag_t *t = kai_parse_string(
		"<input semantic=\"xxx\" source=\"yyy\" offset=\"10\" />"
	);

	struct ka_input_t input_shared;
	int result = kai_read_input_shared(&input_shared, t);
	kai_tag_destroy(t);

	CHECK_EQ(result, 0, "%d");
	CHECK_EQ(input_shared.shared, true, "%d");
	CHECK_EQ(input_shared.offset, 10, "%d");
	CHECK_EQS(input_shared.semantic, "xxx");
	CHECK_EQS(input_shared.source, "yyy");
	CHECK_EQ(input_shared.use_set, false, "%d");
	kai_release_input(input_shared);

	t = kai_parse_string(
		"<input semantic=\"xxx\" source=\"yyy\" offset=\"10\" set=\"4\" />"
	);

	result = kai_read_input_shared(&input_shared, t);
	kai_tag_destroy(t);

	CHECK_EQ(result, 0, "%d");
	CHECK_EQ(input_shared.shared, true, "%d");
	CHECK_EQ(input_shared.offset, 10, "%d");
	CHECK_EQS(input_shared.semantic, "xxx");
	CHECK_EQS(input_shared.source, "yyy");
	CHECK_EQ(input_shared.use_set, true, "%d");
	CHECK_EQ(input_shared.set, 4, "%d");
	kai_release_input(input_shared);
}
#include LILY_PUSH_TEST()


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

	struct ka_vertices_t vertices;
	int result = kai_read_vertices(&vertices, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


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

	struct ka_vertices_t vertices;
	int result = kai_read_vertices(&vertices, t);
	CHECK_EQ(result, -1, "%d");
	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("read vertices tag")
{
	struct kai_tag_t *t = kai_parse_string(
		"<vertices id=\"xxx\" name=\"yyy\" >"
		"	<input semantic=\"zzz\" source=\"xxx\" />"
		"	<input semantic=\"www\" source=\"xxx\" />"
		"</vertices>"
	);

	struct ka_vertices_t vertices;
	vertices.input = NULL;

	int result = kai_read_vertices(&vertices, t);
	kai_tag_destroy(t);

	REQUIRE_EQ(result, 0, "%d");
	CHECK_EQS(vertices.id, "xxx");
	CHECK_EQS(vertices.name, "yyy");
	CHECK_EQ(vertices.input_count, 2, "%d");
	CHECK_NEQ(vertices.input, NULL, "%p");

	kai_release_vertices(vertices);
}
#include LILY_PUSH_TEST()


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

	struct ka_triangles_t triangles;
	int result = kai_read_triangles(&triangles, t);
	CHECK_EQ(result, -1, "%d");

	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


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

	struct ka_triangles_t triangles;
	int result = kai_read_triangles(&triangles, t);
	CHECK_EQ(result, -1, "%d");
	kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()


LILY_TEST("read triangles tag")
{
	struct kai_tag_t *t = kai_parse_string(
		"<triangles count=\"2\" material=\"Bricks\">"
		"	<input semantic=\"VERTEX\" source=\"#verts\" offset=\"0\"/>"
		"	<input semantic=\"NORMAL\" source=\"#normal\" offset=\"1\"/>"
		"	<p>"
		"		0 0 1 3 2 1"
		"		0 0 2 1 3 2"
		"	</p>"
		"</triangles>"
	);

	struct ka_triangles_t triangles;
	int result = kai_read_triangles(&triangles, t);
	kai_tag_destroy(t);

	REQUIRE_EQ(result, 0, "%d");
	CHECK_EQ(triangles.name, NULL, "%p");
	CHECK_EQ(triangles.count, 2, "%d");
	CHECK_EQS(triangles.material, "Bricks");
	CHECK_EQ(triangles.input_count, 2, "%d");
	CHECK_EQS(triangles.input[1].semantic, "NORMAL");
	CHECK_EQ(triangles.p_count, 12, "%d");
	CHECK_EQ(triangles.p[0], 0, "%d");
	CHECK_EQ(triangles.p[1], 0, "%d");
	CHECK_EQ(triangles.p[2], 1, "%d");
	CHECK_EQ(triangles.p[3], 3, "%d");
	CHECK_EQ(triangles.p[4], 2, "%d");
	CHECK_EQ(triangles.p[5], 1, "%d");

	CHECK_EQ(triangles.p[6], 0, "%d");
	CHECK_EQ(triangles.p[7], 0, "%d");
	CHECK_EQ(triangles.p[8], 2, "%d");
	CHECK_EQ(triangles.p[9], 1, "%d");
	CHECK_EQ(triangles.p[10], 3, "%d");
	CHECK_EQ(triangles.p[11], 2, "%d");

	kai_release_triangles(triangles);
}
#include LILY_PUSH_TEST()



#define LILY_FILE_END
#include LILY_REGISTER_TESTS()