1/** 2 * @file path_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 "path_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 path_filter f1("foo,*bar", "foobar"); 29 check(f1, "foo/barfoobar", true); 30 check(f1, "foo/bar", true); 31 check(f1, "/foo/foobar/foo", false); 32 check(f1, "fooobar1", false); 33 check(f1, "foo1", false); 34 check(f1, "foobar", false); 35 check(f1, "bar1", false); 36 37 path_filter f2("foo", ""); 38 check(f2, "foo", true); 39 check(f2, "foo1", false); 40 check(f2, "foo/foo", true); 41 42 path_filter f3("", "foo"); 43 check(f3, "foo", false); 44 check(f3, "foo1", true); 45 check(f3, "foo/foo", false); 46 47 path_filter f4("foo", "foo"); 48 check(f4, "foo", false); 49 check(f4, "foo1", false); 50 check(f4, "foo/foo", false); 51 52 path_filter f5("*foo*", "*bar*"); 53 check(f5, "foo", true); 54 check(f5, "bar", false); 55 check(f5, "foobar", false); 56 check(f5, "barfoo", false); 57 check(f5, "foo/bar", false); 58 59 path_filter f6(" foo,bar", "bar "); 60 check(f6, "foo", false); 61 check(f6, "foo ", false); 62 check(f6, " foo", true); 63 check(f6, "bar", true); 64 check(f6, "bar ", false); 65 check(f6, " bar", false); 66 check(f6, "foo ", false); 67 check(f6, "foo/ bar", false); 68 69 path_filter f7(".", ""); 70 check(f7, ".", true); 71 // a bit surprising but right IMHO, our implementation use successive 72 // dirname(input) to check vs the included path and 73 // dirname("foo") == "." so all relative path input match a "." 74 // included filter 75 check(f7, "foo", true); 76 77 return EXIT_SUCCESS; 78} 79