1/*
2 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16*/
17
18/** Unit test case for the function explain_filename(). */
19
20#include <tap.h>
21#include <mysqld_error.h>
22#include <sql_class.h>
23#include <sql_table.h>
24
25#define BUFLEN 1000
26char to[BUFLEN];
27char from[BUFLEN];
28
29static const char *error_messages_txt[1000];
30static const char **error_messages[1]= { error_messages_txt };
31
32int setup()
33{
34 system_charset_info = &my_charset_utf8_bin;
35 my_default_lc_messages = &my_locale_en_US;
36
37 /* Populate the necessary error messages */
38 error_messages[0][ER_DATABASE_NAME - ER_ERROR_FIRST] = "Database";
39 error_messages[0][ER_TABLE_NAME - ER_ERROR_FIRST] = "Table";
40 error_messages[0][ER_PARTITION_NAME - ER_ERROR_FIRST] = "Partition";
41 error_messages[0][ER_SUBPARTITION_NAME - ER_ERROR_FIRST] = "Subpartition";
42 error_messages[0][ER_TEMPORARY_NAME - ER_ERROR_FIRST] = "Temporary";
43 error_messages[0][ER_RENAMED_NAME - ER_ERROR_FIRST] = "Renamed";
44
45 my_default_lc_messages->errmsgs->errmsgs = error_messages;
46
47 return 0;
48}
49
50void test_1(const char *in, const char *exp, enum_explain_filename_mode mode)
51{
52 char out[BUFLEN];
53
54 uint len1 = explain_filename(0, in, out, BUFLEN, mode);
55
56 /* expected output and actual output must be same */
57 bool pass = (strcmp(exp, out) == 0);
58
59 /* length returned by explain_filename is fine */
60 bool length = (len1 == strlen(exp));
61
62 ok( (pass && length) , "(%d): %s => %s", mode, in, out);
63}
64
65int main(int argc __attribute__((unused)),char *argv[])
66{
67 MY_INIT(argv[0]);
68 setup();
69 plan(22);
70
71 test_1("test/t1.ibd",
72 "Database `test`, Table `t1.ibd`",
73 EXPLAIN_ALL_VERBOSE);
74
75 test_1("test/t1.ibd",
76 "`test`.`t1.ibd`",
77 EXPLAIN_PARTITIONS_VERBOSE);
78
79 test_1("test/t1.ibd",
80 "`test`.`t1.ibd`",
81 EXPLAIN_PARTITIONS_AS_COMMENT);
82
83 test_1("test/t1#TMP#",
84 "Database `test`, Table `t1#TMP#`",
85 EXPLAIN_ALL_VERBOSE);
86
87 test_1("test/#sql-2882.ibd",
88 "Database `test`, Table `#sql-2882.ibd`",
89 EXPLAIN_ALL_VERBOSE);
90
91 test_1("test/t1#REN#",
92 "Database `test`, Table `t1#REN#`",
93 EXPLAIN_ALL_VERBOSE);
94
95 test_1("test/t1@0023REN@0023",
96 "Database `test`, Table `t1#REN#`",
97 EXPLAIN_ALL_VERBOSE);
98
99 test_1("test/t1#p#p1",
100 "Database `test`, Table `t1`, Partition `p1`",
101 EXPLAIN_ALL_VERBOSE);
102
103 test_1("test/t1#P#p1",
104 "`test`.`t1` /* Partition `p1` */",
105 EXPLAIN_PARTITIONS_AS_COMMENT);
106
107 test_1("test/t1#P#p1@00231",
108 "`test`.`t1` /* Partition `p1#1` */",
109 EXPLAIN_PARTITIONS_AS_COMMENT);
110
111 test_1("test/t1#P#p1#SP#sp1",
112 "`test`.`t1` /* Partition `p1`, Subpartition `sp1` */",
113 EXPLAIN_PARTITIONS_AS_COMMENT);
114
115 test_1("test/t1#p1#SP#sp1",
116 "`test`.`t1#p1#SP#sp1`",
117 EXPLAIN_PARTITIONS_AS_COMMENT);
118
119 test_1("test/t1#p#p1@00232#SP#sp1@00231#REN#",
120 "`test`.`t1` /* Renamed Partition `p1#2`, Subpartition `sp1#1` */",
121 EXPLAIN_PARTITIONS_AS_COMMENT);
122
123 test_1("test/t1#p#p1#SP#sp1#TMP#",
124 "`test`.`t1` /* Temporary Partition `p1`, Subpartition `sp1` */",
125 EXPLAIN_PARTITIONS_AS_COMMENT);
126
127 test_1("test/#sql-t1#P#p1#SP#sp1#TMP#",
128 "`test`.`#sql-t1#P#p1#SP#sp1#TMP#` /* Temporary Partition `p1`, Subpartition `sp1` */",
129 EXPLAIN_PARTITIONS_AS_COMMENT);
130
131 test_1("test/#sql-t1#P#p1#SP#sp1",
132 "`test`.`#sql-t1#P#p1#SP#sp1` /* Partition `p1`, Subpartition `sp1` */",
133 EXPLAIN_PARTITIONS_AS_COMMENT);
134
135 test_1("test/#sqlx-33",
136 "`test`.`#sqlx-33`",
137 EXPLAIN_PARTITIONS_AS_COMMENT);
138
139 test_1("test/#mysql50#t",
140 "`test`.`#mysql50#t`",
141 EXPLAIN_PARTITIONS_AS_COMMENT);
142
143 test_1("#mysql50#t",
144 "`#mysql50#t`",
145 EXPLAIN_PARTITIONS_AS_COMMENT);
146
147 test_1("@0023t",
148 "`#t`",
149 EXPLAIN_PARTITIONS_AS_COMMENT);
150
151 test_1("test/t@0023",
152 "`test`.`t#`",
153 EXPLAIN_PARTITIONS_AS_COMMENT);
154
155 /*
156 If a character not allowed in my_charset_filename is encountered,
157 then it will not be converted to system_charset_info!
158 */
159 test_1("test/t@0023#",
160 "`test`.`t@0023#`",
161 EXPLAIN_PARTITIONS_AS_COMMENT);
162
163 my_end(0);
164 return exit_status();
165}
166
167