diff options
| author | 彭宣正 <[email protected]> | 2021-12-20 15:37:00 +0800 |
|---|---|---|
| committer | 彭宣正 <[email protected]> | 2021-12-20 15:37:00 +0800 |
| commit | 3488e3aba8008b0a3073a00e01332d872580779a (patch) | |
| tree | 2c816b82f35a95716dd0317c6a21307b6281f339 /gtest/gtest_get_weixinnum.cpp | |
| parent | 0dbf2e6957168a9f271881adf565918143f96586 (diff) | |
🧪 test(gtest. CI): 增加gtest用例,增加CPPCHECK,删除生成的可执行文件
Diffstat (limited to 'gtest/gtest_get_weixinnum.cpp')
| -rw-r--r-- | gtest/gtest_get_weixinnum.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/gtest/gtest_get_weixinnum.cpp b/gtest/gtest_get_weixinnum.cpp new file mode 100644 index 0000000..e7a30a2 --- /dev/null +++ b/gtest/gtest_get_weixinnum.cpp @@ -0,0 +1,119 @@ +#include <gtest/gtest.h> +#include "tsg_lua_interface.h" + +static char *get_file_to_buffer(const char *file, int *len) +{ + FILE *fp = fopen(file, "r"); + if (fp) + { + fseek(fp, 0, 2); + *len = ftell(fp); + fseek(fp, 0, 0); + if (*len <= 0) + { + fclose(fp); + return NULL; + } + char *buff = (char *)malloc((*len) + 1); + int num = fread(buff, 1, *len, fp); + if (num != 0) + { + buff[num] = 0; + *len = num - 1; + fclose(fp); + return buff; + } + free(buff); + fclose(fp); + } + return NULL; +} + +TEST(tsg_lua_get_weixinnum, exec_cache_script) +{ + tsg_lua_handle L = NULL; + int script_len; + int data_len; + char out[255]; + size_t out_len = 0; + size_t out_type = 0; + memset(out, 0, 255); + + L = tsg_lua_vm_create(); + const char *script = get_file_to_buffer("./script/handle_weixinnum.lua", &script_len); + int script_id = tsg_lua_cache_script(L, script, script_len); + const char *data = get_file_to_buffer("./script/weixin_id_ios_20200423_004.pcap", &data_len); + int ret = tsg_lua_cache_exec(L, script_id, data, data_len, out, &out_len, &out_type); + free((void *)data); + free((void *)script); + + EXPECT_EQ(0, ret); + EXPECT_EQ(10, out_len); + EXPECT_EQ(STRING, out_type); + EXPECT_STREQ("1955740780", out); +} + +TEST(tsg_lua_get_weixinnum, exec_cache_file) +{ + tsg_lua_handle L = NULL; + int data_len; + char out[255]; + size_t out_len = 0; + size_t out_type = 0; + + memset(out, 0, 255); + L = tsg_lua_vm_create(); + int script_id = tsg_lua_cache_script_file(L, "./script/handle_weixinnum.lua"); + const char *data = get_file_to_buffer("./script/weixin_id_ios_20200423_004.pcap", &data_len); + int ret = tsg_lua_cache_exec(L, script_id, data, data_len, out, &out_len, &out_type); + free((void *)data); + + EXPECT_EQ(0, ret); + EXPECT_EQ(10, out_len); + EXPECT_EQ(STRING, out_type); + EXPECT_STREQ("1955740780", out); +} + +TEST(tsg_lua_get_weixinnum, exec_script) +{ + tsg_lua_handle L = NULL; + int script_len; + int data_len; + char out[255]; + size_t out_len = 0; + size_t out_type = 0; + + memset(out, 0, 255); + L = tsg_lua_vm_create(); + const char *script = get_file_to_buffer("./script/handle_weixinnum.lua", &script_len); + const char *data = get_file_to_buffer("./script/weixin_id_ios_20200423_004.pcap", &data_len); + int ret = tsg_lua_exec(L, script, script_len, data, data_len, out, &out_len, &out_type); + free((void *)data); + free((void *)script); + + EXPECT_EQ(0, ret); + EXPECT_EQ(10, out_len); + EXPECT_EQ(STRING, out_type); + EXPECT_STREQ("1955740780", out); +} + +TEST(tsg_lua_get_weixinnum, exec_file) +{ + tsg_lua_handle L = NULL; + int data_len; + char out[255]; + size_t out_len = 0; + size_t out_type = 0; + + memset(out, 0, 255); + L = tsg_lua_vm_create(); + const char *script = "./script/handle_weixinnum.lua"; + const char *data = get_file_to_buffer("./script/weixin_id_ios_20200423_004.pcap", &data_len); + int ret = tsg_lua_exec_file(L, script, data, data_len, out, &out_len, &out_type); + free((void *)data); + + EXPECT_EQ(0, ret); + EXPECT_EQ(10, out_len); + EXPECT_EQ(STRING, out_type); + EXPECT_STREQ("1955740780", out); +}
\ No newline at end of file |
