diff options
| author | 彭宣正 <[email protected]> | 2022-09-08 14:27:31 +0800 |
|---|---|---|
| committer | 彭宣正 <[email protected]> | 2022-09-08 14:27:31 +0800 |
| commit | 82005b0c81b7e62046acdcda17477138ac08cd6b (patch) | |
| tree | 4941812320d5c573aadcd8a38f525ddd2ad03506 /gtest | |
| parent | 2b67279071b4fded5d9381e09cbf39cce56562c4 (diff) | |
✨ feat(TSG-11870): 允许elua_exec_script 输入input为空
Diffstat (limited to 'gtest')
| -rw-r--r-- | gtest/gtest_tsg_lua_cache_exec.cpp | 31 | ||||
| -rw-r--r-- | gtest/script/input_is_null.lua | 1 |
2 files changed, 22 insertions, 10 deletions
diff --git a/gtest/gtest_tsg_lua_cache_exec.cpp b/gtest/gtest_tsg_lua_cache_exec.cpp index 7e75c68..c74376d 100644 --- a/gtest/gtest_tsg_lua_cache_exec.cpp +++ b/gtest/gtest_tsg_lua_cache_exec.cpp @@ -121,15 +121,21 @@ TEST(elua_execute_script, input_isnull) elua_vm *L = NULL; L = elua_create_vm(NULL); - const char *script = "./script/return_string_normal.lua"; + const char *script = "./script/input_is_null.lua"; struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data out; - out.type = INTEGER; + char buff[1024]; + memset(buff, 0, 1024); + out.buff = buff; + out.len = 1024; + out.type = STRING; int ret = elua_execute_script(escript, NULL, strlen(data), NULL, NULL, &out); /* check */ - EXPECT_EQ(-1, ret); - EXPECT_STREQ(elua_get_last_error_string(L), "[elua_execute_script:1168] input or input_len is invaild."); + EXPECT_EQ(0, ret); + EXPECT_EQ(5, out.len); + EXPECT_EQ(STRING, out.type); + EXPECT_STREQ("hello", out.buff); } TEST(elua_execute_script, in_len_invaild) @@ -137,20 +143,25 @@ TEST(elua_execute_script, in_len_invaild) elua_vm *L = NULL; L = elua_create_vm(NULL); - const char *script = "./script/return_string_normal.lua"; + const char *script = "./script/input_is_null.lua"; struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data out; - char *buff = (char *)data; + char buff[1024]; + memset(buff, 0, 1024); int len = 0; - out.type = INTEGER; - int ret = elua_execute_script(escript, buff, len, NULL, NULL, &out); + out.buff = buff; + out.len = 1024; + out.type = STRING; + int ret = elua_execute_script(escript, data, len, NULL, NULL, &out); /* check */ - EXPECT_EQ(-1, ret); - EXPECT_STREQ(elua_get_last_error_string(L), "[elua_execute_script:1168] input or input_len is invaild."); + EXPECT_EQ(0, ret); + EXPECT_EQ(5, out.len); + EXPECT_EQ(STRING, out.type); + EXPECT_STREQ("hello", out.buff); } TEST(elua_execute_script, string_expected_but_nil) diff --git a/gtest/script/input_is_null.lua b/gtest/script/input_is_null.lua new file mode 100644 index 0000000..5e26eba --- /dev/null +++ b/gtest/script/input_is_null.lua @@ -0,0 +1 @@ +return 5,"hello"
\ No newline at end of file |
