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