summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2021-07-03 01:20:01 -0500
committersanine-a <sanine.not@pm.me>2021-07-03 01:20:01 -0500
commitf83e8d242b8a719733498181f4cad3fbb9c97ca7 (patch)
treeedc44f1e16499f0138d62ed45fb12bba42840570 /src
parentdb2b31a335b531d7e54ab3e7d494bbf33050ac60 (diff)
create hs_process_table_tests.c and add basic table processing test
Diffstat (limited to 'src')
-rw-r--r--src/honeysuckle.c8
l---------src/tests/.#hs_create_table_tests.c1
-rw-r--r--src/tests/hs_create_enum_tests.c1
-rw-r--r--src/tests/hs_create_table_tests.c4
-rw-r--r--src/tests/hs_process_table_tests.c77
-rw-r--r--src/tests/tests_main.c2
6 files changed, 90 insertions, 3 deletions
diff --git a/src/honeysuckle.c b/src/honeysuckle.c
index 8cb8194..11f3f53 100644
--- a/src/honeysuckle.c
+++ b/src/honeysuckle.c
@@ -34,6 +34,14 @@ int hs_create_enum(lua_State *L, ...)
}
+void hs_process_table(lua_State *L, int table_index, void *data, ...)
+{
+ L = L;
+ table_index = table_index;
+ data = data;
+}
+
+
void hs_pushstring(lua_State *L, const char *format_string, ...)
{
lua_pushnumber(L, 0.4);
diff --git a/src/tests/.#hs_create_table_tests.c b/src/tests/.#hs_create_table_tests.c
deleted file mode 120000
index 68ed537..0000000
--- a/src/tests/.#hs_create_table_tests.c
+++ /dev/null
@@ -1 +0,0 @@
-kate@amalthea.194602:1624721630 \ No newline at end of file
diff --git a/src/tests/hs_create_enum_tests.c b/src/tests/hs_create_enum_tests.c
index 0cc3d0b..b24ec71 100644
--- a/src/tests/hs_create_enum_tests.c
+++ b/src/tests/hs_create_enum_tests.c
@@ -13,6 +13,7 @@
lua_pop(L, -1); \
} while(0)
+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* tests
diff --git a/src/tests/hs_create_table_tests.c b/src/tests/hs_create_table_tests.c
index 8a8ebe2..460832f 100644
--- a/src/tests/hs_create_table_tests.c
+++ b/src/tests/hs_create_table_tests.c
@@ -1,6 +1,6 @@
#include "hs_tests.h"
-int testfunc(lua_State *L) { return 0; }
+static int testfunc(lua_State *L) { return 0; }
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
@@ -29,7 +29,7 @@ TEST(table_correct_index)
#define check_bool(field, expected) check_table_element(field, lua_isboolean, "boolean", bool, lua_toboolean, value == expected)
#define check_int(field, expected) check_table_element(field, lua_isnumber, "integer", int, lua_tointeger, value == expected)
#define check_num(field, expected) check_table_element(field, lua_isnumber, "number", float, lua_tonumber, value == expected)
-#define check_string(field, expected) check_table_element(field, lua_isstring, "string", char*, lua_tostring, strcmp(value, expected))
+#define check_string(field, expected) check_table_element(field, lua_isstring, "string", const char*, lua_tostring, strcmp(value, expected))
#define check_cfunc(field, expected) check_table_element(field, lua_iscfunction, "C function", lua_CFunction, lua_tocfunction, value == expected)
#define check_user(field, expected) check_table_element(field, lua_isuserdata, "userdata", void*, lua_touserdata, value == expected)
#define check_light(field, expected) check_table_element(field, lua_islightuserdata, "light userdata", void*, lua_touserdata, value == expected)
diff --git a/src/tests/hs_process_table_tests.c b/src/tests/hs_process_table_tests.c
new file mode 100644
index 0000000..eedf600
--- /dev/null
+++ b/src/tests/hs_process_table_tests.c
@@ -0,0 +1,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);
+}
diff --git a/src/tests/tests_main.c b/src/tests/tests_main.c
index 207e233..51c2462 100644
--- a/src/tests/tests_main.c
+++ b/src/tests/tests_main.c
@@ -21,6 +21,8 @@ int main()
hs_create_table_tests();
hs_create_enum_tests();
+ hs_process_table_tests();
+
hs_pushstring_tests();
printf("\n=============== tests finished ===============\n\n");