Home | History | Annotate | Download | only in tests
      1 /**
      2  * @file glob_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 "glob_filter.h"
     16 
     17 using 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 
     26 int main()
     27 {
     28 	glob_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 	glob_filter f2("foo", "");
     38 	check(f2, "foo", true);
     39 	check(f2, "foo1", false);
     40 	check(f2, "foo/foo", false);
     41 
     42 	glob_filter f3("", "foo");
     43 	check(f3, "foo", false);
     44 	check(f3, "foo1", true);
     45 	check(f3, "foo/foo", true);
     46 
     47 	glob_filter f4("foo", "foo");
     48 	check(f4, "foo", false);
     49 	check(f4, "foo1", false);
     50 	check(f4, "foo/foo", false);
     51 
     52 	return EXIT_SUCCESS;
     53 }
     54