Skip to content

Commit 9ae7a65

Browse files
committed
WL#8206: Intoduce separate error code range for 5.7
Post-push fix: Fix unit tests failing in PB2.
1 parent 976e479 commit 9ae7a65

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

sql/derror.h

+22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#define DERROR_INCLUDED
1818

1919
#include "my_global.h" /* uint */
20+
#ifdef EXTRA_CODE_FOR_UNIT_TESTING
21+
#include "mysqld_error.h"
22+
#endif
2023

2124
class THD;
2225

@@ -33,6 +36,25 @@ class MY_LOCALE_ERRMSGS
3336
/** Return error message string for a given error number. */
3437
const char *lookup(int mysql_errno);
3538

39+
#ifdef EXTRA_CODE_FOR_UNIT_TESTING
40+
bool replace_msg(int mysql_errno, const char *new_msg)
41+
{
42+
int offset= 0; // Position where the current section starts in the array.
43+
int num_sections= sizeof(errmsg_section_start) /
44+
sizeof(errmsg_section_start[0]);
45+
for (int i= 0; i < num_sections; i++)
46+
{
47+
if (mysql_errno < (errmsg_section_start[i] + errmsg_section_size[i]))
48+
{
49+
errmsgs[mysql_errno - errmsg_section_start[i] + offset]= new_msg;
50+
return false;
51+
}
52+
offset+= errmsg_section_size[i];
53+
}
54+
return true;
55+
}
56+
#endif
57+
3658
/** Has the error message file been sucessfully loaded? */
3759
bool is_loaded() const { return errmsgs != NULL; }
3860

unittest/gunit/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ MESSAGE(STATUS "GTEST_LIBRARIES:${GTEST_LIBRARIES}")
237237

238238
# Add some defines.
239239
ADD_DEFINITIONS(-DMYSQL_SERVER -DEXTRA_CODE_FOR_UNIT_TESTING)
240-
ADD_DEFINITIONS(-DERRMSG_DIR=\"${CMAKE_BINARY_DIR}/sql/share/\")
241240

242241
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
243242

unittest/gunit/explain_filename-t.cc

+11
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ class PartitionTest : public ::testing::Test
3535
protected:
3636
virtual void SetUp()
3737
{
38+
// Save global settings.
3839
m_charset= system_charset_info;
3940
m_locale= my_default_lc_messages;
41+
4042
system_charset_info = &my_charset_utf8_bin;
4143
my_default_lc_messages = &my_locale_en_US;
44+
45+
/* Populate the necessary error messages */
46+
MY_LOCALE_ERRMSGS *errmsgs= my_default_lc_messages->errmsgs;
47+
EXPECT_FALSE(errmsgs->replace_msg(ER_DATABASE_NAME, "Database"));
48+
EXPECT_FALSE(errmsgs->replace_msg(ER_TABLE_NAME, "Table"));
49+
EXPECT_FALSE(errmsgs->replace_msg(ER_PARTITION_NAME, "Partition"));
50+
EXPECT_FALSE(errmsgs->replace_msg(ER_SUBPARTITION_NAME, "Subpartition"));
51+
EXPECT_FALSE(errmsgs->replace_msg(ER_TEMPORARY_NAME, "Temporary"));
52+
EXPECT_FALSE(errmsgs->replace_msg(ER_RENAMED_NAME, "Renamed"));
4253
}
4354

4455
virtual void TearDown()

unittest/gunit/test_utils.cc

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void setup_server_for_unit_tests()
4848
mysql_mutex_init(key_LOCK_error_log, &LOCK_error_log, MY_MUTEX_INIT_FAST);
4949
system_charset_info= &my_charset_utf8_general_ci;
5050
sys_var_init();
51-
strcpy(lc_messages_dir, ERRMSG_DIR);
5251
init_common_variables();
5352
my_init_signals();
5453
randominit(&sql_rand, 0, 0);

0 commit comments

Comments
 (0)