Debian Codegraph @

unittest/gunit/mock_field_timestampf.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_TIMESTAMPF_H
25 #define MOCK_FIELD_TIMESTAMPF_H
26
27 #include "sql/field.h"
28 #include "unittest/gunit/fake_table.h"
29
30 class Mock_field_timestampf : public Field_timestampf {
31 void initialize() {
32 table = new Fake_TABLE(this);
33 EXPECT_FALSE(table == nullptr) << "Out of memory";
34 ptr = table->record[0] + 1;
35 set_null_ptr(table->record[0], 1);
36 }
37
38 public:
39 bool store_timestamp_internal_called;
40 Mock_field_timestampf(uchar auto_flags_arg, int scale)
41 : Field_timestampf(nullptr, // ptr_arg
42 nullptr, // null_ptr_arg
43 '\0', // null_bit_arg
44 auto_flags_arg, // auto_flags_arg
45 "", // field_name_arg
46 static_cast<uint8>(scale)), // dec_arg a.k.a. scale.
47 store_timestamp_internal_called(false) {
48 initialize();
49 }
50
51 my_timeval to_timeval() {
52 my_timeval tm;
53 int warnings = 0;
54 get_timestamp(&tm, &warnings);
55 EXPECT_EQ(0, warnings);
56 return tm;
57 }
58
59 /* Averts ASSERT_COLUMN_MARKED_FOR_WRITE assertion. */
60 void make_writable() { bitmap_set_bit(table->write_set, field_index()); }
61
62 void store_timestamp_internal(const my_timeval *tm) override {
63 store_timestamp_internal_called = true;
64 return Field_timestampf::store_timestamp_internal(tm);
65 }
66
67 ~Mock_field_timestampf() override { delete static_cast<Fake_TABLE *>(table); }
68 };
69
70 #endif // MOCK_FIELD_TIMESTAMPF_H