patternMatchTest.cpp 2.4 KB
Newer Older
H
hjxilinx 已提交
1 2 3 4 5
#include <gtest/gtest.h>
#include <sys/time.h>
#include <cassert>
#include <iostream>

H
Haojun Liao 已提交
6
#include "qAggMain.h"
7
#include "tcompare.h"
H
hjxilinx 已提交
8

S
Shengliang Guan 已提交
9
#pragma GCC diagnostic push
S
Shengliang Guan 已提交
10 11
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
12

H
hjxilinx 已提交
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
TEST(testCase, patternMatchTest) {
  SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;

  const char* str = "abcdef";
  int32_t ret = patternMatch("a%b%", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "tm01";
  ret = patternMatch("tm__", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "tkm1";
  ret = patternMatch("t%m1", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "tkm1";
  ret = patternMatch("%m1", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "";
  ret = patternMatch("%_", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);

  str = "1";
  ret = patternMatch("%__", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);

  str = "";
  ret = patternMatch("%", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = " ";
  ret = patternMatch("_", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "!";
  ret = patternMatch("%_", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefg";
  ret = patternMatch("abc%fg", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("abc%fg", str, 7, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("abc%f_", str, 6, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);

  str = "abcdefgabcdeju";
H
hjxilinx 已提交
65
  ret = patternMatch("abc%f_", str, 1, &info);  // pattern string is longe than the size
H
hjxilinx 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78
  EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("ab", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("a%", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("a__", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH);
H
hjxilinx 已提交
79 80 81 82
  
  str = "carzero";
  ret = patternMatch("%o", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);
H
hjLiao 已提交
83 84 85 86
  
  str = "19";
  ret = patternMatch("%9", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);
H
hjxilinx 已提交
87
}
S
Shengliang Guan 已提交
88 89

#pragma GCC diagnostic pop