forked from MahletNigusse/write-after-read-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_field_long.h
82 lines (70 loc) · 2.83 KB
/
mock_field_long.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef MOCK_FIELD_LONG_INCLUDED
#define MOCK_FIELD_LONG_INCLUDED
/* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
#include "m_string.h"
#include "field.h"
/*
Base class for creating mock Field objects.
To do: Make all other tests #include this file instead of using
their own copy-pasted variants.
*/
class Mock_field_long : public Field_long
{
uchar buffer[PACK_LENGTH];
uchar null_byte;
char m_name[1024];
void initialize(const char *name)
{
ptr= buffer;
memset(buffer, 0, PACK_LENGTH);
static const char *table_name_buf= "table_name";
table_name= &table_name_buf;
if (name)
{
my_snprintf(m_name, sizeof(m_name), "%.1023s", name);
field_name= m_name;
}
}
public:
Mock_field_long(const char *name, bool is_nullable)
: Field_long(0, // ptr_arg
8, // len_arg
is_nullable ? &null_byte : NULL, // null_ptr_arg
is_nullable ? 1 : 0, // null_bit_arg
Field::NONE, // unireg_check_arg
"field_name", // field_name_arg
false, // zero_arg
false), // unsigned_arg
null_byte('\0')
{
initialize(name);
if (is_nullable)
set_null_ptr(&null_byte, 1);
}
/// Creates a non NULLable column with an optional name.
Mock_field_long(const char *name)
: Field_long(0, // ptr_arg
8, // len_arg
NULL, // null_ptr_arg
0, // null_bit_arg
Field::NONE, // unireg_check_arg
"field_name", // field_name_arg
false, // zero_arg
false) // unsigned_arg
{
initialize(name);
}
void make_writable() { bitmap_set_bit(table->write_set, field_index); }
void make_readable() { bitmap_set_bit(table->read_set, field_index); }
};
#endif // MOCK_FIELD_LONG_INCLUDED