~drizzle-trunk/drizzle/development

1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Pawel Blokus
5
 *
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.
10
 *
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.
15
 *
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
19
 */
20
21
#include "config.h"
22
23
#include <gtest/gtest.h>
24
#include <drizzled/temporal.h>
25
1377.9.1 by Paweł Blokus
updated includes to last file rename
26
#include "temporal_generator.h"
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
27
28
using namespace drizzled;
29
30
class NanoTimestampTest : public ::testing::Test
31
{
32
  protected:
33
    NanoTimestamp nano_timestamp;
34
    bool result;
35
};
36
37
TEST_F(NanoTimestampTest, is_valid_minOfNanoTimestampRange_shouldReturn_True)
38
{
39
  uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, nanosecond= 0;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
40
  TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
41
42
  result= nano_timestamp.is_valid();
43
44
  ASSERT_TRUE(result);
45
}
46
47
TEST_F(NanoTimestampTest, is_valid_maxOfNanoTimestampRange_shouldReturn_True)
48
{
49
  uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, nanosecond= 0;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
50
  TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
51
52
  result= nano_timestamp.is_valid();
53
54
  ASSERT_TRUE(result);
55
}
56
57
TEST_F(NanoTimestampTest, is_valid_oneMicroSecondBeforeNanoTimestampMinOfRange_shouldReturn_False)
58
{
59
  uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, nanosecond= 999999999;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
60
  TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
61
62
  result= nano_timestamp.is_valid();
63
64
  ASSERT_FALSE(result);
65
}
66
67
TEST_F(NanoTimestampTest, is_valid_oneMicroSecondAfterNanoTimestampMaxOfRange_shouldReturn_False)
68
{
69
  uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, nanosecond= 1;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
70
  TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
71
72
  result= nano_timestamp.is_valid();
73
74
  ASSERT_FALSE(result);
75
}
76
77
TEST_F(NanoTimestampTest, is_valid_InsideOfNanoTimestampRange_shouldReturn_True)
78
{
79
  uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, nanosecond= 3265832;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
80
  TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
81
82
  result= nano_timestamp.is_valid();
83
84
  ASSERT_TRUE(result);
85
}
86
87
TEST_F(NanoTimestampTest, to_timespec)
88
{
89
  struct timespec filled;
90
  uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, nanosecond= 675;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
91
  TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
92
93
  nano_timestamp.to_timespec(&filled);
94
95
  EXPECT_EQ(1244005141, filled.tv_sec);
96
  EXPECT_EQ(675, filled.tv_nsec);
97
}