1/**
2 * @file string_filter_tests.cpp
3 *
4 * @remark Copyright 2003 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon
8 * @author Philippe Elie
9 */
10
11#include <stdlib.h>
12
13#include <iostream>
14
15#include "string_filter.h"
16
17using namespace std;
18
19#define check(filter, str, result) \
20	if (filter.match(str) != result) { \
21		cerr << "\"" << str << "\" matched with " #filter \
22		     << " did not return " #result << endl; \
23		exit(EXIT_FAILURE); \
24	}
25
26int main()
27{
28	string_filter f1;
29	check(f1, "", true);
30	check(f1, "ok", true);
31
32	string_filter f2("ok", "");
33	check(f2, "ok", true);
34	check(f2, "no", false);
35
36	string_filter f3("", "no");
37	check(f3, "ok", true);
38	check(f3, "no", false);
39
40	string_filter f4("ok,ok2,", "");
41	check(f4, "ok", true);
42	check(f4, "ok2", true);
43	check(f4, "no", false);
44
45	string_filter f5("ok,ok2", "no,no2");
46	check(f5, "ok", true);
47	check(f5, "ok2", true);
48	check(f5, "no", false);
49	check(f5, "no2", false);
50
51	vector<string> v1;
52	vector<string> v2;
53
54	string_filter f6(v1, v2);
55	check(f6, "", true);
56	check(f6, "ok", true);
57
58	v1.push_back("ok");
59	v1.push_back("ok2");
60
61	string_filter f7(v1, v2);
62	check(f7, "ok", true);
63	check(f7, "ok2", true);
64	check(f7, "no", false);
65
66	v1.clear();
67
68	v2.push_back("no");
69	v2.push_back("no2");
70
71	string_filter f8(v1, v2);
72	check(f8, "ok", true);
73	check(f8, "no", false);
74	check(f8, "no", false);
75
76	v1.push_back("ok");
77	v1.push_back("ok2");
78
79	string_filter f9(v1, v2);
80	check(f9, "ok", true);
81	check(f9, "no2", false);
82
83	string_filter f10(" foo ", "");
84	check(f10, " foo ", true);
85	check(f10, " foo", false);
86	check(f10, "foo ", false);
87	check(f10, "foo", false);
88
89	return EXIT_SUCCESS;
90}
91