~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/date_time_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:
21
21
#include "config.h"
22
22
 
23
23
#include <gtest/gtest.h>
 
24
#include <drizzled/decimal.h>
24
25
#include <drizzled/temporal.h>
25
26
#include <drizzled/temporal_format.h>
26
27
 
194
195
  ASSERT_EQ(DateTime::MAX_STRING_LENGTH - 1 - 7, length);  
195
196
}
196
197
 
197
 
TEST_F(DateTimeTest, from_string_validString_shouldPopulateCorrectly)
198
 
{
199
 
  char valid_string[DateTime::MAX_STRING_LENGTH]= "2010-05-01 08:07:06";
200
 
 
201
 
  init_temporal_formats();
202
 
  
203
 
  result = datetime.from_string(valid_string, DateTime::MAX_STRING_LENGTH - 1);
204
 
  ASSERT_TRUE(result);
205
 
 
206
 
  assignDateTimeValues();
207
 
  
208
 
  EXPECT_EQ(2010, years);
209
 
  EXPECT_EQ(5, months);
210
 
  EXPECT_EQ(1, days);
211
 
  EXPECT_EQ(8, hours);
212
 
  EXPECT_EQ(7, minutes);
213
 
  EXPECT_EQ(6, seconds);
214
 
 
215
 
  deinit_temporal_formats();
216
 
}
217
 
 
218
198
TEST_F(DateTimeTest, to_int64_t)
219
199
{
220
200
  Generator::DateTimeGen::make_datetime(&datetime, 2030, 8, 7, 14, 5, 13);
315
295
  EXPECT_EQ(6, filled.tm_wday);
316
296
  EXPECT_EQ(-1, filled.tm_isdst);
317
297
}
 
298
 
 
299
TEST_F(DateTimeTest, to_decimal)
 
300
{
 
301
  drizzled::my_decimal to;
 
302
  Generator::DateTimeGen::make_datetime(&datetime, 1987, 6, 13, 5, 10, 13);
 
303
 
 
304
  datetime.to_decimal(&to);
 
305
  
 
306
  ASSERT_EQ(19870,to.buf[0]);
 
307
  ASSERT_EQ(613051013,to.buf[1]);
 
308
}
 
309
 
 
310
 
 
311
/*
 
312
class DateTimeFromStringTest: public ::testing::TestWithParam<const char*>
 
313
{
 
314
  protected:
 
315
    DateTime datetime;
 
316
    bool result;
 
317
    uint32_t years, months, days;
 
318
    uint32_t hours, minutes, seconds;
 
319
 
 
320
    virtual void SetUp()
 
321
    {
 
322
      init_temporal_formats();
 
323
    }
 
324
 
 
325
    virtual void TearDown()
 
326
    {
 
327
      deinit_temporal_formats();
 
328
    }
 
329
 
 
330
    void assignDateTimeValues()
 
331
    {
 
332
      years = datetime.years();
 
333
      months = datetime.months();
 
334
      days = datetime.days();
 
335
      hours = datetime.hours();
 
336
      minutes = datetime.minutes();
 
337
      seconds = datetime.seconds();
 
338
    }
 
339
};
 
340
 
 
341
TEST_P(DateTimeFromStringTest, from_string_validString_formatsWithDateAndTimePresent_shouldPopulateCorrectly)
 
342
{
 
343
  const char *valid_string = GetParam();
 
344
 
 
345
  result = datetime.from_string(valid_string, strlen(valid_string));
 
346
  ASSERT_TRUE(result);
 
347
 
 
348
  assignDateTimeValues();
 
349
 
 
350
  EXPECT_EQ(2010, years);
 
351
  EXPECT_EQ(5, months);
 
352
  EXPECT_EQ(1, days);
 
353
  EXPECT_EQ(8, hours);
 
354
  EXPECT_EQ(7, minutes);
 
355
  EXPECT_EQ(6, seconds);
 
356
}
 
357
 
 
358
INSTANTIATE_TEST_CASE_P(FormatsWithDateAndTimePresent, DateTimeFromStringTest,
 
359
                        ::testing::Values("20100501080706",
 
360
                                          "2010-05-01 08:07:06",
 
361
                                          "2010/05/01T08:07:06",
 
362
                                          "2010.5.1 08:07:06",
 
363
                                          "10-05-01 08:07:06",
 
364
                                          "10/5/1 08:07:06",
 
365
                                          "10.5.1 08:07:06"));
 
366
 
 
367
TEST_P(DateTimeFromStringTest, from_string_validString_formatsWithDateHourAndMinutePresent_shouldPopulateCorrectly)
 
368
{
 
369
  const char *valid_string = GetParam();
 
370
 
 
371
  result = datetime.from_string(valid_string, strlen(valid_string));
 
372
  ASSERT_TRUE(result);
 
373
 
 
374
  assignDateTimeValues();
 
375
 
 
376
  EXPECT_EQ(2010, years);
 
377
  EXPECT_EQ(5, months);
 
378
  EXPECT_EQ(1, days);
 
379
  EXPECT_EQ(8, hours);
 
380
  EXPECT_EQ(7, minutes);
 
381
}
 
382
 
 
383
INSTANTIATE_TEST_CASE_P(FormatsWithDateHourAndMinutePresent, DateTimeFromStringTest,
 
384
                        ::testing::Values("2010-05-01 08:07",
 
385
                                          "2010/05/01 08:07"
 
386
                                          "2010.5.1 08:07",
 
387
                                          "10-05-01 08:07",
 
388
                                          "10/5/1 08:07",
 
389
                                          "10.5.1 08:07"));
 
390
*/