diff options
Diffstat (limited to 'gtest')
| -rw-r--r-- | gtest/gtest_get_weixinnum.cpp | 8 | ||||
| -rw-r--r-- | gtest/gtest_lua_remove_cmd.cpp | 2 | ||||
| -rw-r--r-- | gtest/gtest_lua_timeout.cpp | 24 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_cache_exec.cpp | 10 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_exec_with_context.cpp | 50 | ||||
| -rw-r--r-- | gtest/gtest_tsg_lua_register_function.cpp | 46 |
6 files changed, 71 insertions, 69 deletions
diff --git a/gtest/gtest_get_weixinnum.cpp b/gtest/gtest_get_weixinnum.cpp index 630fa78..72a71b1 100644 --- a/gtest/gtest_get_weixinnum.cpp +++ b/gtest/gtest_get_weixinnum.cpp @@ -39,7 +39,7 @@ TEST(elua_get_weixinnum, exec_cache_script) struct elua_data output; output.len = 1024; output.type = STRING; - output.string = buff; + output.buff = buff; L = elua_create_vm(NULL); const char *script = get_file_to_buffer("./script/handle_weixinnum.lua", &script_len); @@ -52,7 +52,7 @@ TEST(elua_get_weixinnum, exec_cache_script) EXPECT_EQ(0, ret); EXPECT_EQ(10, output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ("1955740780", output.string); + EXPECT_STREQ("1955740780", output.buff); } TEST(elua_get_weixinnum, exec_cache_script_file) @@ -65,7 +65,7 @@ TEST(elua_get_weixinnum, exec_cache_script_file) struct elua_data output; output.len = 1024; output.type = STRING; - output.string = buff; + output.buff = buff; L = elua_create_vm(NULL); struct elua_script *escript = elua_cache_script_file(L, "./script/handle_weixinnum.lua", 0); const char *data = get_file_to_buffer("./script/weixin_id_ios_20200423_004.pcap", &data_len); @@ -75,5 +75,5 @@ TEST(elua_get_weixinnum, exec_cache_script_file) EXPECT_EQ(0, ret); EXPECT_EQ(10, output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ("1955740780", output.string); + EXPECT_STREQ("1955740780", output.buff); }
\ No newline at end of file diff --git a/gtest/gtest_lua_remove_cmd.cpp b/gtest/gtest_lua_remove_cmd.cpp index 2cc28df..6d095c3 100644 --- a/gtest/gtest_lua_remove_cmd.cpp +++ b/gtest/gtest_lua_remove_cmd.cpp @@ -9,7 +9,7 @@ TEST(lua_remove_cmd, normal) elua_data out; out.type = STRING; out.integer = 1024; - out.string = buff; + out.buff = buff; elua_remove_function(L, "print"); diff --git a/gtest/gtest_lua_timeout.cpp b/gtest/gtest_lua_timeout.cpp index a5ecf9c..21a89c1 100644 --- a/gtest/gtest_lua_timeout.cpp +++ b/gtest/gtest_lua_timeout.cpp @@ -36,7 +36,7 @@ TEST(elua_time_out, lua) elua_data out; out.type = STRING; out.integer = 1024; - out.string = (char *)calloc(1, 1024); + out.buff = (char *)calloc(1, 1024); long tt, elapsed; int ret = 0; @@ -45,7 +45,7 @@ TEST(elua_time_out, lua) ret = elua_execute_script(escript, buff, len, (void *)ud, NULL, &out); EXPECT_EQ(ret, -1); EXPECT_STREQ(elua_get_last_error_string(L), "[elua_call_script:1074] Lua script killed by time out.."); - bzero(out.string, 1024); + bzero(out.buff, 1024); struct elua_script *escript0 = elua_cache_script_file(L, script, 0); tt = mstime(); @@ -55,18 +55,18 @@ TEST(elua_time_out, lua) EXPECT_LE(10, elapsed); EXPECT_EQ(len, out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(buff, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(buff, out.buff); + bzero(out.buff, 1024); ret = elua_execute_script(escript, buff, len, (void *)ud, NULL, &out); EXPECT_EQ(ret, -1); EXPECT_STREQ(elua_get_last_error_string(L), "[elua_call_script:1074] Lua script killed by time out.."); - bzero(out.string, 1024); + bzero(out.buff, 1024); elua_cleanup_script(escript); elua_cleanup_script(escript0); elua_destroy_vm(L); - free(out.string); + free(out.buff); } TEST(elua_time_out, c) @@ -82,7 +82,7 @@ TEST(elua_time_out, c) struct elua_data out; out.type = STRING; out.integer = 1024; - out.string = (char *)calloc(1, 1024); + out.buff = (char *)calloc(1, 1024); long tt, elapsed; elua_register_cbinding(L, NULL, "set_count", count_set); @@ -94,7 +94,7 @@ TEST(elua_time_out, c) EXPECT_STREQ(elua_get_last_error_string(L), "[elua_call_script:1074] Lua script killed by time out.."); EXPECT_LE(10, elapsed); EXPECT_EQ(10000000, count); - bzero(out.string, 1024); + bzero(out.buff, 1024); struct elua_script *escript0 = elua_cache_script_file(L, script, 0); tt = mstime(); @@ -104,9 +104,9 @@ TEST(elua_time_out, c) EXPECT_LE(10, elapsed); EXPECT_EQ(len, out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(buff, out.string); + EXPECT_STREQ(buff, out.buff); EXPECT_EQ(10000000, count); - bzero(out.string, 1024); + bzero(out.buff, 1024); tt = mstime(); ret = elua_execute_script(escript, buff, len, (void *)&count, NULL, &out); @@ -115,10 +115,10 @@ TEST(elua_time_out, c) EXPECT_STREQ(elua_get_last_error_string(L), "[elua_call_script:1074] Lua script killed by time out.."); EXPECT_LE(10, elapsed); EXPECT_EQ(10000000, count); - bzero(out.string, 1024); + bzero(out.buff, 1024); elua_cleanup_script(escript0); elua_cleanup_script(escript); elua_destroy_vm(L); - free(out.string); + free(out.buff); }
\ No newline at end of file diff --git a/gtest/gtest_tsg_lua_cache_exec.cpp b/gtest/gtest_tsg_lua_cache_exec.cpp index ed1099c..7e75c68 100644 --- a/gtest/gtest_tsg_lua_cache_exec.cpp +++ b/gtest/gtest_tsg_lua_cache_exec.cpp @@ -18,9 +18,10 @@ TEST(elua_execute_script, normal_return_string) int len = strlen(data); struct elua_data out; char buff[1024]; + memset(buff, 0, 1024); out.type = STRING; out.integer = 1204; - out.string = buff; + out.buff = buff; struct elua_script *escript = elua_cache_script_file(L, script, 0); int ret = elua_execute_script(escript, data, len, NULL, NULL, &out); @@ -29,7 +30,7 @@ TEST(elua_execute_script, normal_return_string) EXPECT_EQ(0, ret); EXPECT_EQ(11, out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ("hello world", out.string); + EXPECT_STREQ("hello world", out.buff); } TEST(elua_execute_script, normal_return_boolean) @@ -286,7 +287,8 @@ TEST(elua_execute_script, normal_return_string_sharp) out.type = STRING; out.len = 1024; char buff[1024]; - out.string = buff; + memset(buff, 0, 1024); + out.buff = buff; int len = strlen(data); int ret = elua_execute_script(escript, data, len, NULL, NULL, &out); @@ -294,5 +296,5 @@ TEST(elua_execute_script, normal_return_string_sharp) /* check */ EXPECT_EQ(0, ret); EXPECT_EQ(len, out.len); - EXPECT_STREQ(data, out.string); + EXPECT_STREQ(data, out.buff); }
\ No newline at end of file diff --git a/gtest/gtest_tsg_lua_exec_with_context.cpp b/gtest/gtest_tsg_lua_exec_with_context.cpp index dc52575..ca9acca 100644 --- a/gtest/gtest_tsg_lua_exec_with_context.cpp +++ b/gtest/gtest_tsg_lua_exec_with_context.cpp @@ -24,7 +24,7 @@ int get_userdata(elua_vm *L) void *ud = elua_get_execute_userdata(L); struct elua_data edata; edata.type = STRING; - edata.string = (char *)ud; + edata.buff = (char *)ud; edata.len = strlen((char *)ud); elua_cbinding_set_output_params(L, &edata, 1); return 1; @@ -41,7 +41,7 @@ TEST(lua_execute_file, normal) struct elua_data out; out.type = STRING; out.len = 1024; - out.string = (char *)calloc(1, 1024); + out.buff = (char *)calloc(1, 1024); elua_register_cbinding(L, "get", "get_userdata", get_userdata); elua_context *context = NULL; @@ -52,8 +52,8 @@ TEST(lua_execute_file, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); ud = "hello lua."; ret = elua_execute_script(escript, input, len, (void *)ud, context, &out); @@ -61,8 +61,8 @@ TEST(lua_execute_file, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); elua_context *context2 = NULL; context2 = elua_create_context(L, "context"); @@ -71,13 +71,13 @@ TEST(lua_execute_file, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); elua_destroy_context(context); elua_destroy_context(context2); elua_destroy_vm(L); - free(out.string); + free(out.buff); } TEST(lua_exec, normal) @@ -90,7 +90,7 @@ TEST(lua_exec, normal) struct elua_data out; out.type = STRING; out.integer = 1024; - out.string = (char *)calloc(1, 1024); + out.buff = (char *)calloc(1, 1024); char *script = get_script_buffer("./script/exec_with_context.lua"); int script_len = strlen(script); elua_script *escript = elua_cache_script(L, script, script_len, 0); @@ -103,8 +103,8 @@ TEST(lua_exec, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); ud = "hello lua."; ret = elua_execute_script(escript, input, len, (void *)ud, context, &out); @@ -112,8 +112,8 @@ TEST(lua_exec, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); elua_context *context2 = NULL; context2 = elua_create_context(L, "context"); @@ -122,13 +122,13 @@ TEST(lua_exec, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); elua_destroy_context(context); elua_destroy_context(context2); elua_destroy_vm(L); - free(out.string); + free(out.buff); } TEST(elua_execute_script, normal) @@ -141,7 +141,7 @@ TEST(elua_execute_script, normal) struct elua_data out; out.type = STRING; out.integer = 1024; - out.string = (char *)calloc(1, 1024); + out.buff = (char *)calloc(1, 1024); const char *script = get_script_buffer("./script/exec_with_context.lua"); struct elua_script *escript = elua_cache_script(L, script, strlen(script), 0); @@ -153,8 +153,8 @@ TEST(elua_execute_script, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); ud = "hello lua."; ret = elua_execute_script(escript, input, len, (void *)ud, context, &out); @@ -162,8 +162,8 @@ TEST(elua_execute_script, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); elua_context *context2 = NULL; context2 = elua_create_context(L, "context"); @@ -172,11 +172,11 @@ TEST(elua_execute_script, normal) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(str), out.len); EXPECT_EQ(STRING, out.type); - EXPECT_STREQ(str, out.string); - bzero(out.string, 1024); + EXPECT_STREQ(str, out.buff); + bzero(out.buff, 1024); elua_destroy_context(context); elua_destroy_context(context2); elua_destroy_vm(L); - free(out.string); + free(out.buff); } diff --git a/gtest/gtest_tsg_lua_register_function.cpp b/gtest/gtest_tsg_lua_register_function.cpp index fc31d65..b826434 100644 --- a/gtest/gtest_tsg_lua_register_function.cpp +++ b/gtest/gtest_tsg_lua_register_function.cpp @@ -10,7 +10,7 @@ int get_hello(elua_vm *L) { struct elua_data ldata; ldata.type = STRING; - ldata.string = (char *)"hello"; + ldata.buff = (char *)"hello"; ldata.len = 5; elua_cbinding_set_output_params(L, &ldata, 1); return 1; @@ -41,10 +41,10 @@ int set_world(elua_vm *L) struct elua_data retvalue; retvalue.type = STRING; retvalue.len = argv[0].len + argv[1].len + 2; - retvalue.string = (char *)calloc(1, retvalue.len); - sprintf(retvalue.string, "%s %s.", argv[0].string, argv[1].string); + retvalue.buff = (char *)calloc(1, retvalue.len); + sprintf(retvalue.buff, "%s %s.", argv[0].buff, argv[1].buff); elua_cbinding_set_output_params(L, &retvalue, 1); - free(retvalue.string); + free(retvalue.buff); return 1; } @@ -64,9 +64,9 @@ int get_req_header(elua_vm *L) for (int i = 0; i < (int)(sizeof(key) / sizeof(key[0])); i++) { ekey.len = strlen(key[i]); - ekey.string = (char *)key[i]; + ekey.buff = (char *)key[i]; evalue.len = strlen(value[i]); - evalue.string = (char *)value[i]; + evalue.buff = (char *)value[i]; elua_add_table(etab, &ekey, &evalue); } @@ -94,9 +94,9 @@ int get_rsp_header(elua_vm *L) for (int i = 0; i < (int)(sizeof(key) / sizeof(key[0])); i++) { ekey.len = strlen(key[i]); - ekey.string = (char *)key[i]; + ekey.buff = (char *)key[i]; evalue.len = strlen(value[i]); - evalue.string = (char *)value[i]; + evalue.buff = (char *)value[i]; elua_add_table(etab, &ekey, &evalue); } @@ -148,7 +148,7 @@ int set_repeat(elua_vm *L) elua_cbinding_set_output_params(L, &retvalue, 1); retvalue.type = STRING; retvalue.len = 5; - retvalue.string = (char *)"hello"; + retvalue.buff = (char *)"hello"; elua_cbinding_set_output_params(L, &retvalue, 1); return 1; @@ -167,7 +167,7 @@ int set_multi_type_retvalue(elua_vm *L) ekey.type = STRING; evalue.type = INTEGER; ekey.len = 5; - ekey.string = buff; + ekey.buff = buff; evalue.len = sizeof(int); evalue.integer = i; elua_add_table(etab, &ekey, &evalue); @@ -178,7 +178,7 @@ int set_multi_type_retvalue(elua_vm *L) ekey.len = sizeof(int); ekey.integer = i; evalue.len = 5; - evalue.string = buff; + evalue.buff = buff; elua_add_table(etab, &ekey, &evalue); } @@ -207,7 +207,7 @@ TEST(elua_register_cbinding, normal) struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data output; output.type = STRING; - output.string = buff; + output.buff = buff; output.len = 1024; memset(buff, 0, 1024); int ret = elua_execute_script(escript, "hello", strlen("hello"), NULL, NULL, &output); @@ -215,7 +215,7 @@ TEST(elua_register_cbinding, normal) EXPECT_EQ(0, ret); EXPECT_EQ(12, output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ("hello world.", output.string); + EXPECT_STREQ("hello world.", output.buff); elua_destroy_vm(L); } @@ -233,7 +233,7 @@ TEST(elua_register_cbinding, get_header) struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data output; output.type = STRING; - output.string = buff; + output.buff = buff; output.len = 1024; memset(buff, 0, 1024); int ret = elua_execute_script(escript, "hello", strlen("hello"), NULL, NULL, &output); @@ -242,7 +242,7 @@ TEST(elua_register_cbinding, get_header) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(result), output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ(result, output.string); + EXPECT_STREQ(result, output.buff); elua_destroy_vm(L); } @@ -261,7 +261,7 @@ TEST(elua_register_cbinding, other) struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data output; output.type = STRING; - output.string = buff; + output.buff = buff; output.len = 1024; memset(buff, 0, 1024); int ret = elua_execute_script(escript, "hello", strlen("hello"), NULL, NULL, &output); @@ -271,7 +271,7 @@ TEST(elua_register_cbinding, other) EXPECT_EQ(0, ret); EXPECT_EQ(strlen(result), output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ(result, output.string); + EXPECT_STREQ(result, output.buff); elua_destroy_vm(L); } @@ -289,7 +289,7 @@ TEST(elua_register_cbinding, invalid_args) struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data output; output.type = STRING; - output.string = buff; + output.buff = buff; output.len = 1024; memset(buff, 0, 1024); int ret = elua_execute_script(escript, "hello", strlen("hello"), NULL, NULL, &output); @@ -297,7 +297,7 @@ TEST(elua_register_cbinding, invalid_args) EXPECT_EQ(0, ret); EXPECT_EQ(12, output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ("hello world.", output.string); + EXPECT_STREQ("hello world.", output.buff); elua_destroy_vm(L); } @@ -314,7 +314,7 @@ TEST(elua_register_cbinding, set_repeat) struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data output; output.type = STRING; - output.string = buff; + output.buff = buff; output.len = 1024; memset(buff, 0, 1024); int ret = elua_execute_script(escript, "hello", strlen("hello"), NULL, NULL, &output); @@ -322,7 +322,7 @@ TEST(elua_register_cbinding, set_repeat) EXPECT_EQ(0, ret); EXPECT_EQ(5, output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ("hello", output.string); + EXPECT_STREQ("hello", output.buff); elua_destroy_vm(L); } @@ -339,7 +339,7 @@ TEST(elua_register_cbinding, get_value) struct elua_script *escript = elua_cache_script_file(L, script, 0); struct elua_data output; output.type = STRING; - output.string = buff; + output.buff = buff; output.len = 1024; memset(buff, 0, 1024); int ret = elua_execute_script(escript, "hello", strlen("hello"), NULL, NULL, &output); @@ -348,6 +348,6 @@ TEST(elua_register_cbinding, get_value) printf(elua_get_last_error_string(L)); EXPECT_EQ(47, output.len); EXPECT_EQ(STRING, output.type); - EXPECT_STREQ("0:test0,1:test1,2:test2,test1:1,test0:0,test2:2", output.string); + EXPECT_STREQ("0:test0,1:test1,2:test2,test1:1,test0:0,test2:2", output.buff); elua_destroy_vm(L); }
\ No newline at end of file |
