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
|
#include "hs_tests.h"
struct process_types {
bool boolean;
lua_Integer integer;
lua_Number number;
const char *string;
};
void set_boolean(bool value, void *data)
{
struct process_types *d = data;
d->boolean = value;
}
void set_integer(lua_Integer value, void *data)
{
struct process_types *d = data;
d->integer = value;
}
void set_number(lua_Number value, void *data)
{
struct process_types *d = data;
d->number = value;
}
void set_string(const char *value, void *data)
{
struct process_types *d = data;
d->string = value;
}
TEST(process_basic_types)
{
lua_createtable(L, 0, 0);
lua_pushboolean(L, true);
lua_setfield(L, -2, "boolean");
lua_pushinteger(L, 14);
lua_setfield(L, -2, "integer");
lua_pushnumber(L, 44.66);
lua_setfield(L, -2, "number");
lua_pushstring(L, "c: c: c:");
lua_setfield(L, -2, "string");
struct process_types data = { false, 0, 0, "" };
hs_process_table(L, -1, &data,
"boolean", HS_BOOL, set_boolean,
"integer", HS_INT, set_integer,
"number", HS_NUM, set_number,
"string", HS_STR, set_string,
HS_END);
mu_assert("failed to set boolean!", data.boolean == true);
mu_assert("failed to set integer!", data.integer == 14);
mu_assert("failed to set number!", data.number == 44.66);
mu_assert("failed to set string!", strcmp(data.string, "c: c: c:") == 0);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* test suite
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
void hs_process_table_tests()
{
printf("running hs_process_table() tests...\n");
mu_run_test("process basic types", process_basic_types);
}
|