Merge lp:~linuxjedi/drizzle/trunk-unittests into lp:drizzle/7.0
- trunk-unittests
- Merge into 7.0
Proposed by
Andrew Hutchings
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Brian Aker | ||||||||
Approved revision: | 2105 | ||||||||
Merged at revision: | 2109 | ||||||||
Proposed branch: | lp:~linuxjedi/drizzle/trunk-unittests | ||||||||
Merge into: | lp:drizzle/7.0 | ||||||||
Diff against target: |
7218 lines (+200/-3799) 27 files modified
configure.ac (+1/-1) docs/installing/from_source.rst (+1/-1) docs/installing/requirements.rst (+2/-1) m4/pandora_have_libboost_test.m4 (+45/-0) m4/pandora_have_libgtest.m4 (+0/-47) unittests/atomics_test.cc (+73/-87) unittests/calendar_test.cc (+47/-47) unittests/client_server.c (+0/-567) unittests/constrained_value.cc (+0/-57) unittests/date_test.cc (+0/-522) unittests/date_time_test.cc (+0/-460) unittests/generators.cc (+0/-72) unittests/global_buffer_test.cc (+0/-60) unittests/include.am (+8/-16) unittests/libdrizzle_test.cc (+0/-59) unittests/main.cc (+23/-12) unittests/micro_timestamp_test.cc (+0/-108) unittests/nano_timestamp_test.cc (+0/-97) unittests/option_context.cc (+0/-56) unittests/pthread_atomics_test.cc (+0/-134) unittests/table_identifier.cc (+0/-88) unittests/temporal_format_test.cc (+0/-151) unittests/temporal_generator.cc (+0/-195) unittests/temporal_interval_test.cc (+0/-230) unittests/time_test.cc (+0/-381) unittests/timestamp_test.cc (+0/-262) unittests/utf8_test.cc (+0/-88) |
||||||||
To merge this branch: | bzr merge lp:~linuxjedi/drizzle/trunk-unittests | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Drizzle Developers | Pending | ||
Review via email: mp+47221@code.launchpad.net |
Commit message
Description of the change
Fix or remove disabled unit tests
Port unit tests to boost::test and remove gtest dependency
To post a comment you must log in.
- 2103. By Andrew Hutchings
-
Merge trunk into branch
- 2104. By Andrew Hutchings
-
Remove gtest dependency from docs
- 2105. By Andrew Hutchings
-
And add boost::test to the doc
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configure.ac' |
2 | --- configure.ac 2010-12-19 16:20:13 +0000 |
3 | +++ configure.ac 2011-01-24 09:18:02 +0000 |
4 | @@ -83,7 +83,7 @@ |
5 | AC_DEFINE([BUILDING_DRIZZLED],[1], |
6 | [Define indicating we are building and not consuming drizzle.]) |
7 | |
8 | -PANDORA_HAVE_LIBGTEST |
9 | +PANDORA_HAVE_BOOST_TEST |
10 | PANDORA_HAVE_LIBSQLITE3 |
11 | |
12 | AC_CHECK_FUNC(inet_ntoa, [], [AC_CHECK_LIB(nsl, inet_ntoa)]) |
13 | |
14 | === modified file 'docs/installing/from_source.rst' |
15 | --- docs/installing/from_source.rst 2011-01-21 13:56:53 +0000 |
16 | +++ docs/installing/from_source.rst 2011-01-24 09:18:02 +0000 |
17 | @@ -22,8 +22,8 @@ |
18 | * libboost-iostreams-dev |
19 | * libboost-program-options-dev |
20 | * libboost-regex-dev |
21 | + * libboost-test-dev |
22 | * libboost-thread-dev |
23 | - * libgtest (1.5.0) |
24 | * libpcre3-dev |
25 | * libreadline5-dev | libreadline-dev |
26 | * libtool |
27 | |
28 | === modified file 'docs/installing/requirements.rst' |
29 | --- docs/installing/requirements.rst 2011-01-21 13:56:53 +0000 |
30 | +++ docs/installing/requirements.rst 2011-01-24 09:18:02 +0000 |
31 | @@ -18,7 +18,8 @@ |
32 | * Apple OSX 10.6.4 |
33 | |
34 | We recommend using these platforms with Drizzle, older version may have various |
35 | -unforseen difficulties when compiling and/or installing. |
36 | +unforseen difficulties when compiling and/or installing. Drizzle is tested on |
37 | +both 32bit and 64bit platforms but we recommend using a 64bit platform. |
38 | |
39 | Software Requirements |
40 | --------------------- |
41 | |
42 | === added file 'm4/pandora_have_libboost_test.m4' |
43 | --- m4/pandora_have_libboost_test.m4 1970-01-01 00:00:00 +0000 |
44 | +++ m4/pandora_have_libboost_test.m4 2011-01-24 09:18:02 +0000 |
45 | @@ -0,0 +1,45 @@ |
46 | +dnl Copyright (C) 2011 Andrew Hutchings |
47 | +dnl This file is free software; Andrew Hutchings |
48 | +dnl gives unlimited permission to copy and/or distribute it, |
49 | +dnl with or without modifications, as long as this notice is preserved. |
50 | + |
51 | +AC_DEFUN([_PANDORA_SEARCH_BOOST_TEST],[ |
52 | + AC_REQUIRE([AC_LIB_PREFIX]) |
53 | + |
54 | + dnl -------------------------------------------------------------------- |
55 | + dnl Check for boost::test |
56 | + dnl -------------------------------------------------------------------- |
57 | + |
58 | + AC_LANG_PUSH(C++) |
59 | + AC_LIB_HAVE_LINKFLAGS(boost_unit_test_framework-mt,,[ |
60 | + #include <boost/test/unit_test.hpp> |
61 | + ],[ |
62 | + boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages); |
63 | + ]) |
64 | + AS_IF([test "x${ac_cv_libboost_test_framework_mt}" = "xno"],[ |
65 | + AC_LIB_HAVE_LINKFLAGS(boost_unit_test_framework,,[ |
66 | + #include <boost/test/unit_test.hpp> |
67 | + ],[ |
68 | + boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages); |
69 | + ]) |
70 | + ]) |
71 | + AC_LANG_POP() |
72 | + |
73 | + AM_CONDITIONAL(HAVE_BOOST_TEST, |
74 | + [test "x${ac_cv_libboost_test_framework}" = "xyes" -o "x${ac_cv_libboost_test_framework_mt}" = "xyes"]) |
75 | + BOOST_LIBS="${BOOST_LIBS} ${LTLIBBOOST_TEST_MT} ${LTLIBBOOST_TEST}" |
76 | + AC_SUBST(BOOST_LIBS) |
77 | +]) |
78 | + |
79 | +AC_DEFUN([PANDORA_HAVE_BOOST_TEST],[ |
80 | + PANDORA_HAVE_BOOST($1) |
81 | + _PANDORA_SEARCH_BOOST_TEST($1) |
82 | +]) |
83 | + |
84 | +AC_DEFUN([PANDORA_REQUIRE_BOOST_TEST],[ |
85 | + PANDORA_REQUIRE_BOOST($1) |
86 | + _PANDORA_SEARCH_BOOST_TEST($1) |
87 | + AS_IF([test "x${ac_cv_libboost_test_framework}" = "xno" -a "x${ac_cv_libboost_test_framework_mt}" = "xno"], |
88 | + AC_MSG_ERROR([boost::test is required for ${PACKAGE}])) |
89 | +]) |
90 | + |
91 | |
92 | === removed file 'm4/pandora_have_libgtest.m4' |
93 | --- m4/pandora_have_libgtest.m4 2010-09-19 18:03:28 +0000 |
94 | +++ m4/pandora_have_libgtest.m4 1970-01-01 00:00:00 +0000 |
95 | @@ -1,47 +0,0 @@ |
96 | -dnl Copyright (C) 2010 Monty Taylor |
97 | -dnl This file is free software; Monty Taylor |
98 | -dnl gives unlimited permission to copy and/or distribute it, |
99 | -dnl with or without modifications, as long as this notice is preserved. |
100 | - |
101 | -AC_DEFUN([_PANDORA_SEARCH_LIBGTEST],[ |
102 | - AC_REQUIRE([AC_LIB_PREFIX]) |
103 | - |
104 | - dnl -------------------------------------------------------------------- |
105 | - dnl Check for libgtest |
106 | - dnl -------------------------------------------------------------------- |
107 | - |
108 | - AC_ARG_ENABLE([libgtest], |
109 | - [AS_HELP_STRING([--disable-libgtest], |
110 | - [Build with libgtest support @<:@default=on@:>@])], |
111 | - [ac_enable_libgtest="$enableval"], |
112 | - [ac_enable_libgtest="yes"]) |
113 | - |
114 | - AS_IF([test "x$ac_enable_libgtest" = "xyes"],[ |
115 | - AC_LANG_PUSH(C++) |
116 | - save_CXXFLAGS="${CXXFLAGS}" |
117 | - CXXFLAGS="${AM_CXXFLAGS} ${CXXFLAGS}" |
118 | - AC_LIB_HAVE_LINKFLAGS(gtest,,[ |
119 | - #include <gtest/gtest.h> |
120 | -TEST(pandora_test_libgtest, PandoraTest) |
121 | -{ |
122 | - ASSERT_EQ(1, 1); |
123 | -} |
124 | - ],[]) |
125 | - CXXFLAGS="${save_CXXFLAGS}" |
126 | - AC_LANG_POP() |
127 | - ],[ |
128 | - ac_cv_libgtest="no" |
129 | - ]) |
130 | - |
131 | - AM_CONDITIONAL(HAVE_LIBGTEST, [test "x${ac_cv_libgtest}" = "xyes"]) |
132 | -]) |
133 | - |
134 | -AC_DEFUN([PANDORA_HAVE_LIBGTEST],[ |
135 | - AC_REQUIRE([_PANDORA_SEARCH_LIBGTEST]) |
136 | -]) |
137 | - |
138 | -AC_DEFUN([PANDORA_REQUIRE_LIBGTEST],[ |
139 | - AC_REQUIRE([_PANDORA_SEARCH_LIBGTEST]) |
140 | - AS_IF([test "x${ac_cv_libgtest}" = "xno"], |
141 | - AC_MSG_ERROR([libgtest is required for ${PACKAGE}])) |
142 | -]) |
143 | |
144 | === modified file 'unittests/atomics_test.cc' |
145 | --- unittests/atomics_test.cc 2010-10-20 09:32:35 +0000 |
146 | +++ unittests/atomics_test.cc 2011-01-24 09:18:02 +0000 |
147 | @@ -19,101 +19,87 @@ |
148 | */ |
149 | |
150 | #include "config.h" |
151 | - |
152 | -#include <gtest/gtest.h> |
153 | +#define BOOST_TEST_DYN_LINK |
154 | +#include <boost/test/unit_test.hpp> |
155 | |
156 | #include <drizzled/atomics.h> |
157 | |
158 | using namespace drizzled; |
159 | |
160 | -TEST(atomic_operations, fetch_and_store) |
161 | -{ |
162 | - atomic<uint32_t> u235; |
163 | - |
164 | - EXPECT_EQ(0, u235.fetch_and_store(1)); |
165 | - |
166 | - u235.fetch_and_store(15); |
167 | - |
168 | - EXPECT_EQ(15, u235.fetch_and_store(100)); |
169 | - EXPECT_EQ(100, u235); |
170 | -} |
171 | - |
172 | -TEST(atomic_operations, fetch_and_increment) |
173 | -{ |
174 | - atomic<uint32_t> u235; |
175 | - |
176 | - EXPECT_EQ(0, u235.fetch_and_increment()); |
177 | - EXPECT_EQ(1, u235); |
178 | -} |
179 | - |
180 | -TEST(atomic_operations, fetch_and_add) |
181 | -{ |
182 | - atomic<uint32_t> u235; |
183 | - |
184 | - EXPECT_EQ(0, u235.fetch_and_add(2)); |
185 | - EXPECT_EQ(2, u235); |
186 | -} |
187 | - |
188 | -TEST(atomic_operations, add_and_fetch) |
189 | -{ |
190 | - atomic<uint32_t> u235; |
191 | - |
192 | - EXPECT_EQ(10, u235.add_and_fetch(10)); |
193 | - EXPECT_EQ(10, u235); |
194 | -} |
195 | - |
196 | -TEST(atomic_operations, fetch_and_decrement) |
197 | -{ |
198 | - atomic<uint32_t> u235; |
199 | - |
200 | - u235.fetch_and_store(15); |
201 | - |
202 | - EXPECT_EQ(15, u235.fetch_and_decrement()); |
203 | - EXPECT_EQ(14, u235); |
204 | -} |
205 | - |
206 | -TEST(atomic_operations, compare_and_swap) |
207 | +BOOST_AUTO_TEST_SUITE(AtomicOperations) |
208 | +BOOST_AUTO_TEST_CASE(fetch_and_store) |
209 | +{ |
210 | + atomic<uint32_t> u235; |
211 | + |
212 | + BOOST_REQUIRE_EQUAL(0, u235.fetch_and_store(1)); |
213 | + |
214 | + u235.fetch_and_store(15); |
215 | + |
216 | + BOOST_REQUIRE_EQUAL(15, u235.fetch_and_store(100)); |
217 | + BOOST_REQUIRE_EQUAL(100, u235); |
218 | +} |
219 | + |
220 | +BOOST_AUTO_TEST_CASE(fetch_and_increment) |
221 | +{ |
222 | + atomic<uint32_t> u235; |
223 | + |
224 | + BOOST_REQUIRE_EQUAL(0, u235.fetch_and_increment()); |
225 | + BOOST_REQUIRE_EQUAL(1, u235); |
226 | +} |
227 | + |
228 | +BOOST_AUTO_TEST_CASE(fetch_and_add) |
229 | +{ |
230 | + atomic<uint32_t> u235; |
231 | + |
232 | + BOOST_REQUIRE_EQUAL(0, u235.fetch_and_add(2)); |
233 | + BOOST_REQUIRE_EQUAL(2, u235); |
234 | +} |
235 | + |
236 | +BOOST_AUTO_TEST_CASE(add_and_fetch) |
237 | +{ |
238 | + atomic<uint32_t> u235; |
239 | + |
240 | + BOOST_REQUIRE_EQUAL(10, u235.add_and_fetch(10)); |
241 | + BOOST_REQUIRE_EQUAL(10, u235); |
242 | +} |
243 | + |
244 | +BOOST_AUTO_TEST_CASE(fetch_and_decrement) |
245 | +{ |
246 | + atomic<uint32_t> u235; |
247 | + |
248 | + u235.fetch_and_store(15); |
249 | + |
250 | + BOOST_REQUIRE_EQUAL(15, u235.fetch_and_decrement()); |
251 | + BOOST_REQUIRE_EQUAL(14, u235); |
252 | +} |
253 | + |
254 | +BOOST_AUTO_TEST_CASE(compare_and_swap) |
255 | { |
256 | atomic<uint32_t> u235; |
257 | |
258 | u235.fetch_and_store(100); |
259 | |
260 | - ASSERT_FALSE(u235.compare_and_swap(42, 200)); |
261 | - ASSERT_TRUE(u235.compare_and_swap(200, 100)); |
262 | - EXPECT_EQ(200, u235); |
263 | -} |
264 | - |
265 | -TEST(atomic_operations, increment) |
266 | -{ |
267 | - atomic<uint32_t> u235; |
268 | - u235.fetch_and_store(200); |
269 | - EXPECT_EQ(201, u235.increment()); |
270 | -} |
271 | - |
272 | -TEST(atomic_operations, decrement) |
273 | -{ |
274 | - atomic<uint32_t> u235; |
275 | - u235.fetch_and_store(200); |
276 | - |
277 | - EXPECT_EQ(199, u235.decrement()); |
278 | -} |
279 | - |
280 | -/* |
281 | -TEST(atomic_operations, increment_assign) |
282 | -{ |
283 | - atomic<uint32_t> u235; |
284 | - u235.fetch_and_store(200); |
285 | - |
286 | - EXPECT_EQ(242, u235+=42); |
287 | -} |
288 | - |
289 | -TEST(atomic_operations, decrement_assign) |
290 | -{ |
291 | - atomic<uint32_t> u235; |
292 | - u235.fetch_and_store(200); |
293 | - |
294 | - EXPECT_EQ(158, u235-=42); |
295 | -} |
296 | -*/ |
297 | - |
298 | + BOOST_REQUIRE(not u235.compare_and_swap(42, 200)); |
299 | + BOOST_REQUIRE(u235.compare_and_swap(200, 100)); |
300 | + BOOST_REQUIRE_EQUAL(200, u235); |
301 | +} |
302 | + |
303 | +BOOST_AUTO_TEST_CASE(increment) |
304 | +{ |
305 | + atomic<uint32_t> u235; |
306 | + u235.fetch_and_store(200); |
307 | + BOOST_REQUIRE_EQUAL(201, u235.increment()); |
308 | +} |
309 | + |
310 | +BOOST_AUTO_TEST_CASE(decrement) |
311 | +{ |
312 | + atomic<uint32_t> u235; |
313 | + u235.fetch_and_store(200); |
314 | + |
315 | + BOOST_REQUIRE_EQUAL(199, u235.decrement()); |
316 | +} |
317 | + |
318 | +BOOST_AUTO_TEST_SUITE_END() |
319 | + |
320 | +/* TODO: add tests for += and -= when supported */ |
321 | |
322 | |
323 | === modified file 'unittests/calendar_test.cc' |
324 | --- unittests/calendar_test.cc 2011-01-20 07:24:29 +0000 |
325 | +++ unittests/calendar_test.cc 2011-01-24 09:18:02 +0000 |
326 | @@ -19,113 +19,113 @@ |
327 | */ |
328 | |
329 | #include "config.h" |
330 | - |
331 | -#include <gtest/gtest.h> |
332 | +#define BOOST_TEST_DYN_LINK |
333 | +#include <boost/test/unit_test.hpp> |
334 | |
335 | #include <drizzled/calendar.h> |
336 | |
337 | using namespace drizzled; |
338 | - |
339 | -TEST(calendar_julian_day_number_from_gregorian_date_test, CalculationTest) |
340 | +BOOST_AUTO_TEST_SUITE(CalculationTest) |
341 | +BOOST_AUTO_TEST_CASE(calendar_julian_day_number_from_gregorian_date_test) |
342 | { |
343 | uint32_t year, month, day; |
344 | |
345 | year= 2010; month= 4; day= 2; |
346 | - EXPECT_EQ(2455289, julian_day_number_from_gregorian_date(year, month, day)); |
347 | + BOOST_REQUIRE_EQUAL(2455289, julian_day_number_from_gregorian_date(year, month, day)); |
348 | |
349 | year= 1976; month= 12; day= 21; |
350 | - EXPECT_EQ(2443134, julian_day_number_from_gregorian_date(year, month, day)); |
351 | + BOOST_REQUIRE_EQUAL(2443134, julian_day_number_from_gregorian_date(year, month, day)); |
352 | |
353 | year= 2050; month= 6; day= 15; |
354 | - EXPECT_EQ(2469973, julian_day_number_from_gregorian_date(year, month, day)); |
355 | + BOOST_REQUIRE_EQUAL(2469973, julian_day_number_from_gregorian_date(year, month, day)); |
356 | |
357 | year= 1999; month= 12; day= 31; |
358 | - EXPECT_EQ(2451544, julian_day_number_from_gregorian_date(year, month, day)); |
359 | + BOOST_REQUIRE_EQUAL(2451544, julian_day_number_from_gregorian_date(year, month, day)); |
360 | |
361 | year= 2008; month= 2; day= 29; |
362 | - EXPECT_EQ(2454526, julian_day_number_from_gregorian_date(year, month, day)); |
363 | + BOOST_REQUIRE_EQUAL(2454526, julian_day_number_from_gregorian_date(year, month, day)); |
364 | } |
365 | |
366 | -TEST(calendar_gregorian_date_from_julian_day_number_test, CalculationTest) |
367 | +BOOST_AUTO_TEST_CASE(calendar_gregorian_date_from_julian_day_number_test) |
368 | { |
369 | int64_t julian_day; |
370 | uint32_t year_out, month_out, day_out; |
371 | |
372 | julian_day= 2455289; |
373 | gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out); |
374 | - EXPECT_TRUE((year_out == 2010) && (month_out == 4) && (day_out == 2)); |
375 | + BOOST_REQUIRE((year_out == 2010) && (month_out == 4) && (day_out == 2)); |
376 | |
377 | julian_day= 2443134; |
378 | gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out); |
379 | - EXPECT_TRUE((year_out == 1976) && (month_out == 12) && (day_out == 21)); |
380 | + BOOST_REQUIRE((year_out == 1976) && (month_out == 12) && (day_out == 21)); |
381 | |
382 | julian_day= 2469973; |
383 | gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out); |
384 | - EXPECT_TRUE((year_out == 2050) && (month_out == 6) && (day_out == 15)); |
385 | + BOOST_REQUIRE((year_out == 2050) && (month_out == 6) && (day_out == 15)); |
386 | |
387 | julian_day= 2451544; |
388 | gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out); |
389 | - EXPECT_TRUE((year_out == 1999) && (month_out == 12) && (day_out == 31)); |
390 | + BOOST_REQUIRE((year_out == 1999) && (month_out == 12) && (day_out == 31)); |
391 | |
392 | julian_day= 2454526; |
393 | gregorian_date_from_julian_day_number(julian_day, &year_out, &month_out, &day_out); |
394 | - EXPECT_TRUE((year_out == 2008) && (month_out == 2) && (day_out == 29)); |
395 | -} |
396 | - |
397 | - |
398 | - |
399 | - |
400 | -TEST(calendar_day_of_week_test, MondayFirst) |
401 | -{ |
402 | - /* Friday 2010 IV 2 */ |
403 | - ASSERT_EQ(4, day_of_week(2455289, false)); |
404 | -} |
405 | - |
406 | -TEST(calendar_day_of_week_test, SundayFirst) |
407 | -{ |
408 | - /* Friday 2010 IV 2 */ |
409 | - ASSERT_EQ(5, day_of_week(2455289, true)); |
410 | -} |
411 | - |
412 | - |
413 | - |
414 | - |
415 | -TEST(calendar_in_unix_epoch_range_test, MinOfRange) |
416 | + BOOST_REQUIRE((year_out == 2008) && (month_out == 2) && (day_out == 29)); |
417 | +} |
418 | +BOOST_AUTO_TEST_SUITE_END() |
419 | + |
420 | +BOOST_AUTO_TEST_SUITE(DayOfWeek) |
421 | +BOOST_AUTO_TEST_CASE(MondayFirst) |
422 | +{ |
423 | + /* Friday 2010 IV 2 */ |
424 | + BOOST_REQUIRE_EQUAL(4, day_of_week(2455289, false)); |
425 | +} |
426 | + |
427 | +BOOST_AUTO_TEST_CASE(SundayFirst) |
428 | +{ |
429 | + /* Friday 2010 IV 2 */ |
430 | + BOOST_REQUIRE_EQUAL(5, day_of_week(2455289, true)); |
431 | +} |
432 | +BOOST_AUTO_TEST_SUITE_END() |
433 | + |
434 | + |
435 | +BOOST_AUTO_TEST_SUITE(CalendarInUnixEpochRange) |
436 | +BOOST_AUTO_TEST_CASE(MinOfRange) |
437 | { |
438 | uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0; |
439 | |
440 | - ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
441 | + BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
442 | } |
443 | |
444 | -TEST(calendar_in_unix_epoch_range_test, MaxOfRange) |
445 | +BOOST_AUTO_TEST_CASE(MaxOfRange) |
446 | { |
447 | uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7; |
448 | |
449 | - ASSERT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
450 | + BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
451 | } |
452 | |
453 | -TEST(calendar_in_unix_epoch_range_test, OneSecondBeforeMinOfRange) |
454 | +BOOST_AUTO_TEST_CASE(OneSecondBeforeMinOfRange) |
455 | { |
456 | uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59; |
457 | |
458 | - ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
459 | + BOOST_REQUIRE(not in_unix_epoch_range(year, month, day, hour, minute, second)); |
460 | } |
461 | |
462 | -TEST(calendar_in_unix_epoch_range_test, OneSecondAfterMaxOfRange) |
463 | +BOOST_AUTO_TEST_CASE(OneSecondAfterMaxOfRange) |
464 | { |
465 | uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8; |
466 | |
467 | - ASSERT_FALSE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
468 | + BOOST_REQUIRE(not in_unix_epoch_range(year, month, day, hour, minute, second)); |
469 | } |
470 | |
471 | -TEST(calendar_in_unix_epoch_range_test, InsideRange) |
472 | +BOOST_AUTO_TEST_CASE(InsideRange) |
473 | { |
474 | uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5; |
475 | - EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
476 | + BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
477 | |
478 | year= 2010; month= 4; day= 2; hour= 21; minute= 44; second= 0; |
479 | - EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
480 | + BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
481 | |
482 | year= 2020; month= 7; day= 13; hour= 16; minute= 56; second= 59; |
483 | - EXPECT_TRUE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
484 | + BOOST_REQUIRE(in_unix_epoch_range(year, month, day, hour, minute, second)); |
485 | } |
486 | +BOOST_AUTO_TEST_SUITE_END() |
487 | |
488 | === removed file 'unittests/client_server.c' |
489 | --- unittests/client_server.c 2010-12-04 02:13:38 +0000 |
490 | +++ unittests/client_server.c 1970-01-01 00:00:00 +0000 |
491 | @@ -1,567 +0,0 @@ |
492 | -/* |
493 | - * Drizzle Client & Protocol Library |
494 | - * |
495 | - * Copyright (C) 2008 Eric Day (eday@oddments.org) |
496 | - * All rights reserved. |
497 | - * |
498 | - * Redistribution and use in source and binary forms, with or without |
499 | - * modification, are permitted provided that the following conditions are |
500 | - * met: |
501 | - * |
502 | - * * Redistributions of source code must retain the above copyright |
503 | - * notice, this list of conditions and the following disclaimer. |
504 | - * |
505 | - * * Redistributions in binary form must reproduce the above |
506 | - * copyright notice, this list of conditions and the following disclaimer |
507 | - * in the documentation and/or other materials provided with the |
508 | - * distribution. |
509 | - * |
510 | - * * The names of its contributors may not be used to endorse or |
511 | - * promote products derived from this software without specific prior |
512 | - * written permission. |
513 | - * |
514 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
515 | - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
516 | - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
517 | - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
518 | - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
519 | - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
520 | - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
521 | - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
522 | - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
523 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
524 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
525 | - * |
526 | - */ |
527 | - |
528 | -/** |
529 | - * @file |
530 | - * @brief Tests for drizzle_st Structures |
531 | - */ |
532 | - |
533 | -#include "common.h" |
534 | - |
535 | -#include <assert.h> |
536 | - |
537 | -#define DRIZZLE_TEST_HOST "127.0.0.1" |
538 | -#define DRIZZLE_TEST_PORT 12399 |
539 | - |
540 | -typedef enum |
541 | -{ |
542 | - SERVER_STATE_START, |
543 | - SERVER_STATE_HANDSHAKE_WRITE, |
544 | - SERVER_STATE_HANDSHAKE_READ, |
545 | - SERVER_STATE_HANDSHAKE_RESULT, |
546 | - SERVER_STATE_COMMAND_BUFFER, |
547 | - SERVER_STATE_RESULT_HEADER, |
548 | - SERVER_STATE_RESULT_COLUMN_1, |
549 | - SERVER_STATE_RESULT_COLUMN_2, |
550 | - SERVER_STATE_RESULT_COLUMN_EOF, |
551 | - SERVER_STATE_RESULT_ROW_1, |
552 | - SERVER_STATE_RESULT_ROW_1_FIELD_1, |
553 | - SERVER_STATE_RESULT_ROW_1_FIELD_2, |
554 | - SERVER_STATE_RESULT_ROW_EOF, |
555 | - SERVER_STATE_DONE |
556 | -} server_state_t; |
557 | - |
558 | -typedef struct |
559 | -{ |
560 | - server_state_t state; |
561 | - drizzle_result_st result; |
562 | - drizzle_column_st column; |
563 | - drizzle_command_t command; |
564 | - char *data; |
565 | - size_t total; |
566 | -} server_state_st; |
567 | - |
568 | -typedef enum |
569 | -{ |
570 | - CLIENT_STATE_START, |
571 | - CLIENT_STATE_RESULT, |
572 | - CLIENT_STATE_DONE |
573 | -} client_state_t; |
574 | - |
575 | -typedef struct |
576 | -{ |
577 | - client_state_t state; |
578 | - drizzle_result_st result; |
579 | -} client_state_st; |
580 | - |
581 | -static void _server(drizzle_con_st *con, server_state_st *state); |
582 | -static void _client(drizzle_con_st *con, client_state_st *state); |
583 | - |
584 | -int main(void) |
585 | -{ |
586 | - drizzle_st drizzle; |
587 | - drizzle_con_st listen_con; |
588 | - drizzle_con_st client; |
589 | - drizzle_con_st server; |
590 | - drizzle_return_t ret; |
591 | - bool server_accepted = false; |
592 | - server_state_st server_state; |
593 | - client_state_st client_state; |
594 | - |
595 | - drizzle_test("drizzle_create"); |
596 | - if (drizzle_create(&drizzle) == NULL) |
597 | - drizzle_test_error("returned NULL"); |
598 | - |
599 | - drizzle_test("drizzle_con_add_tcp_listen"); |
600 | - if (drizzle_con_add_tcp_listen(&drizzle, &listen_con, DRIZZLE_TEST_HOST, |
601 | - DRIZZLE_TEST_PORT, 1, |
602 | - DRIZZLE_CON_NONE) == NULL) |
603 | - { |
604 | - drizzle_test_error("returned NULL"); |
605 | - } |
606 | - |
607 | - drizzle_test("drizzle_con_listen"); |
608 | - ret= drizzle_con_listen(&listen_con); |
609 | - if (ret != DRIZZLE_RETURN_OK) |
610 | - drizzle_test_error("returned %s (%d)", drizzle_error(&drizzle), ret); |
611 | - |
612 | - drizzle_test("drizzle_con_add_tcp"); |
613 | - if (drizzle_con_add_tcp(&drizzle, &client, DRIZZLE_TEST_HOST, |
614 | - DRIZZLE_TEST_PORT, NULL, NULL, NULL, |
615 | - DRIZZLE_CON_NONE) == NULL) |
616 | - { |
617 | - drizzle_test_error("returned NULL"); |
618 | - } |
619 | - |
620 | - drizzle_test("drizzle_add_options"); |
621 | - drizzle_add_options(&drizzle, DRIZZLE_NON_BLOCKING); |
622 | - |
623 | - server_state.state= SERVER_STATE_START; |
624 | - client_state.state= CLIENT_STATE_START; |
625 | - |
626 | - while (true) |
627 | - { |
628 | - if (!server_accepted) |
629 | - { |
630 | - drizzle_test("drizzle_con_accept"); |
631 | - (void)drizzle_con_accept(&drizzle, &server, &ret); |
632 | - if (ret == DRIZZLE_RETURN_OK) |
633 | - server_accepted = true; |
634 | - else if (ret != DRIZZLE_RETURN_IO_WAIT) |
635 | - drizzle_test_error("returned %s (%d)", drizzle_error(&drizzle), ret); |
636 | - } |
637 | - |
638 | - if (server_accepted) |
639 | - _server(&server, &server_state); |
640 | - |
641 | - _client(&client, &client_state); |
642 | - |
643 | - if (server_state.state == SERVER_STATE_DONE && |
644 | - client_state.state == CLIENT_STATE_DONE) |
645 | - { |
646 | - break; |
647 | - } |
648 | - |
649 | - drizzle_test("drizzle_con_wait"); |
650 | - ret= drizzle_con_wait(&drizzle); |
651 | - if (ret != DRIZZLE_RETURN_OK) |
652 | - drizzle_test_error("returned %s (%d)", drizzle_error(&drizzle), ret); |
653 | - } |
654 | - |
655 | - if (server_accepted) |
656 | - { |
657 | - drizzle_test("drizzle_con_free"); |
658 | - drizzle_con_free(&server); |
659 | - } |
660 | - |
661 | - drizzle_test("drizzle_con_free"); |
662 | - drizzle_con_free(&client); |
663 | - |
664 | - drizzle_test("drizzle_con_free"); |
665 | - drizzle_con_free(&listen_con); |
666 | - |
667 | - drizzle_test("drizzle_free"); |
668 | - drizzle_free(&drizzle); |
669 | - |
670 | - return 0; |
671 | -} |
672 | - |
673 | -static void _server(drizzle_con_st *con, server_state_st *state) |
674 | -{ |
675 | - drizzle_return_t ret; |
676 | - const drizzle_field_t const fields[2]= |
677 | - { |
678 | - (const drizzle_field_t)"test_field_1", |
679 | - (const drizzle_field_t)"test_field_2" |
680 | - }; |
681 | - const size_t field_sizes[2]= { 12, 12 }; |
682 | - |
683 | - switch(state->state) |
684 | - { |
685 | - case SERVER_STATE_START: |
686 | - drizzle_con_set_protocol_version(con, 10); |
687 | - drizzle_con_set_server_version(con, "test_version"); |
688 | - drizzle_con_set_thread_id(con, 1); |
689 | - drizzle_con_set_scramble(con, (const uint8_t *)"ABCDEFGHIJKLMNOPQRST"); |
690 | - drizzle_con_set_capabilities(con, DRIZZLE_CAPABILITIES_NONE); |
691 | - drizzle_con_set_charset(con, 8); |
692 | - drizzle_con_set_status(con, DRIZZLE_CON_STATUS_NONE); |
693 | - drizzle_con_set_max_packet_size(con, DRIZZLE_MAX_PACKET_SIZE); |
694 | - |
695 | - case SERVER_STATE_HANDSHAKE_WRITE: |
696 | - drizzle_test("drizzle_handshake_server_write"); |
697 | - ret= drizzle_handshake_server_write(con); |
698 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
699 | - { |
700 | - state->state = SERVER_STATE_HANDSHAKE_WRITE; |
701 | - return; |
702 | - } |
703 | - else if (ret != DRIZZLE_RETURN_OK) |
704 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
705 | - |
706 | - case SERVER_STATE_HANDSHAKE_READ: |
707 | - drizzle_test("drizzle_handshake_client_read"); |
708 | - ret= drizzle_handshake_client_read(con); |
709 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
710 | - { |
711 | - state->state = SERVER_STATE_HANDSHAKE_READ; |
712 | - return; |
713 | - } |
714 | - else if (ret != DRIZZLE_RETURN_OK) |
715 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
716 | - |
717 | - drizzle_test("drizzle_result_create"); |
718 | - if (drizzle_result_create(con, &state->result) == NULL) |
719 | - drizzle_test_error("returned %s", drizzle_con_error(con)); |
720 | - |
721 | - case SERVER_STATE_HANDSHAKE_RESULT: |
722 | - drizzle_test("drizzle_handshake_result_write"); |
723 | - ret= drizzle_result_write(con, &state->result, true); |
724 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
725 | - { |
726 | - state->state = SERVER_STATE_HANDSHAKE_RESULT; |
727 | - return; |
728 | - } |
729 | - else if (ret != DRIZZLE_RETURN_OK) |
730 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
731 | - |
732 | - drizzle_result_free(&state->result); |
733 | - |
734 | - case SERVER_STATE_COMMAND_BUFFER: |
735 | - drizzle_test("drizzle_con_command_buffer"); |
736 | - state->data= drizzle_con_command_buffer(con, &state->command, &state->total, |
737 | - &ret); |
738 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
739 | - { |
740 | - state->state = SERVER_STATE_COMMAND_BUFFER; |
741 | - return; |
742 | - } |
743 | - else if (ret != DRIZZLE_RETURN_OK) |
744 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
745 | - |
746 | - if (state->command != DRIZZLE_COMMAND_QUERY) |
747 | - drizzle_test_error("command was not a query"); |
748 | - |
749 | - if (state->total != 6 && !memcmp(state->data, "SELECT", 6)) |
750 | - drizzle_test_error("query doesn't match"); |
751 | - |
752 | - if (state->data != NULL) |
753 | - { |
754 | - free(state->data); |
755 | - state->data= NULL; |
756 | - } |
757 | - |
758 | - drizzle_test("drizzle_result_create"); |
759 | - if (drizzle_result_create(con, &state->result) == NULL) |
760 | - drizzle_test_error("returned %s", drizzle_con_error(con)); |
761 | - |
762 | - drizzle_result_set_column_count(&state->result, 2); |
763 | - |
764 | - case SERVER_STATE_RESULT_HEADER: |
765 | - drizzle_test("drizzle_handshake_result_write"); |
766 | - ret= drizzle_result_write(con, &state->result, false); |
767 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
768 | - { |
769 | - state->state = SERVER_STATE_RESULT_HEADER; |
770 | - return; |
771 | - } |
772 | - else if (ret != DRIZZLE_RETURN_OK) |
773 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
774 | - |
775 | - drizzle_test("drizzle_column_create"); |
776 | - if (drizzle_column_create(&state->result, &state->column) == NULL) |
777 | - drizzle_test_error("returned %s", drizzle_con_error(con)); |
778 | - |
779 | - drizzle_column_set_catalog(&state->column, "test_catalog"); |
780 | - drizzle_column_set_db(&state->column, "test_db"); |
781 | - drizzle_column_set_table(&state->column, "test_table"); |
782 | - drizzle_column_set_orig_table(&state->column, "test_orig_table"); |
783 | - drizzle_column_set_name(&state->column, "test_column_1"); |
784 | - drizzle_column_set_orig_name(&state->column, "test_orig_column_1"); |
785 | - drizzle_column_set_charset(&state->column, 8); |
786 | - drizzle_column_set_size(&state->column, 32); |
787 | - drizzle_column_set_type(&state->column, DRIZZLE_COLUMN_TYPE_VARCHAR); |
788 | - drizzle_column_set_flags(&state->column, DRIZZLE_COLUMN_FLAGS_NONE); |
789 | - |
790 | - case SERVER_STATE_RESULT_COLUMN_1: |
791 | - drizzle_test("drizzle_column_write"); |
792 | - ret= drizzle_column_write(&state->result, &state->column); |
793 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
794 | - { |
795 | - state->state = SERVER_STATE_RESULT_COLUMN_1; |
796 | - return; |
797 | - } |
798 | - else if (ret != DRIZZLE_RETURN_OK) |
799 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
800 | - |
801 | - drizzle_column_set_name(&state->column, "test_column_2"); |
802 | - drizzle_column_set_orig_name(&state->column, "test_orig_column_2"); |
803 | - |
804 | - case SERVER_STATE_RESULT_COLUMN_2: |
805 | - drizzle_test("drizzle_column_write"); |
806 | - ret= drizzle_column_write(&state->result, &state->column); |
807 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
808 | - { |
809 | - state->state = SERVER_STATE_RESULT_COLUMN_2; |
810 | - return; |
811 | - } |
812 | - else if (ret != DRIZZLE_RETURN_OK) |
813 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
814 | - |
815 | - drizzle_test("drizzle_column_free"); |
816 | - drizzle_column_free(&state->column); |
817 | - |
818 | - drizzle_result_set_eof(&state->result, true); |
819 | - |
820 | - case SERVER_STATE_RESULT_COLUMN_EOF: |
821 | - drizzle_test("drizzle_handshake_result_write"); |
822 | - ret= drizzle_result_write(con, &state->result, false); |
823 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
824 | - { |
825 | - state->state = SERVER_STATE_RESULT_COLUMN_EOF; |
826 | - return; |
827 | - } |
828 | - else if (ret != DRIZZLE_RETURN_OK) |
829 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
830 | - |
831 | - drizzle_result_calc_row_size(&state->result, fields, field_sizes); |
832 | - |
833 | - case SERVER_STATE_RESULT_ROW_1: |
834 | - ret= drizzle_row_write(&state->result); |
835 | - |
836 | - case SERVER_STATE_RESULT_ROW_1_FIELD_1: |
837 | - ret= drizzle_field_write(&state->result, fields[0], field_sizes[0], |
838 | - field_sizes[0]); |
839 | - |
840 | - case SERVER_STATE_RESULT_ROW_1_FIELD_2: |
841 | - ret= drizzle_field_write(&state->result, fields[1], field_sizes[1], |
842 | - field_sizes[1]); |
843 | - |
844 | - case SERVER_STATE_RESULT_ROW_EOF: |
845 | - drizzle_test("drizzle_handshake_result_write"); |
846 | - ret= drizzle_result_write(con, &state->result, true); |
847 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
848 | - { |
849 | - state->state = SERVER_STATE_RESULT_ROW_EOF; |
850 | - return; |
851 | - } |
852 | - else if (ret != DRIZZLE_RETURN_OK) |
853 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
854 | - |
855 | - drizzle_result_free(&state->result); |
856 | - |
857 | - state->state = SERVER_STATE_DONE; |
858 | - |
859 | - case SERVER_STATE_DONE: |
860 | - return; |
861 | - |
862 | - default: |
863 | - drizzle_test_error("invalid server state"); |
864 | - } |
865 | -} |
866 | - |
867 | -static void _client(drizzle_con_st *con, client_state_st *state) |
868 | -{ |
869 | - drizzle_return_t ret; |
870 | - drizzle_column_st *column; |
871 | - drizzle_row_t row; |
872 | - size_t *field_sizes; |
873 | - |
874 | - switch(state->state) |
875 | - { |
876 | - case CLIENT_STATE_START: |
877 | - drizzle_test("drizzle_query_str"); |
878 | - (void)drizzle_query_str(con, &state->result, "SELECT", &ret); |
879 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
880 | - { |
881 | - state->state = CLIENT_STATE_START; |
882 | - return; |
883 | - } |
884 | - else if (ret != DRIZZLE_RETURN_OK) |
885 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
886 | - |
887 | - case CLIENT_STATE_RESULT: |
888 | - drizzle_test("drizzle_result_buffer"); |
889 | - ret = drizzle_result_buffer(&state->result); |
890 | - if (ret == DRIZZLE_RETURN_IO_WAIT) |
891 | - { |
892 | - state->state = CLIENT_STATE_RESULT; |
893 | - return; |
894 | - } |
895 | - else if (ret != DRIZZLE_RETURN_OK) |
896 | - drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret); |
897 | - |
898 | - drizzle_test("drizzle_con_protocol_version"); |
899 | - if (drizzle_con_protocol_version(con) != 10) |
900 | - drizzle_test_error("no match"); |
901 | - |
902 | - drizzle_test("drizzle_con_server_version"); |
903 | - if (strcmp(drizzle_con_server_version(con), "test_version")) |
904 | - drizzle_test_error("no match"); |
905 | - |
906 | - drizzle_test("drizzle_con_thread_id"); |
907 | - if (drizzle_con_thread_id(con) != 1) |
908 | - drizzle_test_error("no match"); |
909 | - |
910 | - drizzle_test("drizzle_con_scramble"); |
911 | - if (memcmp(drizzle_con_scramble(con), "ABCDEFGHIJKLMNOPQRST", |
912 | - DRIZZLE_MAX_SCRAMBLE_SIZE)) |
913 | - { |
914 | - drizzle_test_error("no match"); |
915 | - } |
916 | - |
917 | - /* We default to MySQL protocol right now, which sets this flag. */ |
918 | - drizzle_test("drizzle_con_capabilities"); |
919 | - if (drizzle_con_capabilities(con) != DRIZZLE_CAPABILITIES_PROTOCOL_41) |
920 | - drizzle_test_error("no match"); |
921 | - |
922 | - drizzle_test("drizzle_con_charset"); |
923 | - if (drizzle_con_charset(con) != 8) |
924 | - drizzle_test_error("no match"); |
925 | - |
926 | - drizzle_test("drizzle_con_status"); |
927 | - if (drizzle_con_status(con) != DRIZZLE_CON_STATUS_NONE) |
928 | - drizzle_test_error("no match"); |
929 | - |
930 | - drizzle_test("drizzle_con_packet_size"); |
931 | - if (drizzle_con_max_packet_size(con) != DRIZZLE_MAX_PACKET_SIZE) |
932 | - drizzle_test_error("no match"); |
933 | - |
934 | - drizzle_test("drizzle_column_next"); |
935 | - column= drizzle_column_next(&state->result); |
936 | - if (column == NULL) |
937 | - drizzle_test_error("column not found"); |
938 | - |
939 | - drizzle_test("drizzle_column_drizzle_result"); |
940 | - if (drizzle_column_drizzle_result(column) != &state->result) |
941 | - drizzle_test_error("no match"); |
942 | - |
943 | - drizzle_test("drizzle_column_catalog"); |
944 | - if (strcmp(drizzle_column_catalog(column), "test_catalog")) |
945 | - drizzle_test_error("no match"); |
946 | - |
947 | - drizzle_test("drizzle_column_db"); |
948 | - if (strcmp(drizzle_column_db(column), "test_db")) |
949 | - drizzle_test_error("no match"); |
950 | - |
951 | - drizzle_test("drizzle_column_table"); |
952 | - if (strcmp(drizzle_column_table(column), "test_table")) |
953 | - drizzle_test_error("no match"); |
954 | - |
955 | - drizzle_test("drizzle_column_orig_table"); |
956 | - if (strcmp(drizzle_column_orig_table(column), "test_orig_table")) |
957 | - drizzle_test_error("no match"); |
958 | - |
959 | - drizzle_test("drizzle_column_name"); |
960 | - if (strcmp(drizzle_column_name(column), "test_column_1")) |
961 | - drizzle_test_error("no match"); |
962 | - |
963 | - drizzle_test("drizzle_column_orig_name"); |
964 | - if (strcmp(drizzle_column_orig_name(column), "test_orig_column_1")) |
965 | - drizzle_test_error("no match"); |
966 | - |
967 | - drizzle_test("drizzle_column_charset"); |
968 | - if (drizzle_column_charset(column) != 8) |
969 | - drizzle_test_error("no match"); |
970 | - |
971 | - drizzle_test("drizzle_column_size"); |
972 | - if (drizzle_column_size(column) != 32) |
973 | - drizzle_test_error("no match"); |
974 | - |
975 | - drizzle_test("drizzle_column_max_size"); |
976 | - if (drizzle_column_max_size(column) != 12) |
977 | - drizzle_test_error("no match"); |
978 | - |
979 | - drizzle_test("drizzle_column_type_drizzle"); |
980 | - if (drizzle_column_type_drizzle(column) != DRIZZLE_COLUMN_TYPE_DRIZZLE_VARCHAR) |
981 | - drizzle_test_error("no match"); |
982 | - |
983 | - drizzle_test("drizzle_column_flags"); |
984 | - if (drizzle_column_flags(column) != DRIZZLE_COLUMN_FLAGS_NONE) |
985 | - drizzle_test_error("no match"); |
986 | - |
987 | - drizzle_test("drizzle_column_next"); |
988 | - column= drizzle_column_next(&state->result); |
989 | - if (column == NULL) |
990 | - drizzle_test_error("column not found"); |
991 | - |
992 | - drizzle_test("drizzle_column_name"); |
993 | - if (strcmp(drizzle_column_name(column), "test_column_2")) |
994 | - drizzle_test_error("no match"); |
995 | - |
996 | - drizzle_test("drizzle_column_next"); |
997 | - column= drizzle_column_next(&state->result); |
998 | - if (column != NULL) |
999 | - drizzle_test_error("column found"); |
1000 | - |
1001 | - drizzle_test("drizzle_column_prev"); |
1002 | - column= drizzle_column_prev(&state->result); |
1003 | - if (column == NULL) |
1004 | - drizzle_test_error("column not found"); |
1005 | - |
1006 | - drizzle_test("drizzle_column_name"); |
1007 | - if (strcmp(drizzle_column_name(column), "test_column_2")) |
1008 | - drizzle_test_error("no match"); |
1009 | - |
1010 | - drizzle_test("drizzle_row_next"); |
1011 | - row= drizzle_row_next(&state->result); |
1012 | - if (row == NULL) |
1013 | - drizzle_test_error("row not found"); |
1014 | - |
1015 | - if (strcmp(row[0], "test_field_1") || strcmp(row[1], "test_field_2")) |
1016 | - drizzle_test_error("no match"); |
1017 | - |
1018 | - drizzle_test("drizzle_row_field_sizes"); |
1019 | - field_sizes= drizzle_row_field_sizes(&state->result); |
1020 | - if (field_sizes[0] != 12 || field_sizes[1] != 12) |
1021 | - drizzle_test_error("no match"); |
1022 | - |
1023 | - drizzle_test("drizzle_row_prev"); |
1024 | - row = drizzle_row_prev(&state->result); |
1025 | - if (row == NULL) |
1026 | - drizzle_test_error("row not found"); |
1027 | - |
1028 | - if (strcmp(row[0], "test_field_1") || strcmp(row[1], "test_field_2")) |
1029 | - drizzle_test_error("no match"); |
1030 | - |
1031 | - drizzle_test("drizzle_row_next"); |
1032 | - row = drizzle_row_next(&state->result); |
1033 | - |
1034 | - drizzle_test("drizzle_row_index"); |
1035 | - row = drizzle_row_index(&state->result, 0); |
1036 | - if (row == NULL) |
1037 | - drizzle_test_error("row not found"); |
1038 | - |
1039 | - if (strcmp(row[0], "test_field_1") || strcmp(row[1], "test_field_2")) |
1040 | - drizzle_test_error("no match"); |
1041 | - |
1042 | - drizzle_test("drizzle_row_index"); |
1043 | - row = drizzle_row_index(&state->result, 1); |
1044 | - if (row != NULL) |
1045 | - drizzle_test_error("row found"); |
1046 | - |
1047 | - drizzle_test("drizzle_result_free"); |
1048 | - drizzle_result_free(&state->result); |
1049 | - |
1050 | - state->state = CLIENT_STATE_DONE; |
1051 | - |
1052 | - case CLIENT_STATE_DONE: |
1053 | - return; |
1054 | - |
1055 | - default: |
1056 | - drizzle_test_error("invalid client state"); |
1057 | - } |
1058 | -} |
1059 | |
1060 | === added file 'unittests/constrained_value.cc' |
1061 | --- unittests/constrained_value.cc 1970-01-01 00:00:00 +0000 |
1062 | +++ unittests/constrained_value.cc 2011-01-24 09:18:02 +0000 |
1063 | @@ -0,0 +1,58 @@ |
1064 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1065 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1066 | + * |
1067 | + * Copyright (C) 2010 Monty Taylor |
1068 | + * |
1069 | + * This program is free software; you can redistribute it and/or modify |
1070 | + * it under the terms of the GNU General Public License as published by |
1071 | + * the Free Software Foundation; either version 2 of the License, or |
1072 | + * (at your option) any later version. |
1073 | + * |
1074 | + * This program is distributed in the hope that it will be useful, |
1075 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1076 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1077 | + * GNU General Public License for more details. |
1078 | + * |
1079 | + * You should have received a copy of the GNU General Public License |
1080 | + * along with this program; if not, write to the Free Software |
1081 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1082 | + */ |
1083 | + |
1084 | +#include "config.h" |
1085 | + |
1086 | +#include <string> |
1087 | + |
1088 | +#define BOOST_TEST_DYN_LINK |
1089 | +#include <boost/test/unit_test.hpp> |
1090 | + |
1091 | +#include <drizzled/constrained_value.h> |
1092 | +#include <boost/lexical_cast.hpp> |
1093 | + |
1094 | +using namespace drizzled; |
1095 | + |
1096 | +namespace po= boost::program_options; |
1097 | + |
1098 | +BOOST_AUTO_TEST_SUITE(ConstrainedValue) |
1099 | +BOOST_AUTO_TEST_CASE(raw_usage) |
1100 | +{ |
1101 | + constrained_check<uint64_t,1024,1,10> val(1); |
1102 | + |
1103 | + BOOST_REQUIRE_EQUAL(UINT64_C(1), (uint64_t)val); |
1104 | + |
1105 | + BOOST_REQUIRE_THROW(val= 1025 , po::validation_error); |
1106 | + BOOST_REQUIRE_THROW(val= 0 , po::validation_error); |
1107 | + |
1108 | + val= 25; |
1109 | + |
1110 | + BOOST_REQUIRE_EQUAL(20, (uint64_t)val); |
1111 | +} |
1112 | + |
1113 | +BOOST_AUTO_TEST_CASE(lexical_cast_usage) |
1114 | +{ |
1115 | + constrained_check<uint64_t,1024,1,10> val(1); |
1116 | + |
1117 | + std::string string_val= boost::lexical_cast<std::string>(val); |
1118 | + |
1119 | + BOOST_REQUIRE_EQUAL(std::string("1"), string_val); |
1120 | +} |
1121 | +BOOST_AUTO_TEST_SUITE_END() |
1122 | |
1123 | === removed file 'unittests/constrained_value.cc' |
1124 | --- unittests/constrained_value.cc 2010-10-19 21:51:42 +0000 |
1125 | +++ unittests/constrained_value.cc 1970-01-01 00:00:00 +0000 |
1126 | @@ -1,57 +0,0 @@ |
1127 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1128 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1129 | - * |
1130 | - * Copyright (C) 2010 Monty Taylor |
1131 | - * |
1132 | - * This program is free software; you can redistribute it and/or modify |
1133 | - * it under the terms of the GNU General Public License as published by |
1134 | - * the Free Software Foundation; either version 2 of the License, or |
1135 | - * (at your option) any later version. |
1136 | - * |
1137 | - * This program is distributed in the hope that it will be useful, |
1138 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1139 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1140 | - * GNU General Public License for more details. |
1141 | - * |
1142 | - * You should have received a copy of the GNU General Public License |
1143 | - * along with this program; if not, write to the Free Software |
1144 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1145 | - */ |
1146 | - |
1147 | -#include "config.h" |
1148 | - |
1149 | -#include <string> |
1150 | - |
1151 | -#include <gtest/gtest.h> |
1152 | - |
1153 | -#include <drizzled/constrained_value.h> |
1154 | -#include <boost/lexical_cast.hpp> |
1155 | - |
1156 | -using namespace drizzled; |
1157 | - |
1158 | -namespace po= boost::program_options; |
1159 | - |
1160 | -TEST(constrained_value, raw_usage) |
1161 | -{ |
1162 | - constrained_check<uint64_t,1024,1,10> val(1); |
1163 | - |
1164 | - EXPECT_EQ(UINT64_C(1), (uint64_t)val); |
1165 | - |
1166 | - ASSERT_THROW(val= 1025 , po::validation_error); |
1167 | - ASSERT_THROW(val= 0 , po::validation_error); |
1168 | - |
1169 | - val= 25; |
1170 | - |
1171 | - EXPECT_EQ(20, (uint64_t)val); |
1172 | -} |
1173 | - |
1174 | -TEST(constrained_value, lexical_cast_usage) |
1175 | -{ |
1176 | - constrained_check<uint64_t,1024,1,10> val(1); |
1177 | - |
1178 | - std::string string_val= boost::lexical_cast<std::string>(val); |
1179 | - |
1180 | - EXPECT_EQ(std::string("1"), string_val); |
1181 | -} |
1182 | - |
1183 | - |
1184 | |
1185 | === added file 'unittests/date_test.cc' |
1186 | --- unittests/date_test.cc 1970-01-01 00:00:00 +0000 |
1187 | +++ unittests/date_test.cc 2011-01-24 09:18:02 +0000 |
1188 | @@ -0,0 +1,562 @@ |
1189 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1190 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1191 | + * |
1192 | + * Copyright (C) 2010 Pawel Blokus |
1193 | + * |
1194 | + * This program is free software; you can redistribute it and/or modify |
1195 | + * it under the terms of the GNU General Public License as published by |
1196 | + * the Free Software Foundation; either version 2 of the License, or |
1197 | + * (at your option) any later version. |
1198 | + * |
1199 | + * This program is distributed in the hope that it will be useful, |
1200 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1201 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1202 | + * GNU General Public License for more details. |
1203 | + * |
1204 | + * You should have received a copy of the GNU General Public License |
1205 | + * along with this program; if not, write to the Free Software |
1206 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1207 | + */ |
1208 | + |
1209 | +#include "config.h" |
1210 | + |
1211 | +#define BOOST_TEST_DYN_LINK |
1212 | +#include <boost/test/unit_test.hpp> |
1213 | + |
1214 | +#include <drizzled/type/decimal.h> |
1215 | +#include <drizzled/temporal.h> |
1216 | +#include <drizzled/temporal_format.h> |
1217 | + |
1218 | +#include "temporal_generator.h" |
1219 | + |
1220 | +using namespace drizzled; |
1221 | + |
1222 | +class DateTestCompareOperators |
1223 | +{ |
1224 | + protected: |
1225 | + Date sample_date; |
1226 | + bool result; |
1227 | + |
1228 | + Date identical_with_sample_date, before_sample_date, after_sample_date; |
1229 | + |
1230 | + DateTestCompareOperators() |
1231 | + { |
1232 | + TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8); |
1233 | + TemporalGenerator::DateGen::make_date(&before_sample_date, 1980, 1, 1); |
1234 | + TemporalGenerator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8); |
1235 | + TemporalGenerator::DateGen::make_date(&after_sample_date, 2019, 5, 30); |
1236 | + } |
1237 | +}; |
1238 | + |
1239 | +class DateTimeTestCompareOperators |
1240 | +{ |
1241 | + protected: |
1242 | + Date sample_date; |
1243 | + bool result; |
1244 | + |
1245 | + DateTime identical_with_sample_date, before_sample_date, after_sample_date; |
1246 | + |
1247 | + DateTimeTestCompareOperators() |
1248 | + { |
1249 | + TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8); |
1250 | + TemporalGenerator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30); |
1251 | + TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0); |
1252 | + TemporalGenerator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4); |
1253 | + } |
1254 | +}; |
1255 | + |
1256 | +class TimestampTestCompareOperators |
1257 | +{ |
1258 | + protected: |
1259 | + Date sample_date; |
1260 | + bool result; |
1261 | + |
1262 | + Timestamp identical_with_sample_date, before_sample_date, after_sample_date; |
1263 | + |
1264 | + TimestampTestCompareOperators() |
1265 | + { |
1266 | + TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8); |
1267 | + TemporalGenerator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41); |
1268 | + TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0); |
1269 | + TemporalGenerator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13); |
1270 | + } |
1271 | +}; |
1272 | + |
1273 | +BOOST_AUTO_TEST_SUITE(DateTestCompare) |
1274 | +BOOST_FIXTURE_TEST_CASE(operatorComparingDate, DateTestCompareOperators) |
1275 | +{ |
1276 | + result= (sample_date == identical_with_sample_date); |
1277 | + BOOST_REQUIRE(result); |
1278 | + |
1279 | + result= (sample_date == before_sample_date); |
1280 | + BOOST_REQUIRE(not result); |
1281 | + |
1282 | + result= (sample_date != identical_with_sample_date); |
1283 | + BOOST_REQUIRE(not result); |
1284 | + |
1285 | + result= (sample_date != before_sample_date); |
1286 | + BOOST_REQUIRE(result); |
1287 | + |
1288 | + result= (sample_date > identical_with_sample_date); |
1289 | + BOOST_REQUIRE(not this->result); |
1290 | + |
1291 | + result= (sample_date > after_sample_date); |
1292 | + BOOST_REQUIRE(not result); |
1293 | + |
1294 | + result= (sample_date > before_sample_date); |
1295 | + BOOST_REQUIRE(result); |
1296 | + |
1297 | + result= (sample_date >= identical_with_sample_date); |
1298 | + BOOST_REQUIRE(result); |
1299 | + |
1300 | + result= (sample_date >= after_sample_date); |
1301 | + BOOST_REQUIRE(not result); |
1302 | + |
1303 | + result= (sample_date >= before_sample_date); |
1304 | + BOOST_REQUIRE(result); |
1305 | + |
1306 | + result= (sample_date < identical_with_sample_date); |
1307 | + |
1308 | + BOOST_REQUIRE(not result); |
1309 | + |
1310 | + result= (sample_date < after_sample_date); |
1311 | + BOOST_REQUIRE(result); |
1312 | + |
1313 | + result= (sample_date < before_sample_date); |
1314 | + BOOST_REQUIRE(not result); |
1315 | + |
1316 | + result= (sample_date <= identical_with_sample_date); |
1317 | + BOOST_REQUIRE(result); |
1318 | + |
1319 | + result= (sample_date <= after_sample_date); |
1320 | + |
1321 | + BOOST_REQUIRE(result); |
1322 | + |
1323 | + result= (sample_date <= before_sample_date); |
1324 | + BOOST_REQUIRE(not result); |
1325 | +} |
1326 | + |
1327 | +BOOST_FIXTURE_TEST_CASE(operatorComparingDateTime, DateTimeTestCompareOperators) |
1328 | +{ |
1329 | + result= (sample_date == identical_with_sample_date); |
1330 | + BOOST_REQUIRE(result); |
1331 | + |
1332 | + result= (sample_date == before_sample_date); |
1333 | + BOOST_REQUIRE(not result); |
1334 | + |
1335 | + result= (sample_date != identical_with_sample_date); |
1336 | + BOOST_REQUIRE(not result); |
1337 | + |
1338 | + result= (sample_date != before_sample_date); |
1339 | + BOOST_REQUIRE(result); |
1340 | + |
1341 | + result= (sample_date > identical_with_sample_date); |
1342 | + BOOST_REQUIRE(not this->result); |
1343 | + |
1344 | + result= (sample_date > after_sample_date); |
1345 | + BOOST_REQUIRE(not result); |
1346 | + |
1347 | + result= (sample_date > before_sample_date); |
1348 | + BOOST_REQUIRE(result); |
1349 | + |
1350 | + result= (sample_date >= identical_with_sample_date); |
1351 | + BOOST_REQUIRE(result); |
1352 | + |
1353 | + result= (sample_date >= after_sample_date); |
1354 | + BOOST_REQUIRE(not result); |
1355 | + |
1356 | + result= (sample_date >= before_sample_date); |
1357 | + BOOST_REQUIRE(result); |
1358 | + |
1359 | + result= (sample_date < identical_with_sample_date); |
1360 | + |
1361 | + BOOST_REQUIRE(not result); |
1362 | + |
1363 | + result= (sample_date < after_sample_date); |
1364 | + BOOST_REQUIRE(result); |
1365 | + |
1366 | + result= (sample_date < before_sample_date); |
1367 | + BOOST_REQUIRE(not result); |
1368 | + |
1369 | + result= (sample_date <= identical_with_sample_date); |
1370 | + BOOST_REQUIRE(result); |
1371 | + |
1372 | + result= (sample_date <= after_sample_date); |
1373 | + |
1374 | + BOOST_REQUIRE(result); |
1375 | + |
1376 | + result= (sample_date <= before_sample_date); |
1377 | + BOOST_REQUIRE(not result); |
1378 | +} |
1379 | + |
1380 | + |
1381 | +BOOST_FIXTURE_TEST_CASE(operatorComparingTimestamp, TimestampTestCompareOperators) |
1382 | +{ |
1383 | + result= (sample_date == identical_with_sample_date); |
1384 | + BOOST_REQUIRE(result); |
1385 | + |
1386 | + result= (sample_date == before_sample_date); |
1387 | + BOOST_REQUIRE(not result); |
1388 | + |
1389 | + result= (sample_date != identical_with_sample_date); |
1390 | + BOOST_REQUIRE(not result); |
1391 | + |
1392 | + result= (sample_date != before_sample_date); |
1393 | + BOOST_REQUIRE(result); |
1394 | + |
1395 | + result= (sample_date > identical_with_sample_date); |
1396 | + BOOST_REQUIRE(not this->result); |
1397 | + |
1398 | + result= (sample_date > after_sample_date); |
1399 | + BOOST_REQUIRE(not result); |
1400 | + |
1401 | + result= (sample_date > before_sample_date); |
1402 | + BOOST_REQUIRE(result); |
1403 | + |
1404 | + result= (sample_date >= identical_with_sample_date); |
1405 | + BOOST_REQUIRE(result); |
1406 | + |
1407 | + result= (sample_date >= after_sample_date); |
1408 | + BOOST_REQUIRE(not result); |
1409 | + |
1410 | + result= (sample_date >= before_sample_date); |
1411 | + BOOST_REQUIRE(result); |
1412 | + |
1413 | + result= (sample_date < identical_with_sample_date); |
1414 | + |
1415 | + BOOST_REQUIRE(not result); |
1416 | + |
1417 | + result= (sample_date < after_sample_date); |
1418 | + BOOST_REQUIRE(result); |
1419 | + |
1420 | + result= (sample_date < before_sample_date); |
1421 | + BOOST_REQUIRE(not result); |
1422 | + |
1423 | + result= (sample_date <= identical_with_sample_date); |
1424 | + BOOST_REQUIRE(result); |
1425 | + |
1426 | + result= (sample_date <= after_sample_date); |
1427 | + |
1428 | + BOOST_REQUIRE(result); |
1429 | + |
1430 | + result= (sample_date <= before_sample_date); |
1431 | + BOOST_REQUIRE(not result); |
1432 | +} |
1433 | +BOOST_AUTO_TEST_SUITE_END() |
1434 | + |
1435 | + |
1436 | +class DateTest |
1437 | +{ |
1438 | + protected: |
1439 | + Date date; |
1440 | + bool result; |
1441 | + |
1442 | + DateTest() |
1443 | + { |
1444 | + TemporalGenerator::DateGen::make_valid_date(&date); |
1445 | + } |
1446 | +}; |
1447 | + |
1448 | +BOOST_AUTO_TEST_SUITE(CurrentDateValidationTest) |
1449 | +BOOST_FIXTURE_TEST_CASE(operatorAssign_shouldCopyDateRelatadComponents, DateTest) |
1450 | +{ |
1451 | + Date copy= date; |
1452 | + |
1453 | + BOOST_REQUIRE_EQUAL(date.years(), copy.years()); |
1454 | + BOOST_REQUIRE_EQUAL(date.months(), copy.months()); |
1455 | + BOOST_REQUIRE_EQUAL(date.days(), copy.days()); |
1456 | +} |
1457 | + |
1458 | +BOOST_FIXTURE_TEST_CASE(is_valid_onValidDate_shouldReturn_True, DateTest) |
1459 | +{ |
1460 | + result= date.is_valid(); |
1461 | + BOOST_REQUIRE(result); |
1462 | +} |
1463 | + |
1464 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithYearBelowMinimum_shouldReturn_False, DateTest) |
1465 | +{ |
1466 | + date.set_years(DRIZZLE_MIN_YEARS_SQL - 1); |
1467 | + |
1468 | + result= date.is_valid(); |
1469 | + |
1470 | + BOOST_REQUIRE(not result); |
1471 | +} |
1472 | + |
1473 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithYearAboveMaximum_shouldReturn_False, DateTest) |
1474 | +{ |
1475 | + date.set_years(DRIZZLE_MAX_YEARS_SQL + 1); |
1476 | + |
1477 | + result= date.is_valid(); |
1478 | + |
1479 | + BOOST_REQUIRE(not result); |
1480 | +} |
1481 | + |
1482 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithMonthSetToZero_shouldReturn_False, DateTest) |
1483 | +{ |
1484 | + date.set_months(0); |
1485 | + |
1486 | + result= date.is_valid(); |
1487 | + |
1488 | + BOOST_REQUIRE(not result); |
1489 | +} |
1490 | + |
1491 | + |
1492 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithMonthAboveMaximum_shouldReturn_False, DateTest) |
1493 | +{ |
1494 | + date.set_months(13); |
1495 | + |
1496 | + result= date.is_valid(); |
1497 | + |
1498 | + BOOST_REQUIRE(not result); |
1499 | +} |
1500 | + |
1501 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithDaySetToZero_shouldReturn_False, DateTest) |
1502 | +{ |
1503 | + date.set_days(0); |
1504 | + |
1505 | + result= date.is_valid(); |
1506 | + |
1507 | + BOOST_REQUIRE(not result); |
1508 | +} |
1509 | + |
1510 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithDayAboveDaysInMonth_shouldReturn_False, DateTest) |
1511 | +{ |
1512 | + date.set_days(32); |
1513 | + |
1514 | + result= date.is_valid(); |
1515 | + |
1516 | + BOOST_REQUIRE(not result); |
1517 | +} |
1518 | + |
1519 | +BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithLeapDayInNonLeapYear_shouldReturn_False, DateTest) |
1520 | +{ |
1521 | + TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&date); |
1522 | + |
1523 | + result= date.is_valid(); |
1524 | + |
1525 | + BOOST_REQUIRE(not result); |
1526 | +} |
1527 | + |
1528 | +BOOST_FIXTURE_TEST_CASE(is_valid_onValidDateWithLeapDayInLeapYear_shouldReturn_True, DateTest) |
1529 | +{ |
1530 | + TemporalGenerator::TemporalGen::leap_day_in_leap_year(&date); |
1531 | + |
1532 | + result= date.is_valid(); |
1533 | + |
1534 | + BOOST_REQUIRE(result); |
1535 | +} |
1536 | + |
1537 | +BOOST_FIXTURE_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements, DateTest) |
1538 | +{ |
1539 | + char expected[Date::MAX_STRING_LENGTH]= "2010-05-01"; |
1540 | + char returned[Date::MAX_STRING_LENGTH]; |
1541 | + TemporalGenerator::DateGen::make_date(&date, 2010, 5, 1); |
1542 | + |
1543 | + date.to_string(returned, Date::MAX_STRING_LENGTH); |
1544 | + |
1545 | + BOOST_REQUIRE_EQUAL(expected, returned); |
1546 | +} |
1547 | + |
1548 | +BOOST_FIXTURE_TEST_CASE(to_string_nullBuffer_shouldReturnProperLengthAnyway, DateTest) |
1549 | +{ |
1550 | + int length= date.to_string(NULL, 0); |
1551 | + |
1552 | + BOOST_REQUIRE_EQUAL(Date::MAX_STRING_LENGTH - 1, length); |
1553 | +} |
1554 | + |
1555 | +BOOST_FIXTURE_TEST_CASE(from_string_validString_shouldPopulateCorrectly, DateTest) |
1556 | +{ |
1557 | + char valid_string[Date::MAX_STRING_LENGTH]= "2010-05-01"; |
1558 | + uint32_t years, months, days; |
1559 | + |
1560 | + init_temporal_formats(); |
1561 | + |
1562 | + result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1); |
1563 | + BOOST_REQUIRE(result); |
1564 | + |
1565 | + years= date.years(); |
1566 | + months= date.months(); |
1567 | + days= date.days(); |
1568 | + |
1569 | + deinit_temporal_formats(); |
1570 | + |
1571 | + BOOST_REQUIRE_EQUAL(2010, years); |
1572 | + BOOST_REQUIRE_EQUAL(5, months); |
1573 | + BOOST_REQUIRE_EQUAL(1, days); |
1574 | +} |
1575 | + |
1576 | +BOOST_FIXTURE_TEST_CASE(from_string_invalidString_shouldReturn_False, DateTest) |
1577 | +{ |
1578 | + char valid_string[Date::MAX_STRING_LENGTH]= "2x10-05-01"; |
1579 | + |
1580 | + init_temporal_formats(); |
1581 | + result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1); |
1582 | + deinit_temporal_formats(); |
1583 | + |
1584 | + BOOST_REQUIRE(not result); |
1585 | +} |
1586 | + |
1587 | +BOOST_FIXTURE_TEST_CASE(to_int64_t, DateTest) |
1588 | +{ |
1589 | + TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17); |
1590 | + int64_t representation; |
1591 | + |
1592 | + date.to_int64_t(&representation); |
1593 | + |
1594 | + BOOST_REQUIRE_EQUAL(20300817, representation); |
1595 | +} |
1596 | + |
1597 | +BOOST_FIXTURE_TEST_CASE(to_int32_t, DateTest) |
1598 | +{ |
1599 | + TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17); |
1600 | + int32_t representation; |
1601 | + |
1602 | + date.to_int32_t(&representation); |
1603 | + |
1604 | + BOOST_REQUIRE_EQUAL(20300817, representation); |
1605 | +} |
1606 | + |
1607 | +BOOST_FIXTURE_TEST_CASE(from_int32_t_shouldPopulateDateCorrectly, DateTest) |
1608 | +{ |
1609 | + uint32_t decoded_years, decoded_months, decoded_days; |
1610 | + |
1611 | + date.from_int32_t(20300817); |
1612 | + |
1613 | + decoded_years= date.years(); |
1614 | + decoded_months= date.months(); |
1615 | + decoded_days= date.days(); |
1616 | + |
1617 | + BOOST_REQUIRE_EQUAL(2030, decoded_years); |
1618 | + BOOST_REQUIRE_EQUAL(8, decoded_months); |
1619 | + BOOST_REQUIRE_EQUAL(17, decoded_days); |
1620 | +} |
1621 | + |
1622 | +BOOST_FIXTURE_TEST_CASE(to_julian_day_number, DateTest) |
1623 | +{ |
1624 | + int64_t julian_day; |
1625 | + TemporalGenerator::DateGen::make_date(&date, 1999, 12, 31); |
1626 | + |
1627 | + date.to_julian_day_number(&julian_day); |
1628 | + |
1629 | + BOOST_REQUIRE_EQUAL(2451544, julian_day); |
1630 | +} |
1631 | + |
1632 | +BOOST_FIXTURE_TEST_CASE(from_julian_day_number, DateTest) |
1633 | +{ |
1634 | + int64_t julian_day= 2451544; |
1635 | + uint32_t years, months, days; |
1636 | + |
1637 | + date.from_julian_day_number(julian_day); |
1638 | + |
1639 | + years= date.years(); |
1640 | + months= date.months(); |
1641 | + days= date.days(); |
1642 | + |
1643 | + BOOST_REQUIRE_EQUAL(1999, years); |
1644 | + BOOST_REQUIRE_EQUAL(12, months); |
1645 | + BOOST_REQUIRE_EQUAL(31, days); |
1646 | +} |
1647 | + |
1648 | +BOOST_FIXTURE_TEST_CASE(to_tm, DateTest) |
1649 | +{ |
1650 | + uint32_t years= 2030, months= 8, days= 17; |
1651 | + TemporalGenerator::DateGen::make_date(&date, years, months, days); |
1652 | + struct tm filled; |
1653 | + |
1654 | + date.to_tm(&filled); |
1655 | + |
1656 | + BOOST_REQUIRE_EQUAL(130, filled.tm_year); |
1657 | + BOOST_REQUIRE_EQUAL(7, filled.tm_mon); |
1658 | + BOOST_REQUIRE_EQUAL(17, filled.tm_mday); |
1659 | + BOOST_REQUIRE_EQUAL(0, filled.tm_hour); |
1660 | + BOOST_REQUIRE_EQUAL(0, filled.tm_min); |
1661 | + BOOST_REQUIRE_EQUAL(0, filled.tm_sec); |
1662 | + |
1663 | + /* TODO: these fail, shouldn't they also be set properly? */ |
1664 | + /* From Andrew: These fail because Temporal::to_tm doesn't populate them. |
1665 | + Does it need to or would we be wasting cycles doing it? */ |
1666 | + |
1667 | + BOOST_WARN_EQUAL(228, filled.tm_yday); |
1668 | + BOOST_WARN_EQUAL(6, filled.tm_wday); |
1669 | + BOOST_WARN_EQUAL(-1, filled.tm_isdst); |
1670 | +} |
1671 | + |
1672 | +BOOST_FIXTURE_TEST_CASE(from_tm, DateTest) |
1673 | +{ |
1674 | + uint32_t years, months, days; |
1675 | + struct tm from; |
1676 | + from.tm_year= 1956 - 1900; |
1677 | + from.tm_mon= 2; |
1678 | + from.tm_mday= 30; |
1679 | + |
1680 | + date.from_tm(&from); |
1681 | + |
1682 | + years= date.years(); |
1683 | + months= date.months(); |
1684 | + days= date.days(); |
1685 | + |
1686 | + BOOST_REQUIRE_EQUAL(1956, years); |
1687 | + BOOST_REQUIRE_EQUAL(3, months); |
1688 | + BOOST_REQUIRE_EQUAL(30, days); |
1689 | +} |
1690 | + |
1691 | +BOOST_FIXTURE_TEST_CASE(to_time_t, DateTest) |
1692 | +{ |
1693 | + time_t time; |
1694 | + TemporalGenerator::DateGen::make_date(&date, 1990, 9, 9); |
1695 | + |
1696 | + date.to_time_t(time); |
1697 | + |
1698 | + BOOST_REQUIRE_EQUAL(652838400, time); |
1699 | +} |
1700 | + |
1701 | +BOOST_FIXTURE_TEST_CASE(from_time_t, DateTest) |
1702 | +{ |
1703 | + uint32_t years, months, days; |
1704 | + |
1705 | + date.from_time_t(652838400); |
1706 | + |
1707 | + years= date.years(); |
1708 | + months= date.months(); |
1709 | + days= date.days(); |
1710 | + |
1711 | + BOOST_REQUIRE_EQUAL(1990, years); |
1712 | + BOOST_REQUIRE_EQUAL(9, months); |
1713 | + BOOST_REQUIRE_EQUAL(9, days); |
1714 | +} |
1715 | + |
1716 | +BOOST_FIXTURE_TEST_CASE(to_decimal, DateTest) |
1717 | +{ |
1718 | + drizzled::type::Decimal to; |
1719 | + TemporalGenerator::DateGen::make_date(&date, 1987, 5, 6); |
1720 | + |
1721 | + date.to_decimal(&to); |
1722 | + |
1723 | + BOOST_REQUIRE_EQUAL(19870506, to.buf[0]); |
1724 | +} |
1725 | +BOOST_AUTO_TEST_SUITE_END() |
1726 | + |
1727 | +BOOST_AUTO_TEST_SUITE(DateStringTest) |
1728 | +BOOST_AUTO_TEST_CASE(DateFromStringTest) |
1729 | +{ |
1730 | + Date date; |
1731 | + const char *valid_strings[]= {"20100607", /* YYYYMMDD */ |
1732 | + "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/ |
1733 | + "10.06.07",/* YY[-/.]MM[-/.]DD */ |
1734 | + "10/6/7",/* YY[-/.][M]M[-/.][D]D */ |
1735 | + "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */}; |
1736 | + |
1737 | + init_temporal_formats(); |
1738 | + for (int it= 0; it < 5; it++) |
1739 | + { |
1740 | + const char *valid_string= valid_strings[it]; |
1741 | + bool result= date.from_string(valid_string, strlen(valid_string)); |
1742 | + BOOST_REQUIRE(result); |
1743 | + |
1744 | + BOOST_REQUIRE_EQUAL(2010, date.years()); |
1745 | + BOOST_REQUIRE_EQUAL(6, date.months()); |
1746 | + BOOST_REQUIRE_EQUAL(7, date.days()); |
1747 | + } |
1748 | + deinit_temporal_formats(); |
1749 | +} |
1750 | +BOOST_AUTO_TEST_SUITE_END() |
1751 | |
1752 | === removed file 'unittests/date_test.cc' |
1753 | --- unittests/date_test.cc 2010-12-26 00:07:57 +0000 |
1754 | +++ unittests/date_test.cc 1970-01-01 00:00:00 +0000 |
1755 | @@ -1,522 +0,0 @@ |
1756 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1757 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1758 | - * |
1759 | - * Copyright (C) 2010 Pawel Blokus |
1760 | - * |
1761 | - * This program is free software; you can redistribute it and/or modify |
1762 | - * it under the terms of the GNU General Public License as published by |
1763 | - * the Free Software Foundation; either version 2 of the License, or |
1764 | - * (at your option) any later version. |
1765 | - * |
1766 | - * This program is distributed in the hope that it will be useful, |
1767 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1768 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1769 | - * GNU General Public License for more details. |
1770 | - * |
1771 | - * You should have received a copy of the GNU General Public License |
1772 | - * along with this program; if not, write to the Free Software |
1773 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1774 | - */ |
1775 | - |
1776 | -#include "config.h" |
1777 | - |
1778 | -#include <gtest/gtest.h> |
1779 | -#include <drizzled/type/decimal.h> |
1780 | -#include <drizzled/temporal.h> |
1781 | -#include <drizzled/temporal_format.h> |
1782 | - |
1783 | -#include "temporal_generator.h" |
1784 | - |
1785 | -using namespace drizzled; |
1786 | - |
1787 | -template <typename TemporalType> |
1788 | -class DateTestCompareOperators : public ::testing::Test |
1789 | -{ |
1790 | - protected: |
1791 | - Date sample_date; |
1792 | - bool result; |
1793 | - |
1794 | - TemporalType identical_with_sample_date, before_sample_date, after_sample_date; |
1795 | - |
1796 | - void initBeforeIdenticalAfter(); |
1797 | - |
1798 | - virtual void SetUp() |
1799 | - { |
1800 | - TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8); |
1801 | - initBeforeIdenticalAfter(); |
1802 | - } |
1803 | -}; |
1804 | - |
1805 | -template<> void DateTestCompareOperators<Date>::initBeforeIdenticalAfter() |
1806 | -{ |
1807 | - TemporalGenerator::DateGen::make_date(&before_sample_date, 1980, 1, 1); |
1808 | - TemporalGenerator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8); |
1809 | - TemporalGenerator::DateGen::make_date(&after_sample_date, 2019, 5, 30); |
1810 | -} |
1811 | - |
1812 | -template<> void DateTestCompareOperators<DateTime>::initBeforeIdenticalAfter() |
1813 | -{ |
1814 | - TemporalGenerator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30); |
1815 | - TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0); |
1816 | - TemporalGenerator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4); |
1817 | -} |
1818 | - |
1819 | -template<> void DateTestCompareOperators<Timestamp>::initBeforeIdenticalAfter() |
1820 | -{ |
1821 | - TemporalGenerator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41); |
1822 | - TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0); |
1823 | - TemporalGenerator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13); |
1824 | -} |
1825 | - |
1826 | -typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTestCompareOperators; |
1827 | -TYPED_TEST_CASE(DateTestCompareOperators, typesForDateTestCompareOperators); |
1828 | - |
1829 | -TYPED_TEST(DateTestCompareOperators, operatorEqual_ComparingWithIdencticalTemporal_ShouldReturn_True) |
1830 | -{ |
1831 | - this->result= (this->sample_date == this->identical_with_sample_date); |
1832 | - |
1833 | - ASSERT_TRUE(this->result); |
1834 | -} |
1835 | - |
1836 | -TYPED_TEST(DateTestCompareOperators, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False) |
1837 | -{ |
1838 | - this->result= (this->sample_date == this->before_sample_date); |
1839 | - |
1840 | - ASSERT_FALSE(this->result); |
1841 | -} |
1842 | - |
1843 | -TYPED_TEST(DateTestCompareOperators, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False) |
1844 | -{ |
1845 | - this->result= (this->sample_date != this->identical_with_sample_date); |
1846 | - |
1847 | - ASSERT_FALSE(this->result); |
1848 | -} |
1849 | - |
1850 | -TYPED_TEST(DateTestCompareOperators, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True) |
1851 | -{ |
1852 | - this->result= (this->sample_date != this->before_sample_date); |
1853 | - |
1854 | - ASSERT_TRUE(this->result); |
1855 | -} |
1856 | - |
1857 | -TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False) |
1858 | -{ |
1859 | - this->result= (this->sample_date > this->identical_with_sample_date); |
1860 | - |
1861 | - ASSERT_FALSE(this->result); |
1862 | -} |
1863 | - |
1864 | -TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False) |
1865 | -{ |
1866 | - this->result= (this->sample_date > this->after_sample_date); |
1867 | - |
1868 | - ASSERT_FALSE(this->result); |
1869 | -} |
1870 | - |
1871 | -TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True) |
1872 | -{ |
1873 | - this->result= (this->sample_date > this->before_sample_date); |
1874 | - |
1875 | - ASSERT_TRUE(this->result); |
1876 | -} |
1877 | - |
1878 | -TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True) |
1879 | -{ |
1880 | - this->result= (this->sample_date >= this->identical_with_sample_date); |
1881 | - |
1882 | - ASSERT_TRUE(this->result); |
1883 | -} |
1884 | - |
1885 | -TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False) |
1886 | -{ |
1887 | - this->result= (this->sample_date >= this->after_sample_date); |
1888 | - |
1889 | - ASSERT_FALSE(this->result); |
1890 | -} |
1891 | - |
1892 | -TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True) |
1893 | -{ |
1894 | - this->result= (this->sample_date >= this->before_sample_date); |
1895 | - |
1896 | - ASSERT_TRUE(this->result); |
1897 | -} |
1898 | - |
1899 | -TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False) |
1900 | -{ |
1901 | - this->result= (this->sample_date < this->identical_with_sample_date); |
1902 | - |
1903 | - ASSERT_FALSE(this->result); |
1904 | -} |
1905 | - |
1906 | -TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True) |
1907 | -{ |
1908 | - this->result= (this->sample_date < this->after_sample_date); |
1909 | - |
1910 | - ASSERT_TRUE(this->result); |
1911 | -} |
1912 | - |
1913 | -TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False) |
1914 | -{ |
1915 | - this->result= (this->sample_date < this->before_sample_date); |
1916 | - |
1917 | - ASSERT_FALSE(this->result); |
1918 | -} |
1919 | - |
1920 | -TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True) |
1921 | -{ |
1922 | - this->result= (this->sample_date <= this->identical_with_sample_date); |
1923 | - |
1924 | - ASSERT_TRUE(this->result); |
1925 | -} |
1926 | - |
1927 | -TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True) |
1928 | -{ |
1929 | - this->result= (this->sample_date <= this->after_sample_date); |
1930 | - |
1931 | - ASSERT_TRUE(this->result); |
1932 | -} |
1933 | - |
1934 | -TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False) |
1935 | -{ |
1936 | - this->result= (this->sample_date <= this->before_sample_date); |
1937 | - |
1938 | - ASSERT_FALSE(this->result); |
1939 | -} |
1940 | - |
1941 | -class DateTest : public ::testing::Test |
1942 | -{ |
1943 | - protected: |
1944 | - Date date; |
1945 | - bool result; |
1946 | - |
1947 | - virtual void SetUp() |
1948 | - { |
1949 | - TemporalGenerator::DateGen::make_valid_date(&date); |
1950 | - } |
1951 | -}; |
1952 | - |
1953 | -TEST_F(DateTest, operatorAssign_shouldCopyDateRelatadComponents) |
1954 | -{ |
1955 | - Date copy= date; |
1956 | - |
1957 | - EXPECT_EQ(date.years(), copy.years()); |
1958 | - EXPECT_EQ(date.months(), copy.months()); |
1959 | - EXPECT_EQ(date.days(), copy.days()); |
1960 | -} |
1961 | - |
1962 | -TEST_F(DateTest, is_valid_onValidDate_shouldReturn_True) |
1963 | -{ |
1964 | - result= date.is_valid(); |
1965 | - ASSERT_TRUE(result); |
1966 | -} |
1967 | - |
1968 | -TEST_F(DateTest, is_valid_onInvalidDateWithYearBelowMinimum_shouldReturn_False) |
1969 | -{ |
1970 | - date.set_years(DRIZZLE_MIN_YEARS_SQL - 1); |
1971 | - |
1972 | - result= date.is_valid(); |
1973 | - |
1974 | - ASSERT_FALSE(result); |
1975 | -} |
1976 | - |
1977 | -TEST_F(DateTest, is_valid_onInvalidDateWithYearAboveMaximum_shouldReturn_False) |
1978 | -{ |
1979 | - date.set_years(DRIZZLE_MAX_YEARS_SQL + 1); |
1980 | - |
1981 | - result= date.is_valid(); |
1982 | - |
1983 | - ASSERT_FALSE(result); |
1984 | -} |
1985 | - |
1986 | -TEST_F(DateTest, is_valid_onInvalidDateWithMonthSetToZero_shouldReturn_False) |
1987 | -{ |
1988 | - date.set_months(0); |
1989 | - |
1990 | - result= date.is_valid(); |
1991 | - |
1992 | - ASSERT_FALSE(result); |
1993 | -} |
1994 | - |
1995 | - |
1996 | -TEST_F(DateTest, is_valid_onInvalidDateWithMonthAboveMaximum_shouldReturn_False) |
1997 | -{ |
1998 | - date.set_months(13); |
1999 | - |
2000 | - result= date.is_valid(); |
2001 | - |
2002 | - ASSERT_FALSE(result); |
2003 | -} |
2004 | - |
2005 | -TEST_F(DateTest, is_valid_onInvalidDateWithDaySetToZero_shouldReturn_False) |
2006 | -{ |
2007 | - date.set_days(0); |
2008 | - |
2009 | - result= date.is_valid(); |
2010 | - |
2011 | - ASSERT_FALSE(result); |
2012 | -} |
2013 | - |
2014 | -TEST_F(DateTest, is_valid_onInvalidDateWithDayAboveDaysInMonth_shouldReturn_False) |
2015 | -{ |
2016 | - date.set_days(32); |
2017 | - |
2018 | - result= date.is_valid(); |
2019 | - |
2020 | - ASSERT_FALSE(result); |
2021 | -} |
2022 | - |
2023 | -TEST_F(DateTest, is_valid_onInvalidDateWithLeapDayInNonLeapYear_shouldReturn_False) |
2024 | -{ |
2025 | - TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&date); |
2026 | - |
2027 | - result= date.is_valid(); |
2028 | - |
2029 | - ASSERT_FALSE(result); |
2030 | -} |
2031 | - |
2032 | -TEST_F(DateTest, is_valid_onValidDateWithLeapDayInLeapYear_shouldReturn_True) |
2033 | -{ |
2034 | - TemporalGenerator::TemporalGen::leap_day_in_leap_year(&date); |
2035 | - |
2036 | - result= date.is_valid(); |
2037 | - |
2038 | - ASSERT_TRUE(result); |
2039 | -} |
2040 | - |
2041 | -TEST_F(DateTest, to_string_shouldProduce_hyphenSeperatedDateElements) |
2042 | -{ |
2043 | - char expected[Date::MAX_STRING_LENGTH]= "2010-05-01"; |
2044 | - char returned[Date::MAX_STRING_LENGTH]; |
2045 | - TemporalGenerator::DateGen::make_date(&date, 2010, 5, 1); |
2046 | - |
2047 | - date.to_string(returned, Date::MAX_STRING_LENGTH); |
2048 | - |
2049 | - ASSERT_STREQ(expected, returned); |
2050 | -} |
2051 | - |
2052 | -TEST_F(DateTest, to_string_nullBuffer_shouldReturnProperLengthAnyway) |
2053 | -{ |
2054 | - int length= date.to_string(NULL, 0); |
2055 | - |
2056 | - ASSERT_EQ(Date::MAX_STRING_LENGTH - 1, length); |
2057 | -} |
2058 | - |
2059 | -TEST_F(DateTest, from_string_validString_shouldPopulateCorrectly) |
2060 | -{ |
2061 | - char valid_string[Date::MAX_STRING_LENGTH]= "2010-05-01"; |
2062 | - uint32_t years, months, days; |
2063 | - |
2064 | - init_temporal_formats(); |
2065 | - |
2066 | - result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1); |
2067 | - ASSERT_TRUE(result); |
2068 | - |
2069 | - years= date.years(); |
2070 | - months= date.months(); |
2071 | - days= date.days(); |
2072 | - |
2073 | - deinit_temporal_formats(); |
2074 | - |
2075 | - EXPECT_EQ(2010, years); |
2076 | - EXPECT_EQ(5, months); |
2077 | - EXPECT_EQ(1, days); |
2078 | -} |
2079 | - |
2080 | -TEST_F(DateTest, from_string_invalidString_shouldReturn_False) |
2081 | -{ |
2082 | - char valid_string[Date::MAX_STRING_LENGTH]= "2x10-05-01"; |
2083 | - |
2084 | - init_temporal_formats(); |
2085 | - result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1); |
2086 | - deinit_temporal_formats(); |
2087 | - |
2088 | - ASSERT_FALSE(result); |
2089 | -} |
2090 | - |
2091 | -TEST_F(DateTest, to_int64_t) |
2092 | -{ |
2093 | - TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17); |
2094 | - int64_t representation; |
2095 | - |
2096 | - date.to_int64_t(&representation); |
2097 | - |
2098 | - ASSERT_EQ(20300817, representation); |
2099 | -} |
2100 | - |
2101 | -TEST_F(DateTest, to_int32_t) |
2102 | -{ |
2103 | - TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17); |
2104 | - int32_t representation; |
2105 | - |
2106 | - date.to_int32_t(&representation); |
2107 | - |
2108 | - ASSERT_EQ(20300817, representation); |
2109 | -} |
2110 | - |
2111 | -TEST_F(DateTest, from_int32_t_shouldPopulateDateCorrectly) |
2112 | -{ |
2113 | - uint32_t decoded_years, decoded_months, decoded_days; |
2114 | - |
2115 | - date.from_int32_t(20300817); |
2116 | - |
2117 | - decoded_years= date.years(); |
2118 | - decoded_months= date.months(); |
2119 | - decoded_days= date.days(); |
2120 | - |
2121 | - EXPECT_EQ(2030, decoded_years); |
2122 | - EXPECT_EQ(8, decoded_months); |
2123 | - EXPECT_EQ(17, decoded_days); |
2124 | -} |
2125 | - |
2126 | -TEST_F(DateTest, to_julian_day_number) |
2127 | -{ |
2128 | - int64_t julian_day; |
2129 | - TemporalGenerator::DateGen::make_date(&date, 1999, 12, 31); |
2130 | - |
2131 | - date.to_julian_day_number(&julian_day); |
2132 | - |
2133 | - ASSERT_EQ(2451544, julian_day); |
2134 | -} |
2135 | - |
2136 | -TEST_F(DateTest, from_julian_day_number) |
2137 | -{ |
2138 | - int64_t julian_day= 2451544; |
2139 | - uint32_t years, months, days; |
2140 | - |
2141 | - date.from_julian_day_number(julian_day); |
2142 | - |
2143 | - years= date.years(); |
2144 | - months= date.months(); |
2145 | - days= date.days(); |
2146 | - |
2147 | - EXPECT_EQ(1999, years); |
2148 | - EXPECT_EQ(12, months); |
2149 | - EXPECT_EQ(31, days); |
2150 | -} |
2151 | - |
2152 | -TEST_F(DateTest, DISABLED_to_tm) |
2153 | -{ |
2154 | - uint32_t years= 2030, months= 8, days= 17; |
2155 | - TemporalGenerator::DateGen::make_date(&date, years, months, days); |
2156 | - struct tm filled; |
2157 | - |
2158 | - date.to_tm(&filled); |
2159 | - |
2160 | - EXPECT_EQ(130, filled.tm_year); |
2161 | - EXPECT_EQ(7, filled.tm_mon); |
2162 | - EXPECT_EQ(17, filled.tm_mday); |
2163 | - EXPECT_EQ(0, filled.tm_hour); |
2164 | - EXPECT_EQ(0, filled.tm_min); |
2165 | - EXPECT_EQ(0, filled.tm_sec); |
2166 | - |
2167 | - /* TODO:these fail, shouldn't they also be set properly? */ |
2168 | - EXPECT_EQ(228, filled.tm_yday); |
2169 | - EXPECT_EQ(6, filled.tm_wday); |
2170 | - EXPECT_EQ(-1, filled.tm_isdst); |
2171 | -} |
2172 | - |
2173 | -TEST_F(DateTest, from_tm) |
2174 | -{ |
2175 | - uint32_t years, months, days; |
2176 | - struct tm from; |
2177 | - from.tm_year= 1956 - 1900; |
2178 | - from.tm_mon= 2; |
2179 | - from.tm_mday= 30; |
2180 | - |
2181 | - date.from_tm(&from); |
2182 | - |
2183 | - years= date.years(); |
2184 | - months= date.months(); |
2185 | - days= date.days(); |
2186 | - |
2187 | - EXPECT_EQ(1956, years); |
2188 | - EXPECT_EQ(3, months); |
2189 | - EXPECT_EQ(30, days); |
2190 | -} |
2191 | - |
2192 | -TEST_F(DateTest, to_time_t) |
2193 | -{ |
2194 | - time_t time; |
2195 | - TemporalGenerator::DateGen::make_date(&date, 1990, 9, 9); |
2196 | - |
2197 | - date.to_time_t(time); |
2198 | - |
2199 | - ASSERT_EQ(652838400, time); |
2200 | -} |
2201 | - |
2202 | -TEST_F(DateTest, from_time_t) |
2203 | -{ |
2204 | - uint32_t years, months, days; |
2205 | - |
2206 | - date.from_time_t(652838400); |
2207 | - |
2208 | - years= date.years(); |
2209 | - months= date.months(); |
2210 | - days= date.days(); |
2211 | - |
2212 | - EXPECT_EQ(1990, years); |
2213 | - EXPECT_EQ(9, months); |
2214 | - EXPECT_EQ(9, days); |
2215 | -} |
2216 | - |
2217 | -TEST_F(DateTest, to_decimal) |
2218 | -{ |
2219 | - drizzled::type::Decimal to; |
2220 | - TemporalGenerator::DateGen::make_date(&date, 1987, 5, 6); |
2221 | - |
2222 | - date.to_decimal(&to); |
2223 | - |
2224 | - ASSERT_EQ(19870506, to.buf[0]); |
2225 | -} |
2226 | - |
2227 | -class DateFromStringTest: public ::testing::TestWithParam<const char*> |
2228 | -{ |
2229 | - protected: |
2230 | - Date date; |
2231 | - bool result; |
2232 | - uint32_t years, months, days; |
2233 | - |
2234 | - virtual void SetUp() |
2235 | - { |
2236 | - init_temporal_formats(); |
2237 | - } |
2238 | - |
2239 | - virtual void TearDown() |
2240 | - { |
2241 | - deinit_temporal_formats(); |
2242 | - } |
2243 | - |
2244 | - void assign_date_values() |
2245 | - { |
2246 | - years= date.years(); |
2247 | - months= date.months(); |
2248 | - days= date.days(); |
2249 | - } |
2250 | -}; |
2251 | - |
2252 | -TEST_P(DateFromStringTest, from_string) |
2253 | -{ |
2254 | - const char *valid_string= GetParam(); |
2255 | - |
2256 | - result= date.from_string(valid_string, strlen(valid_string)); |
2257 | - ASSERT_TRUE(result); |
2258 | - |
2259 | - assign_date_values(); |
2260 | - |
2261 | - EXPECT_EQ(2010, years); |
2262 | - EXPECT_EQ(6, months); |
2263 | - EXPECT_EQ(7, days); |
2264 | -} |
2265 | - |
2266 | -/* TODO:for some reason this was not declared by the macro, needs clarification*/ |
2267 | -testing::internal::ParamGenerator<const char*> gtest_ValidStringDateFromStringTest_EvalGenerator_(); |
2268 | - |
2269 | -INSTANTIATE_TEST_CASE_P(ValidString, DateFromStringTest, |
2270 | - ::testing::Values("20100607", /* YYYYMMDD */ |
2271 | - "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/ |
2272 | - "10.06.07",/* YY[-/.]MM[-/.]DD */ |
2273 | - "10/6/7",/* YY[-/.][M]M[-/.][D]D */ |
2274 | - "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */)); |
2275 | - |
2276 | - |
2277 | - |
2278 | |
2279 | === added file 'unittests/date_time_test.cc' |
2280 | --- unittests/date_time_test.cc 1970-01-01 00:00:00 +0000 |
2281 | +++ unittests/date_time_test.cc 2011-01-24 09:18:02 +0000 |
2282 | @@ -0,0 +1,478 @@ |
2283 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2284 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2285 | +* |
2286 | +* Copyright (C) 2010 Pawel Blokus |
2287 | +* |
2288 | +* This program is free software; you can redistribute it and/or modify |
2289 | +* it under the terms of the GNU General Public License as published by |
2290 | +* the Free Software Foundation; either version 2 of the License, or |
2291 | +* (at your option) any later version. |
2292 | +* |
2293 | +* This program is distributed in the hope that it will be useful, |
2294 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2295 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2296 | +* GNU General Public License for more details. |
2297 | +* |
2298 | +* You should have received a copy of the GNU General Public License |
2299 | +* along with this program; if not, write to the Free Software |
2300 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2301 | +*/ |
2302 | + |
2303 | +#include "config.h" |
2304 | + |
2305 | +#define BOOST_TEST_DYN_LINK |
2306 | +#include <boost/test/unit_test.hpp> |
2307 | + |
2308 | +#include <drizzled/type/decimal.h> |
2309 | +#include <drizzled/temporal.h> |
2310 | +#include <drizzled/temporal_format.h> |
2311 | + |
2312 | +#include "temporal_generator.h" |
2313 | + |
2314 | +using namespace drizzled; |
2315 | + |
2316 | +class DateTimeTest |
2317 | +{ |
2318 | + protected: |
2319 | + DateTime datetime; |
2320 | + bool result; |
2321 | + uint32_t years, months, days; |
2322 | + uint32_t hours, minutes, seconds; |
2323 | + |
2324 | + DateTimeTest() |
2325 | + { |
2326 | + TemporalGenerator::DateTimeGen::make_valid_datetime(&datetime); |
2327 | + } |
2328 | + |
2329 | + void assignDateTimeValues() |
2330 | + { |
2331 | + years= datetime.years(); |
2332 | + months= datetime.months(); |
2333 | + days= datetime.days(); |
2334 | + hours= datetime.hours(); |
2335 | + minutes= datetime.minutes(); |
2336 | + seconds= datetime.seconds(); |
2337 | + } |
2338 | +}; |
2339 | + |
2340 | +BOOST_FIXTURE_TEST_SUITE(DateTimeTestValidation, DateTimeTest) |
2341 | +BOOST_AUTO_TEST_CASE(is_valid_onValidDateTime_shouldReturn_True) |
2342 | +{ |
2343 | + result= datetime.is_valid(); |
2344 | + BOOST_REQUIRE(result); |
2345 | +} |
2346 | + |
2347 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithYearBelowMinimum_shouldReturn_False) |
2348 | +{ |
2349 | + datetime.set_years(DRIZZLE_MIN_YEARS_SQL - 1); |
2350 | + |
2351 | + result= datetime.is_valid(); |
2352 | + |
2353 | + BOOST_REQUIRE(not result); |
2354 | +} |
2355 | + |
2356 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithYearAboveMaximum_shouldReturn_False) |
2357 | +{ |
2358 | + datetime.set_years(DRIZZLE_MAX_YEARS_SQL + 1); |
2359 | + |
2360 | + result= datetime.is_valid(); |
2361 | + |
2362 | + BOOST_REQUIRE(not result); |
2363 | +} |
2364 | + |
2365 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithMonthSetToZero_shouldReturn_False) |
2366 | +{ |
2367 | + datetime.set_months(0); |
2368 | + |
2369 | + result= datetime.is_valid(); |
2370 | + |
2371 | + BOOST_REQUIRE(not result); |
2372 | +} |
2373 | + |
2374 | + |
2375 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithMonthAboveMaximum_shouldReturn_False) |
2376 | +{ |
2377 | + datetime.set_months(13); |
2378 | + |
2379 | + result= datetime.is_valid(); |
2380 | + |
2381 | + BOOST_REQUIRE(not result); |
2382 | +} |
2383 | + |
2384 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithDaySetToZero_shouldReturn_False) |
2385 | +{ |
2386 | + datetime.set_days(0); |
2387 | + |
2388 | + result= datetime.is_valid(); |
2389 | + |
2390 | + BOOST_REQUIRE(not result); |
2391 | +} |
2392 | + |
2393 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithDayAboveDaysInMonth_shouldReturn_False) |
2394 | +{ |
2395 | + datetime.set_days(32); |
2396 | + |
2397 | + result= datetime.is_valid(); |
2398 | + |
2399 | + BOOST_REQUIRE(not result); |
2400 | +} |
2401 | + |
2402 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithLeapDayInNonLeapYear_shouldReturn_False) |
2403 | +{ |
2404 | + TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&datetime); |
2405 | + |
2406 | + result= datetime.is_valid(); |
2407 | + |
2408 | + BOOST_REQUIRE(not result); |
2409 | +} |
2410 | + |
2411 | +BOOST_AUTO_TEST_CASE(is_valid_onValidDateTimeWithLeapDayInLeapYear_shouldReturn_True) |
2412 | +{ |
2413 | + TemporalGenerator::TemporalGen::leap_day_in_leap_year(&datetime); |
2414 | + |
2415 | + result= datetime.is_valid(); |
2416 | + |
2417 | + BOOST_REQUIRE(result); |
2418 | +} |
2419 | + |
2420 | +BOOST_AUTO_TEST_CASE(is_valid_onValidMinimalTime_shouldReturn_True) |
2421 | +{ |
2422 | + TemporalGenerator::TemporalGen::make_min_time(&datetime); |
2423 | + |
2424 | + result= datetime.is_valid(); |
2425 | + |
2426 | + BOOST_REQUIRE(result); |
2427 | +} |
2428 | + |
2429 | +BOOST_AUTO_TEST_CASE(is_valid_onValidMaximalTime_shouldReturn_True) |
2430 | +{ |
2431 | + TemporalGenerator::TemporalGen::make_max_time(&datetime); |
2432 | + |
2433 | + result= datetime.is_valid(); |
2434 | + |
2435 | + BOOST_REQUIRE(result); |
2436 | +} |
2437 | + |
2438 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithHourAboveMaximum23_shouldReturn_False) |
2439 | +{ |
2440 | + datetime.set_hours(24); |
2441 | + |
2442 | + result= datetime.is_valid(); |
2443 | + |
2444 | + BOOST_REQUIRE(not result); |
2445 | +} |
2446 | + |
2447 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithMinutesAboveMaximum59_shouldReturn_False) |
2448 | +{ |
2449 | + datetime.set_minutes(60); |
2450 | + |
2451 | + result= datetime.is_valid(); |
2452 | + |
2453 | + BOOST_REQUIRE(not result); |
2454 | +} |
2455 | + |
2456 | +BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithSecondsAboveMaximum61_shouldReturn_False) |
2457 | +{ |
2458 | + datetime.set_seconds(62); |
2459 | + |
2460 | + result= datetime.is_valid(); |
2461 | + |
2462 | + BOOST_REQUIRE(not result); |
2463 | +} |
2464 | + |
2465 | +BOOST_AUTO_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements) |
2466 | +{ |
2467 | + char expected[DateTime::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.123456"; |
2468 | + char returned[DateTime::MAX_STRING_LENGTH]; |
2469 | + TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2010, 5, 1, 8, 7, 6, 123456); |
2470 | + |
2471 | + datetime.to_string(returned, DateTime::MAX_STRING_LENGTH); |
2472 | + |
2473 | + BOOST_REQUIRE_EQUAL(expected, returned); |
2474 | +} |
2475 | + |
2476 | +BOOST_AUTO_TEST_CASE(to_string_nullBuffer_noMicroSeconds_shouldReturnProperLengthAnyway) |
2477 | +{ |
2478 | + int length= datetime.to_string(NULL, 0); |
2479 | + |
2480 | + BOOST_REQUIRE_EQUAL(DateTime::MAX_STRING_LENGTH - 1 - 7, length); |
2481 | +} |
2482 | + |
2483 | +BOOST_AUTO_TEST_CASE(to_int64_t) |
2484 | +{ |
2485 | + TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2030, 8, 7, 14, 5, 13); |
2486 | + int64_t representation; |
2487 | + |
2488 | + datetime.to_int64_t(&representation); |
2489 | + |
2490 | + BOOST_REQUIRE_EQUAL(20300807140513LL, representation); |
2491 | +} |
2492 | + |
2493 | +BOOST_AUTO_TEST_CASE(from_int64_t_no_conversion_format_YYYYMMDDHHMMSSshouldPopulateDateTimeCorrectly) |
2494 | +{ |
2495 | + datetime.from_int64_t(20300807140513LL, false); |
2496 | + |
2497 | + assignDateTimeValues(); |
2498 | + |
2499 | + BOOST_REQUIRE_EQUAL(2030, years); |
2500 | + BOOST_REQUIRE_EQUAL(8, months); |
2501 | + BOOST_REQUIRE_EQUAL(7, days); |
2502 | + BOOST_REQUIRE_EQUAL(14, hours); |
2503 | + BOOST_REQUIRE_EQUAL(5, minutes); |
2504 | + BOOST_REQUIRE_EQUAL(13, seconds); |
2505 | +} |
2506 | + |
2507 | +BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearOver2000) |
2508 | +{ |
2509 | + datetime.from_int64_t(20300807140513LL, true); |
2510 | + |
2511 | + assignDateTimeValues(); |
2512 | + |
2513 | + BOOST_REQUIRE_EQUAL(2030, years); |
2514 | + BOOST_REQUIRE_EQUAL(8, months); |
2515 | + BOOST_REQUIRE_EQUAL(7, days); |
2516 | + BOOST_REQUIRE_EQUAL(14, hours); |
2517 | + BOOST_REQUIRE_EQUAL(5, minutes); |
2518 | + BOOST_REQUIRE_EQUAL(13, seconds); |
2519 | +} |
2520 | + |
2521 | +BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearBelow2000) |
2522 | +{ |
2523 | + datetime.from_int64_t(19900807140513LL, true); |
2524 | + |
2525 | + assignDateTimeValues(); |
2526 | + |
2527 | + BOOST_REQUIRE_EQUAL(1990, years); |
2528 | + BOOST_REQUIRE_EQUAL(8, months); |
2529 | + BOOST_REQUIRE_EQUAL(7, days); |
2530 | + BOOST_REQUIRE_EQUAL(14, hours); |
2531 | + BOOST_REQUIRE_EQUAL(5, minutes); |
2532 | + BOOST_REQUIRE_EQUAL(13, seconds); |
2533 | +} |
2534 | + |
2535 | +BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearOver2000) |
2536 | +{ |
2537 | + datetime.from_int64_t(300807140513LL, true); |
2538 | + |
2539 | + assignDateTimeValues(); |
2540 | + |
2541 | + BOOST_REQUIRE_EQUAL(2030, years); |
2542 | + BOOST_REQUIRE_EQUAL(8, months); |
2543 | + BOOST_REQUIRE_EQUAL(7, days); |
2544 | + BOOST_REQUIRE_EQUAL(14, hours); |
2545 | + BOOST_REQUIRE_EQUAL(5, minutes); |
2546 | + BOOST_REQUIRE_EQUAL(13, seconds); |
2547 | +} |
2548 | + |
2549 | +BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearBelow2000) |
2550 | +{ |
2551 | + datetime.from_int64_t(900807140513LL, true); |
2552 | + |
2553 | + assignDateTimeValues(); |
2554 | + |
2555 | + BOOST_REQUIRE_EQUAL(1990, years); |
2556 | + BOOST_REQUIRE_EQUAL(8, months); |
2557 | + BOOST_REQUIRE_EQUAL(7, days); |
2558 | + BOOST_REQUIRE_EQUAL(14, hours); |
2559 | + BOOST_REQUIRE_EQUAL(5, minutes); |
2560 | + BOOST_REQUIRE_EQUAL(13, seconds); |
2561 | +} |
2562 | + |
2563 | +BOOST_AUTO_TEST_CASE(to_tm) |
2564 | +{ |
2565 | + years= 2030, months= 8, days= 17, hours= 14, minutes= 45, seconds= 13; |
2566 | + TemporalGenerator::DateTimeGen::make_datetime(&datetime, years, months, days, hours, minutes, seconds); |
2567 | + struct tm filled; |
2568 | + |
2569 | + datetime.to_tm(&filled); |
2570 | + |
2571 | + BOOST_REQUIRE_EQUAL(2030 - 1900, filled.tm_year); |
2572 | + BOOST_REQUIRE_EQUAL(8 - 1, filled.tm_mon); |
2573 | + BOOST_REQUIRE_EQUAL(17, filled.tm_mday); |
2574 | + BOOST_REQUIRE_EQUAL(14, filled.tm_hour); |
2575 | + BOOST_REQUIRE_EQUAL(45, filled.tm_min); |
2576 | + BOOST_REQUIRE_EQUAL(13, filled.tm_sec); |
2577 | + |
2578 | + /* TODO:these fail, shouldn't they also be set properly? */ |
2579 | + BOOST_WARN_EQUAL(228, filled.tm_yday); |
2580 | + BOOST_WARN_EQUAL(6, filled.tm_wday); |
2581 | + BOOST_WARN_EQUAL(-1, filled.tm_isdst); |
2582 | +} |
2583 | + |
2584 | +BOOST_AUTO_TEST_CASE(to_decimal) |
2585 | +{ |
2586 | + drizzled::type::Decimal to; |
2587 | + TemporalGenerator::DateTimeGen::make_datetime(&datetime, 1987, 6, 13, 5, 10, 13, 456); |
2588 | + |
2589 | + datetime.to_decimal(&to); |
2590 | + |
2591 | + BOOST_REQUIRE_EQUAL(19870,to.buf[0]); |
2592 | + BOOST_REQUIRE_EQUAL(613051013,to.buf[1]); |
2593 | + BOOST_REQUIRE_EQUAL(456000,to.buf[2]); |
2594 | +} |
2595 | +BOOST_AUTO_TEST_SUITE_END() |
2596 | + |
2597 | + |
2598 | +class DateTimeFromStringTest |
2599 | +{ |
2600 | + protected: |
2601 | + static const char* allStrings[]; |
2602 | + DateTime datetime; |
2603 | + bool result; |
2604 | + uint32_t years, months, days; |
2605 | + uint32_t hours, minutes, seconds; |
2606 | + |
2607 | + DateTimeFromStringTest() |
2608 | + { |
2609 | + init_temporal_formats(); |
2610 | + } |
2611 | + |
2612 | + virtual ~DateTimeFromStringTest() |
2613 | + { |
2614 | + deinit_temporal_formats(); |
2615 | + } |
2616 | + |
2617 | + virtual int stringCount() { return 0; } |
2618 | + virtual const char** strings() { return NULL; } |
2619 | + |
2620 | + void assignDateTimeValues() |
2621 | + { |
2622 | + years= datetime.years(); |
2623 | + months= datetime.months(); |
2624 | + days= datetime.days(); |
2625 | + hours= datetime.hours(); |
2626 | + minutes= datetime.minutes(); |
2627 | + seconds= datetime.seconds(); |
2628 | + } |
2629 | +}; |
2630 | + |
2631 | +const char* DateTimeFromStringTest::allStrings[]= {"NULL"}; |
2632 | + |
2633 | + |
2634 | +class DateTimeFromStringFullFormatTest : public DateTimeFromStringTest |
2635 | +{ |
2636 | + protected: |
2637 | + static const char* allStrings[]; |
2638 | + |
2639 | + const char** strings() |
2640 | + { |
2641 | + return allStrings; |
2642 | + } |
2643 | + |
2644 | + int stringCount() |
2645 | + { |
2646 | + return 7; |
2647 | + } |
2648 | +}; |
2649 | + |
2650 | +const char* DateTimeFromStringFullFormatTest::allStrings[]= {"20100501080706", |
2651 | + "2010-05-01 08:07:06", |
2652 | + "2010/05/01T08:07:06", |
2653 | + "2010.5.1 08:07:06", |
2654 | + "10-05-01 08:07:06", |
2655 | + "10/5/1 08:07:06", |
2656 | + "10.5.1 08:07:06"}; |
2657 | + |
2658 | +class DateTimeFromStringNoSecondFormatTest : public DateTimeFromStringTest |
2659 | +{ |
2660 | + protected: |
2661 | + static const char* allStrings[]; |
2662 | + |
2663 | + const char** strings() |
2664 | + { |
2665 | + return allStrings; |
2666 | + } |
2667 | + |
2668 | + int stringCount() |
2669 | + { |
2670 | + return 6; |
2671 | + } |
2672 | +}; |
2673 | + |
2674 | +const char* DateTimeFromStringNoSecondFormatTest::allStrings[]= {"2010-05-01 08:07", |
2675 | + "2010/05/01 08:07", |
2676 | + "2010.5.1 08:07", |
2677 | + "10-05-01 08:07", |
2678 | + "10/5/1 08:07", |
2679 | + "10.5.1 08:07"}; |
2680 | + |
2681 | +class DateTimeFromStringDateOnlyTest: public DateTimeFromStringTest |
2682 | +{ |
2683 | + protected: |
2684 | + static const char* allStrings[]; |
2685 | + |
2686 | + const char** strings() |
2687 | + { |
2688 | + return allStrings; |
2689 | + } |
2690 | + |
2691 | + int stringCount() |
2692 | + { |
2693 | + return 5; |
2694 | + } |
2695 | +}; |
2696 | + |
2697 | +const char* DateTimeFromStringDateOnlyTest::allStrings[]= {"20100607", /* YYYYMMDD */ |
2698 | + "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/ |
2699 | + "10.06.07",/* YY[-/.]MM[-/.]DD */ |
2700 | + "10/6/7",/* YY[-/.][M]M[-/.][D]D */ |
2701 | + "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */}; |
2702 | + |
2703 | +BOOST_AUTO_TEST_SUITE(DateTimeFromStringTestSuite) |
2704 | +BOOST_FIXTURE_TEST_CASE(from_string_validStringFull, DateTimeFromStringFullFormatTest) |
2705 | +{ |
2706 | + for (int it= 0; it < stringCount(); it++) |
2707 | + { |
2708 | + const char *valid_string= strings()[it]; |
2709 | + |
2710 | + result= datetime.from_string(valid_string, strlen(valid_string)); |
2711 | + BOOST_REQUIRE(result); |
2712 | + |
2713 | + assignDateTimeValues(); |
2714 | + |
2715 | + BOOST_REQUIRE_EQUAL(2010, years); |
2716 | + BOOST_REQUIRE_EQUAL(5, months); |
2717 | + BOOST_REQUIRE_EQUAL(1, days); |
2718 | + BOOST_REQUIRE_EQUAL(8, hours); |
2719 | + BOOST_REQUIRE_EQUAL(7, minutes); |
2720 | + BOOST_REQUIRE_EQUAL(6, seconds); |
2721 | + } |
2722 | +} |
2723 | + |
2724 | +BOOST_FIXTURE_TEST_CASE(from_string_validStringNoSecond, DateTimeFromStringNoSecondFormatTest) |
2725 | +{ |
2726 | + for (int it= 0; it < stringCount(); it++) |
2727 | + { |
2728 | + const char *valid_string= strings()[it]; |
2729 | + |
2730 | + result= datetime.from_string(valid_string, strlen(valid_string)); |
2731 | + BOOST_REQUIRE(result); |
2732 | + |
2733 | + assignDateTimeValues(); |
2734 | + |
2735 | + BOOST_REQUIRE_EQUAL(2010, years); |
2736 | + BOOST_REQUIRE_EQUAL(5, months); |
2737 | + BOOST_REQUIRE_EQUAL(1, days); |
2738 | + BOOST_REQUIRE_EQUAL(8, hours); |
2739 | + BOOST_REQUIRE_EQUAL(7, minutes); |
2740 | + } |
2741 | +} |
2742 | + |
2743 | +BOOST_FIXTURE_TEST_CASE(from_string_validStringDateOnly, DateTimeFromStringDateOnlyTest) |
2744 | +{ |
2745 | + for (int it= 0; it < stringCount(); it++) |
2746 | + { |
2747 | + const char *valid_string= strings()[it]; |
2748 | + |
2749 | + result= datetime.from_string(valid_string, strlen(valid_string)); |
2750 | + BOOST_REQUIRE(result); |
2751 | + |
2752 | + assignDateTimeValues(); |
2753 | + |
2754 | + BOOST_REQUIRE_EQUAL(2010, years); |
2755 | + BOOST_REQUIRE_EQUAL(6, months); |
2756 | + BOOST_REQUIRE_EQUAL(7, days); |
2757 | + } |
2758 | +} |
2759 | + |
2760 | +BOOST_AUTO_TEST_SUITE_END() |
2761 | |
2762 | === removed file 'unittests/date_time_test.cc' |
2763 | --- unittests/date_time_test.cc 2010-12-26 00:07:57 +0000 |
2764 | +++ unittests/date_time_test.cc 1970-01-01 00:00:00 +0000 |
2765 | @@ -1,460 +0,0 @@ |
2766 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2767 | -* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2768 | -* |
2769 | -* Copyright (C) 2010 Pawel Blokus |
2770 | -* |
2771 | -* This program is free software; you can redistribute it and/or modify |
2772 | -* it under the terms of the GNU General Public License as published by |
2773 | -* the Free Software Foundation; either version 2 of the License, or |
2774 | -* (at your option) any later version. |
2775 | -* |
2776 | -* This program is distributed in the hope that it will be useful, |
2777 | -* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2778 | -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2779 | -* GNU General Public License for more details. |
2780 | -* |
2781 | -* You should have received a copy of the GNU General Public License |
2782 | -* along with this program; if not, write to the Free Software |
2783 | -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2784 | -*/ |
2785 | - |
2786 | -#include "config.h" |
2787 | - |
2788 | -#include <gtest/gtest.h> |
2789 | -#include <drizzled/type/decimal.h> |
2790 | -#include <drizzled/temporal.h> |
2791 | -#include <drizzled/temporal_format.h> |
2792 | - |
2793 | -#include "temporal_generator.h" |
2794 | - |
2795 | -using namespace drizzled; |
2796 | - |
2797 | -class DateTimeTest: public ::testing::Test |
2798 | -{ |
2799 | - protected: |
2800 | - DateTime datetime; |
2801 | - bool result; |
2802 | - uint32_t years, months, days; |
2803 | - uint32_t hours, minutes, seconds; |
2804 | - |
2805 | - virtual void SetUp() |
2806 | - { |
2807 | - TemporalGenerator::DateTimeGen::make_valid_datetime(&datetime); |
2808 | - } |
2809 | - |
2810 | - void assignDateTimeValues() |
2811 | - { |
2812 | - years= datetime.years(); |
2813 | - months= datetime.months(); |
2814 | - days= datetime.days(); |
2815 | - hours= datetime.hours(); |
2816 | - minutes= datetime.minutes(); |
2817 | - seconds= datetime.seconds(); |
2818 | - } |
2819 | -}; |
2820 | - |
2821 | -TEST_F(DateTimeTest, is_valid_onValidDateTime_shouldReturn_True) |
2822 | -{ |
2823 | - result= datetime.is_valid(); |
2824 | - ASSERT_TRUE(result); |
2825 | -} |
2826 | - |
2827 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithYearBelowMinimum_shouldReturn_False) |
2828 | -{ |
2829 | - datetime.set_years(DRIZZLE_MIN_YEARS_SQL - 1); |
2830 | - |
2831 | - result= datetime.is_valid(); |
2832 | - |
2833 | - ASSERT_FALSE(result); |
2834 | -} |
2835 | - |
2836 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithYearAboveMaximum_shouldReturn_False) |
2837 | -{ |
2838 | - datetime.set_years(DRIZZLE_MAX_YEARS_SQL + 1); |
2839 | - |
2840 | - result= datetime.is_valid(); |
2841 | - |
2842 | - ASSERT_FALSE(result); |
2843 | -} |
2844 | - |
2845 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithMonthSetToZero_shouldReturn_False) |
2846 | -{ |
2847 | - datetime.set_months(0); |
2848 | - |
2849 | - result= datetime.is_valid(); |
2850 | - |
2851 | - ASSERT_FALSE(result); |
2852 | -} |
2853 | - |
2854 | - |
2855 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithMonthAboveMaximum_shouldReturn_False) |
2856 | -{ |
2857 | - datetime.set_months(13); |
2858 | - |
2859 | - result= datetime.is_valid(); |
2860 | - |
2861 | - ASSERT_FALSE(result); |
2862 | -} |
2863 | - |
2864 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithDaySetToZero_shouldReturn_False) |
2865 | -{ |
2866 | - datetime.set_days(0); |
2867 | - |
2868 | - result= datetime.is_valid(); |
2869 | - |
2870 | - ASSERT_FALSE(result); |
2871 | -} |
2872 | - |
2873 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithDayAboveDaysInMonth_shouldReturn_False) |
2874 | -{ |
2875 | - datetime.set_days(32); |
2876 | - |
2877 | - result= datetime.is_valid(); |
2878 | - |
2879 | - ASSERT_FALSE(result); |
2880 | -} |
2881 | - |
2882 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithLeapDayInNonLeapYear_shouldReturn_False) |
2883 | -{ |
2884 | - TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&datetime); |
2885 | - |
2886 | - result= datetime.is_valid(); |
2887 | - |
2888 | - ASSERT_FALSE(result); |
2889 | -} |
2890 | - |
2891 | -TEST_F(DateTimeTest, is_valid_onValidDateTimeWithLeapDayInLeapYear_shouldReturn_True) |
2892 | -{ |
2893 | - TemporalGenerator::TemporalGen::leap_day_in_leap_year(&datetime); |
2894 | - |
2895 | - result= datetime.is_valid(); |
2896 | - |
2897 | - ASSERT_TRUE(result); |
2898 | -} |
2899 | - |
2900 | -TEST_F(DateTimeTest, is_valid_onValidMinimalTime_shouldReturn_True) |
2901 | -{ |
2902 | - TemporalGenerator::TemporalGen::make_min_time(&datetime); |
2903 | - |
2904 | - result= datetime.is_valid(); |
2905 | - |
2906 | - ASSERT_TRUE(result); |
2907 | -} |
2908 | - |
2909 | -TEST_F(DateTimeTest, is_valid_onValidMaximalTime_shouldReturn_True) |
2910 | -{ |
2911 | - TemporalGenerator::TemporalGen::make_max_time(&datetime); |
2912 | - |
2913 | - result= datetime.is_valid(); |
2914 | - |
2915 | - ASSERT_TRUE(result); |
2916 | -} |
2917 | - |
2918 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithHourAboveMaximum23_shouldReturn_False) |
2919 | -{ |
2920 | - datetime.set_hours(24); |
2921 | - |
2922 | - result= datetime.is_valid(); |
2923 | - |
2924 | - ASSERT_FALSE(result); |
2925 | -} |
2926 | - |
2927 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithMinutesAboveMaximum59_shouldReturn_False) |
2928 | -{ |
2929 | - datetime.set_minutes(60); |
2930 | - |
2931 | - result= datetime.is_valid(); |
2932 | - |
2933 | - ASSERT_FALSE(result); |
2934 | -} |
2935 | - |
2936 | -TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithSecondsAboveMaximum61_shouldReturn_False) |
2937 | -{ |
2938 | - datetime.set_seconds(62); |
2939 | - |
2940 | - result= datetime.is_valid(); |
2941 | - |
2942 | - ASSERT_FALSE(result); |
2943 | -} |
2944 | - |
2945 | -TEST_F(DateTimeTest, to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements) |
2946 | -{ |
2947 | - char expected[DateTime::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.123456"; |
2948 | - char returned[DateTime::MAX_STRING_LENGTH]; |
2949 | - TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2010, 5, 1, 8, 7, 6, 123456); |
2950 | - |
2951 | - datetime.to_string(returned, DateTime::MAX_STRING_LENGTH); |
2952 | - |
2953 | - ASSERT_STREQ(expected, returned); |
2954 | -} |
2955 | - |
2956 | -TEST_F(DateTimeTest, to_string_nullBuffer_noMicroSeconds_shouldReturnProperLengthAnyway) |
2957 | -{ |
2958 | - int length= datetime.to_string(NULL, 0); |
2959 | - |
2960 | - ASSERT_EQ(DateTime::MAX_STRING_LENGTH - 1 - 7, length); |
2961 | -} |
2962 | - |
2963 | -TEST_F(DateTimeTest, to_int64_t) |
2964 | -{ |
2965 | - TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2030, 8, 7, 14, 5, 13); |
2966 | - int64_t representation; |
2967 | - |
2968 | - datetime.to_int64_t(&representation); |
2969 | - |
2970 | - ASSERT_EQ(20300807140513LL, representation); |
2971 | -} |
2972 | - |
2973 | -TEST_F(DateTimeTest, from_int64_t_no_conversion_format_YYYYMMDDHHMMSSshouldPopulateDateTimeCorrectly) |
2974 | -{ |
2975 | - datetime.from_int64_t(20300807140513LL, false); |
2976 | - |
2977 | - assignDateTimeValues(); |
2978 | - |
2979 | - EXPECT_EQ(2030, years); |
2980 | - EXPECT_EQ(8, months); |
2981 | - EXPECT_EQ(7, days); |
2982 | - EXPECT_EQ(14, hours); |
2983 | - EXPECT_EQ(5, minutes); |
2984 | - EXPECT_EQ(13, seconds); |
2985 | -} |
2986 | - |
2987 | -TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearOver2000) |
2988 | -{ |
2989 | - datetime.from_int64_t(20300807140513LL, true); |
2990 | - |
2991 | - assignDateTimeValues(); |
2992 | - |
2993 | - EXPECT_EQ(2030, years); |
2994 | - EXPECT_EQ(8, months); |
2995 | - EXPECT_EQ(7, days); |
2996 | - EXPECT_EQ(14, hours); |
2997 | - EXPECT_EQ(5, minutes); |
2998 | - EXPECT_EQ(13, seconds); |
2999 | -} |
3000 | - |
3001 | -TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearBelow2000) |
3002 | -{ |
3003 | - datetime.from_int64_t(19900807140513LL, true); |
3004 | - |
3005 | - assignDateTimeValues(); |
3006 | - |
3007 | - EXPECT_EQ(1990, years); |
3008 | - EXPECT_EQ(8, months); |
3009 | - EXPECT_EQ(7, days); |
3010 | - EXPECT_EQ(14, hours); |
3011 | - EXPECT_EQ(5, minutes); |
3012 | - EXPECT_EQ(13, seconds); |
3013 | -} |
3014 | - |
3015 | -TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearOver2000) |
3016 | -{ |
3017 | - datetime.from_int64_t(300807140513LL, true); |
3018 | - |
3019 | - assignDateTimeValues(); |
3020 | - |
3021 | - EXPECT_EQ(2030, years); |
3022 | - EXPECT_EQ(8, months); |
3023 | - EXPECT_EQ(7, days); |
3024 | - EXPECT_EQ(14, hours); |
3025 | - EXPECT_EQ(5, minutes); |
3026 | - EXPECT_EQ(13, seconds); |
3027 | -} |
3028 | - |
3029 | -TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearBelow2000) |
3030 | -{ |
3031 | - datetime.from_int64_t(900807140513LL, true); |
3032 | - |
3033 | - assignDateTimeValues(); |
3034 | - |
3035 | - EXPECT_EQ(1990, years); |
3036 | - EXPECT_EQ(8, months); |
3037 | - EXPECT_EQ(7, days); |
3038 | - EXPECT_EQ(14, hours); |
3039 | - EXPECT_EQ(5, minutes); |
3040 | - EXPECT_EQ(13, seconds); |
3041 | -} |
3042 | - |
3043 | -TEST_F(DateTimeTest, DISABLED_to_tm) |
3044 | -{ |
3045 | - years= 2030, months= 8, days= 17, hours= 14, minutes= 45, seconds= 13; |
3046 | - TemporalGenerator::DateTimeGen::make_datetime(&datetime, years, months, days, hours, minutes, seconds); |
3047 | - struct tm filled; |
3048 | - |
3049 | - datetime.to_tm(&filled); |
3050 | - |
3051 | - EXPECT_EQ(2030 - 1900, filled.tm_year); |
3052 | - EXPECT_EQ(8 - 1, filled.tm_mon); |
3053 | - EXPECT_EQ(17, filled.tm_mday); |
3054 | - EXPECT_EQ(14, filled.tm_hour); |
3055 | - EXPECT_EQ(45, filled.tm_min); |
3056 | - EXPECT_EQ(13, filled.tm_sec); |
3057 | - |
3058 | - /* TODO:these fail, shouldn't they also be set properly? */ |
3059 | - EXPECT_EQ(228, filled.tm_yday); |
3060 | - EXPECT_EQ(6, filled.tm_wday); |
3061 | - EXPECT_EQ(-1, filled.tm_isdst); |
3062 | -} |
3063 | - |
3064 | -TEST_F(DateTimeTest, to_decimal) |
3065 | -{ |
3066 | - drizzled::type::Decimal to; |
3067 | - TemporalGenerator::DateTimeGen::make_datetime(&datetime, 1987, 6, 13, 5, 10, 13, 456); |
3068 | - |
3069 | - datetime.to_decimal(&to); |
3070 | - |
3071 | - EXPECT_EQ(19870,to.buf[0]); |
3072 | - EXPECT_EQ(613051013,to.buf[1]); |
3073 | - EXPECT_EQ(456000,to.buf[2]); |
3074 | -} |
3075 | - |
3076 | - |
3077 | - |
3078 | -class DateTimeFromStringTest |
3079 | -{ |
3080 | - protected: |
3081 | - DateTime datetime; |
3082 | - bool result; |
3083 | - uint32_t years, months, days; |
3084 | - uint32_t hours, minutes, seconds; |
3085 | - |
3086 | - void init() |
3087 | - { |
3088 | - init_temporal_formats(); |
3089 | - } |
3090 | - |
3091 | - void deinit() |
3092 | - { |
3093 | - deinit_temporal_formats(); |
3094 | - } |
3095 | - |
3096 | - void assignDateTimeValues() |
3097 | - { |
3098 | - years= datetime.years(); |
3099 | - months= datetime.months(); |
3100 | - days= datetime.days(); |
3101 | - hours= datetime.hours(); |
3102 | - minutes= datetime.minutes(); |
3103 | - seconds= datetime.seconds(); |
3104 | - } |
3105 | -}; |
3106 | - |
3107 | -class DateTimeFromStringFullFormatTest: public ::testing::TestWithParam<const char*>, public DateTimeFromStringTest |
3108 | -{ |
3109 | - virtual void SetUp() |
3110 | - { |
3111 | - init(); |
3112 | - } |
3113 | - |
3114 | - virtual void TearDown() |
3115 | - { |
3116 | - deinit(); |
3117 | - } |
3118 | -}; |
3119 | - |
3120 | -class DateTimeFromStringNoSecondFormatTest: public ::testing::TestWithParam<const char*>, public DateTimeFromStringTest |
3121 | -{ |
3122 | - virtual void SetUp() |
3123 | - { |
3124 | - init(); |
3125 | - } |
3126 | - |
3127 | - virtual void TearDown() |
3128 | - { |
3129 | - deinit(); |
3130 | - } |
3131 | -}; |
3132 | - |
3133 | -class DateTimeFromStringDateOnlyTest: public ::testing::TestWithParam<const char*>, public DateTimeFromStringTest |
3134 | -{ |
3135 | - virtual void SetUp() |
3136 | - { |
3137 | - init(); |
3138 | - } |
3139 | - |
3140 | - virtual void TearDown() |
3141 | - { |
3142 | - deinit(); |
3143 | - } |
3144 | -}; |
3145 | - |
3146 | -TEST_P(DateTimeFromStringFullFormatTest, from_string_validString) |
3147 | -{ |
3148 | - const char *valid_string= GetParam(); |
3149 | - |
3150 | - result= datetime.from_string(valid_string, strlen(valid_string)); |
3151 | - ASSERT_TRUE(result); |
3152 | - |
3153 | - assignDateTimeValues(); |
3154 | - |
3155 | - EXPECT_EQ(2010, years); |
3156 | - EXPECT_EQ(5, months); |
3157 | - EXPECT_EQ(1, days); |
3158 | - EXPECT_EQ(8, hours); |
3159 | - EXPECT_EQ(7, minutes); |
3160 | - EXPECT_EQ(6, seconds); |
3161 | -} |
3162 | -/* TODO:for some reason this was not declared by the macro, needs clarification*/ |
3163 | -testing::internal::ParamGenerator<const char*> gtest_ValidStringDateTimeFromStringFullFormatTest_EvalGenerator_(); |
3164 | -INSTANTIATE_TEST_CASE_P(ValidString, DateTimeFromStringFullFormatTest, |
3165 | - ::testing::Values("20100501080706", |
3166 | - "2010-05-01 08:07:06", |
3167 | - "2010/05/01T08:07:06", |
3168 | - "2010.5.1 08:07:06", |
3169 | - "10-05-01 08:07:06", |
3170 | - "10/5/1 08:07:06", |
3171 | - "10.5.1 08:07:06")); |
3172 | - |
3173 | - |
3174 | -TEST_P(DateTimeFromStringNoSecondFormatTest, from_string_validString) |
3175 | -{ |
3176 | - const char *valid_string= GetParam(); |
3177 | - |
3178 | - result= datetime.from_string(valid_string, strlen(valid_string)); |
3179 | - ASSERT_TRUE(result); |
3180 | - |
3181 | - assignDateTimeValues(); |
3182 | - |
3183 | - EXPECT_EQ(2010, years); |
3184 | - EXPECT_EQ(5, months); |
3185 | - EXPECT_EQ(1, days); |
3186 | - EXPECT_EQ(8, hours); |
3187 | - EXPECT_EQ(7, minutes); |
3188 | -} |
3189 | - |
3190 | -/* TODO:for some reason this was not declared by the macro, needs clarification*/ |
3191 | -testing::internal::ParamGenerator<const char*> gtest_ValidStringDateTimeFromStringNoSecondFormatTest_EvalGenerator_(); |
3192 | -INSTANTIATE_TEST_CASE_P(ValidString, DateTimeFromStringNoSecondFormatTest, |
3193 | - ::testing::Values("2010-05-01 08:07", |
3194 | - "2010/05/01 08:07", |
3195 | - "2010.5.1 08:07", |
3196 | - "10-05-01 08:07", |
3197 | - "10/5/1 08:07", |
3198 | - "10.5.1 08:07")); |
3199 | - |
3200 | - |
3201 | - |
3202 | -TEST_P(DateTimeFromStringDateOnlyTest, from_string_validString) |
3203 | -{ |
3204 | - const char *valid_string= GetParam(); |
3205 | - |
3206 | - result= datetime.from_string(valid_string, strlen(valid_string)); |
3207 | - ASSERT_TRUE(result); |
3208 | - |
3209 | - assignDateTimeValues(); |
3210 | - |
3211 | - EXPECT_EQ(2010, years); |
3212 | - EXPECT_EQ(6, months); |
3213 | - EXPECT_EQ(7, days); |
3214 | -} |
3215 | - |
3216 | -/* TODO:for some reason this was not declared by the macro, needs clarification*/ |
3217 | -testing::internal::ParamGenerator<const char*> gtest_ValidStringDateTimeFromStringDateOnlyTest_EvalGenerator_(); |
3218 | -INSTANTIATE_TEST_CASE_P(ValidString, DateTimeFromStringDateOnlyTest, |
3219 | - ::testing::Values("20100607", /* YYYYMMDD */ |
3220 | - "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/ |
3221 | - "10.06.07",/* YY[-/.]MM[-/.]DD */ |
3222 | - "10/6/7",/* YY[-/.][M]M[-/.][D]D */ |
3223 | - "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */)); |
3224 | - |
3225 | - |
3226 | |
3227 | === removed file 'unittests/generators.cc' |
3228 | --- unittests/generators.cc 2010-07-09 17:59:07 +0000 |
3229 | +++ unittests/generators.cc 1970-01-01 00:00:00 +0000 |
3230 | @@ -1,72 +0,0 @@ |
3231 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3232 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3233 | - * |
3234 | - * Copyright (C) 2010 Brian Aker |
3235 | - * |
3236 | - * This program is free software; you can redistribute it and/or modify |
3237 | - * it under the terms of the GNU General Public License as published by |
3238 | - * the Free Software Foundation; either version 2 of the License, or |
3239 | - * (at your option) any later version. |
3240 | - * |
3241 | - * This program is distributed in the hope that it will be useful, |
3242 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3243 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3244 | - * GNU General Public License for more details. |
3245 | - * |
3246 | - * You should have received a copy of the GNU General Public License |
3247 | - * along with this program; if not, write to the Free Software |
3248 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3249 | - */ |
3250 | - |
3251 | -#include "config.h" |
3252 | - |
3253 | -#include <gtest/gtest.h> |
3254 | - |
3255 | -#include <drizzled/generator.h> |
3256 | -#include <drizzled/plugin/listen.h> |
3257 | - |
3258 | -/* |
3259 | - These will not work currently because of init issues for the server. |
3260 | -*/ |
3261 | -#if 0 |
3262 | -TEST(generator_test, schema) |
3263 | -{ |
3264 | - drizzled::Session session(drizzled::plugin::Listen::getNullClient()); |
3265 | - drizzled::generator::Schema generator(session); |
3266 | - |
3267 | - const drizzled::message::Schema *schema_ptr; |
3268 | - if ((schema_ptr= generator)) |
3269 | - ASSERT_TRUE(0); |
3270 | -} |
3271 | - |
3272 | -TEST(generator_test, table) |
3273 | -{ |
3274 | - drizzled::Session session(drizzled::plugin::Listen::getNullClient()); |
3275 | - drizzled::SchemaIdentifier schema("foo"); |
3276 | - drizzled::generator::Table generator(session, schema); |
3277 | - const drizzled::message::Table *table_ptr; |
3278 | - |
3279 | - if ((table_ptr= generator)) |
3280 | - ASSERT_TRUE(0); |
3281 | -} |
3282 | - |
3283 | -TEST(generator_test, all_tables) |
3284 | -{ |
3285 | - drizzled::Session session(drizzled::plugin::Listen::getNullClient()); |
3286 | - drizzled::generator::AllTables generator(session); |
3287 | - const drizzled::message::Table *table_ptr; |
3288 | - |
3289 | - if ((table_ptr= generator)) |
3290 | - ASSERT_TRUE(0); |
3291 | -} |
3292 | - |
3293 | -TEST(generator_test, all_fields) |
3294 | -{ |
3295 | - drizzled::Session session(drizzled::plugin::Listen::getNullClient()); |
3296 | - drizzled::generator::AllFields generator(session); |
3297 | - const drizzled::message::Table::Field *field_ptr; |
3298 | - |
3299 | - if ((field_ptr= generator)) |
3300 | - ASSERT_TRUE(0); |
3301 | -} |
3302 | -#endif |
3303 | |
3304 | === added file 'unittests/global_buffer_test.cc' |
3305 | --- unittests/global_buffer_test.cc 1970-01-01 00:00:00 +0000 |
3306 | +++ unittests/global_buffer_test.cc 2011-01-24 09:18:02 +0000 |
3307 | @@ -0,0 +1,64 @@ |
3308 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3309 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3310 | + * |
3311 | + * Copyright (C) 2010 Andrew Hutchings |
3312 | + * |
3313 | + * This program is free software; you can redistribute it and/or modify |
3314 | + * it under the terms of the GNU General Public License as published by |
3315 | + * the Free Software Foundation; either version 2 of the License, or |
3316 | + * (at your option) any later version. |
3317 | + * |
3318 | + * This program is distributed in the hope that it will be useful, |
3319 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3320 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3321 | + * GNU General Public License for more details. |
3322 | + * |
3323 | + * You should have received a copy of the GNU General Public License |
3324 | + * along with this program; if not, write to the Free Software |
3325 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3326 | + */ |
3327 | + |
3328 | +#include "config.h" |
3329 | + |
3330 | +#define BOOST_TEST_DYN_LINK |
3331 | +#include <boost/test/unit_test.hpp> |
3332 | + |
3333 | +#include "drizzled/global_buffer.h" |
3334 | + |
3335 | +BOOST_AUTO_TEST_SUITE(GlobalBufferTests) |
3336 | +BOOST_AUTO_TEST_CASE(overflow) |
3337 | +{ |
3338 | + drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3339 | + |
3340 | + BOOST_REQUIRE(test_buffer.add(512)); |
3341 | + BOOST_REQUIRE(test_buffer.add(512)); |
3342 | + BOOST_REQUIRE(not test_buffer.add(1)); |
3343 | +} |
3344 | + |
3345 | +BOOST_AUTO_TEST_CASE(subtract) |
3346 | +{ |
3347 | + drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3348 | + |
3349 | + BOOST_REQUIRE(test_buffer.add(1024)); |
3350 | + BOOST_REQUIRE(test_buffer.sub(512)); |
3351 | + BOOST_REQUIRE(test_buffer.add(512)); |
3352 | + BOOST_REQUIRE(not test_buffer.add(1)); |
3353 | +} |
3354 | + |
3355 | +BOOST_AUTO_TEST_CASE(underflow) |
3356 | +{ |
3357 | + drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3358 | + |
3359 | + BOOST_REQUIRE(test_buffer.add(10)); |
3360 | + BOOST_REQUIRE(not test_buffer.sub(11)); |
3361 | +} |
3362 | + |
3363 | +BOOST_AUTO_TEST_CASE(change_max) |
3364 | +{ |
3365 | + drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3366 | + |
3367 | + test_buffer.setMaxSize(512); |
3368 | + |
3369 | + BOOST_REQUIRE(not test_buffer.add(513)); |
3370 | +} |
3371 | +BOOST_AUTO_TEST_SUITE_END() |
3372 | |
3373 | === removed file 'unittests/global_buffer_test.cc' |
3374 | --- unittests/global_buffer_test.cc 2010-10-20 09:34:21 +0000 |
3375 | +++ unittests/global_buffer_test.cc 1970-01-01 00:00:00 +0000 |
3376 | @@ -1,60 +0,0 @@ |
3377 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3378 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3379 | - * |
3380 | - * Copyright (C) 2010 Andrew Hutchings |
3381 | - * |
3382 | - * This program is free software; you can redistribute it and/or modify |
3383 | - * it under the terms of the GNU General Public License as published by |
3384 | - * the Free Software Foundation; either version 2 of the License, or |
3385 | - * (at your option) any later version. |
3386 | - * |
3387 | - * This program is distributed in the hope that it will be useful, |
3388 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3389 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3390 | - * GNU General Public License for more details. |
3391 | - * |
3392 | - * You should have received a copy of the GNU General Public License |
3393 | - * along with this program; if not, write to the Free Software |
3394 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3395 | - */ |
3396 | - |
3397 | -#include "config.h" |
3398 | - |
3399 | -#include <gtest/gtest.h> |
3400 | -#include "drizzled/global_buffer.h" |
3401 | - |
3402 | -TEST(global_buffer, overflow) |
3403 | -{ |
3404 | - drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3405 | - |
3406 | - ASSERT_TRUE(test_buffer.add(512)); |
3407 | - ASSERT_TRUE(test_buffer.add(512)); |
3408 | - ASSERT_FALSE(test_buffer.add(1)); |
3409 | -} |
3410 | - |
3411 | -TEST(global_buffer, subtract) |
3412 | -{ |
3413 | - drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3414 | - |
3415 | - ASSERT_TRUE(test_buffer.add(1024)); |
3416 | - ASSERT_TRUE(test_buffer.sub(512)); |
3417 | - ASSERT_TRUE(test_buffer.add(512)); |
3418 | - ASSERT_FALSE(test_buffer.add(1)); |
3419 | -} |
3420 | - |
3421 | -TEST(global_buffer, underflow) |
3422 | -{ |
3423 | - drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3424 | - |
3425 | - ASSERT_TRUE(test_buffer.add(10)); |
3426 | - ASSERT_FALSE(test_buffer.sub(11)); |
3427 | -} |
3428 | - |
3429 | -TEST(global_buffer, change_max) |
3430 | -{ |
3431 | - drizzled::global_buffer_constraint<uint64_t> test_buffer(1024); |
3432 | - |
3433 | - test_buffer.setMaxSize(512); |
3434 | - |
3435 | - ASSERT_FALSE(test_buffer.add(513)); |
3436 | -} |
3437 | |
3438 | === modified file 'unittests/include.am' |
3439 | --- unittests/include.am 2010-12-28 20:54:15 +0000 |
3440 | +++ unittests/include.am 2011-01-24 09:18:02 +0000 |
3441 | @@ -17,8 +17,7 @@ |
3442 | # along with this program; if not, write to the Free Software |
3443 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3444 | |
3445 | - |
3446 | -if HAVE_LIBGTEST |
3447 | +if HAVE_BOOST_TEST |
3448 | check_PROGRAMS += unittests/unittests |
3449 | endif |
3450 | |
3451 | @@ -26,9 +25,6 @@ |
3452 | unittests/plugin/plugin_stubs.h \ |
3453 | unittests/temporal_generator.h |
3454 | |
3455 | -EXTRA_DIST += \ |
3456 | - unittests/client_server.c |
3457 | - |
3458 | unit: unittests/unittests |
3459 | unittests/unittests |
3460 | |
3461 | @@ -38,30 +34,26 @@ |
3462 | # |
3463 | |
3464 | unittests_unittests_SOURCES = \ |
3465 | + unittests/main.cc \ |
3466 | unittests/atomics_test.cc \ |
3467 | unittests/calendar_test.cc \ |
3468 | unittests/constrained_value.cc \ |
3469 | unittests/date_test.cc \ |
3470 | unittests/date_time_test.cc \ |
3471 | - unittests/generators.cc \ |
3472 | - unittests/global_buffer_test.cc \ |
3473 | - unittests/libdrizzle_test.cc \ |
3474 | - unittests/main.cc \ |
3475 | + unittests/global_buffer_test.cc \ |
3476 | + unittests/libdrizzle_test.cc \ |
3477 | unittests/micro_timestamp_test.cc \ |
3478 | unittests/nano_timestamp_test.cc \ |
3479 | unittests/option_context.cc \ |
3480 | - unittests/plugin/authentication_test.cc \ |
3481 | - unittests/plugin/client_test.cc \ |
3482 | - unittests/plugin/error_message_test.cc \ |
3483 | unittests/pthread_atomics_test.cc \ |
3484 | unittests/table_identifier.cc \ |
3485 | unittests/temporal_format_test.cc \ |
3486 | - unittests/temporal_generator.cc \ |
3487 | + unittests/temporal_generator.cc \ |
3488 | + unittests/timestamp_test.cc \ |
3489 | unittests/time_test.cc \ |
3490 | - unittests/timestamp_test.cc \ |
3491 | unittests/utf8_test.cc |
3492 | |
3493 | unittests_unittests_LDADD= \ |
3494 | $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \ |
3495 | - ${drizzled_drizzled_LDADD} ${LTLIBGTEST} ${BOOST_LIBS} \ |
3496 | - libdrizzle/libdrizzle.la |
3497 | + ${drizzled_drizzled_LDADD} ${BOOST_LIBS} libdrizzle/libdrizzle.la \ |
3498 | + ${LTLIBBOOST_UNIT_TEST_FRAMEWORK} ${LTLIBBOOST_UNIT_TEST_FRAMEWORK_MT} |
3499 | |
3500 | === added file 'unittests/libdrizzle_test.cc' |
3501 | --- unittests/libdrizzle_test.cc 1970-01-01 00:00:00 +0000 |
3502 | +++ unittests/libdrizzle_test.cc 2011-01-24 09:18:02 +0000 |
3503 | @@ -0,0 +1,63 @@ |
3504 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3505 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3506 | + * |
3507 | + * Copyright (C) 2010 Andrew Hutchings |
3508 | + * |
3509 | + * This program is free software; you can redistribute it and/or modify |
3510 | + * it under the terms of the GNU General Public License as published by |
3511 | + * the Free Software Foundation; either version 2 of the License, or |
3512 | + * (at your option) any later version. |
3513 | + * |
3514 | + * This program is distributed in the hope that it will be useful, |
3515 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3516 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3517 | + * GNU General Public License for more details. |
3518 | + * |
3519 | + * You should have received a copy of the GNU General Public License |
3520 | + * along with this program; if not, write to the Free Software |
3521 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3522 | + */ |
3523 | + |
3524 | +#include "config.h" |
3525 | + |
3526 | +#define BOOST_TEST_DYN_LINK |
3527 | +#include <boost/test/unit_test.hpp> |
3528 | + |
3529 | +#include <libdrizzle/drizzle_client.h> |
3530 | +#include <libdrizzle/drizzle_server.h> |
3531 | + |
3532 | +BOOST_AUTO_TEST_SUITE(LibDrizzle) |
3533 | +BOOST_AUTO_TEST_CASE(drizzleEscapeString) |
3534 | +{ |
3535 | + const char* orig= "hello \"world\"\n"; |
3536 | + char out[255]; |
3537 | + size_t out_len; |
3538 | + |
3539 | + out_len= drizzle_escape_string(out, orig, strlen(orig)); |
3540 | + |
3541 | + BOOST_REQUIRE_EQUAL(17, out_len); |
3542 | + BOOST_REQUIRE_EQUAL("hello \\\"world\\\"\\n", out); |
3543 | +} |
3544 | + |
3545 | +BOOST_AUTO_TEST_CASE(drizzleHexString) |
3546 | +{ |
3547 | + const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF}; |
3548 | + char out[255]; |
3549 | + size_t out_len; |
3550 | + |
3551 | + out_len= drizzle_hex_string(out, (char*) orig, 5); |
3552 | + |
3553 | + BOOST_REQUIRE_EQUAL(10, out_len); |
3554 | + BOOST_REQUIRE_EQUAL("34268099FF", out); |
3555 | +} |
3556 | + |
3557 | +BOOST_AUTO_TEST_CASE(drizzleMysqlPasswordHash) |
3558 | +{ |
3559 | + const char* orig= "test password"; |
3560 | + char out[255]; |
3561 | + |
3562 | + drizzle_mysql_password_hash(out, orig, strlen(orig)); |
3563 | + |
3564 | + BOOST_REQUIRE_EQUAL("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out); |
3565 | +} |
3566 | +BOOST_AUTO_TEST_SUITE_END() |
3567 | |
3568 | === removed file 'unittests/libdrizzle_test.cc' |
3569 | --- unittests/libdrizzle_test.cc 2010-10-17 16:04:42 +0000 |
3570 | +++ unittests/libdrizzle_test.cc 1970-01-01 00:00:00 +0000 |
3571 | @@ -1,59 +0,0 @@ |
3572 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3573 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3574 | - * |
3575 | - * Copyright (C) 2010 Andrew Hutchings |
3576 | - * |
3577 | - * This program is free software; you can redistribute it and/or modify |
3578 | - * it under the terms of the GNU General Public License as published by |
3579 | - * the Free Software Foundation; either version 2 of the License, or |
3580 | - * (at your option) any later version. |
3581 | - * |
3582 | - * This program is distributed in the hope that it will be useful, |
3583 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3584 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3585 | - * GNU General Public License for more details. |
3586 | - * |
3587 | - * You should have received a copy of the GNU General Public License |
3588 | - * along with this program; if not, write to the Free Software |
3589 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3590 | - */ |
3591 | - |
3592 | -#include "config.h" |
3593 | - |
3594 | -#include <gtest/gtest.h> |
3595 | -#include <libdrizzle/drizzle_client.h> |
3596 | -#include <libdrizzle/drizzle_server.h> |
3597 | - |
3598 | -TEST(libdrizzle, drizzle_escape_string) |
3599 | -{ |
3600 | - const char* orig= "hello \"world\"\n"; |
3601 | - char out[255]; |
3602 | - size_t out_len; |
3603 | - |
3604 | - out_len= drizzle_escape_string(out, orig, strlen(orig)); |
3605 | - |
3606 | - EXPECT_EQ(17, out_len); |
3607 | - ASSERT_STREQ("hello \\\"world\\\"\\n", out); |
3608 | -} |
3609 | - |
3610 | -TEST(libdrizzle, drizzle_hex_string) |
3611 | -{ |
3612 | - const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF}; |
3613 | - char out[255]; |
3614 | - size_t out_len; |
3615 | - |
3616 | - out_len= drizzle_hex_string(out, (char*) orig, 5); |
3617 | - |
3618 | - EXPECT_EQ(10, out_len); |
3619 | - ASSERT_STREQ("34268099FF", out); |
3620 | -} |
3621 | - |
3622 | -TEST(libdrizzle, drizzle_mysql_password_hash) |
3623 | -{ |
3624 | - const char* orig= "test password"; |
3625 | - char out[255]; |
3626 | - |
3627 | - drizzle_mysql_password_hash(out, orig, strlen(orig)); |
3628 | - |
3629 | - ASSERT_STREQ("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out); |
3630 | -} |
3631 | |
3632 | === modified file 'unittests/main.cc' |
3633 | --- unittests/main.cc 2010-06-06 20:55:30 +0000 |
3634 | +++ unittests/main.cc 2011-01-24 09:18:02 +0000 |
3635 | @@ -1,7 +1,7 @@ |
3636 | /* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3637 | * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3638 | * |
3639 | - * Copyright (C) 2010 Stewart Smith |
3640 | + * Copyright (C) 2011 Andrew Hutchings |
3641 | * |
3642 | * This program is free software; you can redistribute it and/or modify |
3643 | * it under the terms of the GNU General Public License as published by |
3644 | @@ -18,15 +18,26 @@ |
3645 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3646 | */ |
3647 | |
3648 | -#include "config.h" |
3649 | - |
3650 | -#include <gtest/gtest.h> |
3651 | - |
3652 | -#include <drizzled/internal/my_sys.h> |
3653 | - |
3654 | -int main(int argc, char **argv) |
3655 | -{ |
3656 | - MY_INIT(argv[0]); |
3657 | - ::testing::InitGoogleTest(&argc, argv); |
3658 | - return RUN_ALL_TESTS(); |
3659 | +#define BOOST_TEST_DYN_LINK |
3660 | +#define BOOST_TEST_MAIN |
3661 | +#include <boost/test/unit_test.hpp> |
3662 | +#include <iostream> |
3663 | + |
3664 | +struct MyConfig |
3665 | +{ |
3666 | + MyConfig() |
3667 | + { |
3668 | + boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages); |
3669 | + } |
3670 | + |
3671 | + ~MyConfig() |
3672 | + { |
3673 | + } |
3674 | +}; |
3675 | + |
3676 | +BOOST_GLOBAL_FIXTURE( MyConfig ) |
3677 | + |
3678 | +BOOST_AUTO_TEST_CASE(MainInit) |
3679 | +{ |
3680 | + BOOST_REQUIRE(true); |
3681 | } |
3682 | |
3683 | === added file 'unittests/micro_timestamp_test.cc' |
3684 | --- unittests/micro_timestamp_test.cc 1970-01-01 00:00:00 +0000 |
3685 | +++ unittests/micro_timestamp_test.cc 2011-01-24 09:18:02 +0000 |
3686 | @@ -0,0 +1,112 @@ |
3687 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3688 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3689 | + * |
3690 | + * Copyright (C) 2010 Pawel Blokus |
3691 | + * |
3692 | + * This program is free software; you can redistribute it and/or modify |
3693 | + * it under the terms of the GNU General Public License as published by |
3694 | + * the Free Software Foundation; either version 2 of the License, or |
3695 | + * (at your option) any later version. |
3696 | + * |
3697 | + * This program is distributed in the hope that it will be useful, |
3698 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3699 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3700 | + * GNU General Public License for more details. |
3701 | + * |
3702 | + * You should have received a copy of the GNU General Public License |
3703 | + * along with this program; if not, write to the Free Software |
3704 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3705 | + */ |
3706 | + |
3707 | +#include "config.h" |
3708 | + |
3709 | +#define BOOST_TEST_DYN_LINK |
3710 | +#include <boost/test/unit_test.hpp> |
3711 | + |
3712 | +#include <drizzled/temporal.h> |
3713 | + |
3714 | +#include "temporal_generator.h" |
3715 | + |
3716 | +using namespace drizzled; |
3717 | + |
3718 | +class MicroTimestampTest |
3719 | +{ |
3720 | + protected: |
3721 | + MicroTimestamp micro_timestamp; |
3722 | + bool result; |
3723 | +}; |
3724 | + |
3725 | +BOOST_FIXTURE_TEST_SUITE(MicroTimestampTestSuite, MicroTimestampTest) |
3726 | +BOOST_AUTO_TEST_CASE(is_valid_minOfMicroTimestampRange_shouldReturn_True) |
3727 | +{ |
3728 | + uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, microsecond= 0; |
3729 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3730 | + |
3731 | + result= micro_timestamp.is_valid(); |
3732 | + |
3733 | + BOOST_REQUIRE(result); |
3734 | +} |
3735 | + |
3736 | +BOOST_AUTO_TEST_CASE(is_valid_maxOfMicroTimestampRange_shouldReturn_True) |
3737 | +{ |
3738 | + uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, microsecond= 0; |
3739 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3740 | + |
3741 | + result= micro_timestamp.is_valid(); |
3742 | + |
3743 | + BOOST_REQUIRE(result); |
3744 | +} |
3745 | + |
3746 | +BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondBeforeMicroTimestampMinOfRange_shouldReturn_False) |
3747 | +{ |
3748 | + uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, microsecond= 999999; |
3749 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3750 | + |
3751 | + result= micro_timestamp.is_valid(); |
3752 | + |
3753 | + BOOST_REQUIRE(not result); |
3754 | +} |
3755 | + |
3756 | +BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondAfterMicroTimestampMaxOfRange_shouldReturn_False) |
3757 | +{ |
3758 | + uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, microsecond= 1; |
3759 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3760 | + |
3761 | + result= micro_timestamp.is_valid(); |
3762 | + |
3763 | + BOOST_REQUIRE(not result); |
3764 | +} |
3765 | + |
3766 | +BOOST_AUTO_TEST_CASE(is_valid_InsideOfMicroTimestampRange_shouldReturn_True) |
3767 | +{ |
3768 | + uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, microsecond= 18263; |
3769 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3770 | + |
3771 | + result= micro_timestamp.is_valid(); |
3772 | + |
3773 | + BOOST_REQUIRE(result); |
3774 | +} |
3775 | + |
3776 | +BOOST_AUTO_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements) |
3777 | +{ |
3778 | + char expected[MicroTimestamp::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.007654"; |
3779 | + char returned[MicroTimestamp::MAX_STRING_LENGTH]; |
3780 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, 2010, 5, 1, 8, 7, 6, 7654); |
3781 | + |
3782 | + micro_timestamp.to_string(returned, MicroTimestamp::MAX_STRING_LENGTH); |
3783 | + |
3784 | + BOOST_REQUIRE_EQUAL(expected, returned); |
3785 | +} |
3786 | + |
3787 | +BOOST_AUTO_TEST_CASE(to_timeval) |
3788 | +{ |
3789 | + struct timeval filled; |
3790 | + uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, microsecond= 675; |
3791 | + TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3792 | + |
3793 | + micro_timestamp.to_timeval(filled); |
3794 | + |
3795 | + BOOST_REQUIRE_EQUAL(1244005141, filled.tv_sec); |
3796 | + BOOST_REQUIRE_EQUAL(675, filled.tv_usec); |
3797 | +} |
3798 | +BOOST_AUTO_TEST_SUITE_END() |
3799 | |
3800 | === removed file 'unittests/micro_timestamp_test.cc' |
3801 | --- unittests/micro_timestamp_test.cc 2011-01-20 07:24:29 +0000 |
3802 | +++ unittests/micro_timestamp_test.cc 1970-01-01 00:00:00 +0000 |
3803 | @@ -1,108 +0,0 @@ |
3804 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3805 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3806 | - * |
3807 | - * Copyright (C) 2010 Pawel Blokus |
3808 | - * |
3809 | - * This program is free software; you can redistribute it and/or modify |
3810 | - * it under the terms of the GNU General Public License as published by |
3811 | - * the Free Software Foundation; either version 2 of the License, or |
3812 | - * (at your option) any later version. |
3813 | - * |
3814 | - * This program is distributed in the hope that it will be useful, |
3815 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3816 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3817 | - * GNU General Public License for more details. |
3818 | - * |
3819 | - * You should have received a copy of the GNU General Public License |
3820 | - * along with this program; if not, write to the Free Software |
3821 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3822 | - */ |
3823 | - |
3824 | -#include "config.h" |
3825 | - |
3826 | -#include <gtest/gtest.h> |
3827 | -#include <drizzled/temporal.h> |
3828 | - |
3829 | -#include "temporal_generator.h" |
3830 | - |
3831 | -using namespace drizzled; |
3832 | - |
3833 | -class MicroTimestampTest : public ::testing::Test |
3834 | -{ |
3835 | - protected: |
3836 | - MicroTimestamp micro_timestamp; |
3837 | - bool result; |
3838 | -}; |
3839 | - |
3840 | -TEST_F(MicroTimestampTest, is_valid_minOfMicroTimestampRange_shouldReturn_True) |
3841 | -{ |
3842 | - uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, microsecond= 0; |
3843 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3844 | - |
3845 | - result= micro_timestamp.is_valid(); |
3846 | - |
3847 | - ASSERT_TRUE(result); |
3848 | -} |
3849 | - |
3850 | -TEST_F(MicroTimestampTest, is_valid_maxOfMicroTimestampRange_shouldReturn_True) |
3851 | -{ |
3852 | - uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, microsecond= 0; |
3853 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3854 | - |
3855 | - result= micro_timestamp.is_valid(); |
3856 | - |
3857 | - ASSERT_TRUE(result); |
3858 | -} |
3859 | - |
3860 | -TEST_F(MicroTimestampTest, is_valid_oneMicroSecondBeforeMicroTimestampMinOfRange_shouldReturn_False) |
3861 | -{ |
3862 | - uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, microsecond= 999999; |
3863 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3864 | - |
3865 | - result= micro_timestamp.is_valid(); |
3866 | - |
3867 | - ASSERT_FALSE(result); |
3868 | -} |
3869 | - |
3870 | -TEST_F(MicroTimestampTest, is_valid_oneMicroSecondAfterMicroTimestampMaxOfRange_shouldReturn_False) |
3871 | -{ |
3872 | - uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, microsecond= 1; |
3873 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3874 | - |
3875 | - result= micro_timestamp.is_valid(); |
3876 | - |
3877 | - ASSERT_FALSE(result); |
3878 | -} |
3879 | - |
3880 | -TEST_F(MicroTimestampTest, is_valid_InsideOfMicroTimestampRange_shouldReturn_True) |
3881 | -{ |
3882 | - uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, microsecond= 18263; |
3883 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3884 | - |
3885 | - result= micro_timestamp.is_valid(); |
3886 | - |
3887 | - ASSERT_TRUE(result); |
3888 | -} |
3889 | - |
3890 | -TEST_F(MicroTimestampTest, to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements) |
3891 | -{ |
3892 | - char expected[MicroTimestamp::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.007654"; |
3893 | - char returned[MicroTimestamp::MAX_STRING_LENGTH]; |
3894 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, 2010, 5, 1, 8, 7, 6, 7654); |
3895 | - |
3896 | - micro_timestamp.to_string(returned, MicroTimestamp::MAX_STRING_LENGTH); |
3897 | - |
3898 | - ASSERT_STREQ(expected, returned); |
3899 | -} |
3900 | - |
3901 | -TEST_F(MicroTimestampTest, to_timeval) |
3902 | -{ |
3903 | - struct timeval filled; |
3904 | - uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, microsecond= 675; |
3905 | - TemporalGenerator::TimestampGen::make_micro_timestamp(µ_timestamp, year, month, day, hour, minute, second, microsecond); |
3906 | - |
3907 | - micro_timestamp.to_timeval(filled); |
3908 | - |
3909 | - EXPECT_EQ(1244005141, filled.tv_sec); |
3910 | - EXPECT_EQ(675, filled.tv_usec); |
3911 | -} |
3912 | |
3913 | === added file 'unittests/nano_timestamp_test.cc' |
3914 | --- unittests/nano_timestamp_test.cc 1970-01-01 00:00:00 +0000 |
3915 | +++ unittests/nano_timestamp_test.cc 2011-01-24 09:18:02 +0000 |
3916 | @@ -0,0 +1,101 @@ |
3917 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3918 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3919 | + * |
3920 | + * Copyright (C) 2010 Pawel Blokus |
3921 | + * |
3922 | + * This program is free software; you can redistribute it and/or modify |
3923 | + * it under the terms of the GNU General Public License as published by |
3924 | + * the Free Software Foundation; either version 2 of the License, or |
3925 | + * (at your option) any later version. |
3926 | + * |
3927 | + * This program is distributed in the hope that it will be useful, |
3928 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3929 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3930 | + * GNU General Public License for more details. |
3931 | + * |
3932 | + * You should have received a copy of the GNU General Public License |
3933 | + * along with this program; if not, write to the Free Software |
3934 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3935 | + */ |
3936 | + |
3937 | +#include "config.h" |
3938 | + |
3939 | +#define BOOST_TEST_DYN_LINK |
3940 | +#include <boost/test/unit_test.hpp> |
3941 | + |
3942 | +#include <drizzled/temporal.h> |
3943 | + |
3944 | +#include "temporal_generator.h" |
3945 | + |
3946 | +using namespace drizzled; |
3947 | + |
3948 | +class NanoTimestampTest |
3949 | +{ |
3950 | + protected: |
3951 | + NanoTimestamp nano_timestamp; |
3952 | + bool result; |
3953 | +}; |
3954 | + |
3955 | +BOOST_FIXTURE_TEST_SUITE(NanoTimestampTestSuite, NanoTimestampTest) |
3956 | +BOOST_AUTO_TEST_CASE(is_valid_minOfNanoTimestampRange_shouldReturn_True) |
3957 | +{ |
3958 | + uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, nanosecond= 0; |
3959 | + TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
3960 | + |
3961 | + result= nano_timestamp.is_valid(); |
3962 | + |
3963 | + BOOST_REQUIRE(result); |
3964 | +} |
3965 | + |
3966 | +BOOST_AUTO_TEST_CASE(is_valid_maxOfNanoTimestampRange_shouldReturn_True) |
3967 | +{ |
3968 | + uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, nanosecond= 0; |
3969 | + TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
3970 | + |
3971 | + result= nano_timestamp.is_valid(); |
3972 | + |
3973 | + BOOST_REQUIRE(result); |
3974 | +} |
3975 | + |
3976 | +BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondBeforeNanoTimestampMinOfRange_shouldReturn_False) |
3977 | +{ |
3978 | + uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, nanosecond= 999999999; |
3979 | + TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
3980 | + |
3981 | + result= nano_timestamp.is_valid(); |
3982 | + |
3983 | + BOOST_REQUIRE(not result); |
3984 | +} |
3985 | + |
3986 | +BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondAfterNanoTimestampMaxOfRange_shouldReturn_False) |
3987 | +{ |
3988 | + uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, nanosecond= 1; |
3989 | + TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
3990 | + |
3991 | + result= nano_timestamp.is_valid(); |
3992 | + |
3993 | + BOOST_REQUIRE(not result); |
3994 | +} |
3995 | + |
3996 | +BOOST_AUTO_TEST_CASE(is_valid_InsideOfNanoTimestampRange_shouldReturn_True) |
3997 | +{ |
3998 | + uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, nanosecond= 3265832; |
3999 | + TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4000 | + |
4001 | + result= nano_timestamp.is_valid(); |
4002 | + |
4003 | + BOOST_REQUIRE(result); |
4004 | +} |
4005 | + |
4006 | +BOOST_AUTO_TEST_CASE(to_timespec) |
4007 | +{ |
4008 | + struct timespec filled; |
4009 | + uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, nanosecond= 675; |
4010 | + TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4011 | + |
4012 | + nano_timestamp.to_timespec(&filled); |
4013 | + |
4014 | + BOOST_REQUIRE_EQUAL(1244005141, filled.tv_sec); |
4015 | + BOOST_REQUIRE_EQUAL(675, filled.tv_nsec); |
4016 | +} |
4017 | +BOOST_AUTO_TEST_SUITE_END() |
4018 | |
4019 | === removed file 'unittests/nano_timestamp_test.cc' |
4020 | --- unittests/nano_timestamp_test.cc 2011-01-20 07:24:29 +0000 |
4021 | +++ unittests/nano_timestamp_test.cc 1970-01-01 00:00:00 +0000 |
4022 | @@ -1,97 +0,0 @@ |
4023 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4024 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4025 | - * |
4026 | - * Copyright (C) 2010 Pawel Blokus |
4027 | - * |
4028 | - * This program is free software; you can redistribute it and/or modify |
4029 | - * it under the terms of the GNU General Public License as published by |
4030 | - * the Free Software Foundation; either version 2 of the License, or |
4031 | - * (at your option) any later version. |
4032 | - * |
4033 | - * This program is distributed in the hope that it will be useful, |
4034 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4035 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4036 | - * GNU General Public License for more details. |
4037 | - * |
4038 | - * You should have received a copy of the GNU General Public License |
4039 | - * along with this program; if not, write to the Free Software |
4040 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4041 | - */ |
4042 | - |
4043 | -#include "config.h" |
4044 | - |
4045 | -#include <gtest/gtest.h> |
4046 | -#include <drizzled/temporal.h> |
4047 | - |
4048 | -#include "temporal_generator.h" |
4049 | - |
4050 | -using namespace drizzled; |
4051 | - |
4052 | -class NanoTimestampTest : public ::testing::Test |
4053 | -{ |
4054 | - protected: |
4055 | - NanoTimestamp nano_timestamp; |
4056 | - bool result; |
4057 | -}; |
4058 | - |
4059 | -TEST_F(NanoTimestampTest, is_valid_minOfNanoTimestampRange_shouldReturn_True) |
4060 | -{ |
4061 | - uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, nanosecond= 0; |
4062 | - TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4063 | - |
4064 | - result= nano_timestamp.is_valid(); |
4065 | - |
4066 | - ASSERT_TRUE(result); |
4067 | -} |
4068 | - |
4069 | -TEST_F(NanoTimestampTest, is_valid_maxOfNanoTimestampRange_shouldReturn_True) |
4070 | -{ |
4071 | - uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, nanosecond= 0; |
4072 | - TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4073 | - |
4074 | - result= nano_timestamp.is_valid(); |
4075 | - |
4076 | - ASSERT_TRUE(result); |
4077 | -} |
4078 | - |
4079 | -TEST_F(NanoTimestampTest, is_valid_oneMicroSecondBeforeNanoTimestampMinOfRange_shouldReturn_False) |
4080 | -{ |
4081 | - uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, nanosecond= 999999999; |
4082 | - TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4083 | - |
4084 | - result= nano_timestamp.is_valid(); |
4085 | - |
4086 | - ASSERT_FALSE(result); |
4087 | -} |
4088 | - |
4089 | -TEST_F(NanoTimestampTest, is_valid_oneMicroSecondAfterNanoTimestampMaxOfRange_shouldReturn_False) |
4090 | -{ |
4091 | - uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, nanosecond= 1; |
4092 | - TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4093 | - |
4094 | - result= nano_timestamp.is_valid(); |
4095 | - |
4096 | - ASSERT_FALSE(result); |
4097 | -} |
4098 | - |
4099 | -TEST_F(NanoTimestampTest, is_valid_InsideOfNanoTimestampRange_shouldReturn_True) |
4100 | -{ |
4101 | - uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, nanosecond= 3265832; |
4102 | - TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4103 | - |
4104 | - result= nano_timestamp.is_valid(); |
4105 | - |
4106 | - ASSERT_TRUE(result); |
4107 | -} |
4108 | - |
4109 | -TEST_F(NanoTimestampTest, to_timespec) |
4110 | -{ |
4111 | - struct timespec filled; |
4112 | - uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, nanosecond= 675; |
4113 | - TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond); |
4114 | - |
4115 | - nano_timestamp.to_timespec(&filled); |
4116 | - |
4117 | - EXPECT_EQ(1244005141, filled.tv_sec); |
4118 | - EXPECT_EQ(675, filled.tv_nsec); |
4119 | -} |
4120 | |
4121 | === added file 'unittests/option_context.cc' |
4122 | --- unittests/option_context.cc 1970-01-01 00:00:00 +0000 |
4123 | +++ unittests/option_context.cc 2011-01-24 09:18:02 +0000 |
4124 | @@ -0,0 +1,60 @@ |
4125 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4126 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4127 | + * |
4128 | + * Copyright (C) 2010 Monty Taylor |
4129 | + * |
4130 | + * This program is free software; you can redistribute it and/or modify |
4131 | + * it under the terms of the GNU General Public License as published by |
4132 | + * the Free Software Foundation; either version 2 of the License, or |
4133 | + * (at your option) any later version. |
4134 | + * |
4135 | + * This program is distributed in the hope that it will be useful, |
4136 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4137 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4138 | + * GNU General Public License for more details. |
4139 | + * |
4140 | + * You should have received a copy of the GNU General Public License |
4141 | + * along with this program; if not, write to the Free Software |
4142 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4143 | + */ |
4144 | + |
4145 | +#include "config.h" |
4146 | + |
4147 | +#define BOOST_TEST_DYN_LINK |
4148 | +#include <boost/test/unit_test.hpp> |
4149 | + |
4150 | +#include <boost/program_options.hpp> |
4151 | + |
4152 | +#include "drizzled/module/option_context.h" |
4153 | + |
4154 | +namespace po=boost::program_options; |
4155 | + |
4156 | +using namespace drizzled; |
4157 | + |
4158 | +BOOST_AUTO_TEST_SUITE(OptionContext) |
4159 | +BOOST_AUTO_TEST_CASE(parsing) |
4160 | +{ |
4161 | + const std::string module_name("test"); |
4162 | + po::options_description command_line_options("Test prefix injection"); |
4163 | + module::option_context ctx(module_name, command_line_options.add_options()); |
4164 | + |
4165 | + ctx("option", po::value<std::string>(), "Test option name prefix injection"); |
4166 | + |
4167 | + po::variables_map vm; |
4168 | + |
4169 | + const char *options[]= { |
4170 | + "test", "--test.option=foo" |
4171 | + }; |
4172 | + |
4173 | + // Disable allow_guessing |
4174 | + int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing; |
4175 | + |
4176 | + po::store(po::command_line_parser(2, (char **)options).style(style). |
4177 | + options(command_line_options).run(), vm); |
4178 | + po::notify(vm); |
4179 | + |
4180 | + BOOST_REQUIRE_EQUAL(0, vm.count("option")); |
4181 | + BOOST_REQUIRE_EQUAL(1, vm.count("test.option")); |
4182 | + BOOST_REQUIRE_EQUAL(0, vm["test.option"].as<std::string>().compare("foo")); |
4183 | +} |
4184 | +BOOST_AUTO_TEST_SUITE_END() |
4185 | |
4186 | === removed file 'unittests/option_context.cc' |
4187 | --- unittests/option_context.cc 2010-09-26 08:33:47 +0000 |
4188 | +++ unittests/option_context.cc 1970-01-01 00:00:00 +0000 |
4189 | @@ -1,56 +0,0 @@ |
4190 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4191 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4192 | - * |
4193 | - * Copyright (C) 2010 Monty Taylor |
4194 | - * |
4195 | - * This program is free software; you can redistribute it and/or modify |
4196 | - * it under the terms of the GNU General Public License as published by |
4197 | - * the Free Software Foundation; either version 2 of the License, or |
4198 | - * (at your option) any later version. |
4199 | - * |
4200 | - * This program is distributed in the hope that it will be useful, |
4201 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4202 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4203 | - * GNU General Public License for more details. |
4204 | - * |
4205 | - * You should have received a copy of the GNU General Public License |
4206 | - * along with this program; if not, write to the Free Software |
4207 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4208 | - */ |
4209 | - |
4210 | -#include "config.h" |
4211 | - |
4212 | -#include <gtest/gtest.h> |
4213 | -#include <boost/program_options.hpp> |
4214 | - |
4215 | -#include "drizzled/module/option_context.h" |
4216 | - |
4217 | -namespace po=boost::program_options; |
4218 | - |
4219 | -using namespace drizzled; |
4220 | - |
4221 | -TEST(option_context, parsing) |
4222 | -{ |
4223 | - const std::string module_name("test"); |
4224 | - po::options_description command_line_options("Test prefix injection"); |
4225 | - module::option_context ctx(module_name, command_line_options.add_options()); |
4226 | - |
4227 | - ctx("option", po::value<std::string>(), "Test option name prefix injection"); |
4228 | - |
4229 | - po::variables_map vm; |
4230 | - |
4231 | - const char *options[]= { |
4232 | - "test", "--test.option=foo" |
4233 | - }; |
4234 | - |
4235 | - // Disable allow_guessing |
4236 | - int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing; |
4237 | - |
4238 | - po::store(po::command_line_parser(2, (char **)options).style(style). |
4239 | - options(command_line_options).run(), vm); |
4240 | - po::notify(vm); |
4241 | - |
4242 | - EXPECT_EQ(0, vm.count("option")); |
4243 | - EXPECT_EQ(1, vm.count("test.option")); |
4244 | - EXPECT_EQ(0, vm["test.option"].as<std::string>().compare("foo")); |
4245 | -} |
4246 | |
4247 | === added file 'unittests/pthread_atomics_test.cc' |
4248 | --- unittests/pthread_atomics_test.cc 1970-01-01 00:00:00 +0000 |
4249 | +++ unittests/pthread_atomics_test.cc 2011-01-24 09:18:02 +0000 |
4250 | @@ -0,0 +1,130 @@ |
4251 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4252 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4253 | + * |
4254 | + * Copyright (C) 2010 Stewart Smith |
4255 | + * |
4256 | + * This program is free software; you can redistribute it and/or modify |
4257 | + * it under the terms of the GNU General Public License as published by |
4258 | + * the Free Software Foundation; either version 2 of the License, or |
4259 | + * (at your option) any later version. |
4260 | + * |
4261 | + * This program is distributed in the hope that it will be useful, |
4262 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4263 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4264 | + * GNU General Public License for more details. |
4265 | + * |
4266 | + * You should have received a copy of the GNU General Public License |
4267 | + * along with this program; if not, write to the Free Software |
4268 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4269 | + */ |
4270 | + |
4271 | +#include "config.h" |
4272 | + |
4273 | +#define BOOST_TEST_DYN_LINK |
4274 | +#include <boost/test/unit_test.hpp> |
4275 | + |
4276 | +# if defined(__SUNPRO_CC) |
4277 | +# include <drizzled/atomic/sun_studio.h> |
4278 | +# endif |
4279 | + |
4280 | +# if !defined(__ICC) && (defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC)) |
4281 | +# include <drizzled/atomic/gcc_traits.h> |
4282 | +# define ATOMIC_TRAITS internal::gcc_traits |
4283 | +# else /* use pthread impl */ |
4284 | +# define ATOMIC_TRAITS internal::pthread_traits |
4285 | +# endif |
4286 | + |
4287 | +#include <pthread.h> |
4288 | +#include <drizzled/atomic/pthread_traits.h> |
4289 | + |
4290 | +#include <drizzled/atomics.h> |
4291 | + |
4292 | +using namespace drizzled; |
4293 | + |
4294 | +template<typename T> |
4295 | +struct atomic_pthread { |
4296 | +}; |
4297 | + |
4298 | +# define __DRIZZLE_DECL_ATOMIC_PTHREAD(T) \ |
4299 | + template<> struct atomic_pthread<T> \ |
4300 | + : internal::atomic_impl<T,T, internal::pthread_traits<T,T> > { \ |
4301 | + atomic_pthread<T>() \ |
4302 | + : internal::atomic_impl<T,T, internal::pthread_traits<T,T> >() {} \ |
4303 | + T operator=( T rhs ) { return store_with_release(rhs); } \ |
4304 | + }; |
4305 | + |
4306 | +__DRIZZLE_DECL_ATOMIC_PTHREAD(unsigned int) |
4307 | + |
4308 | +BOOST_AUTO_TEST_SUITE(PthreadAtomicOperations) |
4309 | +BOOST_AUTO_TEST_CASE(fetch_and_store) |
4310 | +{ |
4311 | + atomic_pthread<uint32_t> u235; |
4312 | + |
4313 | + BOOST_REQUIRE_EQUAL(0, u235.fetch_and_store(1)); |
4314 | + |
4315 | + u235.fetch_and_store(15); |
4316 | + |
4317 | + BOOST_REQUIRE_EQUAL(15, u235.fetch_and_store(100)); |
4318 | + BOOST_REQUIRE_EQUAL(100, u235); |
4319 | +} |
4320 | + |
4321 | +BOOST_AUTO_TEST_CASE(fetch_and_increment) |
4322 | +{ |
4323 | + atomic_pthread<uint32_t> u235; |
4324 | + |
4325 | + BOOST_REQUIRE_EQUAL(0, u235.fetch_and_increment()); |
4326 | + BOOST_REQUIRE_EQUAL(1, u235); |
4327 | +} |
4328 | + |
4329 | +BOOST_AUTO_TEST_CASE(fetch_and_add) |
4330 | +{ |
4331 | + atomic_pthread<uint32_t> u235; |
4332 | + |
4333 | + BOOST_REQUIRE_EQUAL(0, u235.fetch_and_add(2)); |
4334 | + BOOST_REQUIRE_EQUAL(2, u235); |
4335 | +} |
4336 | + |
4337 | +BOOST_AUTO_TEST_CASE(add_and_fetch) |
4338 | +{ |
4339 | + atomic_pthread<uint32_t> u235; |
4340 | + |
4341 | + BOOST_REQUIRE_EQUAL(10, u235.add_and_fetch(10)); |
4342 | + BOOST_REQUIRE_EQUAL(10, u235); |
4343 | +} |
4344 | + |
4345 | +BOOST_AUTO_TEST_CASE(fetch_and_decrement) |
4346 | +{ |
4347 | + atomic_pthread<uint32_t> u235; |
4348 | + |
4349 | + u235.fetch_and_store(15); |
4350 | + |
4351 | + BOOST_REQUIRE_EQUAL(15, u235.fetch_and_decrement()); |
4352 | + BOOST_REQUIRE_EQUAL(14, u235); |
4353 | +} |
4354 | + |
4355 | +BOOST_AUTO_TEST_CASE(compare_and_swap) |
4356 | +{ |
4357 | + atomic_pthread<uint32_t> u235; |
4358 | + |
4359 | + u235.fetch_and_store(100); |
4360 | + |
4361 | + BOOST_REQUIRE(not u235.compare_and_swap(42, 200)); |
4362 | + BOOST_REQUIRE(u235.compare_and_swap(200, 100)); |
4363 | + BOOST_REQUIRE_EQUAL(200, u235); |
4364 | +} |
4365 | + |
4366 | +BOOST_AUTO_TEST_CASE(increment) |
4367 | +{ |
4368 | + atomic_pthread<uint32_t> u235; |
4369 | + u235.fetch_and_store(200); |
4370 | + BOOST_REQUIRE_EQUAL(201, u235.increment()); |
4371 | +} |
4372 | + |
4373 | +BOOST_AUTO_TEST_CASE(decrement) |
4374 | +{ |
4375 | + atomic_pthread<uint32_t> u235; |
4376 | + u235.fetch_and_store(200); |
4377 | + |
4378 | + BOOST_REQUIRE_EQUAL(199, u235.decrement()); |
4379 | +} |
4380 | +BOOST_AUTO_TEST_SUITE_END() |
4381 | |
4382 | === removed file 'unittests/pthread_atomics_test.cc' |
4383 | --- unittests/pthread_atomics_test.cc 2010-10-20 09:36:04 +0000 |
4384 | +++ unittests/pthread_atomics_test.cc 1970-01-01 00:00:00 +0000 |
4385 | @@ -1,134 +0,0 @@ |
4386 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4387 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4388 | - * |
4389 | - * Copyright (C) 2010 Stewart Smith |
4390 | - * |
4391 | - * This program is free software; you can redistribute it and/or modify |
4392 | - * it under the terms of the GNU General Public License as published by |
4393 | - * the Free Software Foundation; either version 2 of the License, or |
4394 | - * (at your option) any later version. |
4395 | - * |
4396 | - * This program is distributed in the hope that it will be useful, |
4397 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4398 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4399 | - * GNU General Public License for more details. |
4400 | - * |
4401 | - * You should have received a copy of the GNU General Public License |
4402 | - * along with this program; if not, write to the Free Software |
4403 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4404 | - */ |
4405 | - |
4406 | -#include "config.h" |
4407 | - |
4408 | -#include <gtest/gtest.h> |
4409 | - |
4410 | -# if defined(__SUNPRO_CC) |
4411 | -# include <drizzled/atomic/sun_studio.h> |
4412 | -# endif |
4413 | - |
4414 | -# if !defined(__ICC) && (defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC)) |
4415 | -# include <drizzled/atomic/gcc_traits.h> |
4416 | -# define ATOMIC_TRAITS internal::gcc_traits |
4417 | -# else /* use pthread impl */ |
4418 | -# define ATOMIC_TRAITS internal::pthread_traits |
4419 | -# endif |
4420 | - |
4421 | -#include <pthread.h> |
4422 | -#include <drizzled/atomic/pthread_traits.h> |
4423 | - |
4424 | -#include <drizzled/atomics.h> |
4425 | - |
4426 | -using namespace drizzled; |
4427 | - |
4428 | -template<typename T> |
4429 | -struct atomic_pthread { |
4430 | -}; |
4431 | - |
4432 | -# define __DRIZZLE_DECL_ATOMIC_PTHREAD(T) \ |
4433 | - template<> struct atomic_pthread<T> \ |
4434 | - : internal::atomic_impl<T,T, internal::pthread_traits<T,T> > { \ |
4435 | - atomic_pthread<T>() \ |
4436 | - : internal::atomic_impl<T,T, internal::pthread_traits<T,T> >() {} \ |
4437 | - T operator=( T rhs ) { return store_with_release(rhs); } \ |
4438 | - }; |
4439 | - |
4440 | -__DRIZZLE_DECL_ATOMIC_PTHREAD(unsigned int) |
4441 | - |
4442 | -TEST(pthread_atomic_operations, fetch_and_store) |
4443 | -{ |
4444 | - atomic_pthread<uint32_t> u235; |
4445 | - |
4446 | - EXPECT_EQ(0, u235.fetch_and_store(1)); |
4447 | - |
4448 | - u235.fetch_and_store(15); |
4449 | - |
4450 | - EXPECT_EQ(15, u235.fetch_and_store(100)); |
4451 | - EXPECT_EQ(100, u235); |
4452 | -} |
4453 | - |
4454 | -TEST(pthread_atomic_operations, fetch_and_increment) |
4455 | -{ |
4456 | - atomic_pthread<uint32_t> u235; |
4457 | - |
4458 | - EXPECT_EQ(0, u235.fetch_and_increment()); |
4459 | - EXPECT_EQ(1, u235); |
4460 | -} |
4461 | - |
4462 | -TEST(pthread_atomic_operations, fetch_and_add) |
4463 | -{ |
4464 | - atomic_pthread<uint32_t> u235; |
4465 | - |
4466 | - EXPECT_EQ(0, u235.fetch_and_add(2)); |
4467 | - EXPECT_EQ(2, u235); |
4468 | -} |
4469 | - |
4470 | -TEST(pthread_atomic_operations, add_and_fetch) |
4471 | -{ |
4472 | - atomic_pthread<uint32_t> u235; |
4473 | - |
4474 | - EXPECT_EQ(10, u235.add_and_fetch(10)); |
4475 | - EXPECT_EQ(10, u235); |
4476 | -} |
4477 | - |
4478 | -TEST(pthread_atomic_operations, fetch_and_decrement) |
4479 | -{ |
4480 | - atomic_pthread<uint32_t> u235; |
4481 | - |
4482 | - u235.fetch_and_store(15); |
4483 | - |
4484 | - EXPECT_EQ(15, u235.fetch_and_decrement()); |
4485 | - EXPECT_EQ(14, u235); |
4486 | -} |
4487 | - |
4488 | -TEST(pthread_atomic_operations, compare_and_swap) |
4489 | -{ |
4490 | - atomic_pthread<uint32_t> u235; |
4491 | - |
4492 | - u235.fetch_and_store(100); |
4493 | - |
4494 | - ASSERT_FALSE(u235.compare_and_swap(42, 200)); |
4495 | - ASSERT_TRUE(u235.compare_and_swap(200, 100)); |
4496 | - EXPECT_EQ(200, u235); |
4497 | -} |
4498 | - |
4499 | -TEST(pthread_atomic_operations, increment) |
4500 | -{ |
4501 | - atomic_pthread<uint32_t> u235; |
4502 | - u235.fetch_and_store(200); |
4503 | - EXPECT_EQ(201, u235.increment()); |
4504 | -} |
4505 | - |
4506 | -TEST(pthread_atomic_operations, decrement) |
4507 | -{ |
4508 | - atomic_pthread<uint32_t> u235; |
4509 | - u235.fetch_and_store(200); |
4510 | - |
4511 | - EXPECT_EQ(199, u235.decrement()); |
4512 | -} |
4513 | - |
4514 | -// these don't build for whatever reason |
4515 | -// EXPECT_EQ(242, u235+=42); |
4516 | -// EXPECT_EQ(200, u235-=42); |
4517 | - |
4518 | - |
4519 | - |
4520 | |
4521 | === added file 'unittests/table_identifier.cc' |
4522 | --- unittests/table_identifier.cc 1970-01-01 00:00:00 +0000 |
4523 | +++ unittests/table_identifier.cc 2011-01-24 09:18:02 +0000 |
4524 | @@ -0,0 +1,91 @@ |
4525 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4526 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4527 | + * |
4528 | + * Copyright (C) 2010 Brian Aker |
4529 | + * |
4530 | + * This program is free software; you can redistribute it and/or modify |
4531 | + * it under the terms of the GNU General Public License as published by |
4532 | + * the Free Software Foundation; either version 2 of the License, or |
4533 | + * (at your option) any later version. |
4534 | + * |
4535 | + * This program is distributed in the hope that it will be useful, |
4536 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4537 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4538 | + * GNU General Public License for more details. |
4539 | + * |
4540 | + * You should have received a copy of the GNU General Public License |
4541 | + * along with this program; if not, write to the Free Software |
4542 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4543 | + */ |
4544 | + |
4545 | +#include "config.h" |
4546 | + |
4547 | +#define BOOST_TEST_DYN_LINK |
4548 | +#include <boost/test/unit_test.hpp> |
4549 | + |
4550 | +#include <drizzled/identifier.h> |
4551 | + |
4552 | +using namespace drizzled; |
4553 | + |
4554 | +BOOST_AUTO_TEST_SUITE(TableIdentifierTest) |
4555 | +BOOST_AUTO_TEST_CASE(CreateStandard) |
4556 | +{ |
4557 | + identifier::Table identifier("test", "a"); |
4558 | + BOOST_REQUIRE_EQUAL("test/a", identifier.getPath()); |
4559 | + std::string path; |
4560 | + identifier.getSQLPath(path); |
4561 | + BOOST_REQUIRE_EQUAL("test.a", path); |
4562 | +} |
4563 | + |
4564 | +BOOST_AUTO_TEST_CASE(CreateTemporary) |
4565 | +{ |
4566 | + identifier::Table identifier("test", "a", message::Table::TEMPORARY); |
4567 | + BOOST_REQUIRE_EQUAL("/#sql", identifier.getPath().substr(0, 5)); |
4568 | + std::string path; |
4569 | + identifier.getSQLPath(path); |
4570 | + BOOST_REQUIRE_EQUAL("test.#a", path); |
4571 | +} |
4572 | + |
4573 | +BOOST_AUTO_TEST_CASE(CreateInternal) |
4574 | +{ |
4575 | + identifier::Table identifier("test", "a", message::Table::TEMPORARY); |
4576 | + BOOST_REQUIRE_EQUAL("/#sql", identifier.getPath().substr(0, 5)); |
4577 | + std::string path; |
4578 | + identifier.getSQLPath(path); |
4579 | + BOOST_REQUIRE_EQUAL("test.#a", path); |
4580 | +} |
4581 | + |
4582 | +BOOST_AUTO_TEST_CASE(StaticTmpTable) |
4583 | +{ |
4584 | + std::vector<char> pathname; |
4585 | + |
4586 | + identifier::Table::build_tmptable_filename(pathname); |
4587 | + |
4588 | + BOOST_REQUIRE_GT(pathname.size(), 0); |
4589 | + BOOST_REQUIRE_GT(strlen(&pathname[0]), 0); |
4590 | +} |
4591 | + |
4592 | +BOOST_AUTO_TEST_CASE(Key) |
4593 | +{ |
4594 | + identifier::Table identifier("test", "a"); |
4595 | + |
4596 | + const identifier::Table::Key key= identifier.getKey(); |
4597 | + |
4598 | + BOOST_REQUIRE_EQUAL(key.size(), 7); |
4599 | + BOOST_REQUIRE_EQUAL(key.vector()[0], 't'); |
4600 | + BOOST_REQUIRE_EQUAL(key.vector()[1], 'e'); |
4601 | + BOOST_REQUIRE_EQUAL(key.vector()[2], 's'); |
4602 | + BOOST_REQUIRE_EQUAL(key.vector()[3], 't'); |
4603 | + BOOST_REQUIRE_EQUAL(key.vector()[4], 0); |
4604 | + BOOST_REQUIRE_EQUAL(key.vector()[5], 'a'); |
4605 | + BOOST_REQUIRE_EQUAL(key.vector()[6], 0); |
4606 | +} |
4607 | + |
4608 | +BOOST_AUTO_TEST_CASE(KeyCompare) |
4609 | +{ |
4610 | + identifier::Table identifier("test", "a"); |
4611 | + identifier::Table identifier2("test", "a"); |
4612 | + |
4613 | + BOOST_REQUIRE_EQUAL((identifier.getKey() == identifier.getKey()), true); |
4614 | +} |
4615 | +BOOST_AUTO_TEST_SUITE_END() |
4616 | |
4617 | === removed file 'unittests/table_identifier.cc' |
4618 | --- unittests/table_identifier.cc 2011-01-17 04:15:23 +0000 |
4619 | +++ unittests/table_identifier.cc 1970-01-01 00:00:00 +0000 |
4620 | @@ -1,88 +0,0 @@ |
4621 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4622 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4623 | - * |
4624 | - * Copyright (C) 2010 Brian Aker |
4625 | - * |
4626 | - * This program is free software; you can redistribute it and/or modify |
4627 | - * it under the terms of the GNU General Public License as published by |
4628 | - * the Free Software Foundation; either version 2 of the License, or |
4629 | - * (at your option) any later version. |
4630 | - * |
4631 | - * This program is distributed in the hope that it will be useful, |
4632 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4633 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4634 | - * GNU General Public License for more details. |
4635 | - * |
4636 | - * You should have received a copy of the GNU General Public License |
4637 | - * along with this program; if not, write to the Free Software |
4638 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4639 | - */ |
4640 | - |
4641 | -#include "config.h" |
4642 | - |
4643 | -#include <gtest/gtest.h> |
4644 | - |
4645 | -#include <drizzled/identifier.h> |
4646 | - |
4647 | -using namespace drizzled; |
4648 | - |
4649 | -TEST(table_identifier_test_standard, Create) |
4650 | -{ |
4651 | - identifier::Table identifier("test", "a"); |
4652 | - EXPECT_EQ("test/a", identifier.getPath()); |
4653 | - std::string path; |
4654 | - identifier.getSQLPath(path); |
4655 | - EXPECT_EQ("test.a", path); |
4656 | -} |
4657 | - |
4658 | -TEST(table_identifier_test_temporary, Create) |
4659 | -{ |
4660 | - identifier::Table identifier("test", "a", message::Table::TEMPORARY); |
4661 | - EXPECT_EQ("/#sql", identifier.getPath().substr(0, 5)); |
4662 | - std::string path; |
4663 | - identifier.getSQLPath(path); |
4664 | - EXPECT_EQ("test.#a", path); |
4665 | -} |
4666 | - |
4667 | -TEST(table_identifier_test_internal, Create) |
4668 | -{ |
4669 | - identifier::Table identifier("test", "a", message::Table::TEMPORARY); |
4670 | - EXPECT_EQ("/#sql", identifier.getPath().substr(0, 5)); |
4671 | - std::string path; |
4672 | - identifier.getSQLPath(path); |
4673 | - EXPECT_EQ("test.#a", path); |
4674 | -} |
4675 | - |
4676 | -TEST(table_identifier_test_build_tmptable_filename, Static) |
4677 | -{ |
4678 | - std::vector<char> pathname; |
4679 | - |
4680 | - identifier::Table::build_tmptable_filename(pathname); |
4681 | - |
4682 | - EXPECT_GT(pathname.size(), 0); |
4683 | - EXPECT_GT(strlen(&pathname[0]), 0); |
4684 | -} |
4685 | - |
4686 | -TEST(table_identifier_test_key, Key) |
4687 | -{ |
4688 | - identifier::Table identifier("test", "a"); |
4689 | - |
4690 | - const identifier::Table::Key key= identifier.getKey(); |
4691 | - |
4692 | - EXPECT_EQ(key.size(), 7); |
4693 | - EXPECT_EQ(key.vector()[0], 't'); |
4694 | - EXPECT_EQ(key.vector()[1], 'e'); |
4695 | - EXPECT_EQ(key.vector()[2], 's'); |
4696 | - EXPECT_EQ(key.vector()[3], 't'); |
4697 | - EXPECT_EQ(key.vector()[4], 0); |
4698 | - EXPECT_EQ(key.vector()[5], 'a'); |
4699 | - EXPECT_EQ(key.vector()[6], 0); |
4700 | -} |
4701 | - |
4702 | -TEST(table_identifier_test_key, KeyCompare) |
4703 | -{ |
4704 | - identifier::Table identifier("test", "a"); |
4705 | - identifier::Table identifier2("test", "a"); |
4706 | - |
4707 | - EXPECT_EQ((identifier.getKey() == identifier.getKey()), true); |
4708 | -} |
4709 | |
4710 | === added file 'unittests/temporal_format_test.cc' |
4711 | --- unittests/temporal_format_test.cc 1970-01-01 00:00:00 +0000 |
4712 | +++ unittests/temporal_format_test.cc 2011-01-24 09:18:02 +0000 |
4713 | @@ -0,0 +1,157 @@ |
4714 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4715 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4716 | + * |
4717 | + * Copyright (C) 2010 Pawel Blokus |
4718 | + * |
4719 | + * This program is free software; you can redistribute it and/or modify |
4720 | + * it under the terms of the GNU General Public License as published by |
4721 | + * the Free Software Foundation; either version 2 of the License, or |
4722 | + * (at your option) any later version. |
4723 | + * |
4724 | + * This program is distributed in the hope that it will be useful, |
4725 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4726 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4727 | + * GNU General Public License for more details. |
4728 | + * |
4729 | + * You should have received a copy of the GNU General Public License |
4730 | + * along with this program; if not, write to the Free Software |
4731 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4732 | + */ |
4733 | + |
4734 | +#include "config.h" |
4735 | + |
4736 | +#include <drizzled/temporal.h> |
4737 | +#include <drizzled/temporal_format.h> |
4738 | + |
4739 | +#define BOOST_TEST_DYN_LINK |
4740 | +#include <boost/test/unit_test.hpp> |
4741 | + |
4742 | +#include <vector> |
4743 | + |
4744 | +#include "temporal_generator.h" |
4745 | + |
4746 | +using namespace drizzled; |
4747 | + |
4748 | +class TemporalFormatTest |
4749 | +{ |
4750 | + protected: |
4751 | + TemporalFormat *tf; |
4752 | + Temporal *temporal; |
4753 | + bool result; |
4754 | + |
4755 | + TemporalFormatTest() |
4756 | + { |
4757 | + tf= NULL; |
4758 | + temporal= NULL; |
4759 | + } |
4760 | + |
4761 | + ~TemporalFormatTest() |
4762 | + { |
4763 | + if (tf != NULL) |
4764 | + delete tf; |
4765 | + if (temporal != NULL) |
4766 | + delete temporal; |
4767 | + } |
4768 | +}; |
4769 | + |
4770 | +BOOST_FIXTURE_TEST_SUITE(TemporalFormatTestSuite, TemporalFormatTest) |
4771 | +BOOST_AUTO_TEST_CASE(constructor_WithValidRegExp_shouldCompile) |
4772 | +{ |
4773 | + tf= new TemporalFormat("^(\\d{4})[-/.]$"); |
4774 | + |
4775 | + result= tf->is_valid(); |
4776 | + |
4777 | + BOOST_REQUIRE(result); |
4778 | +} |
4779 | + |
4780 | +BOOST_AUTO_TEST_CASE(constructor_WithInvalidRegExp_shouldNotCompile) |
4781 | +{ |
4782 | + tf= new TemporalFormat("^\\d{4)[-/.]$"); |
4783 | + |
4784 | + result= tf->is_valid(); |
4785 | + |
4786 | + BOOST_REQUIRE(not result); |
4787 | +} |
4788 | + |
4789 | +BOOST_AUTO_TEST_CASE(matches_OnNotMatchingString_shouldReturn_False) |
4790 | +{ |
4791 | + tf= new TemporalFormat("^(\\d{4})[-/.]$"); |
4792 | + char matched[] ="1234/ABC"; |
4793 | + |
4794 | + result= tf->matches(matched, sizeof(matched) - sizeof(char), NULL); |
4795 | + |
4796 | + BOOST_REQUIRE(not result); |
4797 | +} |
4798 | + |
4799 | +BOOST_AUTO_TEST_CASE(matches_OnMatchingString_FormatWithIndexesSet_shouldPopulateTemporal) |
4800 | +{ |
4801 | + char regexp[]= "^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$"; |
4802 | + char matched[]= "1999/9/14T23:29:05"; |
4803 | + tf= TemporalGenerator::TemporalFormatGen::make_temporal_format(regexp, 1, 2, 3, 4, 5, 6, 0, 0); |
4804 | + temporal= new DateTime(); |
4805 | + |
4806 | + |
4807 | + result= tf->matches(matched, sizeof(matched) - sizeof(char), temporal); |
4808 | + BOOST_REQUIRE(result); |
4809 | + |
4810 | + BOOST_REQUIRE_EQUAL(1999, temporal->years()); |
4811 | + BOOST_REQUIRE_EQUAL(9, temporal->months()); |
4812 | + BOOST_REQUIRE_EQUAL(14, temporal->days()); |
4813 | + BOOST_REQUIRE_EQUAL(23, temporal->hours()); |
4814 | + BOOST_REQUIRE_EQUAL(29, temporal->minutes()); |
4815 | + BOOST_REQUIRE_EQUAL(5, temporal->seconds()); |
4816 | +} |
4817 | + |
4818 | +BOOST_AUTO_TEST_CASE(matches_FormatWithMicroSecondIndexSet_shouldAddTrailingZeros) |
4819 | +{ |
4820 | + tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,6})$", 0, 0, 0, 0, 0, 0, 1, 0); |
4821 | + char matched[]= "560"; |
4822 | + temporal= new Time(); |
4823 | + |
4824 | + tf->matches(matched, sizeof(matched) - sizeof(char), temporal); |
4825 | + |
4826 | + BOOST_REQUIRE_EQUAL(560000, temporal->useconds()); |
4827 | +} |
4828 | + |
4829 | +BOOST_AUTO_TEST_CASE(matches_FormatWithNanoSecondIndexSet_shouldAddTrailingZeros) |
4830 | +{ |
4831 | + tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,9})$", 0, 0, 0, 0, 0, 0, 0, 1); |
4832 | + char matched[]= "4321"; |
4833 | + temporal= new Time(); |
4834 | + |
4835 | + tf->matches(matched, sizeof(matched) - sizeof(char), temporal); |
4836 | + |
4837 | + BOOST_REQUIRE_EQUAL(432100000, temporal->nseconds()); |
4838 | +} |
4839 | +BOOST_AUTO_TEST_SUITE_END() |
4840 | + |
4841 | +namespace drizzled |
4842 | +{ |
4843 | +extern std::vector<TemporalFormat *> known_datetime_formats; |
4844 | +extern std::vector<TemporalFormat *> known_date_formats; |
4845 | +extern std::vector<TemporalFormat *> known_time_formats; |
4846 | +extern std::vector<TemporalFormat *> all_temporal_formats; |
4847 | +} |
4848 | + |
4849 | +BOOST_AUTO_TEST_SUITE(TemporalFormatTestSuite) |
4850 | +BOOST_AUTO_TEST_CASE(init_temporal_formats_vectorsWithKnownFormats_shouldHaveExpectedLengths) |
4851 | +{ |
4852 | + init_temporal_formats(); |
4853 | + |
4854 | + BOOST_REQUIRE_EQUAL(13, known_datetime_formats.size()); |
4855 | + BOOST_REQUIRE_EQUAL(8, known_date_formats.size()); |
4856 | + BOOST_REQUIRE_EQUAL(11, known_time_formats.size()); |
4857 | + BOOST_REQUIRE_EQUAL(19, all_temporal_formats.size()); |
4858 | +} |
4859 | + |
4860 | +BOOST_AUTO_TEST_CASE(deinit_temporal_formats_vectorsWithKnownFormats_shouldHaveZeroLengths) |
4861 | +{ |
4862 | + init_temporal_formats(); |
4863 | + deinit_temporal_formats(); |
4864 | + |
4865 | + BOOST_REQUIRE_EQUAL(0, known_datetime_formats.size()); |
4866 | + BOOST_REQUIRE_EQUAL(0, known_date_formats.size()); |
4867 | + BOOST_REQUIRE_EQUAL(0, known_time_formats.size()); |
4868 | + BOOST_REQUIRE_EQUAL(0, all_temporal_formats.size()); |
4869 | +} |
4870 | +BOOST_AUTO_TEST_SUITE_END() |
4871 | |
4872 | === removed file 'unittests/temporal_format_test.cc' |
4873 | --- unittests/temporal_format_test.cc 2010-12-22 19:43:00 +0000 |
4874 | +++ unittests/temporal_format_test.cc 1970-01-01 00:00:00 +0000 |
4875 | @@ -1,151 +0,0 @@ |
4876 | -/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4877 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4878 | - * |
4879 | - * Copyright (C) 2010 Pawel Blokus |
4880 | - * |
4881 | - * This program is free software; you can redistribute it and/or modify |
4882 | - * it under the terms of the GNU General Public License as published by |
4883 | - * the Free Software Foundation; either version 2 of the License, or |
4884 | - * (at your option) any later version. |
4885 | - * |
4886 | - * This program is distributed in the hope that it will be useful, |
4887 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4888 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4889 | - * GNU General Public License for more details. |
4890 | - * |
4891 | - * You should have received a copy of the GNU General Public License |
4892 | - * along with this program; if not, write to the Free Software |
4893 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4894 | - */ |
4895 | - |
4896 | -#include "config.h" |
4897 | - |
4898 | -#include <drizzled/temporal.h> |
4899 | -#include <drizzled/temporal_format.h> |
4900 | -#include <gtest/gtest.h> |
4901 | -#include <vector> |
4902 | - |
4903 | -#include "temporal_generator.h" |
4904 | - |
4905 | -using namespace drizzled; |
4906 | - |
4907 | -class TemporalFormatTest : public ::testing::Test |
4908 | -{ |
4909 | - protected: |
4910 | - TemporalFormat *tf; |
4911 | - Temporal *temporal; |
4912 | - bool result; |
4913 | - |
4914 | - virtual void SetUp() |
4915 | - { |
4916 | - tf= NULL; |
4917 | - temporal= NULL; |
4918 | - } |
4919 | - |
4920 | - virtual void TearDown() |
4921 | - { |
4922 | - if (tf != NULL) |
4923 | - delete tf; |
4924 | - if (temporal != NULL) |
4925 | - delete temporal; |
4926 | - } |
4927 | -}; |
4928 | - |
4929 | - |
4930 | -TEST_F(TemporalFormatTest, constructor_WithValidRegExp_shouldCompile) |
4931 | -{ |
4932 | - tf= new TemporalFormat("^(\\d{4})[-/.]$"); |
4933 | - |
4934 | - result= tf->is_valid(); |
4935 | - |
4936 | - ASSERT_TRUE(result); |
4937 | -} |
4938 | - |
4939 | -TEST_F(TemporalFormatTest, constructor_WithInvalidRegExp_shouldNotCompile) |
4940 | -{ |
4941 | - tf= new TemporalFormat("^\\d{4)[-/.]$"); |
4942 | - |
4943 | - result= tf->is_valid(); |
4944 | - |
4945 | - ASSERT_FALSE(result); |
4946 | -} |
4947 | - |
4948 | -TEST_F(TemporalFormatTest, matches_OnNotMatchingString_shouldReturn_False) |
4949 | -{ |
4950 | - tf= new TemporalFormat("^(\\d{4})[-/.]$"); |
4951 | - char matched[] ="1234/ABC"; |
4952 | - |
4953 | - result= tf->matches(matched, sizeof(matched) - sizeof(char), NULL); |
4954 | - |
4955 | - ASSERT_FALSE(result); |
4956 | -} |
4957 | - |
4958 | -TEST_F(TemporalFormatTest, matches_OnMatchingString_FormatWithIndexesSet_shouldPopulateTemporal) |
4959 | -{ |
4960 | - char regexp[]= "^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$"; |
4961 | - char matched[]= "1999/9/14T23:29:05"; |
4962 | - tf= TemporalGenerator::TemporalFormatGen::make_temporal_format(regexp, 1, 2, 3, 4, 5, 6, 0, 0); |
4963 | - temporal= new DateTime(); |
4964 | - |
4965 | - |
4966 | - result= tf->matches(matched, sizeof(matched) - sizeof(char), temporal); |
4967 | - ASSERT_TRUE(result); |
4968 | - |
4969 | - EXPECT_EQ(1999, temporal->years()); |
4970 | - EXPECT_EQ(9, temporal->months()); |
4971 | - EXPECT_EQ(14, temporal->days()); |
4972 | - EXPECT_EQ(23, temporal->hours()); |
4973 | - EXPECT_EQ(29, temporal->minutes()); |
4974 | - EXPECT_EQ(5, temporal->seconds()); |
4975 | -} |
4976 | - |
4977 | -TEST_F(TemporalFormatTest, matches_FormatWithMicroSecondIndexSet_shouldAddTrailingZeros) |
4978 | -{ |
4979 | - tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,6})$", 0, 0, 0, 0, 0, 0, 1, 0); |
4980 | - char matched[]= "560"; |
4981 | - temporal= new Time(); |
4982 | - |
4983 | - tf->matches(matched, sizeof(matched) - sizeof(char), temporal); |
4984 | - |
4985 | - ASSERT_EQ(560000, temporal->useconds()); |
4986 | -} |
4987 | - |
4988 | -TEST_F(TemporalFormatTest, matches_FormatWithNanoSecondIndexSet_shouldAddTrailingZeros) |
4989 | -{ |
4990 | - tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,9})$", 0, 0, 0, 0, 0, 0, 0, 1); |
4991 | - char matched[]= "4321"; |
4992 | - temporal= new Time(); |
4993 | - |
4994 | - tf->matches(matched, sizeof(matched) - sizeof(char), temporal); |
4995 | - |
4996 | - ASSERT_EQ(432100000, temporal->nseconds()); |
4997 | -} |
4998 | - |
4999 | -namespace drizzled |
5000 | -{ |
The diff has been truncated for viewing.