~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/Time_test.cc

added Time_test to include.am
added TimeGen class to generators
added tests Time members

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "generator.h"
27
27
 
 
28
using namespace drizzled;
 
29
 
28
30
class TimeTest: public ::testing::Test
29
31
{
 
32
protected:
30
33
  Time sample_time;
31
34
  bool result;
32
35
  
33
 
  Time identical_with_sample_date, before_sample_date, after_sample_date;
34
 
  
35
 
  void initBeforeIdenticalAfter();
 
36
  Time identical_with_sample_time, before_sample_time, after_sample_time;
36
37
  
37
38
  virtual void SetUp()
38
39
  {
39
 
    Generator::DateGen::make_date(&sample_date, 2010, 9, 8);
40
 
    initBeforeIdenticalAfter();
 
40
    Generator::TimeGen::make_time(&sample_time, 18, 34, 59);
 
41
    
 
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);
 
45
    
41
46
  }
42
 
}
 
47
};
43
48
 
44
49
TEST_F(TimeTest, operatorEqual_ComparingWithIdencticalTime_ShouldReturn_True)
45
50
{
46
 
  this->result= (this->sample_date == this->identical_with_sample_date);
 
51
  this->result= (this->sample_time == this->identical_with_sample_time);
47
52
  
48
53
  ASSERT_TRUE(this->result);
49
54
}
50
55
 
51
56
TEST_F(TimeTest, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False)
52
57
{
53
 
  this->result= (this->sample_date == this->before_sample_date);
 
58
  this->result= (this->sample_time == this->before_sample_time);
54
59
  
55
60
  ASSERT_FALSE(this->result);
56
61
}
57
62
 
58
63
TEST_F(TimeTest, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False)
59
64
60
 
  this->result= (this->sample_date != this->identical_with_sample_date);
 
65
  this->result= (this->sample_time != this->identical_with_sample_time);
61
66
  
62
67
  ASSERT_FALSE(this->result);
63
68
}
64
69
 
65
70
TEST_F(TimeTest, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True)
66
71
{
67
 
  this->result= (this->sample_date != this->before_sample_date);
 
72
  this->result= (this->sample_time != this->before_sample_time);
68
73
  
69
74
  ASSERT_TRUE(this->result);
70
75
}
71
76
 
72
77
TEST_F(TimeTest, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
73
78
{
74
 
  this->result= (this->sample_date > this->identical_with_sample_date);
 
79
  this->result= (this->sample_time > this->identical_with_sample_time);
75
80
  
76
81
  ASSERT_FALSE(this->result);
77
82
}
78
83
 
79
84
TEST_F(TimeTest, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False)
80
85
{
81
 
  this->result= (this->sample_date > this->after_sample_date);
 
86
  this->result= (this->sample_time > this->after_sample_time);
82
87
  
83
88
  ASSERT_FALSE(this->result);
84
89
}
85
90
 
86
91
TEST_F(TimeTest, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True)
87
92
{
88
 
  this->result= (this->sample_date > this->before_sample_date);
 
93
  this->result= (this->sample_time > this->before_sample_time);
89
94
  
90
95
  ASSERT_TRUE(this->result);
91
96
}
92
97
 
93
98
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
94
99
{
95
 
  this->result= (this->sample_date >= this->identical_with_sample_date);
 
100
  this->result= (this->sample_time >= this->identical_with_sample_time);
96
101
  
97
102
  ASSERT_TRUE(this->result);
98
103
}
99
104
 
100
105
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False)
101
106
{
102
 
  this->result= (this->sample_date >= this->after_sample_date);
 
107
  this->result= (this->sample_time >= this->after_sample_time);
103
108
  
104
109
  ASSERT_FALSE(this->result);
105
110
}
106
111
 
107
112
TEST_F(TimeTest, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True)
108
113
{
109
 
  this->result= (this->sample_date >= this->before_sample_date);
 
114
  this->result= (this->sample_time >= this->before_sample_time);
110
115
  
111
116
  ASSERT_TRUE(this->result);
112
117
}
113
118
 
114
119
TEST_F(TimeTest, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
115
120
{
116
 
  this->result= (this->sample_date < this->identical_with_sample_date);
 
121
  this->result= (this->sample_time < this->identical_with_sample_time);
117
122
  
118
123
  ASSERT_FALSE(this->result);
119
124
}
120
125
 
121
126
TEST_F(TimeTest, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True)
122
127
{
123
 
  this->result= (this->sample_date < this->after_sample_date);
 
128
  this->result= (this->sample_time < this->after_sample_time);
124
129
  
125
130
  ASSERT_TRUE(this->result);
126
131
}
127
132
 
128
133
TEST_F(TimeTest, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False)
129
134
{
130
 
  this->result= (this->sample_date < this->before_sample_date);
 
135
  this->result= (this->sample_time < this->before_sample_time);
131
136
  
132
137
  ASSERT_FALSE(this->result);
133
138
}
134
139
 
135
140
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
136
141
{
137
 
  this->result= (this->sample_date < this->identical_with_sample_date);
 
142
  this->result= (this->sample_time < this->identical_with_sample_time);
138
143
  
139
144
  ASSERT_TRUE(this->result);
140
145
}
141
146
 
142
147
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True)
143
148
{
144
 
  this->result= (this->sample_date < this->after_sample_date);
 
149
  this->result= (this->sample_time < this->after_sample_time);
145
150
  
146
151
  ASSERT_TRUE(this->result);
147
152
}
148
153
 
149
154
TEST_F(TimeTest, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False)
150
155
{
151
 
  this->result= (this->sample_date < this->before_sample_date);
 
156
  this->result= (this->sample_time < this->before_sample_time);
152
157
  
153
158
  ASSERT_FALSE(this->result);
154
 
}
 
 
b'\\ No newline at end of file'
 
159
}
 
160
 
 
161
TEST_F(TimeTest, is_valid_onValidTime_shouldReturn_True)
 
162
{
 
163
  result= sample_time.is_valid();
 
164
  
 
165
  ASSERT_TRUE(result);
 
166
}
 
167
 
 
168
TEST_F(TimeTest, is_valid_onValidMinimalTime_shouldReturn_True)
 
169
{
 
170
  Generator::TimeGen::make_min_time(&sample_time);
 
171
  
 
172
  result= sample_time.is_valid();
 
173
  
 
174
  ASSERT_TRUE(result);
 
175
}
 
176
 
 
177
TEST_F(TimeTest, is_valid_onValidMaximalTime_shouldReturn_True)
 
178
{
 
179
  Generator::TimeGen::make_max_time(&sample_time);
 
180
  
 
181
  result= sample_time.is_valid();
 
182
  
 
183
  ASSERT_TRUE(result);
 
184
}
 
185
 
 
186
TEST_F(TimeTest, is_valid_onInvalidTimeWithHourAboveMaximum23_shouldReturn_False)
 
187
{
 
188
  sample_time.set_hours(24);
 
189
  
 
190
  result= sample_time.is_valid();
 
191
  
 
192
  ASSERT_FALSE(result);
 
193
}
 
194
 
 
195
TEST_F(TimeTest, is_valid_onInvalidTimeWithMinutesAboveMaximum59_shouldReturn_False)
 
196
{
 
197
  sample_time.set_minutes(60);
 
198
  
 
199
  result= sample_time.is_valid();
 
200
  
 
201
  ASSERT_FALSE(result);
 
202
}
 
203
 
 
204
TEST_F(TimeTest, is_valid_onInvalidTimeWithSecondsAboveMaximum59_shouldReturn_False)
 
205
{
 
206
  sample_time.set_seconds(60);
 
207
  
 
208
  result= sample_time.is_valid();
 
209
  
 
210
  ASSERT_FALSE(result);
 
211
}
 
212
 
 
213
TEST_F(TimeTest, to_string_shouldProduce_colonSeperatedTimeElements)
 
214
{
 
215
  char expected[Time::MAX_STRING_LENGTH]= "18:34:59";
 
216
  char returned[Time::MAX_STRING_LENGTH];
 
217
  
 
218
  sample_time.to_string(returned, Time::MAX_STRING_LENGTH);
 
219
  
 
220
  ASSERT_STREQ(expected, returned);  
 
221
}
 
222
 
 
223
TEST_F(TimeTest, to_string_nullBuffer_shouldReturnProperLengthAnyway)
 
224
{
 
225
  int length= sample_time.to_string(NULL, 0);
 
226
  
 
227
  ASSERT_EQ(Time::MAX_STRING_LENGTH - 1, length);  
 
228
}
 
229
 
 
230
TEST_F(TimeTest, from_string_validString_shouldPopulateCorrectly)
 
231
{
 
232
  char valid_string[Time::MAX_STRING_LENGTH]= "18:34:59";
 
233
  uint32_t hours, minutes, seconds;
 
234
  
 
235
  result = sample_time.from_string(valid_string, Time::MAX_STRING_LENGTH);
 
236
  ASSERT_TRUE(result);
 
237
  
 
238
  hours= sample_time.hours();
 
239
  minutes = sample_time.minutes();
 
240
  seconds = sample_time.seconds();
 
241
  
 
242
  EXPECT_EQ(18, hours);
 
243
  EXPECT_EQ(34, minutes);
 
244
  EXPECT_EQ(59, seconds);
 
245
}
 
246
 
 
247
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False)
 
248
{
 
249
  char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59";
 
250
  
 
251
  result = sample_time.from_string(invalid_string, Time::MAX_STRING_LENGTH);
 
252
  ASSERT_FALSE(result);
 
253
}
 
254
 
 
255
TEST_F(TimeTest, from_int32_t_onValueCreatedBy_to_int32_t_shouldProduceOriginalTime)
 
256
{
 
257
  uint32_t decoded_hours, decoded_minutes, decoded_seconds;
 
258
  int32_t representation;
 
259
  Time decoded_time;
 
260
  
 
261
  sample_time.to_int32_t(&representation);
 
262
  decoded_time.from_int32_t(representation);
 
263
  
 
264
  decoded_hours = decoded_time.hours();
 
265
  decoded_minutes = decoded_time.minutes();
 
266
  decoded_seconds = decoded_time.seconds();
 
267
  
 
268
  EXPECT_EQ(18, decoded_hours);
 
269
  EXPECT_EQ(34, decoded_minutes);
 
270
  EXPECT_EQ(59, decoded_seconds);
 
271
}
 
272
 
 
273
TEST_F(TimeTest, from_time_t)
 
274
{
 
275
  uint32_t hours, minutes, seconds;
 
276
  
 
277
  sample_time.from_time_t(59588);
 
278
  
 
279
  hours = sample_time.hours();
 
280
  minutes = sample_time.minutes();
 
281
  seconds = sample_time.seconds();
 
282
  
 
283
  EXPECT_EQ(16, hours);  
 
284
  EXPECT_EQ(33, minutes);
 
285
  EXPECT_EQ(8, seconds);
 
286
}