patternMatchTest.cpp 2.3 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

9 10
#pragma GCC diagnostic ignored "-Werror=unused-function"

H
hjxilinx 已提交
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 50 51 52 53 54 55 56 57 58 59 60 61 62
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 已提交
63
  ret = patternMatch("abc%f_", str, 1, &info);  // pattern string is longe than the size
H
hjxilinx 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76
  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 已提交
77 78 79 80
  
  str = "carzero";
  ret = patternMatch("%o", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);
H
hjLiao 已提交
81 82 83 84
  
  str = "19";
  ret = patternMatch("%9", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);
H
hjxilinx 已提交
85
}