1 /* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 /* See http://code.google.com/p/googletest/wiki/Primer */
24
25 // First include (the generated) my_config.h, to get correct platform defines.
26 #include "my_config.h"
27
28 #include <gtest/gtest.h>
29
30 #include "univ.i"
31
32 #include "ha_prototypes.h"
33
34 namespace innodb_ha_innodb_unittest {
35
36 /* test innobase_convert_name() */
TEST(hainnodb,innobaseconvertname)37 TEST(hainnodb, innobaseconvertname)
38 {
39 char buf[64];
40 struct {
41 const char* in;
42 ulint in_len;
43 ulint buf_size;
44 const char* buf_expected;
45 } test_data[] = {
46 /* the commented tests below fail, please fix
47 innobase_convert_name() */
48 {"abcd", 4, sizeof(buf), "`abcd`"},
49 {"abcd", 4, 7, "`abcd`"},
50 {"abcd", 4, 6, "`abcd`"},
51 //{"abcd", 4, 5, "`abc`"},
52 //{"abcd", 4, 4, "`ab`"},
53
54 {"ab@0060cd", 9, sizeof(buf), "`ab``cd`"},
55 {"ab@0060cd", 9, 9, "`ab``cd`"},
56 {"ab@0060cd", 9, 8, "`ab``cd`"},
57 {"ab@0060cd", 9, 7, "`ab``cd"},
58 //{"ab@0060cd", 9, 6, "`ab``c"},
59 //{"ab@0060cd", 9, 5, "`ab``"},
60 //{"ab@0060cd", 9, 4, "`ab`"},
61
62 //{"ab`cd", 5, sizeof(buf), "`#mysql50#ab``cd`"},
63 //{"ab`cd", 5, 17, "`#mysql50#ab``cd`"},
64 //{"ab`cd", 5, 16, "`#mysql50#ab``c`"},
65 //{"ab`cd", 5, 15, "`#mysql50#ab```"},
66 //{"ab`cd", 5, 14, "`#mysql50#ab`"},
67 //{"ab`cd", 5, 13, "`#mysql50#ab`"},
68 //{"ab`cd", 5, 12, "`#mysql50#a`"},
69 //{"ab`cd", 5, 11, "`#mysql50#`"},
70 //{"ab`cd", 5, 10, "`#mysql50`"},
71
72 {"ab/cd", 5, sizeof(buf), "`ab`.`cd`"},
73 {"ab/cd", 5, 9, "`ab`.`cd`"},
74 //{"ab/cd", 5, 8, "`ab`.`c`"},
75 //{"ab/cd", 5, 7, "`ab`.``"},
76 //{"ab/cd", 5, 6, "`ab`."},
77 //{"ab/cd", 5, 5, "`ab`."},
78 {"ab/cd", 5, 4, "`ab`"},
79 //{"ab/cd", 5, 3, "`a`"},
80 //{"ab/cd", 5, 2, "``"},
81 //{"ab/cd", 5, 1, "."},
82 {"ab/cd", 5, 0, ""},
83 };
84
85 for (ulint i = 0; i < UT_ARR_SIZE(test_data); i++) {
86
87 char* end;
88 size_t res_len;
89
90 memset(buf, 0, sizeof(buf));
91
92 end = innobase_convert_name(
93 buf,
94 test_data[i].buf_size,
95 test_data[i].in,
96 test_data[i].in_len,
97 NULL);
98
99 res_len = (size_t) (end - buf);
100
101 /* notice that buf is not '\0'-terminated */
102 EXPECT_EQ(strlen(test_data[i].buf_expected), res_len);
103 EXPECT_STREQ(test_data[i].buf_expected, buf);
104 }
105 }
106
107 }
108