summaryrefslogtreecommitdiff
path: root/src/import/import.test.c
blob: a234bda1665077b4df2c591f60504173bb122567 (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
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <honeysuckle.h>
#include "test/honey-test.h"


#include "import.c"


void test_push_vector()
{
	lua_State *L = luaL_newstate();
	struct aiVector3D v;
	v.x = 1.5;
	v.y = 2.0;
	v.z = 3.6;

	push_vector(L, v);

	lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE);

	lua_getfield(L, -1, "x");
	lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
	lily_assert_float_equal(lua_tonumber(L, -1), 1.5, 0.1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "y");
	lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
	lily_assert_float_equal(lua_tonumber(L, -1), 2.0, 0.1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "z");
	lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER);
	lily_assert_float_equal(lua_tonumber(L, -1), 3.6, 0.1);
	lua_pop(L, 1);

	lua_close(L);
}


void test_push_aistring()
{
	lua_State *L = luaL_newstate();
	struct aiString str;
	strcpy(str.data, "hello, world!");

	push_aistring(L, str);

	lily_assert_int_equal(lua_type(L, -1), LUA_TSTRING);
	lily_assert_string_equal((char*) lua_tostring(L, -1), "hello, world!");

	lua_close(L);
}


void suite_import()
{
	lily_run_test(test_push_vector);
	lily_run_test(test_push_aistring);
}