Compile fixes
[ACE_TAO.git] / ACE / tests / Wild_Match_Test.cpp
bloba4af62e0382708f2f31e3d0fd5b2495a32057391
1 #include "ace/ACE.h"
2 #include "ace/Log_Msg.h"
3 #include "test_config.h"
5 bool match (const char *str, const char *pat, bool cs = true, bool cc = false)
7 bool const result = ACE::wild_match (str, pat, cs, cc);
8 ACE_DEBUG ((LM_DEBUG, "string {%C} %C pattern {%C}\t%C\t%C\n", str,
9 (result ? "matches" : "does not match"), pat,
10 (cs ? "" : "case-insensitive"), (cc ? "char classes" : "")));
11 return result;
14 int run_main (int, ACE_TCHAR *[])
16 ACE_START_TEST (ACE_TEXT ("Wild_Match_Test"));
18 bool ok = true;
19 ok &= match ("foo_baz_bar", "foo*bar");
20 ok &= match ("lksfj;laskf;jbaz", "*baz");
21 ok &= !match ("abc", "abc?");
22 ok &= match ("simple", "simple");
23 ok &= !match ("not so simple", "simple");
24 ok &= match ("AbC", "abc", false);
25 ok &= match ("*\\", "\\*\\\\");
26 ok &= match ("Nonwild[foo]", "*[foo]");
27 ok &= match ("Apple][", "[zxya]p*[]125]\\[", false, true);
28 ok &= match ("[!]", "[][!][][!][][!]", true, true);
29 ok &= match ("ace", "[a-e][a-e][a-e]", true, true);
30 ok &= match ("--x", "[-1][2-][!-]", true, true);
32 ok &= !match ("C2", "[!C]?", true, true);
33 ok &= match ("D1", "[!C]?", true, true);
34 ok &= match ("D2", "[!C]?", true, true);
36 ok &= !match ("C2", "?[!2]", true, true);
37 ok &= match ("C1", "?[!2]", true, true);
38 ok &= !match (0, "[!C]?", true, true);
40 // invalid classes: results are undefined but we shouldn't crash
41 match ("foo", "f[o-a]o", true, true);
42 match ("bar", "[f-", true, true);
43 match ("bar", "[z", true, true);
44 match ("bar", "[]x", true, true);
45 match ("foo", "[f-f]oo", true, true);
47 if (!ok)
49 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Wild_Match_Test failed\n")));
52 ACE_END_TEST;
53 return ok ? 0 : 1;