17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "test_utils.h"
21 #include "rpl_handler.h"
23 namespace my_testing {
27 char *end= strend(chars);
28 return string2decimal(chars, to, &end);
35 uint expected_error= 0;
36 extern "C" void test_error_handler_hook(uint err,
const char *str, myf MyFlags)
38 EXPECT_EQ(expected_error, err) << str;
41 void setup_server_for_unit_tests()
43 static char *my_name= strdup(my_progname);
44 char *argv[] = { my_name, 0 };
45 set_remaining_args(1, argv);
47 system_charset_info= &my_charset_utf8_general_ci;
49 init_common_variables();
51 randominit(&sql_rand, 0, 0);
55 error_handler_hook= test_error_handler_hook;
60 void teardown_server_for_unit_tests()
65 gtid_server_cleanup();
67 logger.cleanup_base();
71 void Server_initializer::set_expected_error(uint val)
76 void Server_initializer::SetUp()
79 m_thd=
new THD(
false);
80 THD *stack_thd= m_thd;
81 m_thd->thread_stack= (
char*) &stack_thd;
82 m_thd->store_globals();
84 m_thd->set_current_time();
87 void Server_initializer::TearDown()
89 m_thd->cleanup_after_query();
94 Mock_error_handler::Mock_error_handler(THD *thd, uint expected_error)
96 m_expected_error(expected_error),
99 thd->push_internal_handler(
this);
102 Mock_error_handler::~Mock_error_handler()
105 Internal_error_handler *me=
this;
106 EXPECT_EQ(me, m_thd->pop_internal_handler());
107 if (m_expected_error == 0)
109 EXPECT_EQ(0, m_handle_called);
113 EXPECT_GT(m_handle_called, 0);
117 bool Mock_error_handler::handle_condition(THD *thd,
119 const char* sqlstate,
120 Sql_condition::enum_warning_level
level,
124 EXPECT_EQ(m_expected_error, sql_errno);