1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
1 |
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Pawel Blokus
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
#include "config.h" |
|
22 |
||
23 |
#include <gtest/gtest.h> |
|
24 |
#include <drizzled/temporal.h> |
|
25 |
||
1377.9.1
by Paweł Blokus
updated includes to last file rename |
26 |
#include "temporal_generator.h" |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
27 |
|
28 |
using namespace drizzled; |
|
29 |
||
30 |
template <typename TemporalType> |
|
31 |
class TimestampTestCompareOperators : public ::testing::Test |
|
32 |
{
|
|
33 |
protected: |
|
34 |
Timestamp sample_timestamp; |
|
35 |
bool result; |
|
36 |
||
37 |
TemporalType identical_with_sample_timestamp, before_sample_timestamp, after_sample_timestamp; |
|
38 |
||
39 |
void initBeforeIdenticalAfter(); |
|
40 |
||
41 |
virtual void SetUp() |
|
42 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
43 |
TemporalGenerator::TimestampGen::make_timestamp(&sample_timestamp, 2010, 9, 8, 0, 0, 0); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
44 |
initBeforeIdenticalAfter(); |
45 |
}
|
|
46 |
};
|
|
47 |
||
48 |
template<> void TimestampTestCompareOperators<Date>::initBeforeIdenticalAfter() |
|
49 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
50 |
TemporalGenerator::DateGen::make_date(&before_sample_timestamp, 1980, 1, 1); |
51 |
TemporalGenerator::DateGen::make_date(&identical_with_sample_timestamp, 2010, 9, 8); |
|
52 |
TemporalGenerator::DateGen::make_date(&after_sample_timestamp, 2019, 5, 30); |
|
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
53 |
}
|
54 |
||
55 |
template<> void TimestampTestCompareOperators<DateTime>::initBeforeIdenticalAfter() |
|
56 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
57 |
TemporalGenerator::DateTimeGen::make_datetime(&before_sample_timestamp, 1990, 12, 31, 12, 12, 30); |
58 |
TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_timestamp, 2010, 9, 8, 0, 0, 0); |
|
59 |
TemporalGenerator::DateTimeGen::make_datetime(&after_sample_timestamp, 2020, 4, 4, 4, 4, 4); |
|
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
60 |
}
|
61 |
||
62 |
template<> void TimestampTestCompareOperators<Timestamp>::initBeforeIdenticalAfter() |
|
63 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
64 |
TemporalGenerator::TimestampGen::make_timestamp(&before_sample_timestamp, 2010, 9, 7, 23, 59, 59); |
65 |
TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_timestamp, 2010, 9, 8, 0, 0, 0); |
|
66 |
TemporalGenerator::TimestampGen::make_timestamp(&after_sample_timestamp, 2010, 9, 8, 0, 0, 1); |
|
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
67 |
}
|
68 |
||
69 |
typedef ::testing::Types<Date, DateTime, Timestamp> typesForTimestampTestCompareOperators; |
|
70 |
TYPED_TEST_CASE(TimestampTestCompareOperators, typesForTimestampTestCompareOperators); |
|
71 |
||
72 |
TYPED_TEST(TimestampTestCompareOperators, operatorEqual_ComparingWithIdencticalTemporal_ShouldReturn_True) |
|
73 |
{
|
|
74 |
this->result= (this->sample_timestamp == this->identical_with_sample_timestamp); |
|
75 |
||
76 |
ASSERT_TRUE(this->result); |
|
77 |
}
|
|
78 |
||
79 |
TYPED_TEST(TimestampTestCompareOperators, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False) |
|
80 |
{
|
|
81 |
this->result= (this->sample_timestamp == this->before_sample_timestamp); |
|
82 |
||
83 |
ASSERT_FALSE(this->result); |
|
84 |
}
|
|
85 |
||
86 |
TYPED_TEST(TimestampTestCompareOperators, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False) |
|
87 |
{
|
|
88 |
this->result= (this->sample_timestamp != this->identical_with_sample_timestamp); |
|
89 |
||
90 |
ASSERT_FALSE(this->result); |
|
91 |
}
|
|
92 |
||
93 |
TYPED_TEST(TimestampTestCompareOperators, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True) |
|
94 |
{
|
|
95 |
this->result= (this->sample_timestamp != this->before_sample_timestamp); |
|
96 |
||
97 |
ASSERT_TRUE(this->result); |
|
98 |
}
|
|
99 |
||
100 |
TYPED_TEST(TimestampTestCompareOperators, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False) |
|
101 |
{
|
|
102 |
this->result= (this->sample_timestamp > this->identical_with_sample_timestamp); |
|
103 |
||
104 |
ASSERT_FALSE(this->result); |
|
105 |
}
|
|
106 |
||
107 |
TYPED_TEST(TimestampTestCompareOperators, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False) |
|
108 |
{
|
|
109 |
this->result= (this->sample_timestamp > this->after_sample_timestamp); |
|
110 |
||
111 |
ASSERT_FALSE(this->result); |
|
112 |
}
|
|
113 |
||
114 |
TYPED_TEST(TimestampTestCompareOperators, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True) |
|
115 |
{
|
|
116 |
this->result= (this->sample_timestamp > this->before_sample_timestamp); |
|
117 |
||
118 |
ASSERT_TRUE(this->result); |
|
119 |
}
|
|
120 |
||
121 |
TYPED_TEST(TimestampTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True) |
|
122 |
{
|
|
123 |
this->result= (this->sample_timestamp >= this->identical_with_sample_timestamp); |
|
124 |
||
125 |
ASSERT_TRUE(this->result); |
|
126 |
}
|
|
127 |
||
128 |
TYPED_TEST(TimestampTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False) |
|
129 |
{
|
|
130 |
this->result= (this->sample_timestamp >= this->after_sample_timestamp); |
|
131 |
||
132 |
ASSERT_FALSE(this->result); |
|
133 |
}
|
|
134 |
||
135 |
TYPED_TEST(TimestampTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True) |
|
136 |
{
|
|
137 |
this->result= (this->sample_timestamp >= this->before_sample_timestamp); |
|
138 |
||
139 |
ASSERT_TRUE(this->result); |
|
140 |
}
|
|
141 |
||
142 |
TYPED_TEST(TimestampTestCompareOperators, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False) |
|
143 |
{
|
|
144 |
this->result= (this->sample_timestamp < this->identical_with_sample_timestamp); |
|
145 |
||
146 |
ASSERT_FALSE(this->result); |
|
147 |
}
|
|
148 |
||
149 |
TYPED_TEST(TimestampTestCompareOperators, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True) |
|
150 |
{
|
|
151 |
this->result= (this->sample_timestamp < this->after_sample_timestamp); |
|
152 |
||
153 |
ASSERT_TRUE(this->result); |
|
154 |
}
|
|
155 |
||
156 |
TYPED_TEST(TimestampTestCompareOperators, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False) |
|
157 |
{
|
|
158 |
this->result= (this->sample_timestamp < this->before_sample_timestamp); |
|
159 |
||
160 |
ASSERT_FALSE(this->result); |
|
161 |
}
|
|
162 |
||
163 |
TYPED_TEST(TimestampTestCompareOperators, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True) |
|
164 |
{
|
|
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
165 |
this->result= (this->sample_timestamp <= this->identical_with_sample_timestamp); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
166 |
|
167 |
ASSERT_TRUE(this->result); |
|
168 |
}
|
|
169 |
||
170 |
TYPED_TEST(TimestampTestCompareOperators, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True) |
|
171 |
{
|
|
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
172 |
this->result= (this->sample_timestamp <= this->after_sample_timestamp); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
173 |
|
174 |
ASSERT_TRUE(this->result); |
|
175 |
}
|
|
176 |
||
177 |
TYPED_TEST(TimestampTestCompareOperators, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False) |
|
178 |
{
|
|
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
179 |
this->result= (this->sample_timestamp <= this->before_sample_timestamp); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
180 |
|
181 |
ASSERT_FALSE(this->result); |
|
182 |
}
|
|
183 |
||
184 |
class TimestampTest : public ::testing::Test |
|
185 |
{
|
|
186 |
protected: |
|
187 |
Timestamp timestamp; |
|
188 |
bool result; |
|
189 |
};
|
|
190 |
||
191 |
TEST_F(TimestampTest, is_valid_minOfTimestampRange_shouldReturn_True) |
|
192 |
{
|
|
193 |
uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
194 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, year, month, day, hour, minute, second); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
195 |
|
196 |
result= timestamp.is_valid(); |
|
197 |
||
198 |
ASSERT_TRUE(result); |
|
199 |
}
|
|
200 |
||
201 |
TEST_F(TimestampTest, is_valid_maxOfTimestampRange_shouldReturn_True) |
|
202 |
{
|
|
203 |
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
204 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, year, month, day, hour, minute, second); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
205 |
|
206 |
result= timestamp.is_valid(); |
|
207 |
||
208 |
ASSERT_TRUE(result); |
|
209 |
}
|
|
210 |
||
211 |
TEST_F(TimestampTest, is_valid_oneSecondBeforeTimestampMinOfRange_shouldReturn_False) |
|
212 |
{
|
|
213 |
uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
214 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, year, month, day, hour, minute, second); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
215 |
|
216 |
result= timestamp.is_valid(); |
|
217 |
||
218 |
ASSERT_FALSE(result); |
|
219 |
}
|
|
220 |
||
221 |
TEST_F(TimestampTest, is_valid_oneSecondAfterTimestampMaxOfRange_shouldReturn_False) |
|
222 |
{
|
|
223 |
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
224 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, year, month, day, hour, minute, second); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
225 |
|
226 |
result= timestamp.is_valid(); |
|
227 |
||
228 |
ASSERT_FALSE(result); |
|
229 |
}
|
|
230 |
||
231 |
TEST_F(TimestampTest, is_valid_InsideOfTimestampRange_shouldReturn_True) |
|
232 |
{
|
|
233 |
uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
234 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, year, month, day, hour, minute, second); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
235 |
|
236 |
result= timestamp.is_valid(); |
|
237 |
||
238 |
ASSERT_TRUE(result); |
|
239 |
}
|
|
240 |
||
241 |
TEST_F(TimestampTest, to_time_t) |
|
242 |
{
|
|
243 |
time_t time; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
244 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, 2009, 6, 3, 4, 59, 1); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
245 |
|
2016.1.7
by Brian Aker
Remove MyISAM flip bit, and make sure that we only pass in a good time_t to |
246 |
timestamp.to_time_t(time); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
247 |
|
248 |
ASSERT_EQ(1244005141, time); |
|
249 |
}
|
|
250 |
||
251 |
TEST_F(TimestampTest, outputStreamOperator_shouldWrite_hyphenSeperatedDateElements_and_colonSeperatedTimeElements) |
|
252 |
{
|
|
253 |
std::ostringstream output; |
|
254 |
std::string expected= "2010-05-01 08:07:06"; |
|
255 |
std::string returned; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
256 |
TemporalGenerator::TimestampGen::make_timestamp(×tamp, 2010, 5, 1, 8, 7, 6); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
257 |
|
258 |
output << timestamp; |
|
1377.8.35
by Paweł Blokus
fixed some style issues and decided on buffer size in temporal_interval_test |
259 |
returned= output.str(); |
1377.8.22
by Paweł Blokus
added missing time component parameters to timestamp generator |
260 |
|
261 |
ASSERT_EQ(expected, returned); |
|
262 |
}
|