17 #include "my_config.h"
18 #include <gtest/gtest.h>
19 #include "test_utils.h"
24 #include "mysql_time.h"
29 #include "item_timefunc.h"
35 namespace item_timefunc_unittest {
47 virtual void TearDown() { initializer.TearDown(); }
49 THD *thd() {
return initializer.thd(); }
60 EXPECT_FALSE(item->fix_fields(thd(), NULL));
63 EXPECT_DOUBLE_EQ(20130122145222.234567, item->val_real());
72 unsigned long second_part;
75 ::std::ostream& operator<<(::std::ostream& os,
const struct test_data& data) {
76 return os << data.secs;
89 virtual void TearDown() { initializer.TearDown(); }
91 THD *thd() {
return initializer.thd(); }
99 {
"0.1234564", 0, 0, 0, 123456 },
100 {
"0.1234567", 0, 0, 0, 123457 },
101 {
"0.1234", 0, 0, 0, 123400 },
102 {
"12.1234567", 0, 0, 12, 123457},
103 {
"123", 0, 2, 3, 0 },
104 {
"2378.3422349", 0, 39, 38, 342235 },
105 {
"3020398.999999999", 838, 59, 59, 0 },
106 {
"3020399", 838, 59, 59, 0 },
107 {
"99999999.99999999", 838, 59, 59, 0 }
110 INSTANTIATE_TEST_CASE_P(a, ItemTimeFuncTestP,
111 ::testing::ValuesIn(test_values));
123 long long int mysql_time=
124 10000 * ltime->hour + 100 * ltime->minute + ltime->second;
125 EXPECT_EQ(mysql_time, item->val_int());
127 long long int packed= TIME_to_longlong_packed(ltime);
130 double d= mysql_time + ltime->
second_part / 1000000.0;
131 EXPECT_DOUBLE_EQ(d, item->val_real());
135 double2decimal(d, &decval2);
139 sprintf(s,
"%02d:%02d:%02d", ltime->hour, ltime->minute, ltime->second);
142 while (decs % 10 == 0)
144 sprintf(s + strlen(s),
".%d", decs);
146 else if (decimals > 0)
148 sprintf(s + strlen(s),
".000000");
150 EXPECT_STREQ(s, item->val_str(&timeStr)->c_ptr());
154 item->get_date(&ldate, 0);
156 EXPECT_EQ(ltime->hour % 24, ldate.hour);
157 EXPECT_EQ(ltime->minute, ldate.minute);
158 EXPECT_EQ(ltime->second, ldate.second);
164 TEST_P(ItemTimeFuncTestP, secToTime)
167 new Item_decimal(m_t.secs, strlen(m_t.secs), &my_charset_latin1_bin);
169 EXPECT_FALSE(time->fix_fields(thd(), NULL));
172 time->get_time(<ime);
173 EXPECT_EQ(0
U, ltime.year);
174 EXPECT_EQ(0
U, ltime.month);
175 EXPECT_EQ(0
U, ltime.day);
176 EXPECT_EQ(m_t.hour, ltime.hour);
177 EXPECT_EQ(m_t.minute, ltime.minute);
178 EXPECT_EQ(m_t.second, ltime.second);
179 EXPECT_EQ(m_t.second_part, ltime.second_part);
181 testItemTimeFunctions(time, <ime, sec->decimals);