~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 <drizzled/temporal.h>
1377.8.23 by Paweł Blokus
added generator for TemporalFormat
24
#include <drizzled/temporal_format.h>
1377.8.32 by Paweł Blokus
setters to TemporalInterval
25
#include <drizzled/temporal_interval.h>
1377.8.2 by Paweł Blokus
created files for temporal tests
26
1377.9.1 by Paweł Blokus
updated includes to last file rename
27
#include "temporal_generator.h"
1377.8.2 by Paweł Blokus
created files for temporal tests
28
29
using namespace drizzled;
30
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
31
void TemporalGenerator::DateGen::make_date(Date *date,
1377.8.2 by Paweł Blokus
created files for temporal tests
32
                                          uint32_t years, uint32_t months, uint32_t days)
33
{
34
  date->set_years(years);
35
  date->set_months(months);
36
  date->set_days(days);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
37
  date->set_epoch_seconds();
1377.8.2 by Paweł Blokus
created files for temporal tests
38
}
1377.8.5 by Paweł Blokus
removed an undefined character from the decimal.cc file
39
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
40
void TemporalGenerator::DateGen::make_valid_date(drizzled::Date *date)
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
41
{
42
  date->set_years(2005);
43
  date->set_months(5);
44
  date->set_days(26);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
45
  date->set_epoch_seconds();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
46
}
47
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
48
void TemporalGenerator::TemporalGen::leap_day_in_leap_year(drizzled::Temporal *temporal)
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
49
{
1377.8.20 by Paweł Blokus
moved shared generators to Temporal
50
  temporal->set_years(2008);
51
  temporal->set_months(2);
52
  temporal->set_days(29);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
53
  temporal->set_epoch_seconds();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
54
}
55
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
56
void TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(drizzled::Temporal *temporal)
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
57
{
1377.8.20 by Paweł Blokus
moved shared generators to Temporal
58
  temporal->set_years(2010);
59
  temporal->set_months(2);
60
  temporal->set_days(29);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
61
  temporal->set_epoch_seconds();
1377.8.10 by Paweł Blokus
tests for Date->is_valid()
62
}
63
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
64
void TemporalGenerator::TimeGen::make_time(drizzled::Time *time,
1377.8.34 by Paweł Blokus
take microsedonds into account where they are used in datetime and time
65
                                   uint32_t hours, uint32_t minutes, uint32_t seconds,
66
                                   uint32_t useconds)
1377.8.18 by Paweł Blokus
added Time_test to include.am
67
{
68
  time->set_hours(hours);
69
  time->set_minutes(minutes);
70
  time->set_seconds(seconds);
1377.8.34 by Paweł Blokus
take microsedonds into account where they are used in datetime and time
71
  time->set_useconds(useconds);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
72
  time->set_epoch_seconds();
1377.8.18 by Paweł Blokus
added Time_test to include.am
73
}
74
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
75
void TemporalGenerator::TemporalGen::make_min_time(drizzled::Temporal *temporal)
1377.8.18 by Paweł Blokus
added Time_test to include.am
76
{
1377.8.20 by Paweł Blokus
moved shared generators to Temporal
77
  temporal->set_hours(0);
78
  temporal->set_minutes(0);
79
  temporal->set_seconds(0);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
80
  temporal->set_epoch_seconds();
1377.8.18 by Paweł Blokus
added Time_test to include.am
81
}
82
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
83
void TemporalGenerator::TemporalGen::make_max_time(drizzled::Temporal *temporal)
1377.8.18 by Paweł Blokus
added Time_test to include.am
84
{
1377.8.20 by Paweł Blokus
moved shared generators to Temporal
85
  temporal->set_hours(23);
86
  temporal->set_minutes(59);
87
  temporal->set_seconds(59);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
88
  temporal->set_epoch_seconds();
1377.8.18 by Paweł Blokus
added Time_test to include.am
89
}
90
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
91
void TemporalGenerator::DateTimeGen::make_datetime(drizzled::DateTime *datetime,
1377.8.5 by Paweł Blokus
removed an undefined character from the decimal.cc file
92
                   uint32_t years, uint32_t months, uint32_t days, uint32_t hours,
1377.8.34 by Paweł Blokus
take microsedonds into account where they are used in datetime and time
93
                   uint32_t minutes, uint32_t seconds, uint32_t useconds)
1377.8.5 by Paweł Blokus
removed an undefined character from the decimal.cc file
94
{
95
  datetime->set_years(years);
96
  datetime->set_months(months);
97
  datetime->set_days(days);
98
  datetime->set_hours(hours);
99
  datetime->set_minutes(minutes);
100
  datetime->set_seconds(seconds);
1377.8.34 by Paweł Blokus
take microsedonds into account where they are used in datetime and time
101
  datetime->set_useconds(useconds);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
102
  datetime->set_epoch_seconds();
1377.8.6 by Paweł Blokus
added tests for Date operators used for comparing with timestamps
103
}                     
104
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
105
void TemporalGenerator::DateTimeGen::make_valid_datetime(drizzled::DateTime *datetime)
1377.8.20 by Paweł Blokus
moved shared generators to Temporal
106
{
107
  datetime->set_years(1999);
108
  datetime->set_months(8);
109
  datetime->set_days(15);
110
  datetime->set_hours(13);
111
  datetime->set_minutes(34);
112
  datetime->set_seconds(6);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
113
  datetime->set_epoch_seconds();
1377.8.20 by Paweł Blokus
moved shared generators to Temporal
114
}
115
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
116
void TemporalGenerator::TimestampGen::make_timestamp(drizzled::Timestamp *timestamp,
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
117
                                             uint32_t years, uint32_t months, uint32_t days,
118
                                             uint32_t hours, uint32_t minutes, uint32_t seconds)
1377.8.6 by Paweł Blokus
added tests for Date operators used for comparing with timestamps
119
{
120
  timestamp->set_years(years);
121
  timestamp->set_months(months);
122
  timestamp->set_days(days);
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
123
  timestamp->set_hours(hours);
124
  timestamp->set_minutes(minutes);
125
  timestamp->set_seconds(seconds);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
126
  timestamp->set_epoch_seconds();
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
127
}
128
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
129
void TemporalGenerator::TimestampGen::make_micro_timestamp(drizzled::MicroTimestamp *timestamp,
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
130
                                                   uint32_t years, uint32_t months, uint32_t days,
131
                                                   uint32_t hours, uint32_t minutes,
132
                                                   uint32_t seconds, uint32_t microseconds)
133
{
134
  make_timestamp(timestamp, years, months, days, hours, minutes, seconds);
135
  timestamp->set_useconds(microseconds);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
136
  timestamp->set_epoch_seconds();
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
137
}
138
                                 
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
139
void TemporalGenerator::TimestampGen::make_nano_timestamp(drizzled::NanoTimestamp *timestamp,
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
140
                                                  uint32_t years, uint32_t months, uint32_t days,
141
                                                  uint32_t hours, uint32_t minutes,
142
                                                  uint32_t seconds, uint32_t nanoseconds)
143
{
144
  make_timestamp(timestamp, years, months, days, hours, minutes, seconds);
145
  timestamp->set_nseconds(nanoseconds);
1377.8.25 by Paweł Blokus
this was the first working build, and these changes make almost all the tests pass
146
  timestamp->set_epoch_seconds();
1377.8.22 by Paweł Blokus
added missing time component parameters to timestamp generator
147
}
1377.8.23 by Paweł Blokus
added generator for TemporalFormat
148
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
149
drizzled::TemporalFormat *TemporalGenerator::TemporalFormatGen::make_temporal_format(const char *regexp,
1377.8.23 by Paweł Blokus
added generator for TemporalFormat
150
                                                                  int32_t year_part_index,
151
                                                                  int32_t month_part_index,
152
                                                                  int32_t day_part_index,
153
                                                                  int32_t hour_part_index,
154
                                                                  int32_t minute_part_index,
155
                                                                  int32_t second_part_index,
156
                                                                  int32_t usecond_part_index,
157
                                                                  int32_t nsecond_part_index)
158
{
159
  drizzled::TemporalFormat *temporal_format= new drizzled::TemporalFormat(regexp);
160
  
161
  temporal_format->set_year_part_index(year_part_index);
162
  temporal_format->set_month_part_index(month_part_index);
163
  temporal_format->set_day_part_index(day_part_index);
164
  temporal_format->set_hour_part_index(hour_part_index);
165
  temporal_format->set_minute_part_index(minute_part_index);
166
  temporal_format->set_second_part_index(second_part_index);
167
  temporal_format->set_usecond_part_index(usecond_part_index);
168
  temporal_format->set_nsecond_part_index(nsecond_part_index);
169
170
  return temporal_format;
1377.8.32 by Paweł Blokus
setters to TemporalInterval
171
}
172
1377.8.36 by Paweł Blokus
changed Generator to TemporalGenerator
173
drizzled::TemporalInterval *TemporalGenerator::TemporalIntervalGen::make_temporal_interval(
1377.8.32 by Paweł Blokus
setters to TemporalInterval
174
                                                              uint32_t  year,
175
                                                              uint32_t  month,
176
                                                              uint32_t  day,
177
                                                              uint32_t  hour,
178
                                                              uint64_t  minute,
179
                                                              uint64_t  second,
180
                                                              uint64_t  second_part,
181
                                                              bool neg)
182
{
1377.8.35 by Paweł Blokus
fixed some style issues and decided on buffer size in temporal_interval_test
183
  drizzled::TemporalInterval *interval= new drizzled::TemporalInterval();
1377.8.32 by Paweł Blokus
setters to TemporalInterval
184
185
  interval->set_year(year);
186
  interval->set_month(month);
187
  interval->set_day(day);
188
  interval->set_hour(hour);
189
  interval->set_minute(minute);
190
  interval->set_second(second);
191
  interval->set_second_part(second_part);
192
  interval->setNegative(neg);
193
194
  return interval;
195
}