17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "fake_table.h"
21 #include "mock_field_timestamp.h"
22 #include "test_utils.h"
24 namespace field_timestamp_unittests {
37 virtual void SetUp() { initializer.SetUp(); }
38 virtual void TearDown() { initializer.TearDown(); }
40 THD *get_thd() {
return initializer.thd(); }
50 EXPECT_TRUE(field_dn.has_insert_default_function());
54 EXPECT_FALSE(field_un.has_insert_default_function());
58 EXPECT_TRUE(field_dnun.has_insert_default_function());
63 TEST_F(FieldTimestampTest, hasUpdateDefaultFunction)
67 EXPECT_FALSE(field_dn.has_update_default_function());
71 EXPECT_TRUE(field_un.has_update_default_function());
75 EXPECT_TRUE(field_dnun.has_update_default_function());
84 TEST_F(FieldTimestampTest, EvaluateInsertDefaultFunction)
87 get_thd()->set_time(&now);
91 field_dn.evaluate_insert_default_function();
92 EXPECT_EQ(now.tv_sec, field_dn.to_timeval().tv_sec);
93 EXPECT_EQ(0, field_dn.to_timeval().tv_usec);
97 field_un.evaluate_insert_default_function();
98 EXPECT_EQ(0, field_un.to_timeval().tv_sec);
99 EXPECT_EQ(0, field_un.to_timeval().tv_usec);
103 field_dnun.evaluate_insert_default_function();
104 EXPECT_EQ(now.tv_sec, field_dnun.to_timeval().tv_sec);
105 EXPECT_EQ(0, field_dnun.to_timeval().tv_usec);
114 TEST_F(FieldTimestampTest, EvaluateUpdateDefaultFunction)
117 get_thd()->set_time(&now);
121 field_dn.evaluate_update_default_function();
122 EXPECT_EQ(0, field_dn.to_timeval().tv_sec);
123 EXPECT_EQ(0, field_dn.to_timeval().tv_usec);
127 field_un.evaluate_update_default_function();
128 EXPECT_EQ(now.tv_sec, field_un.to_timeval().tv_sec);
129 EXPECT_EQ(0, field_un.to_timeval().tv_usec);
133 field_dnun.evaluate_update_default_function();
134 EXPECT_EQ(now.tv_sec, field_dnun.to_timeval().tv_sec);
135 EXPECT_EQ(0, field_dnun.to_timeval().tv_usec);