1 /* Copyright (c) 2011, 2021, 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 also distributed 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 included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 22 23 #ifndef MOCK_FIELD_TIMESTAMPF_H 24 #define MOCK_FIELD_TIMESTAMPF_H 25 26 #include "fake_table.h" 27 #include "field.h" 28 29 class Mock_field_timestampf : public Field_timestampf 30 { 31 uchar null_byte; initialize()32 void initialize() 33 { 34 table = new Fake_TABLE(this); 35 EXPECT_FALSE(table == NULL) << "Out of memory"; 36 ptr= buffer; 37 memset(buffer, 0, PACK_LENGTH); 38 set_null_ptr(&null_byte, 1); 39 } 40 41 public: 42 uchar buffer[PACK_LENGTH]; 43 bool store_timestamp_internal_called; Mock_field_timestampf(Field::utype utype,int scale)44 Mock_field_timestampf(Field::utype utype, int scale) : 45 Field_timestampf(static_cast<uchar*>(buffer), // ptr_arg 46 &null_byte, // null_ptr_arg 47 '\0', // null_bit_arg 48 utype,// unireg_check_arg 49 "", // field_name_arg 50 static_cast<uint8>(scale)), // dec_arg a.k.a. scale. 51 null_byte(0), 52 store_timestamp_internal_called(false) 53 { 54 initialize(); 55 } 56 to_timeval()57 timeval to_timeval() 58 { 59 timeval tm; 60 int warnings= 0; 61 get_timestamp(&tm, &warnings); 62 EXPECT_EQ(0, warnings); 63 return tm; 64 } 65 66 /* Averts ASSERT_COLUMN_MARKED_FOR_WRITE assertion. */ make_writable()67 void make_writable() { bitmap_set_bit(table->write_set, field_index); } 68 store_timestamp_internal(const timeval * tm)69 void store_timestamp_internal(const timeval *tm) 70 { 71 store_timestamp_internal_called= true; 72 return Field_timestampf::store_timestamp_internal(tm); 73 } 74 ~Mock_field_timestampf()75 ~Mock_field_timestampf() { delete table; } 76 }; 77 78 #endif // MOCK_FIELD_TIMESTAMPF_H 79