使用pcre2替代glib从中的regex进行替换。
This commit is contained in:
45
plugin/business/pangu-http/test_pattern_replace.cpp
Normal file
45
plugin/business/pangu-http/test_pattern_replace.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "pattern_replace.h"
|
||||
|
||||
#include <sys/types.h>//fstat
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <gtest/gtest.h>
|
||||
TEST(PatternReplace, Pure)
|
||||
{
|
||||
const char* filename="./test_data/facebook_index.html";
|
||||
const char* exec_para="zone=http_resp_body;substitute=/添加手机号/Mobile\bPhone";
|
||||
size_t n_got_rule=0;
|
||||
struct replace_rule rules[16];
|
||||
n_got_rule=format_replace_rule(exec_para, rules, sizeof(rules)/sizeof(rules[0]));
|
||||
EXPECT_EQ(n_got_rule, 1);
|
||||
|
||||
FILE* fp=NULL;
|
||||
struct stat file_info;
|
||||
stat(filename, &file_info);
|
||||
size_t file_size=file_info.st_size;
|
||||
|
||||
fp=fopen(filename,"r");
|
||||
ASSERT_FALSE(fp==NULL);
|
||||
if(fp==NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
char* file_buff=(char*)malloc(file_size);
|
||||
fread(file_buff,1,file_size,fp);
|
||||
fclose(fp);
|
||||
|
||||
struct evbuffer* output=NULL;
|
||||
output=execute_replace_rule(file_buff, file_size, kZoneResponseBody, rules,n_got_rule);
|
||||
EXPECT_FALSE(output==NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user