1377.8.16
by Paweł Blokus
tests for Time compare operators |
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> |
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
24 |
#include <drizzled/decimal.h> |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
25 |
#include <drizzled/temporal.h> |
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
26 |
#include <drizzled/temporal_format.h> |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
27 |
|
1377.9.1
by Paweł Blokus
updated includes to last file rename |
28 |
#include "temporal_generator.h" |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
29 |
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
30 |
using namespace drizzled; |
31 |
||
1377.8.16
by Paweł Blokus
tests for Time compare operators |
32 |
class TimeTest: public ::testing::Test |
33 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
34 |
protected: |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
35 |
Time sample_time; |
36 |
bool result; |
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
37 |
uint32_t hours, minutes, seconds; |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
38 |
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
39 |
Time identical_with_sample_time, before_sample_time, after_sample_time; |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
40 |
|
41 |
virtual void SetUp() |
|
42 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
43 |
TemporalGenerator::TimeGen::make_time(&sample_time, 18, 34, 59); |
1377.8.18
by Paweł Blokus
added Time_test to include.am |
44 |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
45 |
TemporalGenerator::TimeGen::make_time(&before_sample_time, 18, 34, 58); |
46 |
TemporalGenerator::TimeGen::make_time(&identical_with_sample_time, 18, 34, 59); |
|
47 |
TemporalGenerator::TimeGen::make_time(&after_sample_time, 18, 35, 0); |
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
48 |
|
1377.8.16
by Paweł Blokus
tests for Time compare operators |
49 |
}
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
50 |
|
51 |
void assign_time_values() |
|
52 |
{
|
|
53 |
hours= sample_time.hours(); |
|
54 |
minutes= sample_time.minutes(); |
|
55 |
seconds= sample_time.seconds(); |
|
56 |
}
|
|
57 |
||
58 |
void from_string(const char *string) |
|
59 |
{
|
|
60 |
||
61 |
init_temporal_formats(); |
|
62 |
result= sample_time.from_string(string, strlen(string)); |
|
63 |
deinit_temporal_formats(); |
|
64 |
||
65 |
assign_time_values(); |
|
66 |
}
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
67 |
};
|
1377.8.16
by Paweł Blokus
tests for Time compare operators |
68 |
|
69 |
TEST_F(TimeTest, operatorEqual_ComparingWithIdencticalTime_ShouldReturn_True) |
|
70 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
71 |
this->result= (this->sample_time == this->identical_with_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
72 |
|
73 |
ASSERT_TRUE(this->result); |
|
74 |
}
|
|
75 |
||
76 |
TEST_F(TimeTest, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False) |
|
77 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
78 |
this->result= (this->sample_time == this->before_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
79 |
|
80 |
ASSERT_FALSE(this->result); |
|
81 |
}
|
|
82 |
||
83 |
TEST_F(TimeTest, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False) |
|
84 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
85 |
this->result= (this->sample_time != this->identical_with_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
86 |
|
87 |
ASSERT_FALSE(this->result); |
|
88 |
}
|
|
89 |
||
90 |
TEST_F(TimeTest, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True) |
|
91 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
92 |
this->result= (this->sample_time != this->before_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
93 |
|
94 |
ASSERT_TRUE(this->result); |
|
95 |
}
|
|
96 |
||
97 |
TEST_F(TimeTest, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False) |
|
98 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
99 |
this->result= (this->sample_time > this->identical_with_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
100 |
|
101 |
ASSERT_FALSE(this->result); |
|
102 |
}
|
|
103 |
||
104 |
TEST_F(TimeTest, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False) |
|
105 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
106 |
this->result= (this->sample_time > this->after_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
107 |
|
108 |
ASSERT_FALSE(this->result); |
|
109 |
}
|
|
110 |
||
111 |
TEST_F(TimeTest, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True) |
|
112 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
113 |
this->result= (this->sample_time > this->before_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
114 |
|
115 |
ASSERT_TRUE(this->result); |
|
116 |
}
|
|
117 |
||
118 |
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True) |
|
119 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
120 |
this->result= (this->sample_time >= this->identical_with_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
121 |
|
122 |
ASSERT_TRUE(this->result); |
|
123 |
}
|
|
124 |
||
125 |
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False) |
|
126 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
127 |
this->result= (this->sample_time >= this->after_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
128 |
|
129 |
ASSERT_FALSE(this->result); |
|
130 |
}
|
|
131 |
||
132 |
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True) |
|
133 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
134 |
this->result= (this->sample_time >= this->before_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
135 |
|
136 |
ASSERT_TRUE(this->result); |
|
137 |
}
|
|
138 |
||
139 |
TEST_F(TimeTest, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False) |
|
140 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
141 |
this->result= (this->sample_time < this->identical_with_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
142 |
|
143 |
ASSERT_FALSE(this->result); |
|
144 |
}
|
|
145 |
||
146 |
TEST_F(TimeTest, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True) |
|
147 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
148 |
this->result= (this->sample_time < this->after_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
149 |
|
150 |
ASSERT_TRUE(this->result); |
|
151 |
}
|
|
152 |
||
153 |
TEST_F(TimeTest, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False) |
|
154 |
{
|
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
155 |
this->result= (this->sample_time < this->before_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
156 |
|
157 |
ASSERT_FALSE(this->result); |
|
158 |
}
|
|
159 |
||
160 |
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True) |
|
161 |
{
|
|
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
162 |
this->result= (this->sample_time <= this->identical_with_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
163 |
|
164 |
ASSERT_TRUE(this->result); |
|
165 |
}
|
|
166 |
||
167 |
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True) |
|
168 |
{
|
|
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
169 |
this->result= (this->sample_time <= this->after_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
170 |
|
171 |
ASSERT_TRUE(this->result); |
|
172 |
}
|
|
173 |
||
174 |
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False) |
|
175 |
{
|
|
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
176 |
this->result= (this->sample_time <= this->before_sample_time); |
1377.8.16
by Paweł Blokus
tests for Time compare operators |
177 |
|
178 |
ASSERT_FALSE(this->result); |
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
179 |
}
|
180 |
||
181 |
TEST_F(TimeTest, is_valid_onValidTime_shouldReturn_True) |
|
182 |
{
|
|
183 |
result= sample_time.is_valid(); |
|
184 |
||
185 |
ASSERT_TRUE(result); |
|
186 |
}
|
|
187 |
||
188 |
TEST_F(TimeTest, is_valid_onValidMinimalTime_shouldReturn_True) |
|
189 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
190 |
TemporalGenerator::TemporalGen::make_min_time(&sample_time); |
1377.8.18
by Paweł Blokus
added Time_test to include.am |
191 |
|
192 |
result= sample_time.is_valid(); |
|
193 |
||
194 |
ASSERT_TRUE(result); |
|
195 |
}
|
|
196 |
||
197 |
TEST_F(TimeTest, is_valid_onValidMaximalTime_shouldReturn_True) |
|
198 |
{
|
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
199 |
TemporalGenerator::TemporalGen::make_max_time(&sample_time); |
1377.8.18
by Paweł Blokus
added Time_test to include.am |
200 |
|
201 |
result= sample_time.is_valid(); |
|
202 |
||
203 |
ASSERT_TRUE(result); |
|
204 |
}
|
|
205 |
||
206 |
TEST_F(TimeTest, is_valid_onInvalidTimeWithHourAboveMaximum23_shouldReturn_False) |
|
207 |
{
|
|
208 |
sample_time.set_hours(24); |
|
209 |
||
210 |
result= sample_time.is_valid(); |
|
211 |
||
212 |
ASSERT_FALSE(result); |
|
213 |
}
|
|
214 |
||
215 |
TEST_F(TimeTest, is_valid_onInvalidTimeWithMinutesAboveMaximum59_shouldReturn_False) |
|
216 |
{
|
|
217 |
sample_time.set_minutes(60); |
|
218 |
||
219 |
result= sample_time.is_valid(); |
|
220 |
||
221 |
ASSERT_FALSE(result); |
|
222 |
}
|
|
223 |
||
224 |
TEST_F(TimeTest, is_valid_onInvalidTimeWithSecondsAboveMaximum59_shouldReturn_False) |
|
225 |
{
|
|
226 |
sample_time.set_seconds(60); |
|
227 |
||
228 |
result= sample_time.is_valid(); |
|
229 |
||
230 |
ASSERT_FALSE(result); |
|
231 |
}
|
|
232 |
||
233 |
TEST_F(TimeTest, to_string_shouldProduce_colonSeperatedTimeElements) |
|
234 |
{
|
|
235 |
char expected[Time::MAX_STRING_LENGTH]= "18:34:59"; |
|
236 |
char returned[Time::MAX_STRING_LENGTH]; |
|
237 |
||
238 |
sample_time.to_string(returned, Time::MAX_STRING_LENGTH); |
|
239 |
||
240 |
ASSERT_STREQ(expected, returned); |
|
241 |
}
|
|
242 |
||
243 |
TEST_F(TimeTest, to_string_nullBuffer_shouldReturnProperLengthAnyway) |
|
244 |
{
|
|
245 |
int length= sample_time.to_string(NULL, 0); |
|
246 |
||
247 |
ASSERT_EQ(Time::MAX_STRING_LENGTH - 1, length); |
|
248 |
}
|
|
249 |
||
1377.8.25
by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass |
250 |
TEST_F(TimeTest, to_int32_t) |
251 |
{
|
|
252 |
int32_t representation; |
|
253 |
||
254 |
sample_time.to_int32_t(&representation); |
|
255 |
||
256 |
ASSERT_EQ(representation, 183459); |
|
257 |
}
|
|
258 |
||
259 |
TEST_F(TimeTest, from_int32_t_shouldPopulateTimeCorrectly) |
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
260 |
{
|
1377.8.26
by Paweł Blokus
created or modified all to_int**_t and from_int**_t function tests |
261 |
sample_time.from_int32_t(183459); |
262 |
||
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
263 |
assign_time_values();; |
1377.8.18
by Paweł Blokus
added Time_test to include.am |
264 |
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
265 |
EXPECT_EQ(18, hours); |
266 |
EXPECT_EQ(34, minutes); |
|
267 |
EXPECT_EQ(59, seconds); |
|
1377.8.18
by Paweł Blokus
added Time_test to include.am |
268 |
}
|
269 |
||
270 |
TEST_F(TimeTest, from_time_t) |
|
271 |
{
|
|
272 |
sample_time.from_time_t(59588); |
|
273 |
||
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
274 |
assign_time_values(); |
1377.8.18
by Paweł Blokus
added Time_test to include.am |
275 |
|
276 |
EXPECT_EQ(16, hours); |
|
277 |
EXPECT_EQ(33, minutes); |
|
278 |
EXPECT_EQ(8, seconds); |
|
279 |
}
|
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
280 |
|
281 |
TEST_F(TimeTest, to_decimal) |
|
282 |
{
|
|
283 |
drizzled::my_decimal to; |
|
1377.8.36
by Paweł Blokus
changed Generator to TemporalGenerator |
284 |
TemporalGenerator::TimeGen::make_time(&sample_time, 8, 4, 9, 56); |
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
285 |
|
286 |
sample_time.to_decimal(&to); |
|
287 |
||
288 |
ASSERT_EQ(80409, to.buf[0]); |
|
1377.8.34
by Paweł Blokus
take microsedonds into account where they are used in datetime and time |
289 |
ASSERT_EQ(56000, to.buf[1]); |
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
290 |
}
|
291 |
||
292 |
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False) |
|
293 |
{
|
|
294 |
char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59"; |
|
295 |
||
296 |
init_temporal_formats(); |
|
297 |
result= sample_time.from_string(invalid_string, strlen(invalid_string)); |
|
298 |
deinit_temporal_formats(); |
|
299 |
||
300 |
ASSERT_FALSE(result); |
|
301 |
}
|
|
302 |
||
303 |
TEST_F(TimeTest, from_string_validString_minuteAndSecond_shouldPopulateCorrectly) |
|
304 |
{
|
|
305 |
char valid_string[Time::MAX_STRING_LENGTH]= "4:52"; |
|
306 |
||
307 |
from_string(valid_string); |
|
308 |
||
309 |
EXPECT_EQ(4, minutes); |
|
310 |
EXPECT_EQ(52, seconds); |
|
311 |
}
|
|
312 |
||
313 |
TEST_F(TimeTest, from_string_validString_minuteAndSecondNoColon_shouldPopulateCorrectly) |
|
314 |
{
|
|
315 |
char valid_string[Time::MAX_STRING_LENGTH]= "3456"; |
|
316 |
||
317 |
from_string(valid_string); |
|
318 |
||
319 |
EXPECT_EQ(34, minutes); |
|
320 |
EXPECT_EQ(56, seconds); |
|
321 |
}
|
|
322 |
||
323 |
TEST_F(TimeTest, from_string_validString_secondsOnly_shouldPopulateCorrectly) |
|
324 |
{
|
|
325 |
char valid_string[Time::MAX_STRING_LENGTH]= "59"; |
|
326 |
||
327 |
from_string(valid_string); |
|
328 |
||
329 |
EXPECT_EQ(59, seconds); |
|
330 |
}
|
|
1377.8.33
by Paweł Blokus
fix/hack? which makes parameterized tests compile |
331 |
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
332 |
class TimeFromStringTest: public ::testing::TestWithParam<const char*> |
333 |
{
|
|
334 |
protected: |
|
335 |
Time time; |
|
336 |
bool result; |
|
337 |
uint32_t hours, minutes, seconds; |
|
338 |
||
339 |
virtual void SetUp() |
|
340 |
{
|
|
341 |
init_temporal_formats(); |
|
342 |
}
|
|
343 |
||
344 |
virtual void TearDown() |
|
345 |
{
|
|
346 |
deinit_temporal_formats(); |
|
347 |
}
|
|
348 |
||
349 |
void assign_time_values() |
|
350 |
{
|
|
351 |
hours= time.hours(); |
|
352 |
minutes= time.minutes(); |
|
353 |
seconds= time.seconds(); |
|
354 |
}
|
|
355 |
};
|
|
356 |
||
1377.8.33
by Paweł Blokus
fix/hack? which makes parameterized tests compile |
357 |
TEST_P(TimeFromStringTest, from_string) |
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
358 |
{
|
1377.8.35
by Paweł Blokus
fixed some style issues and decided on buffer size in temporal_interval_test |
359 |
const char *valid_string= GetParam(); |
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
360 |
|
361 |
result= time.from_string(valid_string, strlen(valid_string)); |
|
362 |
ASSERT_TRUE(result); |
|
363 |
||
364 |
assign_time_values(); |
|
365 |
||
366 |
EXPECT_EQ(8, hours); |
|
367 |
EXPECT_EQ(4, minutes); |
|
368 |
EXPECT_EQ(9, seconds); |
|
369 |
}
|
|
370 |
||
1377.8.33
by Paweł Blokus
fix/hack? which makes parameterized tests compile |
371 |
/* TODO:for some reason this was not declared by the macro, needs clarification*/
|
372 |
testing::internal::ParamGenerator<const char*> gtest_ValidStringTimeFromStringTest_EvalGenerator_(); |
|
373 |
||
374 |
INSTANTIATE_TEST_CASE_P(ValidString, TimeFromStringTest, |
|
1377.8.27
by Paweł Blokus
tests for to_decimal methods |
375 |
::testing::Values("080409", |
376 |
"80409", |
|
377 |
"08:04:09", |
|
378 |
"8:04:09", |
|
379 |
"8:04:9", |
|
380 |
"8:4:9")); |
|
1377.8.33
by Paweł Blokus
fix/hack? which makes parameterized tests compile |
381 |