#include #include #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( "" ); 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( "" " blah blah internals" "" ); 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( "" " -0.5 0.0 0.5" "" ); 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( "" ); struct ka_param_t param; int result = kai_read_param(¶m, 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( "" ); struct ka_param_t param; int result = kai_read_param(¶m, 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( "" ); struct ka_param_t param; int result = kai_read_param(¶m, 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( "" ); 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( "" ); 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( "" " " " " " " "" ); 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( "" ); 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( "" ); 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( "" " 0.0" " " " " " " " " " " "" ); 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( "" ); 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( "" ); 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( "" ); result = kai_read_input_unshared(&input_unshared, t); CHECK_EQ(result, -1, "%d"); kai_tag_destroy(t); t = kai_parse_string( "" ); 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( "" ); 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( "" ); 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( "" ); 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( "" ); 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( "" ); 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( "" ); 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( "" " " " " "" ); 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( "" ); 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( "" ); 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( "" " " " " "

" " 0 0 1 3 2 1" " 0 0 2 1 3 2" "

" "
" ); 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() LILY_TEST("fail to read non-mesh tag") { struct kai_tag_t *t = kai_parse_string( "" ); struct ka_mesh_t mesh; int result = kai_read_mesh(&mesh, t); CHECK_EQ(result, -1, "%d"); kai_tag_destroy(t); } #include LILY_PUSH_TEST() LILY_TEST("read mesh tag") { struct kai_tag_t *t = kai_parse_string( "" " " " 0.0" " " " " " " " " " " " " " " " " " " " " " " " " "

" " 0 0 1 3 2 1" " 0 0 2 1 3 2" "

" "
" "
" ); struct ka_mesh_t mesh; int result = kai_read_mesh(&mesh, t); kai_tag_destroy(t); REQUIRE_EQ(result, 0, "%d"); CHECK_EQ(mesh.source_count, 1, "%d"); CHECK_EQS(mesh.source[0].id, "source"); CHECK_EQS(mesh.vertices.id, "box-Vtx"); CHECK_EQ(mesh.triangles_count, 1, "%d"); CHECK_EQ(mesh.triangles[0].count, 2, "%d"); kai_release_mesh(mesh); } #include LILY_PUSH_TEST() LILY_TEST("fail to read non-geometry tag") { struct kai_tag_t *t = kai_parse_string( "" ); struct ka_geometry_t geometry; int result = kai_read_geometry(&geometry, t); CHECK_EQ(result, -1, "%d"); kai_tag_destroy(t); } #include LILY_PUSH_TEST() LILY_TEST("read geometry tag") { struct kai_tag_t *t = kai_parse_string( "" " " " " " 0.0" " " " " " " " " " " " " " " " " " " " " " " " " "

" " 0 0 1 3 2 1" " 0 0 2 1 3 2" "

" "
" "
" "
" ); struct ka_geometry_t geometry; int result = kai_read_geometry(&geometry, t); kai_tag_destroy(t); REQUIRE_EQ(result, 0, "%d"); CHECK_EQS(geometry.id, "xxx"); CHECK_EQ(geometry.mesh.source_count, 1, "%d"); CHECK_EQ(geometry.mesh.triangles_count, 1, "%d"); kai_release_geometry(geometry); } #include LILY_PUSH_TEST() #define LILY_FILE_END #include LILY_REGISTER_TESTS()