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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 // First include (the generated) my_config.h, to get correct platform defines,
24 // then gtest.h (before any other MySQL headers), to avoid min() macros etc ...
25 #include "my_config.h"
26 #include <gtest/gtest.h>
27 
28 #include "test_utils.h"
29 #include "mock_create_field.h"
30 #include "item_timefunc.h"         // Item_func_now_local
31 
32 namespace create_field_unittest {
33 
34 using my_testing::Server_initializer;
35 using my_testing::Mock_error_handler;
36 
37 class CreateFieldTest : public ::testing::Test
38 {
39 protected:
SetUp()40   virtual void SetUp() { initializer.SetUp(); }
TearDown()41   virtual void TearDown() { initializer.TearDown(); }
42 
43   Server_initializer initializer;
44 };
45 
46 
TEST_F(CreateFieldTest,init)47 TEST_F(CreateFieldTest, init)
48 {
49   // To do: Add all possible precisions.
50   Item_func_now_local *now= new Item_func_now_local(0);
51 
52   Mock_create_field field_definition_none(MYSQL_TYPE_TIMESTAMP, NULL, NULL);
53   EXPECT_EQ(Field::NONE, field_definition_none.unireg_check);
54 
55   Mock_create_field field_definition_dn(MYSQL_TYPE_TIMESTAMP, now, NULL);
56   EXPECT_EQ(Field::TIMESTAMP_DN_FIELD, field_definition_dn.unireg_check);
57 
58   Mock_create_field field_definition_dnun(MYSQL_TYPE_TIMESTAMP, now, now);
59   EXPECT_EQ(Field::TIMESTAMP_DNUN_FIELD, field_definition_dnun.unireg_check);
60 
61   Mock_create_field field_definition_un(MYSQL_TYPE_TIMESTAMP, NULL, now);
62   EXPECT_EQ(Field::TIMESTAMP_UN_FIELD, field_definition_un.unireg_check);
63 }
64 
65 }
66