MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mock_field_timestamp.h
1 /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 #ifndef MOCK_FIELD_TIMESTAMP_H
17 #define MOCK_FIELD_TIMESTAMP_H
18 
19 #include "fake_table.h"
20 #include "field.h"
21 
22 /*
23  Strictly speaking not a mock class. Does not expect to be used in a
24  certain way.
25 
26  Beware that the class creates manages its own TABLE instance.
27 */
29 {
30  uchar null_byte;
31  void initialize()
32  {
33  table = new Fake_TABLE(this);
34  EXPECT_FALSE(table == NULL) << "Out of memory";
35  ptr= buffer;
36  memset(buffer, 0, PACK_LENGTH);
37  null_ptr= &null_byte;
38  }
39 
40 public:
41  uchar buffer[PACK_LENGTH];
42  bool store_timestamp_called;
43 
44  Mock_field_timestamp(Field::utype utype) :
45  Field_timestamp(NULL, // ptr_arg
46  0, // len_arg
47  NULL, // null_ptr_arg
48  '\0', // null_bit_arg
49  utype,// unireg_check_arg
50  ""), // field_name_arg
51  null_byte(0),
52  store_timestamp_called(false)
53  {
54  initialize();
55  }
56 
58  Field_timestamp(NULL, 0, NULL, '\0', NONE, ""),
59  null_byte(0),
60  store_timestamp_called(false)
61  {
62  initialize();
63  }
64 
65  timeval to_timeval()
66  {
67  timeval tm;
68  int warnings= 0;
69  get_timestamp(&tm, &warnings);
70  EXPECT_EQ(0, warnings);
71  return tm;
72  }
73 
74  /* Averts ASSERT_COLUMN_MARKED_FOR_WRITE assertion. */
75  void make_writable() { bitmap_set_bit(table->write_set, field_index); }
76 
77  void store_timestamp(const timeval *tm)
78  {
79  make_writable();
81  store_timestamp_called= true;
82  }
83 
84  ~Mock_field_timestamp() { delete table; }
85 };
86 
87 #endif // MOCK_FIELD_TIMESTAMP_H