MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
like_range-t.cc
1 /* Copyright (c) 2010, 2012, 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 St, 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_global.h>
21 #include <my_sys.h>
22 
23 namespace like_range_unittest {
24 
25 /*
26  Test that like_range() returns well-formed results.
27 */
28 static void
29 test_like_range_for_charset(CHARSET_INFO *cs, const char *src, size_t src_len)
30 {
31  char min_str[32], max_str[32];
32  size_t min_len, max_len, min_well_formed_len, max_well_formed_len;
33  int error= 0;
34 
35  cs->coll->like_range(cs, src, src_len, '\\', '_', '%',
36  sizeof(min_str), min_str, max_str, &min_len, &max_len);
37  // diag("min_len=%d\tmax_len=%d\t%s", (int) min_len, (int) max_len, cs->name);
38  min_well_formed_len= cs->cset->well_formed_len(cs,
39  min_str, min_str + min_len,
40  10000, &error);
41  max_well_formed_len= cs->cset->well_formed_len(cs,
42  max_str, max_str + max_len,
43  10000, &error);
44  EXPECT_EQ(min_len, min_well_formed_len)
45  << "Bad min_str: min_well_formed_len=" << min_well_formed_len
46  << " min_str[" << min_well_formed_len << "]="
47  << (uchar) min_str[min_well_formed_len];
48  EXPECT_EQ(max_len, max_well_formed_len)
49  << "Bad max_str: max_well_formed_len=" << max_well_formed_len
50  << " max_str[" << max_well_formed_len << "]="
51  << (uchar) max_str[max_well_formed_len];
52 }
53 
54 
55 static CHARSET_INFO *charset_list[]=
56 {
57 #ifdef HAVE_CHARSET_big5
58  &my_charset_big5_chinese_ci,
59  &my_charset_big5_bin,
60 #endif
61 #ifdef HAVE_CHARSET_euckr
62  &my_charset_euckr_korean_ci,
63  &my_charset_euckr_bin,
64 #endif
65 #ifdef HAVE_CHARSET_gb2312
66  &my_charset_gb2312_chinese_ci,
67  &my_charset_gb2312_bin,
68 #endif
69 #ifdef HAVE_CHARSET_gbk
70  &my_charset_gbk_chinese_ci,
71  &my_charset_gbk_bin,
72 #endif
73 #ifdef HAVE_CHARSET_latin1
74  &my_charset_latin1,
75  &my_charset_latin1_bin,
76 #endif
77 #ifdef HAVE_CHARSET_sjis
78  &my_charset_sjis_japanese_ci,
79  &my_charset_sjis_bin,
80 #endif
81 #ifdef HAVE_CHARSET_tis620
82  &my_charset_tis620_thai_ci,
83  &my_charset_tis620_bin,
84 #endif
85 #ifdef HAVE_CHARSET_ujis
86  &my_charset_ujis_japanese_ci,
87  &my_charset_ujis_bin,
88 #endif
89 #ifdef HAVE_CHARSET_utf8
90  &my_charset_utf8_general_ci,
91  &my_charset_utf8_unicode_ci,
92  &my_charset_utf8_bin,
93 #endif
94 };
95 
96 #if defined(GTEST_HAS_PARAM_TEST)
97 
98 class LikeRangeTest : public ::testing::TestWithParam<CHARSET_INFO*>
99 {
100 protected:
101  virtual void SetUp()
102  {
103  m_charset= GetParam();
104  }
105  CHARSET_INFO *m_charset;
106 };
107 
108 INSTANTIATE_TEST_CASE_P(Foo1, LikeRangeTest,
109  ::testing::ValuesIn(charset_list));
110 
111 
112 TEST_P(LikeRangeTest, TestLikeRange)
113 {
114  test_like_range_for_charset(m_charset, "abc%", 4);
115 }
116 
117 #endif
118 
119 }