Debian Codegraph @

unittest/gunit/mock_field_timestamp.h

raw symbols SCIP
1 /* Copyright (c) 2011, 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 MOCK_FIELD_TIMESTAMP_H
25 #define MOCK_FIELD_TIMESTAMP_H
26
27 #include "sql/field.h"
28 #include "unittest/gunit/fake_table.h"
29
30 /*
31 Strictly speaking not a mock class. Does not expect to be used in a
32 certain way.
33
34 Beware that the class creates manages its own TABLE instance.
35 */
36 class Mock_field_timestamp : public Field_timestamp {
37 void initialize() {
38 table = new Fake_TABLE(this);
39 EXPECT_FALSE(table == nullptr) << "Out of memory";
40 ptr = table->record[0] + 1;
41 set_null_ptr(table->record[0], 1);
42 }
43
44 public:
45 bool store_timestamp_called;
46
47 Mock_field_timestamp(uchar auto_flags_arg)
48 : Field_timestamp(nullptr, // ptr_arg
49 0, // len_arg
50 nullptr, // null_ptr_arg
51 '\0', // null_bit_arg
52 auto_flags_arg, // auto_flags_arg
53 ""), // field_name_arg
54 store_timestamp_called(false) {
55 initialize();
56 }
57
58 Mock_field_timestamp()
59 : Field_timestamp(nullptr, 0, nullptr, '\0', NONE, ""),
60 store_timestamp_called(false) {
61 initialize();
62 }
63
64 my_timeval to_timeval() {
65 my_timeval tm;
66 int warnings = 0;
67 get_timestamp(&tm, &warnings);
68 EXPECT_EQ(0, warnings);
69 return tm;
70 }
71
72 /* Averts ASSERT_COLUMN_MARKED_FOR_WRITE assertion. */
73 void make_writable() { bitmap_set_bit(table->write_set, field_index()); }
74 void make_readable() { bitmap_set_bit(table->read_set, field_index()); }
75
76 void store_timestamp(const my_timeval *tm) override {
77 make_writable();
78 Field_temporal_with_date_and_time::store_timestamp(tm);
79 store_timestamp_called = true;
80 }
81
82 ~Mock_field_timestamp() override { delete static_cast<Fake_TABLE *>(table); }
83 };
84
85 #endif // MOCK_FIELD_TIMESTAMP_H