MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_regex-t.cc
1 /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 // First include (the generated) my_config.h, to get correct platform defines.
17 #include "my_config.h"
18 #include <gtest/gtest.h>
19 
20 #include "my_regex.h"
21 
22 /*
23  Thist is just a *very* basic test that things compile/link and execute.
24  The test data is taken from the first few lines in regex/tests.
25  For a full test suite, see regex/main.c which parses test input
26  and tests expected sucess/failure with basic/extended regexps etc. etc.
27  */
28 
29 namespace my_regex_unittest {
30 
31 const int NSUBS= 10;
32 
33 class RegexTest : public ::testing::Test
34 {
35 protected:
36  RegexTest()
37  {
38  memset(&re, 0, sizeof(re));
39  }
40  static void TearDownTestCase()
41  {
42  my_regex_end();
43  }
44 
45  my_regmatch_t subs[NSUBS];
46  my_regex_t re;
47 };
48 
50 {
51  const char* pattern; // Column 1 in regex/tests.
52  const int cflags; // Column 2 in regex/tests.
53  const char* input; // Column 3 in regex/tests.
54 };
55 
56 Re_test_data basic_data[]=
57 {
58  { "a", MY_REG_BASIC, "a" },
59  { "abc", MY_REG_BASIC, "abc" },
60  { "abc|de", MY_REG_EXTENDED, "abc" },
61  { "a|b|c", MY_REG_EXTENDED, "abc" },
62  { NULL, 0, NULL }
63 };
64 
65 TEST_F(RegexTest, BasicTest)
66 {
67  for (int ix=0; basic_data[ix].pattern; ++ix)
68  {
69  EXPECT_EQ(0, my_regcomp(&re,
70  basic_data[ix].pattern,
71  basic_data[ix].cflags,
72  &my_charset_latin1));
73 
74  int err= my_regexec(&re, basic_data[ix].input, NSUBS, subs, 0);
75  EXPECT_EQ(0, err)
76  << "my_regexec returned " << err
77  << " for pattern '" << basic_data[ix].pattern << "'"
78  << " with input '" << basic_data[ix].input << "'";
79  my_regfree(&re);
80  }
81 }
82 
83 } // namespace