1 #ifndef TEST_BASE_H
2 #define TEST_BASE_H
3 
4 #include <stdio.h>
5 #include <string>
6 #include <stdint.h>
7 
8 using namespace std;
9 class ACTestBase {
10 public:
ACTestBase(const char * name)11     ACTestBase(const char* name) :_banner(name) {}
PrintBanner()12     virtual void PrintBanner() {
13         fprintf(stdout, "\n===== %s ====\n", _banner.c_str());
14     }
15 
16     virtual bool Run() = 0;
17 private:
18     string _banner;
19 };
20 
21 typedef std::pair<const char*, int> StrInfo;
22 class BigFileTester {
23 public:
24     BigFileTester(const char* filepath);
~BigFileTester()25     virtual ~BigFileTester() { Cleanup(); }
26 
27     bool Run();
28 
29 protected:
30     virtual buf_header_t* PM_Create(const char** strv, uint32_t* strlenv,
31                                     uint32_t vect_len) = 0;
32     virtual void PM_Free(buf_header_t*) = 0;
33     virtual bool Run_Helper(buf_header_t* PM) = 0;
34 
35     // Return true if the '\0' is valid char of a string.
Str_C_Style()36     virtual bool Str_C_Style() { return true; }
37 
38     bool GenerateKeys();
39     void Cleanup();
40     void PrintStr(FILE*, const char* str, int len);
41 
42 protected:
43     const char* _filepath;
44     int _fd;
45     vector<StrInfo> _keys;
46     char* _msg;
47     int _msg_len;
48     int _key_num;     // number of strings in dictionary
49     int _chunk_sz;
50     int _chunk_num;
51 
52     int _max_key_num;
53     int _key_min_len;
54     int _key_max_len;
55 };
56 
57 extern bool Run_AC_Simple_Test();
58 extern bool Run_AC_Aggressive_Test(const vector<const char*>& files);
59 
60 #endif
61