1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Pawel Blokus
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <gtest/gtest.h>
24
#include <drizzled/temporal.h>
26
#include "temporal_generator.h"
28
using namespace drizzled;
30
class MicroTimestampTest : public ::testing::Test
33
MicroTimestamp micro_timestamp;
37
TEST_F(MicroTimestampTest, is_valid_minOfMicroTimestampRange_shouldReturn_True)
39
uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, microsecond= 0;
40
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond);
42
result= micro_timestamp.is_valid();
47
TEST_F(MicroTimestampTest, is_valid_maxOfMicroTimestampRange_shouldReturn_True)
49
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, microsecond= 0;
50
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond);
52
result= micro_timestamp.is_valid();
57
TEST_F(MicroTimestampTest, is_valid_oneMicroSecondBeforeMicroTimestampMinOfRange_shouldReturn_False)
59
uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, microsecond= 999999;
60
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond);
62
result= micro_timestamp.is_valid();
67
TEST_F(MicroTimestampTest, is_valid_oneMicroSecondAfterMicroTimestampMaxOfRange_shouldReturn_False)
69
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, microsecond= 1;
70
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond);
72
result= micro_timestamp.is_valid();
77
TEST_F(MicroTimestampTest, is_valid_InsideOfMicroTimestampRange_shouldReturn_True)
79
uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, microsecond= 18263;
80
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond);
82
result= micro_timestamp.is_valid();
87
TEST_F(MicroTimestampTest, to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements)
89
char expected[MicroTimestamp::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.007654";
90
char returned[MicroTimestamp::MAX_STRING_LENGTH];
91
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, 2010, 5, 1, 8, 7, 6, 7654);
93
micro_timestamp.to_string(returned, MicroTimestamp::MAX_STRING_LENGTH);
95
ASSERT_STREQ(expected, returned);
98
TEST_F(MicroTimestampTest, to_timeval)
100
struct timeval filled;
101
uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, microsecond= 675;
102
TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond);
104
micro_timestamp.to_timeval(&filled);
106
EXPECT_EQ(1244005141, filled.tv_sec);
107
EXPECT_EQ(675, filled.tv_usec);