46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#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();
|
|
}
|
|
|