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
#define BOOST_TEST_DYN_LINK
24
#include <boost/test/unit_test.hpp>
26
#include <drizzled/temporal.h>
28
#include "temporal_generator.h"
30
using namespace drizzled;
32
class NanoTimestampTest
35
NanoTimestamp nano_timestamp;
39
BOOST_FIXTURE_TEST_SUITE(NanoTimestampTestSuite, NanoTimestampTest)
40
BOOST_AUTO_TEST_CASE(is_valid_minOfNanoTimestampRange_shouldReturn_True)
42
uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, nanosecond= 0;
43
TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
45
result= nano_timestamp.is_valid();
47
BOOST_REQUIRE(result);
50
BOOST_AUTO_TEST_CASE(is_valid_maxOfNanoTimestampRange_shouldReturn_True)
52
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, nanosecond= 0;
53
TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
55
result= nano_timestamp.is_valid();
57
BOOST_REQUIRE(result);
60
BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondBeforeNanoTimestampMinOfRange_shouldReturn_False)
62
uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, nanosecond= 999999999;
63
TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
65
result= nano_timestamp.is_valid();
67
BOOST_REQUIRE(not result);
70
BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondAfterNanoTimestampMaxOfRange_shouldReturn_False)
72
uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, nanosecond= 1;
73
TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
75
result= nano_timestamp.is_valid();
77
BOOST_REQUIRE(not result);
80
BOOST_AUTO_TEST_CASE(is_valid_InsideOfNanoTimestampRange_shouldReturn_True)
82
uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, nanosecond= 3265832;
83
TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
85
result= nano_timestamp.is_valid();
87
BOOST_REQUIRE(result);
90
BOOST_AUTO_TEST_CASE(to_timespec)
92
struct timespec filled;
93
uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, nanosecond= 675;
94
TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
96
nano_timestamp.to_timespec(&filled);
98
BOOST_REQUIRE_EQUAL(1244005141, filled.tv_sec);
99
BOOST_REQUIRE_EQUAL(675, filled.tv_nsec);
101
BOOST_AUTO_TEST_SUITE_END()