~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/date_test.cc

added missing time component parameters to timestamp generator
test for Date::operator=
added generators for micro and nano timestamps
tests for:
  Timestamp
  MicroTimestamp
  NanoTimestamp
cleanup of include.am file
fixed minor style issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
template<> void DateTestCompareOperators<Timestamp>::initBeforeIdenticalAfter()
63
63
{
64
 
  Generator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1);
65
 
  Generator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8);
66
 
  Generator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30);
 
64
  Generator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41);
 
65
  Generator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
 
66
  Generator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13);
67
67
}
68
68
 
69
69
typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTestCompareOperators;
193
193
    }
194
194
};
195
195
 
 
196
TEST_F(DateTest, operatorAssign_shouldCopyDateRelatadComponents)
 
197
{
 
198
  Date copy = date;
 
199
 
 
200
  EXPECT_EQ(date.years(), copy.years());
 
201
  EXPECT_EQ(date.months(), copy.months());
 
202
  EXPECT_EQ(date.days(), copy.days());
 
203
}
 
204
 
196
205
TEST_F(DateTest, is_valid_onValidDate_shouldReturn_True)
197
206
{
198
207
  result= date.is_valid();
331
340
  char valid_string[Date::MAX_STRING_LENGTH]= "2010-05-01";
332
341
  uint32_t years, months, days;
333
342
  
334
 
  result = date.from_string(valid_string, Date::MAX_STRING_LENGTH);
 
343
  result= date.from_string(valid_string, Date::MAX_STRING_LENGTH);
335
344
  ASSERT_TRUE(result);
336
345
  
337
 
  years = date.years();
338
 
  months = date.months();
339
 
  days = date.days();
 
346
  years= date.years();
 
347
  months= date.months();
 
348
  days= date.days();
340
349
  
341
350
  EXPECT_EQ(2010, years);
342
351
  EXPECT_EQ(5, months);
347
356
{
348
357
  char valid_string[Date::MAX_STRING_LENGTH]= "2x10-05-01";
349
358
   
350
 
  result = date.from_string(valid_string, Date::MAX_STRING_LENGTH);
 
359
  result= date.from_string(valid_string, Date::MAX_STRING_LENGTH);
351
360
  ASSERT_FALSE(result);
352
361
}
353
362
 
354
363
TEST_F(DateTest, from_int32_t_onValueCreatedBy_to_int32_t_shouldProduceOriginalDate)
355
364
{
356
 
  uint32_t years = 2030, months = 8, days = 17;
 
365
  uint32_t years= 2030, months= 8, days= 17;
357
366
  Generator::DateGen::make_date(&date, years, months, days);
358
367
  uint32_t decoded_years, decoded_months, decoded_days;
359
368
  int32_t representation;
362
371
  date.to_int32_t(&representation);
363
372
  decoded_date.from_int32_t(representation);
364
373
  
365
 
  decoded_years = decoded_date.years();
366
 
  decoded_months = decoded_date.months();
367
 
  decoded_days = decoded_date.days();
 
374
  decoded_years= decoded_date.years();
 
375
  decoded_months= decoded_date.months();
 
376
  decoded_days= decoded_date.days();
368
377
  
369
378
  EXPECT_EQ(years, decoded_years);
370
379
  EXPECT_EQ(months, decoded_months);
383
392
 
384
393
TEST_F(DateTest, from_julian_day_number)
385
394
{
386
 
  int64_t julian_day = 2451544;
 
395
  int64_t julian_day= 2451544;
387
396
  uint32_t years, months, days;
388
397
   
389
398
  date.from_julian_day_number(julian_day);
390
399
  
391
 
  years = date.years();
392
 
  months = date.months();
393
 
  days = date.days();  
 
400
  years= date.years();
 
401
  months= date.months();
 
402
  days= date.days();
394
403
    
395
404
  EXPECT_EQ(1999, years);
396
405
  EXPECT_EQ(12, months);
399
408
 
400
409
TEST_F(DateTest, to_tm)
401
410
{
402
 
  uint32_t years = 2030, months = 8, days = 17;
 
411
  uint32_t years= 2030, months= 8, days= 17;
403
412
  Generator::DateGen::make_date(&date, years, months, days);
404
413
  struct tm filled;
405
414
  
420
429
{
421
430
  uint32_t years, months, days;
422
431
  struct tm from;
423
 
  from.tm_year = 1956;
424
 
  from.tm_mon = 3;
425
 
  from.tm_mday = 30;
 
432
  from.tm_year= 1956;
 
433
  from.tm_mon= 3;
 
434
  from.tm_mday= 30;
426
435
  
427
436
  date.from_tm(&from);
428
437
  
429
 
  years = date.years();
430
 
  months = date.months();
431
 
  days = date.days();
 
438
  years= date.years();
 
439
  months= date.months();
 
440
  days= date.days();
432
441
  
433
442
  EXPECT_EQ(1956, years);  
434
443
  EXPECT_EQ(3, months);
451
460
  
452
461
  date.from_time_t(652838400);
453
462
  
454
 
  years = date.years();
455
 
  months = date.months();
456
 
  days = date.days();
 
463
  years= date.years();
 
464
  months= date.months();
 
465
  days= date.days();
457
466
  
458
467
  EXPECT_EQ(1990, years);  
459
468
  EXPECT_EQ(9, months);