diff options
-rw-r--r-- | src/tests/hs_create_table_tests.c | 459 |
1 files changed, 458 insertions, 1 deletions
diff --git a/src/tests/hs_create_table_tests.c b/src/tests/hs_create_table_tests.c index f21ca64..029e1f1 100644 --- a/src/tests/hs_create_table_tests.c +++ b/src/tests/hs_create_table_tests.c @@ -596,7 +596,7 @@ TEST(create_table_num_light) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * - * boolean keys + * string keys * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -1262,6 +1262,423 @@ TEST(create_table_func_light) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * + * boolean keys + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +TEST(create_table_cfunc_bool) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_cfunc_bool(testfunc1, true), hs_cfunc_bool(testfunc2, true)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_cfunc(index, testfunc1); + checkval_bool(true); + loadkey_cfunc(index, testfunc2); + checkval_bool(true); + return 0; +} + +TEST(create_table_cfunc_int) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_cfunc_int(testfunc1, 15), hs_cfunc_int(testfunc2, 25)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_cfunc(index, testfunc1); + checkval_int(15); + loadkey_cfunc(index, testfunc2); + checkval_int(25); + return 0; +} + +TEST(create_table_cfunc_num) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_cfunc_num(testfunc1, 2.718), hs_cfunc_num(testfunc2, 1.618)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_cfunc(index, testfunc1); + checkval_num(2.718); + loadkey_cfunc(index, testfunc2); + checkval_num(1.618); + return 0; +} + +TEST(create_table_cfunc_str) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_cfunc_str(testfunc1, "hello"), hs_cfunc_str(testfunc2, "world")); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_cfunc(index, testfunc1); + checkval_str("hello"); + loadkey_cfunc(index, testfunc2); + checkval_str("world"); + return 0; +} + +TEST(create_table_cfunc_tbl) +{ + int oldtop = lua_gettop(L); + + lua_newtable(L); + store(value1); + lua_newtable(L); + store(value2); + + int index = hs_create_table + (L, hs_cfunc_tbl(testfunc1, value1), hs_cfunc_tbl(testfunc2, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(value1); + load(value2); + + loadkey_cfunc(index, testfunc1); + checkval_tbl(value1); + loadkey_cfunc(index, testfunc2); + checkval_tbl(value2); + return 0; +} + +TEST(create_table_cfunc_func) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('hello')"); + store(value1); + luaL_loadstring(L, "print('hello')"); + store(value2); + + int index = hs_create_table + (L, hs_cfunc_func(testfunc1, value1), hs_cfunc_func(testfunc2, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(value1); + load(value2); + + loadkey_cfunc(index, testfunc1); + checkval_func(value1); + loadkey_cfunc(index, testfunc2); + checkval_func(value2); + return 0; +} + +TEST(create_table_cfunc_cfunc) +{ + + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_cfunc_cfunc(testfunc1, testfunc1), hs_cfunc_cfunc(testfunc2, testfunc2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_cfunc(index, testfunc1); + checkval_cfunc(testfunc1); + loadkey_cfunc(index, testfunc2); + checkval_cfunc(testfunc2); + return 0; +} + + +TEST(create_table_cfunc_user) +{ + int oldtop = lua_gettop(L); + + lua_newuserdata(L, sizeof(char)); + store(user1); + lua_newuserdata(L, sizeof(char)); + store(user2); + + int index = hs_create_table + (L, hs_cfunc_user(testfunc1, user1), hs_cfunc_user(testfunc2, user2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_cfunc(index, testfunc1); + checkval_user(user1); + loadkey_cfunc(index, testfunc2); + checkval_user(user2); + return 0; +} + +TEST(create_table_cfunc_light) +{ + int a1 = 5; + void *light1 = (void *) &a1; + int a2 = 6; + void *light2 = (void *) &a2; + + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_cfunc_light(testfunc1, light1), hs_cfunc_light(testfunc2, light2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_cfunc(index, testfunc1); + checkval_light(light1); + loadkey_cfunc(index, testfunc2); + checkval_light(light2); + return 0; +} + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * userdata keys + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +TEST(create_table_user_bool) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + int index = hs_create_table + (L, hs_user_bool(user1, true), hs_user_bool(user2, false)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_user(index, user1); + checkval_bool(true); + loadkey_user(index, user2); + checkval_bool(false); + return 0; +} + +TEST(create_table_user_int) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + int index = hs_create_table + (L, hs_user_int(user1, 15), hs_user_int(user2, 25)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_user(index, user1); + checkval_int(15); + loadkey_user(index, user2); + checkval_int(25); + return 0; +} + +TEST(create_table_user_num) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + int index = hs_create_table + (L, hs_user_num(user1, 2.718), hs_user_num(user2, 1.618)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_user(index, user1); + checkval_num(2.718); + loadkey_user(index, user2); + checkval_num(1.618); + return 0; +} + +TEST(create_table_user_str) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + int index = hs_create_table + (L, hs_user_str(user1, "hello"), hs_user_str(user2, "world")); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_user(index, user1); + checkval_str("hello"); + loadkey_user(index, user2); + checkval_str("world"); + return 0; +} + +TEST(create_table_user_tbl) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + + lua_newtable(L); + store(value1); + lua_newtable(L); + store(value2); + + int index = hs_create_table + (L, hs_user_tbl(user1, value1), hs_user_tbl(user2, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + load(value1); + load(value2); + + loadkey_user(index, user1); + checkval_tbl(value1); + loadkey_user(index, user2); + checkval_tbl(value2); + return 0; +} + +TEST(create_table_user_func) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + + luaL_loadstring(L, "print('hello')"); + store(value1); + luaL_loadstring(L, "print('hello')"); + store(value2); + + int index = hs_create_table + (L, hs_user_func(user1, value1), hs_user_func(user2, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + load(value1); + load(value2); + + loadkey_user(index, user1); + checkval_func(value1); + loadkey_user(index, user2); + checkval_func(value2); + return 0; +} + +TEST(create_table_user_cfunc) +{ + + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + int index = hs_create_table + (L, hs_user_cfunc(user1, testfunc1), hs_user_cfunc(user2, testfunc2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_user(index, user1); + checkval_cfunc(testfunc1); + loadkey_user(index, user2); + checkval_cfunc(testfunc2); + return 0; +} + + +TEST(create_table_user_user) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + + lua_newuserdata(L, sizeof(char)); + store(value1); + lua_newuserdata(L, sizeof(char)); + store(value2); + + int index = hs_create_table + (L, hs_user_user(user1, value1), hs_user_user(user2, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + load(value1); + load(value2); + + loadkey_user(index, user1); + checkval_user(value1); + loadkey_user(index, user2); + checkval_user(value2); + return 0; +} + +TEST(create_table_user_light) +{ + int a1 = 5; + void *light1 = (void *) &a1; + int a2 = 6; + void *light2 = (void *) &a2; + + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('')"); + store(user1); + luaL_loadstring(L, "print('')"); + store(user2); + + int index = hs_create_table + (L, hs_user_light(user1, light1), hs_user_light(user2, light2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_user(index, user1); + checkval_light(light1); + loadkey_user(index, user2); + checkval_light(light2); + return 0; +} + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * * test suite * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1392,4 +1809,44 @@ void hs_create_table_tests() create_table_func_user); mu_run_test("create table with function keys and light userdata values", \ create_table_func_light); + + /* C function keys */ + mu_run_test("create table with C function keys and boolean values", + create_table_cfunc_bool); + mu_run_test("create table with C function keys and integer values", \ + create_table_cfunc_int); + mu_run_test("create table with C function keys and number values", \ + create_table_cfunc_num); + mu_run_test("create table with C function keys and string values", \ + create_table_cfunc_str); + mu_run_test("create table with C function keys and table values", \ + create_table_cfunc_tbl); + mu_run_test("create table with C function keys and function values", \ + create_table_cfunc_func); + mu_run_test("create table with C function keys and C function values", \ + create_table_cfunc_cfunc); + mu_run_test("create table with C function keys and userdata values", \ + create_table_cfunc_user); + mu_run_test("create table with C function keys and light userdata values", \ + create_table_cfunc_light); + + /* userdata keys */ + mu_run_test("create table with userdata keys and boolean values", + create_table_user_bool); + mu_run_test("create table with userdata keys and integer values", \ + create_table_user_int); + mu_run_test("create table with userdata keys and number values", \ + create_table_user_num); + mu_run_test("create table with userdata keys and string values", \ + create_table_user_str); + mu_run_test("create table with userdata keys and table values", \ + create_table_user_tbl); + mu_run_test("create table with userdata keys and function values", \ + create_table_user_func); + mu_run_test("create table with userdata keys and C function values", \ + create_table_user_cfunc); + mu_run_test("create table with userdata keys and userdata values", \ + create_table_user_user); + mu_run_test("create table with userdata keys and light userdata values", \ + create_table_user_light); } |