45
47
Generator::TimeGen::make_time(&after_sample_time, 18, 35, 0);
51
void assign_time_values()
53
hours= sample_time.hours();
54
minutes= sample_time.minutes();
55
seconds= sample_time.seconds();
58
void from_string(const char *string)
61
init_temporal_formats();
62
result= sample_time.from_string(string, strlen(string));
63
deinit_temporal_formats();
50
69
TEST_F(TimeTest, operatorEqual_ComparingWithIdencticalTime_ShouldReturn_True)
228
247
ASSERT_EQ(Time::MAX_STRING_LENGTH - 1, length);
231
TEST_F(TimeTest, from_string_validString_shouldPopulateCorrectly)
233
char valid_string[Time::MAX_STRING_LENGTH]= "18:34:59";
234
uint32_t hours, minutes, seconds;
236
init_temporal_formats();
238
result= sample_time.from_string(valid_string, Time::MAX_STRING_LENGTH - 1);
241
hours= sample_time.hours();
242
minutes= sample_time.minutes();
243
seconds= sample_time.seconds();
245
deinit_temporal_formats();
247
EXPECT_EQ(18, hours);
248
EXPECT_EQ(34, minutes);
249
EXPECT_EQ(59, seconds);
252
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False)
254
char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59";
256
init_temporal_formats();
257
result= sample_time.from_string(invalid_string, Time::MAX_STRING_LENGTH - 1);
258
deinit_temporal_formats();
260
ASSERT_FALSE(result);
263
250
TEST_F(TimeTest, to_int32_t)
265
252
int32_t representation;
272
259
TEST_F(TimeTest, from_int32_t_shouldPopulateTimeCorrectly)
274
uint32_t decoded_hours, decoded_minutes, decoded_seconds;
276
261
sample_time.from_int32_t(183459);
278
decoded_hours= sample_time.hours();
279
decoded_minutes= sample_time.minutes();
280
decoded_seconds= sample_time.seconds();
263
assign_time_values();;
282
EXPECT_EQ(18, decoded_hours);
283
EXPECT_EQ(34, decoded_minutes);
284
EXPECT_EQ(59, decoded_seconds);
265
EXPECT_EQ(18, hours);
266
EXPECT_EQ(34, minutes);
267
EXPECT_EQ(59, seconds);
287
270
TEST_F(TimeTest, from_time_t)
289
uint32_t hours, minutes, seconds;
291
272
sample_time.from_time_t(59588);
293
hours= sample_time.hours();
294
minutes= sample_time.minutes();
295
seconds= sample_time.seconds();
274
assign_time_values();
297
276
EXPECT_EQ(16, hours);
298
277
EXPECT_EQ(33, minutes);
299
278
EXPECT_EQ(8, seconds);
281
TEST_F(TimeTest, to_decimal)
283
drizzled::my_decimal to;
284
Generator::TimeGen::make_time(&sample_time, 8, 4, 9);
286
sample_time.to_decimal(&to);
288
ASSERT_EQ(80409, to.buf[0]);
291
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False)
293
char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59";
295
init_temporal_formats();
296
result= sample_time.from_string(invalid_string, strlen(invalid_string));
297
deinit_temporal_formats();
299
ASSERT_FALSE(result);
302
TEST_F(TimeTest, from_string_validString_minuteAndSecond_shouldPopulateCorrectly)
304
char valid_string[Time::MAX_STRING_LENGTH]= "4:52";
306
from_string(valid_string);
308
EXPECT_EQ(4, minutes);
309
EXPECT_EQ(52, seconds);
312
TEST_F(TimeTest, from_string_validString_minuteAndSecondNoColon_shouldPopulateCorrectly)
314
char valid_string[Time::MAX_STRING_LENGTH]= "3456";
316
from_string(valid_string);
318
EXPECT_EQ(34, minutes);
319
EXPECT_EQ(56, seconds);
322
TEST_F(TimeTest, from_string_validString_secondsOnly_shouldPopulateCorrectly)
324
char valid_string[Time::MAX_STRING_LENGTH]= "59";
326
from_string(valid_string);
328
EXPECT_EQ(59, seconds);
331
class TimeFromStringTest: public ::testing::TestWithParam<const char*>
336
uint32_t hours, minutes, seconds;
340
init_temporal_formats();
343
virtual void TearDown()
345
deinit_temporal_formats();
348
void assign_time_values()
351
minutes= time.minutes();
352
seconds= time.seconds();
356
TEST_P(TimeFromStringTest, from_string_validString_formatsWithAllTimeComponentsPresent_shouldPopulateCorrectly)
358
const char *valid_string = GetParam();
360
result= time.from_string(valid_string, strlen(valid_string));
363
assign_time_values();
366
EXPECT_EQ(4, minutes);
367
EXPECT_EQ(9, seconds);
370
INSTANTIATE_TEST_CASE_P(FormatsWithAllTimeComponentsPresent, TimeFromStringTest,
371
::testing::Values("080409",
b'\\ No newline at end of file'