19 #include "my_config.h"
20 #include <gtest/gtest.h>
22 #include <mysqld_error.h>
23 #include <sql_class.h>
24 #include <sql_table.h>
26 namespace explain_filename_unittest {
28 const int BUFLEN= 1000;
33 const char *error_messages[1000];
41 m_charset= system_charset_info;
42 m_locale= my_default_lc_messages;
43 m_errmsgs= my_default_lc_messages->errmsgs->errmsgs;
45 system_charset_info = &my_charset_utf8_bin;
46 my_default_lc_messages = &my_locale_en_US;
49 error_messages[ER_DATABASE_NAME - ER_ERROR_FIRST] =
"Database";
50 error_messages[ER_TABLE_NAME - ER_ERROR_FIRST] =
"Table";
51 error_messages[ER_PARTITION_NAME - ER_ERROR_FIRST] =
"Partition";
52 error_messages[ER_SUBPARTITION_NAME - ER_ERROR_FIRST] =
"Subpartition";
53 error_messages[ER_TEMPORARY_NAME - ER_ERROR_FIRST] =
"Temporary";
54 error_messages[ER_RENAMED_NAME - ER_ERROR_FIRST] =
"Renamed";
56 my_default_lc_messages->errmsgs->errmsgs = error_messages;
59 virtual void TearDown()
62 system_charset_info= m_charset;
63 my_default_lc_messages= m_locale;
64 my_default_lc_messages->errmsgs->errmsgs= m_errmsgs;
70 const char **m_errmsgs;
73 void test_1(
const char *in,
const char *exp, enum_explain_filename_mode
mode)
77 uint len1 = explain_filename(0, in, out, BUFLEN, mode);
80 bool pass = (strcmp(exp, out) == 0);
83 bool length = (len1 == strlen(exp));
85 EXPECT_EQ( (pass && length),
true);
92 ADD_FAILURE() <<
"input file name: '" << in <<
"' explain output: '"
93 << out <<
"'" << std::endl;
98 TEST_F(PartitionTest, ExplainFilename)
100 test_1(
"test/t1.ibd",
101 "Database \"test\", Table \"t1.ibd\"",
102 EXPLAIN_ALL_VERBOSE);
104 test_1(
"test/t1.ibd",
105 "\"test\".\"t1.ibd\"",
106 EXPLAIN_PARTITIONS_VERBOSE);
108 test_1(
"test/t1.ibd",
109 "\"test\".\"t1.ibd\"",
110 EXPLAIN_PARTITIONS_AS_COMMENT);
112 test_1(
"test/t1#TMP#",
113 "Database \"test\", Table \"t1#TMP#\"",
114 EXPLAIN_ALL_VERBOSE);
116 test_1(
"test/#sql-2882.ibd",
117 "Database \"test\", Table \"#sql-2882.ibd\"",
118 EXPLAIN_ALL_VERBOSE);
120 test_1(
"test/t1#REN#",
121 "Database \"test\", Table \"t1#REN#\"",
122 EXPLAIN_ALL_VERBOSE);
124 test_1(
"test/t1@0023REN@0023",
125 "Database \"test\", Table \"t1#REN#\"",
126 EXPLAIN_ALL_VERBOSE);
128 test_1(
"test/t1#p#p1",
129 "Database \"test\", Table \"t1\", Partition \"p1\"",
130 EXPLAIN_ALL_VERBOSE);
132 test_1(
"test/t1#P#p1",
133 "\"test\".\"t1\" /* Partition \"p1\" */",
134 EXPLAIN_PARTITIONS_AS_COMMENT);
136 test_1(
"test/t1#P#p1@00231",
137 "\"test\".\"t1\" /* Partition \"p1#1\" */",
138 EXPLAIN_PARTITIONS_AS_COMMENT);
140 test_1(
"test/t1#P#p1#SP#sp1",
141 "\"test\".\"t1\" /* Partition \"p1\", Subpartition \"sp1\" */",
142 EXPLAIN_PARTITIONS_AS_COMMENT);
144 test_1(
"test/t1#p1#SP#sp1",
145 "\"test\".\"t1#p1#SP#sp1\"",
146 EXPLAIN_PARTITIONS_AS_COMMENT);
148 test_1(
"test/t1#p#p1@00232#SP#sp1@00231#REN#",
149 "\"test\".\"t1\" /* Renamed Partition \"p1#2\", Subpartition \"sp1#1\" */",
150 EXPLAIN_PARTITIONS_AS_COMMENT);
152 test_1(
"test/t1#p#p1#SP#sp1#TMP#",
153 "\"test\".\"t1\" /* Temporary Partition \"p1\", Subpartition \"sp1\" */",
154 EXPLAIN_PARTITIONS_AS_COMMENT);
156 test_1(
"test/#sql-t1#P#p1#SP#sp1#TMP#",
157 "\"test\".\"#sql-t1#P#p1#SP#sp1#TMP#\" /* Temporary Partition \"p1\", Subpartition \"sp1\" */",
158 EXPLAIN_PARTITIONS_AS_COMMENT);
160 test_1(
"test/#sql-t1#P#p1#SP#sp1",
161 "\"test\".\"#sql-t1#P#p1#SP#sp1\" /* Partition \"p1\", Subpartition \"sp1\" */",
162 EXPLAIN_PARTITIONS_AS_COMMENT);
164 test_1(
"test/#sqlx-33",
165 "\"test\".\"#sqlx-33\"",
166 EXPLAIN_PARTITIONS_AS_COMMENT);
168 test_1(
"test/#mysql50#t",
169 "\"test\".\"#mysql50#t\"",
170 EXPLAIN_PARTITIONS_AS_COMMENT);
174 EXPLAIN_PARTITIONS_AS_COMMENT);
178 EXPLAIN_PARTITIONS_AS_COMMENT);
180 test_1(
"test/t@0023",
182 EXPLAIN_PARTITIONS_AS_COMMENT);
188 test_1(
"test/t@0023#",
189 "\"test\".\"t@0023#\"",
190 EXPLAIN_PARTITIONS_AS_COMMENT);