| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef TEST_UTILS_INCLUDED |
| 25 |
#define TEST_UTILS_INCLUDED |
| 26 |
|
| 27 |
#include <string.h> |
| 28 |
#include <sys/types.h> |
| 29 |
|
| 30 |
#include "gtest/gtest.h" |
| 31 |
#include "my_compiler.h" |
| 32 |
#include "my_sys.h" |
| 33 |
#include "mysql/components/services/bits/mysql_mutex_bits.h" |
| 34 |
#include "sql/error_handler.h" |
| 35 |
#include "sql/sql_error.h" |
| 36 |
|
| 37 |
class THD; |
| 38 |
class my_decimal; |
| 39 |
struct MEM_ROOT; |
| 40 |
|
| 41 |
namespace my_testing { |
| 42 |
|
| 43 |
inline int native_compare(size_t *length, unsigned char **a, |
| 44 |
unsigned char **b) { |
| 45 |
return memcmp(*a, *b, *length); |
| 46 |
} |
| 47 |
|
| 48 |
inline qsort2_cmp get_ptr_compare(size_t size [[maybe_unused]]) { |
| 49 |
return (qsort2_cmp)native_compare; |
| 50 |
} |
| 51 |
|
| 52 |
void setup_server_for_unit_tests(); |
| 53 |
void teardown_server_for_unit_tests(); |
| 54 |
int chars_2_decimal(const char *chars, my_decimal *to); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
class Server_initializer { |
| 61 |
public: |
| 62 |
Server_initializer() : m_thd(nullptr) {} |
| 63 |
~Server_initializer() { TearDown(); } |
| 64 |
|
| 65 |
|
| 66 |
void SetUp(); |
| 67 |
void TearDown(); |
| 68 |
|
| 69 |
|
| 70 |
static void set_expected_error(uint val); |
| 71 |
|
| 72 |
THD *thd() const { return m_thd; } |
| 73 |
|
| 74 |
private: |
| 75 |
THD *m_thd; |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
class Mock_error_handler : public Internal_error_handler { |
| 85 |
public: |
| 86 |
Mock_error_handler(THD *thd, uint expected_error); |
| 87 |
~Mock_error_handler() override; |
| 88 |
|
| 89 |
bool handle_condition(THD *thd, uint sql_errno, const char *sqlstate, |
| 90 |
Sql_condition::enum_severity_level *level, |
| 91 |
const char *msg) override; |
| 92 |
|
| 93 |
int handle_called() const { return m_handle_called; } |
| 94 |
|
| 95 |
private: |
| 96 |
THD *m_thd; |
| 97 |
uint m_expected_error; |
| 98 |
int m_handle_called; |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
class DD_initializer { |
| 106 |
public: |
| 107 |
static void SetUp(); |
| 108 |
static void TearDown(); |
| 109 |
}; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
#endif |