diff options
Diffstat (limited to 'src/tests/hs_process_table_tests.c')
-rw-r--r-- | src/tests/hs_process_table_tests.c | 175 |
1 files changed, 149 insertions, 26 deletions
diff --git a/src/tests/hs_process_table_tests.c b/src/tests/hs_process_table_tests.c index bf6e424..04fc9e4 100644 --- a/src/tests/hs_process_table_tests.c +++ b/src/tests/hs_process_table_tests.c @@ -24,6 +24,15 @@ do { mu_assert("incorrectly set string!", strcmp(string, "") == 0); } while(0); +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * tests for all 16 possible combinations of one table containing one + * boolean, integer, number, and string key each. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + + TEST(process_none) { lua_createtable(L, 0, 0); @@ -37,9 +46,6 @@ TEST(process_none) return 0; } - - - TEST(process_bool) { lua_createtable(L, 0, 0); @@ -55,8 +61,6 @@ TEST(process_bool) return 0; } - - TEST(process_int) { lua_createtable(L, 0, 0); @@ -73,7 +77,6 @@ TEST(process_int) return 0; } - TEST(process_bool_int) { lua_createtable(L, 0, 0); @@ -92,8 +95,6 @@ TEST(process_bool_int) return 0; } - - TEST(process_number) { lua_createtable(L, 0, 0); @@ -109,7 +110,6 @@ TEST(process_number) return 0; } - TEST(process_bool_number) { lua_createtable(L, 0, 0); @@ -128,7 +128,6 @@ TEST(process_bool_number) return 0; } - TEST(process_int_number) { lua_createtable(L, 0, 0); @@ -148,8 +147,6 @@ TEST(process_int_number) return 0; } - - TEST(process_bool_int_number) { lua_createtable(L, 0, 0); @@ -171,8 +168,6 @@ TEST(process_bool_int_number) return 0; } - - TEST(process_string) { lua_createtable(L, 0, 0); @@ -189,9 +184,6 @@ TEST(process_string) return 0; } - - - TEST(process_bool_string) { lua_createtable(L, 0, 0); @@ -210,8 +202,6 @@ TEST(process_bool_string) return 0; } - - TEST(process_int_string) { lua_createtable(L, 0, 0); @@ -231,7 +221,6 @@ TEST(process_int_string) return 0; } - TEST(process_bool_int_string) { lua_createtable(L, 0, 0); @@ -253,8 +242,6 @@ TEST(process_bool_int_string) return 0; } - - TEST(process_number_string) { lua_createtable(L, 0, 0); @@ -273,7 +260,6 @@ TEST(process_number_string) return 0; } - TEST(process_bool_number_string) { lua_createtable(L, 0, 0); @@ -295,7 +281,6 @@ TEST(process_bool_number_string) return 0; } - TEST(process_int_number_string) { lua_createtable(L, 0, 0); @@ -318,8 +303,6 @@ TEST(process_int_number_string) return 0; } - - TEST(process_all) { lua_createtable(L, 0, 0); @@ -345,6 +328,141 @@ TEST(process_all) return 0; } + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * tests for four keys of the same type + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +TEST(process_four_bools) +{ + lua_createtable(L, 0, 4); + + lua_pushboolean(L, true); + lua_setfield(L, -2, "b1"); + + lua_pushboolean(L, false); + lua_setfield(L, -2, "b2"); + + lua_pushboolean(L, false); + lua_setfield(L, -2, "b3"); + + lua_pushboolean(L, true); + lua_setfield(L, -2, "b4"); + + bool b1, b2, b3, b4; + hs_process_table(L, -1, + "b1", HS_BOOL, hs_pt_set_boolean, &b1, + "b2", HS_BOOL, hs_pt_set_boolean, &b2, + "b3", HS_BOOL, hs_pt_set_boolean, &b3, + "b4", HS_BOOL, hs_pt_set_boolean, &b4, + HS_END); + + mu_assert("b1 was not correctly set!", b1 == true); + mu_assert("b2 was not correctly set!", b2 == false); + mu_assert("b3 was not correctly set!", b3 == false); + mu_assert("b4 was not correctly set!", b4 == true); + return 0; +} +TEST(process_four_ints) +{ + lua_createtable(L, 0, 4); + + lua_pushinteger(L, 2); + lua_setfield(L, -2, "j1"); + + lua_pushinteger(L, 1); + lua_setfield(L, -2, "j2"); + + lua_pushinteger(L, 3); + lua_setfield(L, -2, "j3"); + + lua_pushinteger(L, 4); + lua_setfield(L, -2, "j4"); + + int j1, j2, j3, j4; + hs_process_table(L, -1, + "j1", HS_INT, hs_pt_set_integer, &j1, + "j2", HS_INT, hs_pt_set_integer, &j2, + "j3", HS_INT, hs_pt_set_integer, &j3, + "j4", HS_INT, hs_pt_set_integer, &j4, + HS_END); + + mu_assert("j1 was not correctly set!", j1 == 2); + mu_assert("j2 was not correctly set!", j2 == 1); + mu_assert("j3 was not correctly set!", j3 == 3); + mu_assert("j4 was not correctly set!", j4 == 4); + return 0; +} +TEST(process_four_numbers) +{ + lua_createtable(L, 0, 4); + + lua_pushnumber(L, 3.141); + lua_setfield(L, -2, "n1"); + + lua_pushnumber(L, 2.718); + lua_setfield(L, -2, "n2"); + + lua_pushnumber(L, 1.618); + lua_setfield(L, -2, "n3"); + + lua_pushnumber(L, 4.669); + lua_setfield(L, -2, "n4"); + + lua_Number n1, n2, n3, n4; + hs_process_table(L, -1, + "n1", HS_NUM, hs_pt_set_number, &n1, + "n2", HS_NUM, hs_pt_set_number, &n2, + "n3", HS_NUM, hs_pt_set_number, &n3, + "n4", HS_NUM, hs_pt_set_number, &n4, + HS_END); + + mu_assert("n1 was not correctly set!", n1 == 3.141); + mu_assert("n2 was not correctly set!", n2 == 2.718); + mu_assert("n3 was not correctly set!", n3 == 1.618); + mu_assert("n4 was not correctly set!", n4 == 4.669); + return 0; +} +TEST(process_four_strings) +{ + lua_createtable(L, 0, 4); + + lua_pushstring(L, "When meditation is mastered, The mind is unwavering like the Flame of a lamp in a windless place." ); + lua_setfield(L, -2, "s1"); + + lua_pushstring(L, "In the still mind, In the depths of meditation, The Self reveals itself."); + lua_setfield(L, -2, "s2"); + + lua_pushstring(L, "Beholding the Self By means of the Self, An aspirant knows the Joy and peace of complete fulfillment."); + lua_setfield(L, -2, "s3"); + + lua_pushstring(L, "Having attained that Abiding joy beyond the senses, Revealed in the stilled mind, He never swerves from the eternal truth."); + lua_setfield(L, -2, "s4"); + + const char *s1, *s2, *s3, *s4; + hs_process_table(L, -1, + "s1", HS_STR, hs_pt_set_string, &s1, + "s2", HS_STR, hs_pt_set_string, &s2, + "s3", HS_STR, hs_pt_set_string, &s3, + "s4", HS_STR, hs_pt_set_string, &s4, + HS_END); + + mu_assert("s1 was not correctly set!", + strcmp(s1, "When meditation is mastered, The mind is unwavering like the Flame of a lamp in a windless place.") == 0); + mu_assert("s2 was not correctly set!", + strcmp(s2, "In the still mind, In the depths of meditation, The Self reveals itself.") == 0); + mu_assert("s3 was not correctly set!", + strcmp(s3, "Beholding the Self By means of the Self, An aspirant knows the Joy and peace of complete fulfillment.") == 0); + mu_assert("s4 was not correctly set!", + strcmp(s4, "Having attained that Abiding joy beyond the senses, Revealed in the stilled mind, He never swerves from the eternal truth.") == 0); + return 0; +} + + + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * test suite @@ -373,4 +491,9 @@ void hs_process_table_tests() mu_run_test("process boolean, number, and string", process_bool_number_string); mu_run_test("process integer, number, and string", process_int_number_string); mu_run_test("process basic types", process_all); + + mu_run_test("process four booleans", process_four_bools); + mu_run_test("process four integers", process_four_ints); + mu_run_test("process four numbers", process_four_numbers); + mu_run_test("process four strings", process_four_strings); } |