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