~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/date_test.cc

tests for to_decimal methods
parameterized tests for more formats possible for from_strings, however they don't compile ATM so I commented them out

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/temporal.h>
26
26
#include <drizzled/temporal_format.h>
27
27
 
28
 
#include "temporal_generator.h"
 
28
#include "generator.h"
29
29
 
30
30
using namespace drizzled;
31
31
 
42
42
 
43
43
  virtual void SetUp()
44
44
  {
45
 
    TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8);
 
45
    Generator::DateGen::make_date(&sample_date, 2010, 9, 8);
46
46
    initBeforeIdenticalAfter();
47
47
  }
48
48
};
49
49
 
50
50
template<> void DateTestCompareOperators<Date>::initBeforeIdenticalAfter()
51
51
{
52
 
  TemporalGenerator::DateGen::make_date(&before_sample_date, 1980, 1, 1);
53
 
  TemporalGenerator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8);
54
 
  TemporalGenerator::DateGen::make_date(&after_sample_date, 2019, 5, 30);
 
52
  Generator::DateGen::make_date(&before_sample_date, 1980, 1, 1);
 
53
  Generator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8);
 
54
  Generator::DateGen::make_date(&after_sample_date, 2019, 5, 30);
55
55
}
56
56
 
57
57
template<> void DateTestCompareOperators<DateTime>::initBeforeIdenticalAfter()
58
58
{
59
 
  TemporalGenerator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30);
60
 
  TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
61
 
  TemporalGenerator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4);
 
59
  Generator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30);
 
60
  Generator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
 
61
  Generator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4);
62
62
}
63
63
 
64
64
template<> void DateTestCompareOperators<Timestamp>::initBeforeIdenticalAfter()
65
65
{
66
 
  TemporalGenerator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41);
67
 
  TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
68
 
  TemporalGenerator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13);
 
66
  Generator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41);
 
67
  Generator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
 
68
  Generator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13);
69
69
}
70
70
 
71
71
typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTestCompareOperators;
191
191
    
192
192
    virtual void SetUp()
193
193
    {
194
 
      TemporalGenerator::DateGen::make_valid_date(&date);
 
194
      Generator::DateGen::make_valid_date(&date);
195
195
    }
196
196
};
197
197
 
198
198
TEST_F(DateTest, operatorAssign_shouldCopyDateRelatadComponents)
199
199
{
200
 
  Date copy= date;
 
200
  Date copy = date;
201
201
 
202
202
  EXPECT_EQ(date.years(), copy.years());
203
203
  EXPECT_EQ(date.months(), copy.months());
267
267
 
268
268
TEST_F(DateTest, is_valid_onInvalidDateWithLeapDayInNonLeapYear_shouldReturn_False)
269
269
{
270
 
  TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&date);
 
270
  Generator::TemporalGen::leap_day_in_non_leap_year(&date);
271
271
  
272
272
  result= date.is_valid();
273
273
  
276
276
 
277
277
TEST_F(DateTest, is_valid_onValidDateWithLeapDayInLeapYear_shouldReturn_True)
278
278
{
279
 
  TemporalGenerator::TemporalGen::leap_day_in_leap_year(&date);
 
279
  Generator::TemporalGen::leap_day_in_leap_year(&date);
280
280
  
281
281
  result= date.is_valid();
282
282
  
287
287
{
288
288
  char expected[Date::MAX_STRING_LENGTH]= "2010-05-01";
289
289
  char returned[Date::MAX_STRING_LENGTH];
290
 
  TemporalGenerator::DateGen::make_date(&date, 2010, 5, 1);
 
290
  Generator::DateGen::make_date(&date, 2010, 5, 1);
291
291
  
292
292
  date.to_string(returned, Date::MAX_STRING_LENGTH);
293
293
  
335
335
 
336
336
TEST_F(DateTest, to_int64_t)
337
337
{
338
 
  TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
 
338
  Generator::DateGen::make_date(&date, 2030, 8, 17);
339
339
  int64_t representation;
340
340
  
341
341
  date.to_int64_t(&representation);
345
345
 
346
346
TEST_F(DateTest, to_int32_t)
347
347
{
348
 
  TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
 
348
  Generator::DateGen::make_date(&date, 2030, 8, 17);
349
349
  int32_t representation;
350
350
 
351
351
  date.to_int32_t(&representation);
371
371
TEST_F(DateTest, to_julian_day_number)
372
372
{
373
373
  int64_t julian_day;
374
 
  TemporalGenerator::DateGen::make_date(&date, 1999, 12, 31);
 
374
  Generator::DateGen::make_date(&date, 1999, 12, 31);
375
375
  
376
376
  date.to_julian_day_number(&julian_day);
377
377
  
397
397
TEST_F(DateTest, DISABLED_to_tm)
398
398
{
399
399
  uint32_t years= 2030, months= 8, days= 17;
400
 
  TemporalGenerator::DateGen::make_date(&date, years, months, days);
 
400
  Generator::DateGen::make_date(&date, years, months, days);
401
401
  struct tm filled;
402
402
  
403
403
  date.to_tm(&filled);
409
409
  EXPECT_EQ(0, filled.tm_min);
410
410
  EXPECT_EQ(0, filled.tm_sec);
411
411
 
412
 
  /* TODO:these fail, shouldn't they also be set properly? */
 
412
  /* these fail, shouldn't they also be set properly? */
413
413
  EXPECT_EQ(228, filled.tm_yday);
414
414
  EXPECT_EQ(6, filled.tm_wday);
415
415
  EXPECT_EQ(-1, filled.tm_isdst);
437
437
TEST_F(DateTest, to_time_t)
438
438
{
439
439
  time_t time;
440
 
  TemporalGenerator::DateGen::make_date(&date, 1990, 9, 9);
 
440
  Generator::DateGen::make_date(&date, 1990, 9, 9);
441
441
  
442
442
  date.to_time_t(&time);
443
443
  
462
462
TEST_F(DateTest, to_decimal)
463
463
{
464
464
  drizzled::my_decimal to;
465
 
  TemporalGenerator::DateGen::make_date(&date, 1987, 5, 6);
 
465
  Generator::DateGen::make_date(&date, 1987, 5, 6);
466
466
 
467
467
  date.to_decimal(&to);
468
468
 
469
469
  ASSERT_EQ(19870506, to.buf[0]);
470
470
}
471
 
 
472
 
class DateFromStringTest: public ::testing::TestWithParam<const char*>
473
 
{
474
 
  protected:
475
 
    Date date;
476
 
    bool result;
477
 
    uint32_t years, months, days;
478
 
    
479
 
    virtual void SetUp()
480
 
    {
481
 
      init_temporal_formats();
482
 
    }
483
 
    
484
 
    virtual void TearDown()
485
 
    {
486
 
      deinit_temporal_formats();
487
 
    }
488
 
    
489
 
    void assign_date_values()
490
 
    {
491
 
      years= date.years();
492
 
      months= date.months();
493
 
      days= date.days();
494
 
    }
495
 
};
496
 
 
497
 
TEST_P(DateFromStringTest, from_string)
498
 
{
499
 
  const char *valid_string= GetParam();
500
 
  
501
 
  result= date.from_string(valid_string, strlen(valid_string));
502
 
  ASSERT_TRUE(result);
503
 
  
504
 
  assign_date_values();
505
 
  
506
 
  EXPECT_EQ(2010, years);
507
 
  EXPECT_EQ(6, months);
508
 
  EXPECT_EQ(7, days);
509
 
}
510
 
 
511
 
/* TODO:for some reason this was not declared by the macro, needs clarification*/
512
 
testing::internal::ParamGenerator<const char*> gtest_ValidStringDateFromStringTest_EvalGenerator_();
513
 
 
514
 
INSTANTIATE_TEST_CASE_P(ValidString, DateFromStringTest,
515
 
                        ::testing::Values("20100607", /* YYYYMMDD */
516
 
                                          "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/
517
 
                                          "10.06.07",/* YY[-/.]MM[-/.]DD */
518
 
                                          "10/6/7",/* YY[-/.][M]M[-/.][D]D */
519
 
                                          "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */));
520
 
                                          
521
 
 
522
 
                                          
 
 
b'\\ No newline at end of file'