diff options
Diffstat (limited to 'gtest')
| -rw-r--r-- | gtest/gtest_get_weixinnum.cpp | 8 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_cache_exec.cpp | 92 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_exec.cpp | 130 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_exec_bytecode.cpp | 90 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_exec_bytecode_file.cpp | 88 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_exec_file.cpp | 130 | ||||
| -rw-r--r-- | gtest/script/handle_qqnum.lua | 10 | ||||
| -rw-r--r-- | gtest/script/handle_weixinnum.lua | 10 | ||||
| -rw-r--r-- | gtest/script/return_boolean_normal.lua | 4 | ||||
| -rw-r--r-- | gtest/script/return_boolean_normal.luajit | bin | 109 -> 101 bytes | |||
| -rw-r--r-- | gtest/script/return_integer_normal.lua | 4 | ||||
| -rw-r--r-- | gtest/script/return_integer_normal.luajit | bin | 109 -> 97 bytes | |||
| -rw-r--r-- | gtest/script/return_type_invaild.lua | 2 |
13 files changed, 284 insertions, 284 deletions
diff --git a/gtest/gtest_get_weixinnum.cpp b/gtest/gtest_get_weixinnum.cpp index e7a30a2..1be9be2 100644 --- a/gtest/gtest_get_weixinnum.cpp +++ b/gtest/gtest_get_weixinnum.cpp @@ -36,7 +36,7 @@ TEST(tsg_lua_get_weixinnum, exec_cache_script) int data_len; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; memset(out, 0, 255); L = tsg_lua_vm_create(); @@ -59,7 +59,7 @@ TEST(tsg_lua_get_weixinnum, exec_cache_file) int data_len; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; memset(out, 0, 255); L = tsg_lua_vm_create(); @@ -81,7 +81,7 @@ TEST(tsg_lua_get_weixinnum, exec_script) int data_len; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; memset(out, 0, 255); L = tsg_lua_vm_create(); @@ -103,7 +103,7 @@ TEST(tsg_lua_get_weixinnum, exec_file) int data_len; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; memset(out, 0, 255); L = tsg_lua_vm_create(); diff --git a/gtest/gtest_tsg_lua_cache_exec.cpp b/gtest/gtest_tsg_lua_cache_exec.cpp index 7fc2e1e..9907fc5 100644 --- a/gtest/gtest_tsg_lua_cache_exec.cpp +++ b/gtest/gtest_tsg_lua_cache_exec.cpp @@ -13,7 +13,7 @@ TEST(tsg_lua_cache_exec, normal_return_string) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.lua"; @@ -33,7 +33,7 @@ TEST(tsg_lua_cache_exec, normal_return_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = BOOLEAN; L = tsg_lua_vm_create(); const char *script = "./script/return_boolean_normal.lua"; memset(out, 0, 255); @@ -52,7 +52,7 @@ TEST(tsg_lua_cache_exec, normal_return_integer) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = INTEGER; L = tsg_lua_vm_create(); const char *script = "./script/return_integer_normal.lua"; memset(out, 0, 255); @@ -71,7 +71,7 @@ TEST(tsg_lua_cache_exec, lua_vm_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.lua"; @@ -83,7 +83,7 @@ TEST(tsg_lua_cache_exec, lua_vm_isnull) /* check */ EXPECT_EQ(ERR_LUAVM_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -92,7 +92,7 @@ TEST(tsg_lua_cache_exec, script_id_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); memset(out, 0, 255); int script_id = 0; @@ -101,7 +101,7 @@ TEST(tsg_lua_cache_exec, script_id_invaild) /* check */ EXPECT_EQ(ERR_SCRIPT_ID_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -110,7 +110,7 @@ TEST(tsg_lua_cache_exec, input_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; char *input = NULL; L = tsg_lua_vm_create(); @@ -122,7 +122,7 @@ TEST(tsg_lua_cache_exec, input_isnull) /* check */ EXPECT_EQ(ERR_INPUT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -131,7 +131,7 @@ TEST(tsg_lua_cache_exec, in_len_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.lua"; @@ -142,7 +142,7 @@ TEST(tsg_lua_cache_exec, in_len_invaild) /* check */ EXPECT_EQ(ERR_IN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -151,7 +151,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_nil.lua"; @@ -162,7 +162,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -171,7 +171,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_boolean.lua"; @@ -182,7 +182,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_boolean) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -191,7 +191,7 @@ TEST(tsg_lua_cache_exec, call_global_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/call_global_but_nil.lua"; @@ -202,37 +202,37 @@ TEST(tsg_lua_cache_exec, call_global_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_cache_exec, return_too_few) -{ - tsg_lua_handle L = NULL; - char out[255]; - size_t out_len = 0; - size_t out_type = 0; +// TEST(tsg_lua_cache_exec, return_too_few) +// { +// tsg_lua_handle L = NULL; +// char out[255]; +// size_t out_len = 0; +// size_t out_type = STRING; - L = tsg_lua_vm_create(); - const char *script = "./script/return_too_few.lua"; - memset(out, 0, 255); - int script_id = tsg_lua_cache_script_file(L, script); - int ret = tsg_lua_cache_exec(L, script_id, data, strlen(data), out, &out_len, &out_type); +// L = tsg_lua_vm_create(); +// const char *script = "./script/return_too_few.lua"; +// memset(out, 0, 255); +// int script_id = tsg_lua_cache_script_file(L, script); +// int ret = tsg_lua_cache_exec(L, script_id, data, strlen(data), out, &out_len, &out_type); - /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); - EXPECT_STREQ("", out); -} +// /* check */ +// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); +// EXPECT_EQ(0, out_len); +// EXPECT_EQ(STRING, out_type); +// EXPECT_STREQ("", out); +// } TEST(tsg_lua_cache_exec, return_too_much) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_too_much.lua"; @@ -243,16 +243,16 @@ TEST(tsg_lua_cache_exec, return_too_much) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_cache_exec, return_type_invaild) +TEST(tsg_lua_cache_exec, return_type_nil) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_type_invaild.lua"; @@ -261,9 +261,9 @@ TEST(tsg_lua_cache_exec, return_type_invaild) int ret = tsg_lua_cache_exec(L, script_id, data, strlen(data), out, &out_len, &out_type); /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(ERR_RETUNR_NIL, ret); + EXPECT_EQ(5, out_len); + EXPECT_EQ(NIL, out_type); EXPECT_STREQ("", out); } @@ -272,7 +272,7 @@ TEST(tsg_lua_cache_exec, return_length_iszero) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_length_iszero.lua"; @@ -283,7 +283,7 @@ TEST(tsg_lua_cache_exec, return_length_iszero) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -292,7 +292,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_table) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_table.lua"; @@ -303,7 +303,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_table) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -312,7 +312,7 @@ TEST(tsg_lua_cache_exec, normal_return_string_sharp) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal_sharp.lua"; diff --git a/gtest/gtest_tsg_lua_exec.cpp b/gtest/gtest_tsg_lua_exec.cpp index 1be5bcc..d69366e 100644 --- a/gtest/gtest_tsg_lua_exec.cpp +++ b/gtest/gtest_tsg_lua_exec.cpp @@ -31,7 +31,7 @@ TEST(tsg_lua_exec, normal_return_string) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); memset(out, 0, 255); @@ -50,7 +50,7 @@ TEST(tsg_lua_exec, normal_return_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = BOOLEAN; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_boolean_normal.lua"); memset(out, 0, 255); @@ -68,7 +68,7 @@ TEST(tsg_lua_exec, normal_return_integer) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = INTEGER; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_integer_normal.lua"); memset(out, 0, 255); @@ -86,7 +86,7 @@ TEST(tsg_lua_exec, lua_vm_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; const char *script = get_script_buffer("./script/return_string_normal.lua"); memset(out, 0, sizeof(out)); @@ -95,7 +95,7 @@ TEST(tsg_lua_exec, lua_vm_isnull) /* check */ EXPECT_EQ(ERR_LUAVM_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -104,7 +104,7 @@ TEST(tsg_lua_exec, script_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = NULL; memset(out, 0, 255); @@ -113,7 +113,7 @@ TEST(tsg_lua_exec, script_isnull) /* check */ EXPECT_EQ(ERR_SCRIPT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -122,7 +122,7 @@ TEST(tsg_lua_exec, input_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; char *input = NULL; L = tsg_lua_vm_create(); @@ -133,7 +133,7 @@ TEST(tsg_lua_exec, input_isnull) /* check */ EXPECT_EQ(ERR_INPUT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -142,7 +142,7 @@ TEST(tsg_lua_exec, in_len_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_string_normal.lua"); @@ -152,7 +152,7 @@ TEST(tsg_lua_exec, in_len_invaild) /* check */ EXPECT_EQ(ERR_IN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -161,7 +161,7 @@ TEST(tsg_lua_exec, end_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/end_expected.lua"); @@ -171,7 +171,7 @@ TEST(tsg_lua_exec, end_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_END_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -180,7 +180,7 @@ TEST(tsg_lua_exec, then_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/then_expected.lua"); @@ -190,7 +190,7 @@ TEST(tsg_lua_exec, then_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_THEN_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -199,7 +199,7 @@ TEST(tsg_lua_exec, do_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/do_expected.lua"); @@ -209,7 +209,7 @@ TEST(tsg_lua_exec, do_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_DO_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -218,7 +218,7 @@ TEST(tsg_lua_exec, eof_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/eof_expected.lua"); @@ -228,7 +228,7 @@ TEST(tsg_lua_exec, eof_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_EOF_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -237,7 +237,7 @@ TEST(tsg_lua_exec, equal_in_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/equal_in_expected.lua"); @@ -247,7 +247,7 @@ TEST(tsg_lua_exec, equal_in_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_EQUAL_IN_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -256,7 +256,7 @@ TEST(tsg_lua_exec, unexpected_symbol) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/unexpected_symbol.lua"); @@ -266,7 +266,7 @@ TEST(tsg_lua_exec, unexpected_symbol) /* check */ EXPECT_EQ(ERR_SCRIPT_UNEXPECTED_SYMBOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -275,7 +275,7 @@ TEST(tsg_lua_exec, name_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/name_expected.lua"); @@ -285,7 +285,7 @@ TEST(tsg_lua_exec, name_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_NAME_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -294,7 +294,7 @@ TEST(tsg_lua_exec, right_curves_bracket_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/right_curves_bracket_expected.lua"); @@ -304,7 +304,7 @@ TEST(tsg_lua_exec, right_curves_bracket_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_RIGHT_CURVES_BRACKET_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -313,7 +313,7 @@ TEST(tsg_lua_exec, right_curly_bracket_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/right_curly_bracket_expected.lua"); @@ -323,7 +323,7 @@ TEST(tsg_lua_exec, right_curly_bracket_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_RIGHT_CURLY_BRACKET_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -332,7 +332,7 @@ TEST(tsg_lua_exec, string_expected_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/string_expected_but_nil.lua"); @@ -342,7 +342,7 @@ TEST(tsg_lua_exec, string_expected_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -351,7 +351,7 @@ TEST(tsg_lua_exec, string_expected_but_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/string_expected_but_boolean.lua"); @@ -361,7 +361,7 @@ TEST(tsg_lua_exec, string_expected_but_boolean) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -370,7 +370,7 @@ TEST(tsg_lua_exec, string_expected_but_table) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/string_expected_but_table.lua"); @@ -380,7 +380,7 @@ TEST(tsg_lua_exec, string_expected_but_table) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -389,7 +389,7 @@ TEST(tsg_lua_exec, call_global_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/call_global_but_nil.lua"); @@ -399,36 +399,36 @@ TEST(tsg_lua_exec, call_global_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec, return_too_few) -{ - tsg_lua_handle L = NULL; - char out[255]; - size_t out_len = 0; - size_t out_type = 0; +// TEST(tsg_lua_exec, return_too_few) +// { +// tsg_lua_handle L = NULL; +// char out[255]; +// size_t out_len = 0; +// size_t out_type = STRING; - L = tsg_lua_vm_create(); - const char *script = get_script_buffer("./script/return_too_few.lua"); - memset(out, 0, 255); - int ret = tsg_lua_exec(L, script, strlen(script), data, strlen(data), out, &out_len, &out_type); +// L = tsg_lua_vm_create(); +// const char *script = get_script_buffer("./script/return_too_few.lua"); +// memset(out, 0, 255); +// int ret = tsg_lua_exec(L, script, strlen(script), data, strlen(data), out, &out_len, &out_type); - /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); - EXPECT_STREQ("", out); -} +// /* check */ +// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); +// EXPECT_EQ(0, out_len); +// EXPECT_EQ(STRING, out_type); +// EXPECT_STREQ("", out); +// } TEST(tsg_lua_exec, return_too_much) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_too_much.lua"); @@ -438,16 +438,16 @@ TEST(tsg_lua_exec, return_too_much) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec, return_type_invaild) +TEST(tsg_lua_exec, return_type_nil) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_type_invaild.lua"); @@ -455,9 +455,9 @@ TEST(tsg_lua_exec, return_type_invaild) int ret = tsg_lua_exec(L, script, strlen(script), data, strlen(data), out, &out_len, &out_type); /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(ERR_RETUNR_NIL, ret); + EXPECT_EQ(5, out_len); + EXPECT_EQ(NIL, out_type); EXPECT_STREQ("", out); } @@ -466,7 +466,7 @@ TEST(tsg_lua_exec, return_length_iszero) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_length_iszero.lua"); @@ -476,7 +476,7 @@ TEST(tsg_lua_exec, return_length_iszero) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } #if 0 @@ -485,7 +485,7 @@ TEST(tsg_lua_exec, function_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/function_invaild.lua"); @@ -495,7 +495,7 @@ TEST(tsg_lua_exec, function_invaild) /* check */ EXPECT_EQ(ERR_SCRIPT_FUNCTION_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } #endif @@ -505,7 +505,7 @@ TEST(tsg_lua_exec, sharp) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); memset(out, 0, 255); diff --git a/gtest/gtest_tsg_lua_exec_bytecode.cpp b/gtest/gtest_tsg_lua_exec_bytecode.cpp index 0d12b96..2975753 100644 --- a/gtest/gtest_tsg_lua_exec_bytecode.cpp +++ b/gtest/gtest_tsg_lua_exec_bytecode.cpp @@ -33,7 +33,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_string) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); memset(out, 0, 255); @@ -52,7 +52,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = BOOLEAN; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_boolean_normal.luajit"); memset(out, 0, 255); @@ -70,7 +70,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_integer) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = INTEGER; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_integer_normal.luajit"); memset(out, 0, 255); @@ -88,7 +88,7 @@ TEST(tsg_lua_exec_bytecode, lua_vm_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; const char *script = get_script_buffer("./script/return_string_normal.luajit"); memset(out, 0, sizeof(out)); @@ -97,7 +97,7 @@ TEST(tsg_lua_exec_bytecode, lua_vm_isnull) /* check */ EXPECT_EQ(ERR_LUAVM_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -106,7 +106,7 @@ TEST(tsg_lua_exec_bytecode, script_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = NULL; memset(out, 0, 255); @@ -115,7 +115,7 @@ TEST(tsg_lua_exec_bytecode, script_isnull) /* check */ EXPECT_EQ(ERR_SCRIPT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -124,7 +124,7 @@ TEST(tsg_lua_exec_bytecode, input_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; char *input = NULL; L = tsg_lua_vm_create(); @@ -135,7 +135,7 @@ TEST(tsg_lua_exec_bytecode, input_isnull) /* check */ EXPECT_EQ(ERR_INPUT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -144,7 +144,7 @@ TEST(tsg_lua_exec_bytecode, in_len_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_string_normal.luajit"); @@ -154,7 +154,7 @@ TEST(tsg_lua_exec_bytecode, in_len_invaild) /* check */ EXPECT_EQ(ERR_IN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -163,7 +163,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/string_expected_but_nil.luajit"); @@ -173,7 +173,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -182,7 +182,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/string_expected_but_boolean.luajit"); @@ -192,7 +192,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_boolean) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -201,7 +201,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_table) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/string_expected_but_table.luajit"); @@ -211,7 +211,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_table) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -220,7 +220,7 @@ TEST(tsg_lua_exec_bytecode, call_global_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/call_global_but_nil.luajit"); @@ -230,36 +230,36 @@ TEST(tsg_lua_exec_bytecode, call_global_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec_bytecode, return_too_few) -{ - tsg_lua_handle L = NULL; - char out[255]; - size_t out_len = 0; - size_t out_type = 0; +// TEST(tsg_lua_exec_bytecode, return_too_few) +// { +// tsg_lua_handle L = NULL; +// char out[255]; +// size_t out_len = 0; +// size_t out_type = STRING; - L = tsg_lua_vm_create(); - const char *script = get_script_buffer("./script/return_too_few.luajit"); - memset(out, 0, 255); - int ret = tsg_lua_exec(L, script, script_len, data, strlen(data), out, &out_len, &out_type); +// L = tsg_lua_vm_create(); +// const char *script = get_script_buffer("./script/return_too_few.luajit"); +// memset(out, 0, 255); +// int ret = tsg_lua_exec(L, script, script_len, data, strlen(data), out, &out_len, &out_type); - /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); - EXPECT_STREQ("", out); -} +// /* check */ +// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); +// EXPECT_EQ(0, out_len); +// EXPECT_EQ(STRING, out_type); +// EXPECT_STREQ("", out); +// } TEST(tsg_lua_exec_bytecode, return_too_much) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_too_much.luajit"); @@ -269,16 +269,16 @@ TEST(tsg_lua_exec_bytecode, return_too_much) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec_bytecode, return_type_invaild) +TEST(tsg_lua_exec_bytecode, return_type_nil) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_type_invaild.luajit"); @@ -286,9 +286,9 @@ TEST(tsg_lua_exec_bytecode, return_type_invaild) int ret = tsg_lua_exec(L, script, script_len, data, strlen(data), out, &out_len, &out_type); /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(ERR_RETUNR_NIL, ret); + EXPECT_EQ(5, out_len); + EXPECT_EQ(NIL, out_type); EXPECT_STREQ("", out); } @@ -297,7 +297,7 @@ TEST(tsg_lua_exec_bytecode, return_length_iszero) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = get_script_buffer("./script/return_length_iszero.luajit"); @@ -307,7 +307,7 @@ TEST(tsg_lua_exec_bytecode, return_length_iszero) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -316,7 +316,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_string_sharp) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); memset(out, 0, 255); diff --git a/gtest/gtest_tsg_lua_exec_bytecode_file.cpp b/gtest/gtest_tsg_lua_exec_bytecode_file.cpp index 18ae428..f99298c 100644 --- a/gtest/gtest_tsg_lua_exec_bytecode_file.cpp +++ b/gtest/gtest_tsg_lua_exec_bytecode_file.cpp @@ -13,7 +13,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_string) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.luajit"; @@ -32,7 +32,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = BOOLEAN; L = tsg_lua_vm_create(); const char *script = "./script/return_boolean_normal.luajit"; memset(out, 0, 255); @@ -50,7 +50,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_integer) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = INTEGER; L = tsg_lua_vm_create(); const char *script = "./script/return_integer_normal.luajit"; memset(out, 0, 255); @@ -68,7 +68,7 @@ TEST(tsg_lua_exec_bytecode_file, lua_vm_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; const char *script = "./script/return_string_normal.luajit"; memset(out, 0, sizeof(out)); @@ -77,7 +77,7 @@ TEST(tsg_lua_exec_bytecode_file, lua_vm_isnull) /* check */ EXPECT_EQ(ERR_LUAVM_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -86,7 +86,7 @@ TEST(tsg_lua_exec_bytecode_file, script_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = NULL; memset(out, 0, 255); @@ -95,7 +95,7 @@ TEST(tsg_lua_exec_bytecode_file, script_isnull) /* check */ EXPECT_EQ(ERR_SCRIPT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -104,7 +104,7 @@ TEST(tsg_lua_exec_bytecode_file, input_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; char *input = NULL; L = tsg_lua_vm_create(); @@ -115,7 +115,7 @@ TEST(tsg_lua_exec_bytecode_file, input_isnull) /* check */ EXPECT_EQ(ERR_INPUT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -124,7 +124,7 @@ TEST(tsg_lua_exec_bytecode_file, in_len_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.luajit"; @@ -134,7 +134,7 @@ TEST(tsg_lua_exec_bytecode_file, in_len_invaild) /* check */ EXPECT_EQ(ERR_IN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -143,7 +143,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_nil.luajit"; @@ -153,7 +153,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -162,7 +162,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_boolean.luajit"; @@ -172,7 +172,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_boolean) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -181,7 +181,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_table) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_table.luajit"; @@ -191,7 +191,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_table) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -200,7 +200,7 @@ TEST(tsg_lua_exec_bytecode_file, call_global_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/call_global_but_nil.luajit"; @@ -210,36 +210,36 @@ TEST(tsg_lua_exec_bytecode_file, call_global_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec_bytecode_file, return_too_few) -{ - tsg_lua_handle L = NULL; - char out[255]; - size_t out_len = 0; - size_t out_type = 0; +// TEST(tsg_lua_exec_bytecode_file, return_too_few) +// { +// tsg_lua_handle L = NULL; +// char out[255]; +// size_t out_len = 0; +// size_t out_type = STRING; - L = tsg_lua_vm_create(); - const char *script = "./script/return_too_few.luajit"; - memset(out, 0, 255); - int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type); +// L = tsg_lua_vm_create(); +// const char *script = "./script/return_too_few.luajit"; +// memset(out, 0, 255); +// int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type); - /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); - EXPECT_STREQ("", out); -} +// /* check */ +// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); +// EXPECT_EQ(0, out_len); +// EXPECT_EQ(STRING, out_type); +// EXPECT_STREQ("", out); +// } TEST(tsg_lua_exec_bytecode_file, return_too_much) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_too_much.luajit"; @@ -249,7 +249,7 @@ TEST(tsg_lua_exec_bytecode_file, return_too_much) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -258,7 +258,7 @@ TEST(tsg_lua_exec_bytecode_file, return_type_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_type_invaild.luajit"; @@ -266,9 +266,9 @@ TEST(tsg_lua_exec_bytecode_file, return_type_invaild) int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type); /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(ERR_RETUNR_NIL, ret); + EXPECT_EQ(5, out_len); + EXPECT_EQ(NIL, out_type); EXPECT_STREQ("", out); } @@ -277,7 +277,7 @@ TEST(tsg_lua_exec_bytecode_file, return_length_iszero) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_length_iszero.luajit"; @@ -287,7 +287,7 @@ TEST(tsg_lua_exec_bytecode_file, return_length_iszero) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -296,7 +296,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_string_sharp) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal_sharp.luajit"; diff --git a/gtest/gtest_tsg_lua_exec_file.cpp b/gtest/gtest_tsg_lua_exec_file.cpp index 81fbe5c..041b58d 100644 --- a/gtest/gtest_tsg_lua_exec_file.cpp +++ b/gtest/gtest_tsg_lua_exec_file.cpp @@ -14,7 +14,7 @@ TEST(tsg_lua_exec_file, normal_return_string) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.lua"; @@ -33,7 +33,7 @@ TEST(tsg_lua_exec_file, normal_return_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = BOOLEAN; L = tsg_lua_vm_create(); const char *script = "./script/return_boolean_normal.lua"; memset(out, 0, 255); @@ -51,7 +51,7 @@ TEST(tsg_lua_exec_file, normal_return_integer) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = INTEGER; L = tsg_lua_vm_create(); const char *script = "./script/return_integer_normal.lua"; memset(out, 0, 255); @@ -69,7 +69,7 @@ TEST(tsg_lua_exec_file, lua_vm_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; const char *script = "./script/return_string_normal.lua"; memset(out, 0, sizeof(out)); @@ -78,7 +78,7 @@ TEST(tsg_lua_exec_file, lua_vm_isnull) /* check */ EXPECT_EQ(ERR_LUAVM_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -87,7 +87,7 @@ TEST(tsg_lua_exec_file, script_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = NULL; memset(out, 0, 255); @@ -96,7 +96,7 @@ TEST(tsg_lua_exec_file, script_isnull) /* check */ EXPECT_EQ(ERR_SCRIPT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -105,7 +105,7 @@ TEST(tsg_lua_exec_file, input_isnull) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; char *input = NULL; L = tsg_lua_vm_create(); @@ -116,7 +116,7 @@ TEST(tsg_lua_exec_file, input_isnull) /* check */ EXPECT_EQ(ERR_INPUT_ISNULL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -125,7 +125,7 @@ TEST(tsg_lua_exec_file, in_len_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal.lua"; @@ -135,7 +135,7 @@ TEST(tsg_lua_exec_file, in_len_invaild) /* check */ EXPECT_EQ(ERR_IN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -144,7 +144,7 @@ TEST(tsg_lua_exec_file, end_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/end_expected.lua"; @@ -154,7 +154,7 @@ TEST(tsg_lua_exec_file, end_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_END_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -163,7 +163,7 @@ TEST(tsg_lua_exec_file, then_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/then_expected.lua"; @@ -173,7 +173,7 @@ TEST(tsg_lua_exec_file, then_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_THEN_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -182,7 +182,7 @@ TEST(tsg_lua_exec_file, do_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/do_expected.lua"; @@ -192,7 +192,7 @@ TEST(tsg_lua_exec_file, do_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_DO_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -201,7 +201,7 @@ TEST(tsg_lua_exec_file, eof_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/eof_expected.lua"; @@ -211,7 +211,7 @@ TEST(tsg_lua_exec_file, eof_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_EOF_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -220,7 +220,7 @@ TEST(tsg_lua_exec_file, equal_in_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/equal_in_expected.lua"; @@ -230,7 +230,7 @@ TEST(tsg_lua_exec_file, equal_in_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_EQUAL_IN_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -239,7 +239,7 @@ TEST(tsg_lua_exec_file, unexpected_symbol) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/unexpected_symbol.lua"; @@ -249,7 +249,7 @@ TEST(tsg_lua_exec_file, unexpected_symbol) /* check */ EXPECT_EQ(ERR_SCRIPT_UNEXPECTED_SYMBOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -258,7 +258,7 @@ TEST(tsg_lua_exec_file, name_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/name_expected.lua"; @@ -268,7 +268,7 @@ TEST(tsg_lua_exec_file, name_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_NAME_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -277,7 +277,7 @@ TEST(tsg_lua_exec_file, right_curves_bracket_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/right_curves_bracket_expected.lua"; @@ -287,7 +287,7 @@ TEST(tsg_lua_exec_file, right_curves_bracket_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_RIGHT_CURVES_BRACKET_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -296,7 +296,7 @@ TEST(tsg_lua_exec_file, right_curly_bracket_expected) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/right_curly_bracket_expected.lua"; @@ -306,7 +306,7 @@ TEST(tsg_lua_exec_file, right_curly_bracket_expected) /* check */ EXPECT_EQ(ERR_SCRIPT_RIGHT_CURLY_BRACKET_EXPECTED, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -315,7 +315,7 @@ TEST(tsg_lua_exec_file, string_expected_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_nil.lua"; @@ -325,7 +325,7 @@ TEST(tsg_lua_exec_file, string_expected_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -334,7 +334,7 @@ TEST(tsg_lua_exec_file, string_expected_but_boolean) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_boolean.lua"; @@ -344,7 +344,7 @@ TEST(tsg_lua_exec_file, string_expected_but_boolean) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -353,7 +353,7 @@ TEST(tsg_lua_exec_file, string_expected_but_table) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/string_expected_but_table.lua"; @@ -363,7 +363,7 @@ TEST(tsg_lua_exec_file, string_expected_but_table) /* check */ EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } @@ -372,7 +372,7 @@ TEST(tsg_lua_exec_file, call_global_but_nil) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/call_global_but_nil.lua"; @@ -382,36 +382,36 @@ TEST(tsg_lua_exec_file, call_global_but_nil) /* check */ EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec_file, return_too_few) -{ - tsg_lua_handle L = NULL; - char out[255]; - size_t out_len = 0; - size_t out_type = 0; +// TEST(tsg_lua_exec_file, return_too_few) +// { +// tsg_lua_handle L = NULL; +// char out[255]; +// size_t out_len = 0; +// size_t out_type = STRING; - L = tsg_lua_vm_create(); - const char *script = "./script/return_too_few.lua"; - memset(out, 0, 255); - int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type); +// L = tsg_lua_vm_create(); +// const char *script = "./script/return_too_few.lua"; +// memset(out, 0, 255); +// int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type); - /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); - EXPECT_STREQ("", out); -} +// /* check */ +// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret); +// EXPECT_EQ(0, out_len); +// EXPECT_EQ(STRING, out_type); +// EXPECT_STREQ("", out); +// } TEST(tsg_lua_exec_file, return_too_much) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_too_much.lua"; @@ -421,16 +421,16 @@ TEST(tsg_lua_exec_file, return_too_much) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } -TEST(tsg_lua_exec_file, return_type_invaild) +TEST(tsg_lua_exec_file, return_type_nil) { tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_type_invaild.lua"; @@ -438,9 +438,9 @@ TEST(tsg_lua_exec_file, return_type_invaild) int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type); /* check */ - EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret); - EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(ERR_RETUNR_NIL, ret); + EXPECT_EQ(5, out_len); + EXPECT_EQ(NIL, out_type); EXPECT_STREQ("", out); } @@ -449,7 +449,7 @@ TEST(tsg_lua_exec_file, return_length_iszero) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_length_iszero.lua"; @@ -459,7 +459,7 @@ TEST(tsg_lua_exec_file, return_length_iszero) /* check */ EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } #if 0 @@ -468,7 +468,7 @@ TEST(tsg_lua_exec_file, function_invaild) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/function_invaild.lua"; @@ -478,7 +478,7 @@ TEST(tsg_lua_exec_file, function_invaild) /* check */ EXPECT_EQ(ERR_SCRIPT_FUNCTION_INVAILD, ret); EXPECT_EQ(0, out_len); - EXPECT_EQ(0, out_type); + EXPECT_EQ(STRING, out_type); EXPECT_STREQ("", out); } #endif @@ -488,7 +488,7 @@ TEST(tsg_lua_exec_file, normal_return_string_sharp) tsg_lua_handle L = NULL; char out[255]; size_t out_len = 0; - size_t out_type = 0; + size_t out_type = STRING; L = tsg_lua_vm_create(); const char *script = "./script/return_string_normal_sharp.lua"; diff --git a/gtest/script/handle_qqnum.lua b/gtest/script/handle_qqnum.lua index fc0d1a4..4994536 100644 --- a/gtest/script/handle_qqnum.lua +++ b/gtest/script/handle_qqnum.lua @@ -27,28 +27,28 @@ end -- 命中特征"\0\0\0\0" local _, _end = string.find(data, "\0\0\0\0") if not _end then - return 1, false + return false end -- 获取qqnum长度 local qqnum_len = string.byte(data, _end + 1) if not qqnum_len then - return 1,false + return false end locate = _end + 1 qqnum_len = qqnum_len - 4 -- 判断qqnum长度的合法性 if qqnum_len > 12 or qqnum_len > (data_len - locate) then - return 1, false + return false end locate = locate + 1 -- 获取qqnum local qqnum = string.sub(data, locate, locate + qqnum_len - 1) if not qqnum then - return 1, false + return false end -- 验证qqnum由全数字组成 if not tonumber(qqnum) then - return 1, false + return false end return qqnum_len, qqnum diff --git a/gtest/script/handle_weixinnum.lua b/gtest/script/handle_weixinnum.lua index 1b8b448..e1b6db5 100644 --- a/gtest/script/handle_weixinnum.lua +++ b/gtest/script/handle_weixinnum.lua @@ -18,23 +18,23 @@ local locate = 0 -- 字符串中当前正在处理的位置 -- 查找字符串weixinnum位置 local _start, _end = string.find(data, feature) if not _end then - return 1, false + return false end -- 获取weixinnum数值字符串长度 -- weixinnum数值字符串长度不超过12,所以前三位必须为0 if ((string.byte(data, _end + 1) ~= 0) or (string.byte(data, _end + 2) ~=0 ) or (string.byte(data, _end + 3) ~= 0)) then - return 1, false + return false end local weixinnum_len = string.byte(data, _end + offset) if not weixinnum_len then - return 1, false + return false end locate = _end + offset -- 判断weixinnum数值字符串长度的合法性 if weixinnum_len > data_len - _end - offset or weixinnum_len > max_weixinnum_len then - return 1, false + return false end -- 获取weixinnum数值字符串 @@ -43,5 +43,5 @@ local weixinnum = string.sub(data, locate + 1, locate + weixinnum_len) if tonumber(weixinnum) then return weixinnum_len, weixinnum else - return 1, false + return false end diff --git a/gtest/script/return_boolean_normal.lua b/gtest/script/return_boolean_normal.lua index fbf1fbf..5856cc4 100644 --- a/gtest/script/return_boolean_normal.lua +++ b/gtest/script/return_boolean_normal.lua @@ -1,6 +1,6 @@ local str = TSG.data local s_index, e_index = string.find(str, 'hello') if s_index then - return 1, true -else return 1, false + return true +else return false end diff --git a/gtest/script/return_boolean_normal.luajit b/gtest/script/return_boolean_normal.luajit Binary files differindex 9bbbfbb..215e3f9 100644 --- a/gtest/script/return_boolean_normal.luajit +++ b/gtest/script/return_boolean_normal.luajit diff --git a/gtest/script/return_integer_normal.lua b/gtest/script/return_integer_normal.lua index ccb38fe..9c64643 100644 --- a/gtest/script/return_integer_normal.lua +++ b/gtest/script/return_integer_normal.lua @@ -1,7 +1,7 @@ local str = TSG.data local s_index, e_index = string.find(str, 'world') if s_index then - return 8, s_index + return s_index else - return 1, false + return false end diff --git a/gtest/script/return_integer_normal.luajit b/gtest/script/return_integer_normal.luajit Binary files differindex 3abd850..6dac219 100644 --- a/gtest/script/return_integer_normal.luajit +++ b/gtest/script/return_integer_normal.luajit diff --git a/gtest/script/return_type_invaild.lua b/gtest/script/return_type_invaild.lua index 2d4e33e..89fcb65 100644 --- a/gtest/script/return_type_invaild.lua +++ b/gtest/script/return_type_invaild.lua @@ -1,2 +1,2 @@ local str = "hello" -return string.len(str), nil +return string.len(str), nil |
