~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/temporal_test.cc

MergedĀ fromĀ pblokus.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
26
#include "generator.h"
 
27
 
 
28
using namespace drizzled;
 
29
 
 
30
template <typename TemporalType>
 
31
class DateTest : public ::testing::Test
 
32
{
 
33
 protected:
 
34
  Date sample_date;
 
35
  
 
36
  TemporalType identical_with_sample_date, before_sample_date, after_sample_date;
 
37
  
 
38
  void initBeforeIdenticalAfter();
 
39
 
 
40
  virtual void SetUp()
 
41
  {
 
42
    Generator::DateGen::make_date(&sample_date, 2010, 9, 8);
 
43
    initBeforeIdenticalAfter();
 
44
  }
 
45
};
 
46
 
 
47
template<> void DateTest<Date>::initBeforeIdenticalAfter()
 
48
{
 
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);
 
52
}
 
53
 
 
54
template<> void DateTest<DateTime>::initBeforeIdenticalAfter()
 
55
{
 
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);
 
59
}
 
60
 
 
61
template<> void DateTest<Timestamp>::initBeforeIdenticalAfter()
 
62
{
 
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);
 
66
}
 
67
 
 
68
typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTest;
 
69
TYPED_TEST_CASE(DateTest, typesForDateTest);
 
70
 
 
71
TYPED_TEST(DateTest, operatorEqual_ComparingWithIdencticalTemporal_ShouldReturn_True)
 
72
{
 
73
  bool result= (this->sample_date == this->identical_with_sample_date);
 
74
  
 
75
  ASSERT_EQ(true, result);
 
76
}
 
77
 
 
78
TYPED_TEST(DateTest, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False)
 
79
{
 
80
  bool result= (this->sample_date == this->before_sample_date);
 
81
  
 
82
  ASSERT_EQ(false, result);
 
83
}
 
84
 
 
85
TYPED_TEST(DateTest, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False)
 
86
 
87
  bool result= (this->sample_date != this->identical_with_sample_date);
 
88
  
 
89
  ASSERT_EQ(false, result);
 
90
}
 
91
 
 
92
TYPED_TEST(DateTest, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True)
 
93
{
 
94
  bool result= (this->sample_date != this->before_sample_date);
 
95
  
 
96
  ASSERT_EQ(true, result);
 
97
}
 
98
 
 
99
TYPED_TEST(DateTest, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
 
100
{
 
101
  bool result= (this->sample_date > this->identical_with_sample_date);
 
102
  
 
103
  ASSERT_EQ(false, result);
 
104
}
 
105
 
 
106
TYPED_TEST(DateTest, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False)
 
107
{
 
108
  bool result= (this->sample_date > this->after_sample_date);
 
109
  
 
110
  ASSERT_EQ(false, result);
 
111
}
 
112
 
 
113
TYPED_TEST(DateTest, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True)
 
114
{
 
115
  bool result= (this->sample_date > this->before_sample_date);
 
116
  
 
117
  ASSERT_EQ(true, result);
 
118
}
 
119
 
 
120
TYPED_TEST(DateTest, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
 
121
{
 
122
  bool result= (this->sample_date >= this->identical_with_sample_date);
 
123
  
 
124
  ASSERT_EQ(true, result);
 
125
}
 
126
 
 
127
TYPED_TEST(DateTest, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False)
 
128
{
 
129
  bool result= (this->sample_date >= this->after_sample_date);
 
130
  
 
131
  ASSERT_EQ(false, result);
 
132
}
 
133
 
 
134
TYPED_TEST(DateTest, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True)
 
135
{
 
136
  bool result= (this->sample_date >= this->before_sample_date);
 
137
  
 
138
  ASSERT_EQ(true, result);
 
139
}
 
140
 
 
141
TYPED_TEST(DateTest, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
 
142
{
 
143
  bool result= (this->sample_date < this->identical_with_sample_date);
 
144
  
 
145
  ASSERT_EQ(false, result);
 
146
}
 
147
 
 
148
TYPED_TEST(DateTest, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True)
 
149
{
 
150
  bool result= (this->sample_date < this->after_sample_date);
 
151
  
 
152
  ASSERT_EQ(true, result);
 
153
}
 
154
 
 
155
TYPED_TEST(DateTest, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False)
 
156
{
 
157
  bool result= (this->sample_date < this->before_sample_date);
 
158
  
 
159
  ASSERT_EQ(false, result);
 
160
}
 
161
 
 
162
TYPED_TEST(DateTest, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
 
163
{
 
164
  bool result= (this->sample_date < this->identical_with_sample_date);
 
165
  
 
166
  ASSERT_EQ(true, result);
 
167
}
 
168
 
 
169
TYPED_TEST(DateTest, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True)
 
170
{
 
171
  bool result= (this->sample_date < this->after_sample_date);
 
172
  
 
173
  ASSERT_EQ(true, result);
 
174
}
 
175
 
 
176
TYPED_TEST(DateTest, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False)
 
177
{
 
178
  bool result= (this->sample_date < this->before_sample_date);
 
179
  
 
180
  ASSERT_EQ(false, result);
 
181
}