MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_utils.h
1 /* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 
17 #ifndef TEST_UTILS_INCLUDED
18 #define TEST_UTILS_INCLUDED
19 
20 #include "sql_error.h"
21 #include "sql_class.h"
22 #include "set_var.h"
23 
24 extern pthread_key(MEM_ROOT**,THR_MALLOC);
25 extern pthread_key(THD*, THR_THD);
27 extern uint opt_debug_sync_timeout;
28 extern "C" void sql_alloc_error_handler(void);
29 
30 // A simple helper function to determine array size.
31 template <class T, int size>
32 int array_size(const T (&)[size])
33 {
34  return size;
35 }
36 
37 namespace my_testing {
38 
39 void setup_server_for_unit_tests();
40 void teardown_server_for_unit_tests();
41 int chars_2_decimal(const char *chars, my_decimal *to);
42 
43 /*
44  A class which wraps the necessary setup/teardown logic for
45  unit tests which depend on a working THD environment.
46  */
48 {
49 public:
50  Server_initializer() : m_thd(NULL) {}
51 
52  // Invoke these from corresponding functions in test fixture classes.
53  void SetUp();
54  void TearDown();
55 
56  // Sets expected error for error_handler_hook.
57  static void set_expected_error(uint val);
58 
59  THD *thd() const { return m_thd; }
60 private:
61  THD *m_thd;
62 };
63 
70 class Mock_error_handler : public Internal_error_handler
71 {
72 public:
73  Mock_error_handler(THD *thd, uint expected_error);
74  virtual ~Mock_error_handler();
75 
76  virtual bool handle_condition(THD *thd,
77  uint sql_errno,
78  const char* sqlstate,
79  Sql_condition::enum_warning_level level,
80  const char* msg,
81  Sql_condition ** cond_hdl);
82 
83  int handle_called() const { return m_handle_called; }
84 private:
85  THD *m_thd;
86  uint m_expected_error;
87  int m_handle_called;
88 };
89 
90 
91 } // namespace my_testing
92 
93 #endif // TEST_UTILS_INCLUDED