Debian Codegraph @

unittest/gunit/innodb/ha_innodb-t.cc

raw symbols SCIP
1 /* Copyright (c) 2013, 2026, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 /* See http://code.google.com/p/googletest/wiki/Primer */
25
26 #include <gtest/gtest.h>
27
28 #include "storage/innobase/include/ha_prototypes.h"
29 #include "storage/innobase/include/univ.i"
30
31 namespace innodb_ha_innodb_unittest {
32
33 /* test innobase_convert_name() */
34 TEST(hainnodb, innobaseconvertname) {
35 char buf[64];
36 struct {
37 const char *in;
38 ulint in_len;
39 ulint buf_size;
40 const char *buf_expected;
41 } test_data[] = {
42 /* the commented tests below fail, please fix
43 innobase_convert_name() */
44 {"abcd", 4, sizeof(buf), "`abcd`"},
45 {"abcd", 4, 7, "`abcd`"},
46 {"abcd", 4, 6, "`abcd`"},
47 //{"abcd", 4, 5, "`abc`"},
48 //{"abcd", 4, 4, "`ab`"},
49
50 {"ab@0060cd", 9, sizeof(buf), "`ab``cd`"},
51 {"ab@0060cd", 9, 9, "`ab``cd`"},
52 {"ab@0060cd", 9, 8, "`ab``cd`"},
53 {"ab@0060cd", 9, 7, "`ab``cd"},
54 //{"ab@0060cd", 9, 6, "`ab``c"},
55 //{"ab@0060cd", 9, 5, "`ab``"},
56 //{"ab@0060cd", 9, 4, "`ab`"},
57
58 //{"ab`cd", 5, sizeof(buf), "`#mysql50#ab``cd`"},
59 //{"ab`cd", 5, 17, "`#mysql50#ab``cd`"},
60 //{"ab`cd", 5, 16, "`#mysql50#ab``c`"},
61 //{"ab`cd", 5, 15, "`#mysql50#ab```"},
62 //{"ab`cd", 5, 14, "`#mysql50#ab`"},
63 //{"ab`cd", 5, 13, "`#mysql50#ab`"},
64 //{"ab`cd", 5, 12, "`#mysql50#a`"},
65 //{"ab`cd", 5, 11, "`#mysql50#`"},
66 //{"ab`cd", 5, 10, "`#mysql50`"},
67
68 {"ab/cd", 5, sizeof(buf), "`ab`.`cd`"},
69 {"ab/cd", 5, 9, "`ab`.`cd`"},
70 //{"ab/cd", 5, 8, "`ab`.`c`"},
71 //{"ab/cd", 5, 7, "`ab`.``"},
72 //{"ab/cd", 5, 6, "`ab`."},
73 //{"ab/cd", 5, 5, "`ab`."},
74 {"ab/cd", 5, 4, "`ab`"},
75 //{"ab/cd", 5, 3, "`a`"},
76 //{"ab/cd", 5, 2, "``"},
77 //{"ab/cd", 5, 1, "."},
78 {"ab/cd", 5, 0, ""},
79 };
80
81 for (ulint i = 0; i < UT_ARR_SIZE(test_data); i++) {
82 char *end;
83 size_t res_len;
84
85 memset(buf, 0, sizeof(buf));
86
87 end = innobase_convert_name(buf, test_data[i].buf_size, test_data[i].in,
88 test_data[i].in_len, nullptr);
89
90 res_len = (size_t)(end - buf);
91
92 /* notice that buf is not '\0'-terminated */
93 EXPECT_EQ(strlen(test_data[i].buf_expected), res_len);
94 EXPECT_STREQ(test_data[i].buf_expected, buf);
95 }
96 }
97
98 } // namespace innodb_ha_innodb_unittest