File: Wild_Match_Test.cpp

package info (click to toggle)
ace 6.0.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,368 kB
  • sloc: cpp: 341,826; perl: 30,850; ansic: 20,952; makefile: 10,144; sh: 4,744; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; csh: 48; tcl: 5
file content (49 lines) | stat: -rw-r--r-- 1,923 bytes parent folder | download
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;
}