~drizzle-trunk/drizzle/development

1377.8.2 by Paweł Blokus
created files for temporal tests
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>
1377.8.27 by Paweł Blokus
tests for to_decimal methods
24
#include <drizzled/decimal.h>
1377.8.2 by Paweł Blokus
created files for temporal tests
25
#include <drizzled/temporal.h>
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
26
#include <drizzled/temporal_format.h>
1377.8.2 by Paweł Blokus
created files for temporal tests
27
1377.9.1 by Paweł Blokus
updated includes to last file rename
28
#include "temporal_generator.h"
1377.8.2 by Paweł Blokus
created files for temporal tests
29
30
using namespace drizzled;
31
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
32
template <typename TemporalType>
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
33
class DateTestCompareOperators : public ::testing::Test
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
34
{
1377.8.2 by Paweł Blokus
created files for temporal tests
35
 protected:
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
36
  Date sample_date;
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
37
  bool result;
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
38
  
39
  TemporalType identical_with_sample_date, before_sample_date, after_sample_date;
40
  
41
  void initBeforeIdenticalAfter();
42
1377.8.5 by Paweł Blokus
removed an undefined character from the decimal.cc file
43
  virtual void SetUp()
1377.8.2 by Paweł Blokus
created files for temporal tests
44
  {
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
45
    TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
46
    initBeforeIdenticalAfter();
1377.8.2 by Paweł Blokus
created files for temporal tests
47
  }
48
};
49
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
50
template<> void DateTestCompareOperators<Date>::initBeforeIdenticalAfter()
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
51
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
52
  TemporalGenerator::DateGen::make_date(&before_sample_date, 1980, 1, 1);
53
  TemporalGenerator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8);
54
  TemporalGenerator::DateGen::make_date(&after_sample_date, 2019, 5, 30);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
55
}
56
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
57
template<> void DateTestCompareOperators<DateTime>::initBeforeIdenticalAfter()
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
58
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
59
  TemporalGenerator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30);
60
  TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
61
  TemporalGenerator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
62
}
63
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
64
template<> void DateTestCompareOperators<Timestamp>::initBeforeIdenticalAfter()
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
65
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
66
  TemporalGenerator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41);
67
  TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
68
  TemporalGenerator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
69
}
70
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
71
typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTestCompareOperators;
72
TYPED_TEST_CASE(DateTestCompareOperators, typesForDateTestCompareOperators);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
73
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
74
TYPED_TEST(DateTestCompareOperators, operatorEqual_ComparingWithIdencticalTemporal_ShouldReturn_True)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
75
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
76
  this->result= (this->sample_date == this->identical_with_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
77
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
78
  ASSERT_TRUE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
79
}
80
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
81
TYPED_TEST(DateTestCompareOperators, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
82
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
83
  this->result= (this->sample_date == this->before_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
84
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
85
  ASSERT_FALSE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
86
}
87
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
88
TYPED_TEST(DateTestCompareOperators, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
89
{ 
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
90
  this->result= (this->sample_date != this->identical_with_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
91
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
92
  ASSERT_FALSE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
93
}
94
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
95
TYPED_TEST(DateTestCompareOperators, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
96
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
97
  this->result= (this->sample_date != this->before_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
98
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
99
  ASSERT_TRUE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
100
}
101
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
102
TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
103
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
104
  this->result= (this->sample_date > this->identical_with_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
105
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
106
  ASSERT_FALSE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
107
}
108
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
109
TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
110
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
111
  this->result= (this->sample_date > this->after_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
112
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
113
  ASSERT_FALSE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
114
}
115
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
116
TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
117
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
118
  this->result= (this->sample_date > this->before_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
119
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
120
  ASSERT_TRUE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
121
}
122
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
123
TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
124
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
125
  this->result= (this->sample_date >= this->identical_with_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
126
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
127
  ASSERT_TRUE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
128
}
129
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
130
TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
131
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
132
  this->result= (this->sample_date >= this->after_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
133
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
134
  ASSERT_FALSE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
135
}
136
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
137
TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True)
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
138
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
139
  this->result= (this->sample_date >= this->before_sample_date);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
140
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
141
  ASSERT_TRUE(this->result);
1377.8.9 by Paweł Blokus
removed all the repeated tests for different temporal descendants by making a typed test
142
}
143
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
144
TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
145
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
146
  this->result= (this->sample_date < this->identical_with_sample_date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
147
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
148
  ASSERT_FALSE(this->result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
149
}
150
151
TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True)
152
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
153
  this->result= (this->sample_date < this->after_sample_date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
154
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
155
  ASSERT_TRUE(this->result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
156
}
157
158
TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False)
159
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
160
  this->result= (this->sample_date < this->before_sample_date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
161
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
162
  ASSERT_FALSE(this->result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
163
}
164
165
TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
166
{
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
167
  this->result= (this->sample_date <= this->identical_with_sample_date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
168
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
169
  ASSERT_TRUE(this->result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
170
}
171
172
TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True)
173
{
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
174
  this->result= (this->sample_date <= this->after_sample_date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
175
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
176
  ASSERT_TRUE(this->result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
177
}
178
179
TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False)
180
{
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
181
  this->result= (this->sample_date <= this->before_sample_date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
182
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
183
  ASSERT_FALSE(this->result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
184
}
185
186
class DateTest : public ::testing::Test
187
{
188
  protected:
189
    Date date;
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
190
    bool result;
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
191
    
192
    virtual void SetUp()
193
    {
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
194
      TemporalGenerator::DateGen::make_valid_date(&date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
195
    }
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
196
};
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
197
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
198
TEST_F(DateTest, operatorAssign_shouldCopyDateRelatadComponents)
199
{
1377.8.35 by Paweł Blokus
fixed some style issues and decided on buffer size in temporal_interval_test
200
  Date copy= date;
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
201
202
  EXPECT_EQ(date.years(), copy.years());
203
  EXPECT_EQ(date.months(), copy.months());
204
  EXPECT_EQ(date.days(), copy.days());
205
}
206
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
207
TEST_F(DateTest, is_valid_onValidDate_shouldReturn_True)
208
{
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
209
  result= date.is_valid();
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
210
  ASSERT_TRUE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
211
}
212
213
TEST_F(DateTest, is_valid_onInvalidDateWithYearBelowMinimum_shouldReturn_False)
214
{
215
  date.set_years(DRIZZLE_MIN_YEARS_SQL - 1);
216
  
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
217
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
218
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
219
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
220
}
221
222
TEST_F(DateTest, is_valid_onInvalidDateWithYearAboveMaximum_shouldReturn_False)
223
{
224
  date.set_years(DRIZZLE_MAX_YEARS_SQL + 1);
225
    
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
226
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
227
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
228
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
229
}
230
231
TEST_F(DateTest, is_valid_onInvalidDateWithMonthSetToZero_shouldReturn_False)
232
{
233
  date.set_months(0);
234
  
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
235
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
236
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
237
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
238
}
239
240
241
TEST_F(DateTest, is_valid_onInvalidDateWithMonthAboveMaximum_shouldReturn_False)
242
{
243
  date.set_months(13);
244
  
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
245
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
246
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
247
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
248
}
249
250
TEST_F(DateTest, is_valid_onInvalidDateWithDaySetToZero_shouldReturn_False)
251
{
252
  date.set_days(0);
253
  
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
254
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
255
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
256
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
257
}
258
259
TEST_F(DateTest, is_valid_onInvalidDateWithDayAboveDaysInMonth_shouldReturn_False)
260
{
261
  date.set_days(32);
262
  
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
263
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
264
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
265
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
266
}
267
268
TEST_F(DateTest, is_valid_onInvalidDateWithLeapDayInNonLeapYear_shouldReturn_False)
269
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
270
  TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&date);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
271
  
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
272
  result= date.is_valid();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
273
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
274
  ASSERT_FALSE(result);
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
275
}
276
277
TEST_F(DateTest, is_valid_onValidDateWithLeapDayInLeapYear_shouldReturn_True)
278
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
279
  TemporalGenerator::TemporalGen::leap_day_in_leap_year(&date);
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
280
  
281
  result= date.is_valid();
282
  
1377.8.12 by Paweł Blokus
use ASSERT_TRUE/ASSERT_FALSE where possible
283
  ASSERT_TRUE(result);
1377.8.11 by Paweł Blokus
result variable declered in fixture insted of every single test
284
}
285
1377.8.13 by Paweł Blokus
added tests for:
286
TEST_F(DateTest, to_string_shouldProduce_hyphenSeperatedDateElements)
287
{
288
  char expected[Date::MAX_STRING_LENGTH]= "2010-05-01";
289
  char returned[Date::MAX_STRING_LENGTH];
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
290
  TemporalGenerator::DateGen::make_date(&date, 2010, 5, 1);
1377.8.13 by Paweł Blokus
added tests for:
291
  
292
  date.to_string(returned, Date::MAX_STRING_LENGTH);
293
  
294
  ASSERT_STREQ(expected, returned);  
295
}
296
297
TEST_F(DateTest, to_string_nullBuffer_shouldReturnProperLengthAnyway)
298
{
299
  int length= date.to_string(NULL, 0);
300
  
301
  ASSERT_EQ(Date::MAX_STRING_LENGTH - 1, length);  
302
}
303
304
TEST_F(DateTest, from_string_validString_shouldPopulateCorrectly)
305
{
306
  char valid_string[Date::MAX_STRING_LENGTH]= "2010-05-01";
1377.8.19 by Paweł Blokus
changed int to uint32_t where necessary
307
  uint32_t years, months, days;
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
308
309
  init_temporal_formats();
1377.8.13 by Paweł Blokus
added tests for:
310
  
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
311
  result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1);
1377.8.13 by Paweł Blokus
added tests for:
312
  ASSERT_TRUE(result);
313
  
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
314
  years= date.years();
315
  months= date.months();
316
  days= date.days();
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
317
318
  deinit_temporal_formats();
1377.8.13 by Paweł Blokus
added tests for:
319
  
320
  EXPECT_EQ(2010, years);
321
  EXPECT_EQ(5, months);
322
  EXPECT_EQ(1, days);
323
}
324
325
TEST_F(DateTest, from_string_invalidString_shouldReturn_False)
326
{
327
  char valid_string[Date::MAX_STRING_LENGTH]= "2x10-05-01";
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
328
329
  init_temporal_formats();
330
  result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1);
331
  deinit_temporal_formats();
332
  
1377.8.13 by Paweł Blokus
added tests for:
333
  ASSERT_FALSE(result);
334
}
335
1377.8.26 by Paweł Blokus
created or modified all to_int**_t and from_int**_t function tests
336
TEST_F(DateTest, to_int64_t)
337
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
338
  TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
1377.8.26 by Paweł Blokus
created or modified all to_int**_t and from_int**_t function tests
339
  int64_t representation;
340
  
341
  date.to_int64_t(&representation);
342
  
343
  ASSERT_EQ(20300817, representation);
344
}
345
346
TEST_F(DateTest, to_int32_t)
347
{
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
348
  TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
1377.8.13 by Paweł Blokus
added tests for:
349
  int32_t representation;
1377.8.26 by Paweł Blokus
created or modified all to_int**_t and from_int**_t function tests
350
1377.8.13 by Paweł Blokus
added tests for:
351
  date.to_int32_t(&representation);
1377.8.26 by Paweł Blokus
created or modified all to_int**_t and from_int**_t function tests
352
353
  ASSERT_EQ(20300817, representation);
354
}
355
356
TEST_F(DateTest, from_int32_t_shouldPopulateDateCorrectly)
357
{
358
  uint32_t decoded_years, decoded_months, decoded_days;
359
360
  date.from_int32_t(20300817);
361
  
362
  decoded_years= date.years();
363
  decoded_months= date.months();
364
  decoded_days= date.days();
365
  
366
  EXPECT_EQ(2030, decoded_years);
367
  EXPECT_EQ(8, decoded_months);
368
  EXPECT_EQ(17, decoded_days);
1377.8.13 by Paweł Blokus
added tests for:
369
}
370
371
TEST_F(DateTest, to_julian_day_number)
372
{
373
  int64_t julian_day;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
374
  TemporalGenerator::DateGen::make_date(&date, 1999, 12, 31);
1377.8.13 by Paweł Blokus
added tests for:
375
  
376
  date.to_julian_day_number(&julian_day);
377
  
378
  ASSERT_EQ(2451544, julian_day);
379
}
380
381
TEST_F(DateTest, from_julian_day_number)
382
{
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
383
  int64_t julian_day= 2451544;
1377.8.19 by Paweł Blokus
changed int to uint32_t where necessary
384
  uint32_t years, months, days;
1377.8.13 by Paweł Blokus
added tests for:
385
   
386
  date.from_julian_day_number(julian_day);
387
  
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
388
  years= date.years();
389
  months= date.months();
390
  days= date.days();
1377.8.13 by Paweł Blokus
added tests for:
391
    
392
  EXPECT_EQ(1999, years);
393
  EXPECT_EQ(12, months);
394
  EXPECT_EQ(31, days);
395
}
396
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
397
TEST_F(DateTest, DISABLED_to_tm)
1377.8.13 by Paweł Blokus
added tests for:
398
{
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
399
  uint32_t years= 2030, months= 8, days= 17;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
400
  TemporalGenerator::DateGen::make_date(&date, years, months, days);
1377.8.13 by Paweł Blokus
added tests for:
401
  struct tm filled;
402
  
403
  date.to_tm(&filled);
404
  
405
  EXPECT_EQ(130, filled.tm_year);
406
  EXPECT_EQ(7, filled.tm_mon);
407
  EXPECT_EQ(17, filled.tm_mday);
408
  EXPECT_EQ(0, filled.tm_hour);
409
  EXPECT_EQ(0, filled.tm_min);
410
  EXPECT_EQ(0, filled.tm_sec);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
411
1377.8.35 by Paweł Blokus
fixed some style issues and decided on buffer size in temporal_interval_test
412
  /* TODO:these fail, shouldn't they also be set properly? */
1377.8.13 by Paweł Blokus
added tests for:
413
  EXPECT_EQ(228, filled.tm_yday);
414
  EXPECT_EQ(6, filled.tm_wday);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
415
  EXPECT_EQ(-1, filled.tm_isdst);
1377.8.13 by Paweł Blokus
added tests for:
416
}
417
418
TEST_F(DateTest, from_tm)
419
{
1377.8.19 by Paweł Blokus
changed int to uint32_t where necessary
420
  uint32_t years, months, days;
1377.8.13 by Paweł Blokus
added tests for:
421
  struct tm from;
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
422
  from.tm_year= 1956 - 1900;
423
  from.tm_mon= 2;
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
424
  from.tm_mday= 30;
1377.8.13 by Paweł Blokus
added tests for:
425
  
426
  date.from_tm(&from);
427
  
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
428
  years= date.years();
429
  months= date.months();
430
  days= date.days();
1377.8.13 by Paweł Blokus
added tests for:
431
  
432
  EXPECT_EQ(1956, years);  
433
  EXPECT_EQ(3, months);
434
  EXPECT_EQ(30, days);
435
}
436
437
TEST_F(DateTest, to_time_t)
438
{
439
  time_t time;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
440
  TemporalGenerator::DateGen::make_date(&date, 1990, 9, 9);
1377.8.13 by Paweł Blokus
added tests for:
441
  
442
  date.to_time_t(&time);
443
  
444
  ASSERT_EQ(652838400, time);
445
}
1377.8.14 by Paweł Blokus
test for Date::from_time_t
446
447
TEST_F(DateTest, from_time_t)
448
{
1377.8.19 by Paweł Blokus
changed int to uint32_t where necessary
449
  uint32_t years, months, days;
1377.8.14 by Paweł Blokus
test for Date::from_time_t
450
  
451
  date.from_time_t(652838400);
452
  
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
453
  years= date.years();
454
  months= date.months();
455
  days= date.days();
1377.8.14 by Paweł Blokus
test for Date::from_time_t
456
  
457
  EXPECT_EQ(1990, years);  
458
  EXPECT_EQ(9, months);
459
  EXPECT_EQ(9, days);
460
}
1377.8.27 by Paweł Blokus
tests for to_decimal methods
461
462
TEST_F(DateTest, to_decimal)
463
{
464
  drizzled::my_decimal to;
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
465
  TemporalGenerator::DateGen::make_date(&date, 1987, 5, 6);
1377.8.27 by Paweł Blokus
tests for to_decimal methods
466
467
  date.to_decimal(&to);
468
469
  ASSERT_EQ(19870506, to.buf[0]);
470
}
1377.8.33 by Paweł Blokus
fix/hack? which makes parameterized tests compile
471
472
class DateFromStringTest: public ::testing::TestWithParam<const char*>
473
{
474
  protected:
475
    Date date;
476
    bool result;
477
    uint32_t years, months, days;
478
    
479
    virtual void SetUp()
480
    {
481
      init_temporal_formats();
482
    }
483
    
484
    virtual void TearDown()
485
    {
486
      deinit_temporal_formats();
487
    }
488
    
489
    void assign_date_values()
490
    {
491
      years= date.years();
492
      months= date.months();
493
      days= date.days();
494
    }
495
};
496
497
TEST_P(DateFromStringTest, from_string)
498
{
1377.8.35 by Paweł Blokus
fixed some style issues and decided on buffer size in temporal_interval_test
499
  const char *valid_string= GetParam();
1377.8.33 by Paweł Blokus
fix/hack? which makes parameterized tests compile
500
  
501
  result= date.from_string(valid_string, strlen(valid_string));
502
  ASSERT_TRUE(result);
503
  
504
  assign_date_values();
505
  
506
  EXPECT_EQ(2010, years);
507
  EXPECT_EQ(6, months);
508
  EXPECT_EQ(7, days);
509
}
510
511
/* TODO:for some reason this was not declared by the macro, needs clarification*/
512
testing::internal::ParamGenerator<const char*> gtest_ValidStringDateFromStringTest_EvalGenerator_();
513
514
INSTANTIATE_TEST_CASE_P(ValidString, DateFromStringTest,
515
                        ::testing::Values("20100607", /* YYYYMMDD */
516
                                          "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/
517
                                          "10.06.07",/* YY[-/.]MM[-/.]DD */
518
                                          "10/6/7",/* YY[-/.][M]M[-/.][D]D */
519
                                          "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */));
520
                                          
521
522