summaryrefslogtreecommitdiff
path: root/src/tests/hs_process_table_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/hs_process_table_tests.c')
-rw-r--r--src/tests/hs_process_table_tests.c77
1 files changed, 77 insertions, 0 deletions
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);
+}