1 /**
2 * @file comma_list_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 "comma_list.h"
16
17 using namespace std;
18
19 #define check(clist, val, result) \
20 if (clist.match(val) != result) { \
21 cerr << "\"" << #val << "\" matched with " #clist \
22 << " did not return " #result << endl; \
23 exit(EXIT_FAILURE); \
24 }
25
main()26 int main()
27 {
28 comma_list<int> c1;
29
30 check(c1, 1, true);
31
32 c1.set("2");
33
34 check(c1, 2, true);
35 check(c1, 3, false);
36
37 c1.set("3");
38
39 check(c1, 2, false);
40 check(c1, 3, true);
41
42 c1.set("2,3");
43
44 check(c1, 2, true);
45 check(c1, 3, true);
46 check(c1, 4, false);
47
48 c1.set("all");
49
50 check(c1, 2, true);
51 check(c1, 4, true);
52 check(c1, 5, true);
53
54 comma_list<int> c2;
55
56 c2.set("6,all");
57
58 check(c2, 4, true);
59 check(c2, 0, true);
60
61 c2.set("all,6");
62
63 check(c2, 4, true);
64 check(c2, 0, true);
65
66 c2.set("10");
67 check(c2, 10, true);
68 check(c2, 11, false);
69 return EXIT_SUCCESS;
70 }
71