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
|
#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;
/* third layer nodes */
struct aiNode nodeC;
struct aiNode *a_children[] = { &nodeC };
nodeA.mChildren = a_children;
nodeA.mNumChildren = 1;
nodeC.mMeshes = meshes + 7;
nodeC.mNumMeshes = 1;
nodeC.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");
lily_assert_int_equal(lua_objlen(L, -1), 2);
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_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, 1);
/* check layer 3 */
lua_getfield(L, atbl, "children");
childrentbl = lua_gettop(L);
lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
lily_assert_int_equal(lua_objlen(L, -1), 1);
lua_rawgeti(L, childrentbl, 1);
lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
int ctbl = lua_gettop(L);
lua_getfield(L, ctbl, "meshes");
lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);
lily_assert_int_equal(lua_objlen(L, -1), 1);
lua_rawgeti(L, -1, 1);
lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
lily_assert_int_equal(lua_tointeger(L, -1), 8);
lua_close(L);
}
|