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 "generator.h"
28
using namespace drizzled;
30
template <typename TemporalType>
31
class DateTest : public ::testing::Test
36
TemporalType identical_with_sample_date, before_sample_date, after_sample_date;
38
void initBeforeIdenticalAfter();
42
Generator::DateGen::make_date(&sample_date, 2010, 9, 8);
43
initBeforeIdenticalAfter();
47
template<> void DateTest<Date>::initBeforeIdenticalAfter()
49
Generator::DateGen::make_date(&before_sample_date, 1980, 1, 1);
50
Generator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8);
51
Generator::DateGen::make_date(&after_sample_date, 2019, 5, 30);
54
template<> void DateTest<DateTime>::initBeforeIdenticalAfter()
56
Generator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30, 1000);
57
Generator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0, 0);
58
Generator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4, 4000);
61
template<> void DateTest<Timestamp>::initBeforeIdenticalAfter()
63
Generator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1);
64
Generator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8);
65
Generator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30);
68
typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTest;
69
TYPED_TEST_CASE(DateTest, typesForDateTest);
71
TYPED_TEST(DateTest, operatorEqual_ComparingWithIdencticalTemporal_ShouldReturn_True)
73
bool result= (this->sample_date == this->identical_with_sample_date);
75
ASSERT_EQ(true, result);
78
TYPED_TEST(DateTest, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False)
80
bool result= (this->sample_date == this->before_sample_date);
82
ASSERT_EQ(false, result);
85
TYPED_TEST(DateTest, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False)
87
bool result= (this->sample_date != this->identical_with_sample_date);
89
ASSERT_EQ(false, result);
92
TYPED_TEST(DateTest, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True)
94
bool result= (this->sample_date != this->before_sample_date);
96
ASSERT_EQ(true, result);
99
TYPED_TEST(DateTest, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
101
bool result= (this->sample_date > this->identical_with_sample_date);
103
ASSERT_EQ(false, result);
106
TYPED_TEST(DateTest, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False)
108
bool result= (this->sample_date > this->after_sample_date);
110
ASSERT_EQ(false, result);
113
TYPED_TEST(DateTest, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True)
115
bool result= (this->sample_date > this->before_sample_date);
117
ASSERT_EQ(true, result);
120
TYPED_TEST(DateTest, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
122
bool result= (this->sample_date >= this->identical_with_sample_date);
124
ASSERT_EQ(true, result);
127
TYPED_TEST(DateTest, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False)
129
bool result= (this->sample_date >= this->after_sample_date);
131
ASSERT_EQ(false, result);
134
TYPED_TEST(DateTest, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True)
136
bool result= (this->sample_date >= this->before_sample_date);
138
ASSERT_EQ(true, result);
141
TYPED_TEST(DateTest, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
143
bool result= (this->sample_date < this->identical_with_sample_date);
145
ASSERT_EQ(false, result);
148
TYPED_TEST(DateTest, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True)
150
bool result= (this->sample_date < this->after_sample_date);
152
ASSERT_EQ(true, result);
155
TYPED_TEST(DateTest, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False)
157
bool result= (this->sample_date < this->before_sample_date);
159
ASSERT_EQ(false, result);
162
TYPED_TEST(DateTest, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
164
bool result= (this->sample_date < this->identical_with_sample_date);
166
ASSERT_EQ(true, result);
169
TYPED_TEST(DateTest, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True)
171
bool result= (this->sample_date < this->after_sample_date);
173
ASSERT_EQ(true, result);
176
TYPED_TEST(DateTest, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False)
178
bool result= (this->sample_date < this->before_sample_date);
180
ASSERT_EQ(false, result);