26
26
#include "generator.h"
28
using namespace drizzled;
28
30
class TimeTest: public ::testing::Test
33
Time identical_with_sample_date, before_sample_date, after_sample_date;
35
void initBeforeIdenticalAfter();
36
Time identical_with_sample_time, before_sample_time, after_sample_time;
37
38
virtual void SetUp()
39
Generator::DateGen::make_date(&sample_date, 2010, 9, 8);
40
initBeforeIdenticalAfter();
40
Generator::TimeGen::make_time(&sample_time, 18, 34, 59);
42
Generator::TimeGen::make_time(&before_sample_time, 18, 34, 58);
43
Generator::TimeGen::make_time(&identical_with_sample_time, 18, 34, 59);
44
Generator::TimeGen::make_time(&after_sample_time, 18, 35, 0);
44
49
TEST_F(TimeTest, operatorEqual_ComparingWithIdencticalTime_ShouldReturn_True)
46
this->result= (this->sample_date == this->identical_with_sample_date);
51
this->result= (this->sample_time == this->identical_with_sample_time);
48
53
ASSERT_TRUE(this->result);
51
56
TEST_F(TimeTest, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False)
53
this->result= (this->sample_date == this->before_sample_date);
58
this->result= (this->sample_time == this->before_sample_time);
55
60
ASSERT_FALSE(this->result);
58
63
TEST_F(TimeTest, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False)
60
this->result= (this->sample_date != this->identical_with_sample_date);
65
this->result= (this->sample_time != this->identical_with_sample_time);
62
67
ASSERT_FALSE(this->result);
65
70
TEST_F(TimeTest, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True)
67
this->result= (this->sample_date != this->before_sample_date);
72
this->result= (this->sample_time != this->before_sample_time);
69
74
ASSERT_TRUE(this->result);
72
77
TEST_F(TimeTest, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
74
this->result= (this->sample_date > this->identical_with_sample_date);
79
this->result= (this->sample_time > this->identical_with_sample_time);
76
81
ASSERT_FALSE(this->result);
79
84
TEST_F(TimeTest, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False)
81
this->result= (this->sample_date > this->after_sample_date);
86
this->result= (this->sample_time > this->after_sample_time);
83
88
ASSERT_FALSE(this->result);
86
91
TEST_F(TimeTest, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True)
88
this->result= (this->sample_date > this->before_sample_date);
93
this->result= (this->sample_time > this->before_sample_time);
90
95
ASSERT_TRUE(this->result);
93
98
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
95
this->result= (this->sample_date >= this->identical_with_sample_date);
100
this->result= (this->sample_time >= this->identical_with_sample_time);
97
102
ASSERT_TRUE(this->result);
100
105
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False)
102
this->result= (this->sample_date >= this->after_sample_date);
107
this->result= (this->sample_time >= this->after_sample_time);
104
109
ASSERT_FALSE(this->result);
107
112
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True)
109
this->result= (this->sample_date >= this->before_sample_date);
114
this->result= (this->sample_time >= this->before_sample_time);
111
116
ASSERT_TRUE(this->result);
114
119
TEST_F(TimeTest, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
116
this->result= (this->sample_date < this->identical_with_sample_date);
121
this->result= (this->sample_time < this->identical_with_sample_time);
118
123
ASSERT_FALSE(this->result);
121
126
TEST_F(TimeTest, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True)
123
this->result= (this->sample_date < this->after_sample_date);
128
this->result= (this->sample_time < this->after_sample_time);
125
130
ASSERT_TRUE(this->result);
128
133
TEST_F(TimeTest, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False)
130
this->result= (this->sample_date < this->before_sample_date);
135
this->result= (this->sample_time < this->before_sample_time);
132
137
ASSERT_FALSE(this->result);
135
140
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
137
this->result= (this->sample_date < this->identical_with_sample_date);
142
this->result= (this->sample_time < this->identical_with_sample_time);
139
144
ASSERT_TRUE(this->result);
142
147
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True)
144
this->result= (this->sample_date < this->after_sample_date);
149
this->result= (this->sample_time < this->after_sample_time);
146
151
ASSERT_TRUE(this->result);
149
154
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False)
151
this->result= (this->sample_date < this->before_sample_date);
156
this->result= (this->sample_time < this->before_sample_time);
153
158
ASSERT_FALSE(this->result);
b'\\ No newline at end of file'
161
TEST_F(TimeTest, is_valid_onValidTime_shouldReturn_True)
163
result= sample_time.is_valid();
168
TEST_F(TimeTest, is_valid_onValidMinimalTime_shouldReturn_True)
170
Generator::TimeGen::make_min_time(&sample_time);
172
result= sample_time.is_valid();
177
TEST_F(TimeTest, is_valid_onValidMaximalTime_shouldReturn_True)
179
Generator::TimeGen::make_max_time(&sample_time);
181
result= sample_time.is_valid();
186
TEST_F(TimeTest, is_valid_onInvalidTimeWithHourAboveMaximum23_shouldReturn_False)
188
sample_time.set_hours(24);
190
result= sample_time.is_valid();
192
ASSERT_FALSE(result);
195
TEST_F(TimeTest, is_valid_onInvalidTimeWithMinutesAboveMaximum59_shouldReturn_False)
197
sample_time.set_minutes(60);
199
result= sample_time.is_valid();
201
ASSERT_FALSE(result);
204
TEST_F(TimeTest, is_valid_onInvalidTimeWithSecondsAboveMaximum59_shouldReturn_False)
206
sample_time.set_seconds(60);
208
result= sample_time.is_valid();
210
ASSERT_FALSE(result);
213
TEST_F(TimeTest, to_string_shouldProduce_colonSeperatedTimeElements)
215
char expected[Time::MAX_STRING_LENGTH]= "18:34:59";
216
char returned[Time::MAX_STRING_LENGTH];
218
sample_time.to_string(returned, Time::MAX_STRING_LENGTH);
220
ASSERT_STREQ(expected, returned);
223
TEST_F(TimeTest, to_string_nullBuffer_shouldReturnProperLengthAnyway)
225
int length= sample_time.to_string(NULL, 0);
227
ASSERT_EQ(Time::MAX_STRING_LENGTH - 1, length);
230
TEST_F(TimeTest, from_string_validString_shouldPopulateCorrectly)
232
char valid_string[Time::MAX_STRING_LENGTH]= "18:34:59";
233
uint32_t hours, minutes, seconds;
235
result = sample_time.from_string(valid_string, Time::MAX_STRING_LENGTH);
238
hours= sample_time.hours();
239
minutes = sample_time.minutes();
240
seconds = sample_time.seconds();
242
EXPECT_EQ(18, hours);
243
EXPECT_EQ(34, minutes);
244
EXPECT_EQ(59, seconds);
247
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False)
249
char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59";
251
result = sample_time.from_string(invalid_string, Time::MAX_STRING_LENGTH);
252
ASSERT_FALSE(result);
255
TEST_F(TimeTest, from_int32_t_onValueCreatedBy_to_int32_t_shouldProduceOriginalTime)
257
uint32_t decoded_hours, decoded_minutes, decoded_seconds;
258
int32_t representation;
261
sample_time.to_int32_t(&representation);
262
decoded_time.from_int32_t(representation);
264
decoded_hours = decoded_time.hours();
265
decoded_minutes = decoded_time.minutes();
266
decoded_seconds = decoded_time.seconds();
268
EXPECT_EQ(18, decoded_hours);
269
EXPECT_EQ(34, decoded_minutes);
270
EXPECT_EQ(59, decoded_seconds);
273
TEST_F(TimeTest, from_time_t)
275
uint32_t hours, minutes, seconds;
277
sample_time.from_time_t(59588);
279
hours = sample_time.hours();
280
minutes = sample_time.minutes();
281
seconds = sample_time.seconds();
283
EXPECT_EQ(16, hours);
284
EXPECT_EQ(33, minutes);
285
EXPECT_EQ(8, seconds);