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