Debian Codegraph @

unittest/gunit/base_mock_field.h

raw symbols SCIP
1 /* Copyright (c) 2014, 2026, Oracle and/or its affiliates.
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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #ifndef BASE_MOCK_FIELD_INCLUDED
25 #define BASE_MOCK_FIELD_INCLUDED
26
27 #include <gmock/gmock.h>
28 #include <gtest/gtest.h>
29
30 #include "sql-common/json_dom.h"
31 #include "sql/field.h"
32 #include "sql/table.h"
33
34 /**
35 Base mocks for Field_*. Create subclasses mocking additional virtual
36 functions depending on what you want to test.
37 */
38
39 class Base_mock_field_longlong : public Field_longlong {
40 public:
41 Base_mock_field_longlong()
42 : Field_longlong(nullptr, // ptr_arg
43 8, // len_arg
44 &Field::dummy_null_buffer, // null_ptr_arg
45 1, // null_bit_arg
46 Field::NONE, // auto_flags_arg
47 "field_name", // field_name_arg
48 false, // zero_arg
49 false) // unsigned_arg
50 {}
51
52 void make_writable() { bitmap_set_bit(table->write_set, field_index()); }
53 void make_readable() { bitmap_set_bit(table->read_set, field_index()); }
54 };
55
56 class Base_mock_field_varstring : public Field_varstring {
57 public:
58 Base_mock_field_varstring(uint32 length, TABLE_SHARE *share)
59 : Field_varstring(length, // len_arg
60 false, // maybe_null_arg
61 "field_NAME", // field_name_arg
62 share, // share
63 &my_charset_latin1) // char set
64 {}
65 };
66
67 class Base_mock_field_blob : public Field_blob {
68 public:
69 Base_mock_field_blob(const char *field_name_arg, uint32 length)
70 : Field_blob(length, // len_arg
71 false, // maybe_null_arg
72 field_name_arg, // field_name_arg
73 &my_charset_latin1, // char set
74 true) {} // set_packlength
75 };
76
77 class Base_mock_field_json : public Field_json {
78 public:
79 Base_mock_field_json() : Field_json(MAX_BLOB_WIDTH, true, "json_field") {}
80 void make_writable() { bitmap_set_bit(table->write_set, field_index()); }
81 };
82
83 #endif // BASE_MOCK_FIELD_INCLUDED