summaryrefslogtreecommitdiff
path: root/src/import/import_node.test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/import/import_node.test.c')
-rw-r--r--src/import/import_node.test.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/import/import_node.test.c b/src/import/import_node.test.c
new file mode 100644
index 0000000..4d5c9ef
--- /dev/null
+++ b/src/import/import_node.test.c
@@ -0,0 +1,116 @@
+#include <assimp/scene.h>
+#include <lua.h>
+#include <lauxlib.h>
+#include <honeysuckle.h>
+#include "test/lily-test.h"
+#include "import.test.h"
+
+
+#include "import.c"
+
+
+#define MESH_COUNT 13
+void test_push_node()
+{
+ lua_State *L = luaL_newstate();
+
+ int meshes[MESH_COUNT];
+ for (int i=0; i<MESH_COUNT; i++)
+ meshes[i] = i;
+
+ /* first layer node */
+ struct aiNode root;
+ root.mParent = NULL;
+ root.mMeshes = meshes;
+ root.mNumMeshes = 3;
+
+ /* second layer nodes */
+ struct aiNode nodeA, nodeB;
+ struct aiNode *root_children[] = { &nodeA, &nodeB };
+ root.mChildren = root_children;
+ root.mNumChildren = 2;
+
+ nodeA.mMeshes = meshes + 3;
+ nodeA.mNumMeshes = 2;
+ nodeA.mChildren = NULL;
+
+ nodeB.mMeshes = meshes + 5;
+ nodeB.mNumMeshes = 2;
+ nodeB.mChildren = NULL;
+
+ /* push */
+ int top = lua_gettop(L);
+ push_node(L, &root);
+
+ /* check */
+ lily_assert_int_equal(top+1, lua_gettop(L));
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+
+ int nodetbl = lua_gettop(L);
+
+ /* check meshes */
+ lua_getfield(L, nodetbl, "meshes");
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+
+ lua_rawgeti(L, -1, 1);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 1);
+ lua_pop(L, 1);
+
+ lua_rawgeti(L, -1, 2);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 2);
+ lua_pop(L, 1);
+
+ lua_rawgeti(L, -1, 3);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 3);
+ lua_pop(L, 1);
+
+ /* check children */
+ lua_getfield(L, nodetbl, "children");
+ int childrentbl = lua_gettop(L);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+
+ lua_rawgeti(L, childrentbl, 1);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+ int atbl = lua_gettop(L);
+ lua_getfield(L, atbl, "meshes");
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+
+ lua_rawgeti(L, -1, 1);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 4);
+ lua_pop(L, 1);
+
+ lua_rawgeti(L, -1, 2);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 5);
+ lua_pop(L, 2);
+
+ lua_getfield(L, atbl, "children");
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNIL);
+ lua_pop(L, 2);
+
+ lua_rawgeti(L, childrentbl, 2);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+ int btbl = lua_gettop(L);
+ lua_getfield(L, btbl, "meshes");
+ lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
+
+ lua_rawgeti(L, -1, 1);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 6);
+ lua_pop(L, 1);
+
+ lua_rawgeti(L, -1, 2);
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
+ lily_assert_int_equal(lua_tointeger(L, -1), 7);
+ lua_pop(L, 2);
+
+ lua_getfield(L, btbl, "children");
+ lily_assert_int_equal(lua_type(L, -1), LUA_TNIL);
+ lua_pop(L, 2);
+
+ lua_close(L);
+}