Merge lp:~linuxjedi/drizzle/trunk-unittests into lp:drizzle/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
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+47221@code.launchpad.net

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
=== modified file 'configure.ac'
--- configure.ac 2010-12-19 16:20:13 +0000
+++ configure.ac 2011-01-24 09:18:02 +0000
@@ -83,7 +83,7 @@
83AC_DEFINE([BUILDING_DRIZZLED],[1],83AC_DEFINE([BUILDING_DRIZZLED],[1],
84 [Define indicating we are building and not consuming drizzle.])84 [Define indicating we are building and not consuming drizzle.])
8585
86PANDORA_HAVE_LIBGTEST86PANDORA_HAVE_BOOST_TEST
87PANDORA_HAVE_LIBSQLITE387PANDORA_HAVE_LIBSQLITE3
8888
89AC_CHECK_FUNC(inet_ntoa, [], [AC_CHECK_LIB(nsl, inet_ntoa)])89AC_CHECK_FUNC(inet_ntoa, [], [AC_CHECK_LIB(nsl, inet_ntoa)])
9090
=== modified file 'docs/installing/from_source.rst'
--- docs/installing/from_source.rst 2011-01-21 13:56:53 +0000
+++ docs/installing/from_source.rst 2011-01-24 09:18:02 +0000
@@ -22,8 +22,8 @@
22 * libboost-iostreams-dev22 * libboost-iostreams-dev
23 * libboost-program-options-dev23 * libboost-program-options-dev
24 * libboost-regex-dev24 * libboost-regex-dev
25 * libboost-test-dev
25 * libboost-thread-dev26 * libboost-thread-dev
26 * libgtest (1.5.0)
27 * libpcre3-dev27 * libpcre3-dev
28 * libreadline5-dev | libreadline-dev28 * libreadline5-dev | libreadline-dev
29 * libtool29 * libtool
3030
=== modified file 'docs/installing/requirements.rst'
--- docs/installing/requirements.rst 2011-01-21 13:56:53 +0000
+++ docs/installing/requirements.rst 2011-01-24 09:18:02 +0000
@@ -18,7 +18,8 @@
18 * Apple OSX 10.6.418 * Apple OSX 10.6.4
1919
20We recommend using these platforms with Drizzle, older version may have various20We recommend using these platforms with Drizzle, older version may have various
21unforseen difficulties when compiling and/or installing.21unforseen difficulties when compiling and/or installing. Drizzle is tested on
22both 32bit and 64bit platforms but we recommend using a 64bit platform.
2223
23Software Requirements24Software Requirements
24---------------------25---------------------
2526
=== added file 'm4/pandora_have_libboost_test.m4'
--- m4/pandora_have_libboost_test.m4 1970-01-01 00:00:00 +0000
+++ m4/pandora_have_libboost_test.m4 2011-01-24 09:18:02 +0000
@@ -0,0 +1,45 @@
1dnl Copyright (C) 2011 Andrew Hutchings
2dnl This file is free software; Andrew Hutchings
3dnl gives unlimited permission to copy and/or distribute it,
4dnl with or without modifications, as long as this notice is preserved.
5
6AC_DEFUN([_PANDORA_SEARCH_BOOST_TEST],[
7 AC_REQUIRE([AC_LIB_PREFIX])
8
9 dnl --------------------------------------------------------------------
10 dnl Check for boost::test
11 dnl --------------------------------------------------------------------
12
13 AC_LANG_PUSH(C++)
14 AC_LIB_HAVE_LINKFLAGS(boost_unit_test_framework-mt,,[
15 #include <boost/test/unit_test.hpp>
16 ],[
17 boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages);
18 ])
19 AS_IF([test "x${ac_cv_libboost_test_framework_mt}" = "xno"],[
20 AC_LIB_HAVE_LINKFLAGS(boost_unit_test_framework,,[
21 #include <boost/test/unit_test.hpp>
22 ],[
23 boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages);
24 ])
25 ])
26 AC_LANG_POP()
27
28 AM_CONDITIONAL(HAVE_BOOST_TEST,
29 [test "x${ac_cv_libboost_test_framework}" = "xyes" -o "x${ac_cv_libboost_test_framework_mt}" = "xyes"])
30 BOOST_LIBS="${BOOST_LIBS} ${LTLIBBOOST_TEST_MT} ${LTLIBBOOST_TEST}"
31 AC_SUBST(BOOST_LIBS)
32])
33
34AC_DEFUN([PANDORA_HAVE_BOOST_TEST],[
35 PANDORA_HAVE_BOOST($1)
36 _PANDORA_SEARCH_BOOST_TEST($1)
37])
38
39AC_DEFUN([PANDORA_REQUIRE_BOOST_TEST],[
40 PANDORA_REQUIRE_BOOST($1)
41 _PANDORA_SEARCH_BOOST_TEST($1)
42 AS_IF([test "x${ac_cv_libboost_test_framework}" = "xno" -a "x${ac_cv_libboost_test_framework_mt}" = "xno"],
43 AC_MSG_ERROR([boost::test is required for ${PACKAGE}]))
44])
45
046
=== removed file 'm4/pandora_have_libgtest.m4'
--- m4/pandora_have_libgtest.m4 2010-09-19 18:03:28 +0000
+++ m4/pandora_have_libgtest.m4 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1dnl Copyright (C) 2010 Monty Taylor
2dnl This file is free software; Monty Taylor
3dnl gives unlimited permission to copy and/or distribute it,
4dnl with or without modifications, as long as this notice is preserved.
5
6AC_DEFUN([_PANDORA_SEARCH_LIBGTEST],[
7 AC_REQUIRE([AC_LIB_PREFIX])
8
9 dnl --------------------------------------------------------------------
10 dnl Check for libgtest
11 dnl --------------------------------------------------------------------
12
13 AC_ARG_ENABLE([libgtest],
14 [AS_HELP_STRING([--disable-libgtest],
15 [Build with libgtest support @<:@default=on@:>@])],
16 [ac_enable_libgtest="$enableval"],
17 [ac_enable_libgtest="yes"])
18
19 AS_IF([test "x$ac_enable_libgtest" = "xyes"],[
20 AC_LANG_PUSH(C++)
21 save_CXXFLAGS="${CXXFLAGS}"
22 CXXFLAGS="${AM_CXXFLAGS} ${CXXFLAGS}"
23 AC_LIB_HAVE_LINKFLAGS(gtest,,[
24 #include <gtest/gtest.h>
25TEST(pandora_test_libgtest, PandoraTest)
26{
27 ASSERT_EQ(1, 1);
28}
29 ],[])
30 CXXFLAGS="${save_CXXFLAGS}"
31 AC_LANG_POP()
32 ],[
33 ac_cv_libgtest="no"
34 ])
35
36 AM_CONDITIONAL(HAVE_LIBGTEST, [test "x${ac_cv_libgtest}" = "xyes"])
37])
38
39AC_DEFUN([PANDORA_HAVE_LIBGTEST],[
40 AC_REQUIRE([_PANDORA_SEARCH_LIBGTEST])
41])
42
43AC_DEFUN([PANDORA_REQUIRE_LIBGTEST],[
44 AC_REQUIRE([_PANDORA_SEARCH_LIBGTEST])
45 AS_IF([test "x${ac_cv_libgtest}" = "xno"],
46 AC_MSG_ERROR([libgtest is required for ${PACKAGE}]))
47])
480
=== modified file 'unittests/atomics_test.cc'
--- unittests/atomics_test.cc 2010-10-20 09:32:35 +0000
+++ unittests/atomics_test.cc 2011-01-24 09:18:02 +0000
@@ -19,101 +19,87 @@
19 */19 */
2020
21#include "config.h"21#include "config.h"
2222#define BOOST_TEST_DYN_LINK
23#include <gtest/gtest.h>23#include <boost/test/unit_test.hpp>
2424
25#include <drizzled/atomics.h>25#include <drizzled/atomics.h>
2626
27using namespace drizzled;27using namespace drizzled;
2828
29TEST(atomic_operations, fetch_and_store)29BOOST_AUTO_TEST_SUITE(AtomicOperations)
30{30BOOST_AUTO_TEST_CASE(fetch_and_store)
31 atomic<uint32_t> u235;31{
3232 atomic<uint32_t> u235;
33 EXPECT_EQ(0, u235.fetch_and_store(1));33
3434 BOOST_REQUIRE_EQUAL(0, u235.fetch_and_store(1));
35 u235.fetch_and_store(15);35
3636 u235.fetch_and_store(15);
37 EXPECT_EQ(15, u235.fetch_and_store(100));37
38 EXPECT_EQ(100, u235);38 BOOST_REQUIRE_EQUAL(15, u235.fetch_and_store(100));
39}39 BOOST_REQUIRE_EQUAL(100, u235);
4040}
41TEST(atomic_operations, fetch_and_increment)41
42{42BOOST_AUTO_TEST_CASE(fetch_and_increment)
43 atomic<uint32_t> u235;43{
4444 atomic<uint32_t> u235;
45 EXPECT_EQ(0, u235.fetch_and_increment());45
46 EXPECT_EQ(1, u235);46 BOOST_REQUIRE_EQUAL(0, u235.fetch_and_increment());
47}47 BOOST_REQUIRE_EQUAL(1, u235);
4848}
49TEST(atomic_operations, fetch_and_add)49
50{50BOOST_AUTO_TEST_CASE(fetch_and_add)
51 atomic<uint32_t> u235;51{
5252 atomic<uint32_t> u235;
53 EXPECT_EQ(0, u235.fetch_and_add(2));53
54 EXPECT_EQ(2, u235);54 BOOST_REQUIRE_EQUAL(0, u235.fetch_and_add(2));
55}55 BOOST_REQUIRE_EQUAL(2, u235);
5656}
57TEST(atomic_operations, add_and_fetch)57
58{58BOOST_AUTO_TEST_CASE(add_and_fetch)
59 atomic<uint32_t> u235;59{
6060 atomic<uint32_t> u235;
61 EXPECT_EQ(10, u235.add_and_fetch(10));61
62 EXPECT_EQ(10, u235);62 BOOST_REQUIRE_EQUAL(10, u235.add_and_fetch(10));
63}63 BOOST_REQUIRE_EQUAL(10, u235);
6464}
65TEST(atomic_operations, fetch_and_decrement)65
66{66BOOST_AUTO_TEST_CASE(fetch_and_decrement)
67 atomic<uint32_t> u235;67{
6868 atomic<uint32_t> u235;
69 u235.fetch_and_store(15);69
7070 u235.fetch_and_store(15);
71 EXPECT_EQ(15, u235.fetch_and_decrement());71
72 EXPECT_EQ(14, u235);72 BOOST_REQUIRE_EQUAL(15, u235.fetch_and_decrement());
73}73 BOOST_REQUIRE_EQUAL(14, u235);
7474}
75TEST(atomic_operations, compare_and_swap)75
76BOOST_AUTO_TEST_CASE(compare_and_swap)
76{77{
77 atomic<uint32_t> u235;78 atomic<uint32_t> u235;
7879
79 u235.fetch_and_store(100);80 u235.fetch_and_store(100);
8081
81 ASSERT_FALSE(u235.compare_and_swap(42, 200));82 BOOST_REQUIRE(not u235.compare_and_swap(42, 200));
82 ASSERT_TRUE(u235.compare_and_swap(200, 100));83 BOOST_REQUIRE(u235.compare_and_swap(200, 100));
83 EXPECT_EQ(200, u235);84 BOOST_REQUIRE_EQUAL(200, u235);
84}85}
8586
86TEST(atomic_operations, increment)87BOOST_AUTO_TEST_CASE(increment)
87{88{
88 atomic<uint32_t> u235;89 atomic<uint32_t> u235;
89 u235.fetch_and_store(200);90 u235.fetch_and_store(200);
90 EXPECT_EQ(201, u235.increment());91 BOOST_REQUIRE_EQUAL(201, u235.increment());
91}92}
9293
93TEST(atomic_operations, decrement)94BOOST_AUTO_TEST_CASE(decrement)
94{95{
95 atomic<uint32_t> u235;96 atomic<uint32_t> u235;
96 u235.fetch_and_store(200);97 u235.fetch_and_store(200);
9798
98 EXPECT_EQ(199, u235.decrement());99 BOOST_REQUIRE_EQUAL(199, u235.decrement());
99}100}
100101
101/*102BOOST_AUTO_TEST_SUITE_END()
102TEST(atomic_operations, increment_assign)103
103{104/* TODO: add tests for += and -= when supported */
104 atomic<uint32_t> u235;
105 u235.fetch_and_store(200);
106
107 EXPECT_EQ(242, u235+=42);
108}
109
110TEST(atomic_operations, decrement_assign)
111{
112 atomic<uint32_t> u235;
113 u235.fetch_and_store(200);
114
115 EXPECT_EQ(158, u235-=42);
116}
117*/
118
119105
120106
=== modified file 'unittests/calendar_test.cc'
--- unittests/calendar_test.cc 2011-01-20 07:24:29 +0000
+++ unittests/calendar_test.cc 2011-01-24 09:18:02 +0000
@@ -19,113 +19,113 @@
19 */19 */
2020
21#include "config.h"21#include "config.h"
2222#define BOOST_TEST_DYN_LINK
23#include <gtest/gtest.h>23#include <boost/test/unit_test.hpp>
2424
25#include <drizzled/calendar.h>25#include <drizzled/calendar.h>
2626
27using namespace drizzled;27using namespace drizzled;
2828BOOST_AUTO_TEST_SUITE(CalculationTest)
29TEST(calendar_julian_day_number_from_gregorian_date_test, CalculationTest)29BOOST_AUTO_TEST_CASE(calendar_julian_day_number_from_gregorian_date_test)
30{30{
31 uint32_t year, month, day;31 uint32_t year, month, day;
3232
33 year= 2010; month= 4; day= 2;33 year= 2010; month= 4; day= 2;
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));
35 35
36 year= 1976; month= 12; day= 21;36 year= 1976; month= 12; day= 21;
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));
38 38
39 year= 2050; month= 6; day= 15;39 year= 2050; month= 6; day= 15;
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));
41 41
42 year= 1999; month= 12; day= 31;42 year= 1999; month= 12; day= 31;
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));
44 44
45 year= 2008; month= 2; day= 29;45 year= 2008; month= 2; day= 29;
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));
47}47}
4848
49TEST(calendar_gregorian_date_from_julian_day_number_test, CalculationTest)49BOOST_AUTO_TEST_CASE(calendar_gregorian_date_from_julian_day_number_test)
50{50{
51 int64_t julian_day;51 int64_t julian_day;
52 uint32_t year_out, month_out, day_out;52 uint32_t year_out, month_out, day_out;
53 53
54 julian_day= 2455289;54 julian_day= 2455289;
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);
56 EXPECT_TRUE((year_out == 2010) && (month_out == 4) && (day_out == 2));56 BOOST_REQUIRE((year_out == 2010) && (month_out == 4) && (day_out == 2));
57 57
58 julian_day= 2443134;58 julian_day= 2443134;
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);
60 EXPECT_TRUE((year_out == 1976) && (month_out == 12) && (day_out == 21));60 BOOST_REQUIRE((year_out == 1976) && (month_out == 12) && (day_out == 21));
61 61
62 julian_day= 2469973;62 julian_day= 2469973;
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);
64 EXPECT_TRUE((year_out == 2050) && (month_out == 6) && (day_out == 15));64 BOOST_REQUIRE((year_out == 2050) && (month_out == 6) && (day_out == 15));
65 65
66 julian_day= 2451544;66 julian_day= 2451544;
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);
68 EXPECT_TRUE((year_out == 1999) && (month_out == 12) && (day_out == 31));68 BOOST_REQUIRE((year_out == 1999) && (month_out == 12) && (day_out == 31));
69 69
70 julian_day= 2454526;70 julian_day= 2454526;
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);
72 EXPECT_TRUE((year_out == 2008) && (month_out == 2) && (day_out == 29));72 BOOST_REQUIRE((year_out == 2008) && (month_out == 2) && (day_out == 29));
73}73}
7474BOOST_AUTO_TEST_SUITE_END()
7575
7676BOOST_AUTO_TEST_SUITE(DayOfWeek)
7777BOOST_AUTO_TEST_CASE(MondayFirst)
78TEST(calendar_day_of_week_test, MondayFirst)78{
79{79 /* Friday 2010 IV 2 */
80 /* Friday 2010 IV 2 */80 BOOST_REQUIRE_EQUAL(4, day_of_week(2455289, false));
81 ASSERT_EQ(4, day_of_week(2455289, false));81}
82}82
8383BOOST_AUTO_TEST_CASE(SundayFirst)
84TEST(calendar_day_of_week_test, SundayFirst)84{
85{85 /* Friday 2010 IV 2 */
86 /* Friday 2010 IV 2 */86 BOOST_REQUIRE_EQUAL(5, day_of_week(2455289, true));
87 ASSERT_EQ(5, day_of_week(2455289, true));87}
88}88BOOST_AUTO_TEST_SUITE_END()
8989
9090
9191BOOST_AUTO_TEST_SUITE(CalendarInUnixEpochRange)
9292BOOST_AUTO_TEST_CASE(MinOfRange)
93TEST(calendar_in_unix_epoch_range_test, MinOfRange)
94{93{
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;
9695
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));
98}97}
9998
100TEST(calendar_in_unix_epoch_range_test, MaxOfRange)99BOOST_AUTO_TEST_CASE(MaxOfRange)
101{100{
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;
103102
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));
105}104}
106105
107TEST(calendar_in_unix_epoch_range_test, OneSecondBeforeMinOfRange)106BOOST_AUTO_TEST_CASE(OneSecondBeforeMinOfRange)
108{107{
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;
110109
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));
112}111}
113112
114TEST(calendar_in_unix_epoch_range_test, OneSecondAfterMaxOfRange)113BOOST_AUTO_TEST_CASE(OneSecondAfterMaxOfRange)
115{114{
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;
117116
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));
119}118}
120119
121TEST(calendar_in_unix_epoch_range_test, InsideRange)120BOOST_AUTO_TEST_CASE(InsideRange)
122{121{
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;
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));
125124
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;
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));
128127
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;
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));
131}130}
131BOOST_AUTO_TEST_SUITE_END()
132132
=== removed file 'unittests/client_server.c'
--- unittests/client_server.c 2010-12-04 02:13:38 +0000
+++ unittests/client_server.c 1970-01-01 00:00:00 +0000
@@ -1,567 +0,0 @@
1/*
2 * Drizzle Client & Protocol Library
3 *
4 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37/**
38 * @file
39 * @brief Tests for drizzle_st Structures
40 */
41
42#include "common.h"
43
44#include <assert.h>
45
46#define DRIZZLE_TEST_HOST "127.0.0.1"
47#define DRIZZLE_TEST_PORT 12399
48
49typedef enum
50{
51 SERVER_STATE_START,
52 SERVER_STATE_HANDSHAKE_WRITE,
53 SERVER_STATE_HANDSHAKE_READ,
54 SERVER_STATE_HANDSHAKE_RESULT,
55 SERVER_STATE_COMMAND_BUFFER,
56 SERVER_STATE_RESULT_HEADER,
57 SERVER_STATE_RESULT_COLUMN_1,
58 SERVER_STATE_RESULT_COLUMN_2,
59 SERVER_STATE_RESULT_COLUMN_EOF,
60 SERVER_STATE_RESULT_ROW_1,
61 SERVER_STATE_RESULT_ROW_1_FIELD_1,
62 SERVER_STATE_RESULT_ROW_1_FIELD_2,
63 SERVER_STATE_RESULT_ROW_EOF,
64 SERVER_STATE_DONE
65} server_state_t;
66
67typedef struct
68{
69 server_state_t state;
70 drizzle_result_st result;
71 drizzle_column_st column;
72 drizzle_command_t command;
73 char *data;
74 size_t total;
75} server_state_st;
76
77typedef enum
78{
79 CLIENT_STATE_START,
80 CLIENT_STATE_RESULT,
81 CLIENT_STATE_DONE
82} client_state_t;
83
84typedef struct
85{
86 client_state_t state;
87 drizzle_result_st result;
88} client_state_st;
89
90static void _server(drizzle_con_st *con, server_state_st *state);
91static void _client(drizzle_con_st *con, client_state_st *state);
92
93int main(void)
94{
95 drizzle_st drizzle;
96 drizzle_con_st listen_con;
97 drizzle_con_st client;
98 drizzle_con_st server;
99 drizzle_return_t ret;
100 bool server_accepted = false;
101 server_state_st server_state;
102 client_state_st client_state;
103
104 drizzle_test("drizzle_create");
105 if (drizzle_create(&drizzle) == NULL)
106 drizzle_test_error("returned NULL");
107
108 drizzle_test("drizzle_con_add_tcp_listen");
109 if (drizzle_con_add_tcp_listen(&drizzle, &listen_con, DRIZZLE_TEST_HOST,
110 DRIZZLE_TEST_PORT, 1,
111 DRIZZLE_CON_NONE) == NULL)
112 {
113 drizzle_test_error("returned NULL");
114 }
115
116 drizzle_test("drizzle_con_listen");
117 ret= drizzle_con_listen(&listen_con);
118 if (ret != DRIZZLE_RETURN_OK)
119 drizzle_test_error("returned %s (%d)", drizzle_error(&drizzle), ret);
120
121 drizzle_test("drizzle_con_add_tcp");
122 if (drizzle_con_add_tcp(&drizzle, &client, DRIZZLE_TEST_HOST,
123 DRIZZLE_TEST_PORT, NULL, NULL, NULL,
124 DRIZZLE_CON_NONE) == NULL)
125 {
126 drizzle_test_error("returned NULL");
127 }
128
129 drizzle_test("drizzle_add_options");
130 drizzle_add_options(&drizzle, DRIZZLE_NON_BLOCKING);
131
132 server_state.state= SERVER_STATE_START;
133 client_state.state= CLIENT_STATE_START;
134
135 while (true)
136 {
137 if (!server_accepted)
138 {
139 drizzle_test("drizzle_con_accept");
140 (void)drizzle_con_accept(&drizzle, &server, &ret);
141 if (ret == DRIZZLE_RETURN_OK)
142 server_accepted = true;
143 else if (ret != DRIZZLE_RETURN_IO_WAIT)
144 drizzle_test_error("returned %s (%d)", drizzle_error(&drizzle), ret);
145 }
146
147 if (server_accepted)
148 _server(&server, &server_state);
149
150 _client(&client, &client_state);
151
152 if (server_state.state == SERVER_STATE_DONE &&
153 client_state.state == CLIENT_STATE_DONE)
154 {
155 break;
156 }
157
158 drizzle_test("drizzle_con_wait");
159 ret= drizzle_con_wait(&drizzle);
160 if (ret != DRIZZLE_RETURN_OK)
161 drizzle_test_error("returned %s (%d)", drizzle_error(&drizzle), ret);
162 }
163
164 if (server_accepted)
165 {
166 drizzle_test("drizzle_con_free");
167 drizzle_con_free(&server);
168 }
169
170 drizzle_test("drizzle_con_free");
171 drizzle_con_free(&client);
172
173 drizzle_test("drizzle_con_free");
174 drizzle_con_free(&listen_con);
175
176 drizzle_test("drizzle_free");
177 drizzle_free(&drizzle);
178
179 return 0;
180}
181
182static void _server(drizzle_con_st *con, server_state_st *state)
183{
184 drizzle_return_t ret;
185 const drizzle_field_t const fields[2]=
186 {
187 (const drizzle_field_t)"test_field_1",
188 (const drizzle_field_t)"test_field_2"
189 };
190 const size_t field_sizes[2]= { 12, 12 };
191
192 switch(state->state)
193 {
194 case SERVER_STATE_START:
195 drizzle_con_set_protocol_version(con, 10);
196 drizzle_con_set_server_version(con, "test_version");
197 drizzle_con_set_thread_id(con, 1);
198 drizzle_con_set_scramble(con, (const uint8_t *)"ABCDEFGHIJKLMNOPQRST");
199 drizzle_con_set_capabilities(con, DRIZZLE_CAPABILITIES_NONE);
200 drizzle_con_set_charset(con, 8);
201 drizzle_con_set_status(con, DRIZZLE_CON_STATUS_NONE);
202 drizzle_con_set_max_packet_size(con, DRIZZLE_MAX_PACKET_SIZE);
203
204 case SERVER_STATE_HANDSHAKE_WRITE:
205 drizzle_test("drizzle_handshake_server_write");
206 ret= drizzle_handshake_server_write(con);
207 if (ret == DRIZZLE_RETURN_IO_WAIT)
208 {
209 state->state = SERVER_STATE_HANDSHAKE_WRITE;
210 return;
211 }
212 else if (ret != DRIZZLE_RETURN_OK)
213 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
214
215 case SERVER_STATE_HANDSHAKE_READ:
216 drizzle_test("drizzle_handshake_client_read");
217 ret= drizzle_handshake_client_read(con);
218 if (ret == DRIZZLE_RETURN_IO_WAIT)
219 {
220 state->state = SERVER_STATE_HANDSHAKE_READ;
221 return;
222 }
223 else if (ret != DRIZZLE_RETURN_OK)
224 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
225
226 drizzle_test("drizzle_result_create");
227 if (drizzle_result_create(con, &state->result) == NULL)
228 drizzle_test_error("returned %s", drizzle_con_error(con));
229
230 case SERVER_STATE_HANDSHAKE_RESULT:
231 drizzle_test("drizzle_handshake_result_write");
232 ret= drizzle_result_write(con, &state->result, true);
233 if (ret == DRIZZLE_RETURN_IO_WAIT)
234 {
235 state->state = SERVER_STATE_HANDSHAKE_RESULT;
236 return;
237 }
238 else if (ret != DRIZZLE_RETURN_OK)
239 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
240
241 drizzle_result_free(&state->result);
242
243 case SERVER_STATE_COMMAND_BUFFER:
244 drizzle_test("drizzle_con_command_buffer");
245 state->data= drizzle_con_command_buffer(con, &state->command, &state->total,
246 &ret);
247 if (ret == DRIZZLE_RETURN_IO_WAIT)
248 {
249 state->state = SERVER_STATE_COMMAND_BUFFER;
250 return;
251 }
252 else if (ret != DRIZZLE_RETURN_OK)
253 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
254
255 if (state->command != DRIZZLE_COMMAND_QUERY)
256 drizzle_test_error("command was not a query");
257
258 if (state->total != 6 && !memcmp(state->data, "SELECT", 6))
259 drizzle_test_error("query doesn't match");
260
261 if (state->data != NULL)
262 {
263 free(state->data);
264 state->data= NULL;
265 }
266
267 drizzle_test("drizzle_result_create");
268 if (drizzle_result_create(con, &state->result) == NULL)
269 drizzle_test_error("returned %s", drizzle_con_error(con));
270
271 drizzle_result_set_column_count(&state->result, 2);
272
273 case SERVER_STATE_RESULT_HEADER:
274 drizzle_test("drizzle_handshake_result_write");
275 ret= drizzle_result_write(con, &state->result, false);
276 if (ret == DRIZZLE_RETURN_IO_WAIT)
277 {
278 state->state = SERVER_STATE_RESULT_HEADER;
279 return;
280 }
281 else if (ret != DRIZZLE_RETURN_OK)
282 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
283
284 drizzle_test("drizzle_column_create");
285 if (drizzle_column_create(&state->result, &state->column) == NULL)
286 drizzle_test_error("returned %s", drizzle_con_error(con));
287
288 drizzle_column_set_catalog(&state->column, "test_catalog");
289 drizzle_column_set_db(&state->column, "test_db");
290 drizzle_column_set_table(&state->column, "test_table");
291 drizzle_column_set_orig_table(&state->column, "test_orig_table");
292 drizzle_column_set_name(&state->column, "test_column_1");
293 drizzle_column_set_orig_name(&state->column, "test_orig_column_1");
294 drizzle_column_set_charset(&state->column, 8);
295 drizzle_column_set_size(&state->column, 32);
296 drizzle_column_set_type(&state->column, DRIZZLE_COLUMN_TYPE_VARCHAR);
297 drizzle_column_set_flags(&state->column, DRIZZLE_COLUMN_FLAGS_NONE);
298
299 case SERVER_STATE_RESULT_COLUMN_1:
300 drizzle_test("drizzle_column_write");
301 ret= drizzle_column_write(&state->result, &state->column);
302 if (ret == DRIZZLE_RETURN_IO_WAIT)
303 {
304 state->state = SERVER_STATE_RESULT_COLUMN_1;
305 return;
306 }
307 else if (ret != DRIZZLE_RETURN_OK)
308 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
309
310 drizzle_column_set_name(&state->column, "test_column_2");
311 drizzle_column_set_orig_name(&state->column, "test_orig_column_2");
312
313 case SERVER_STATE_RESULT_COLUMN_2:
314 drizzle_test("drizzle_column_write");
315 ret= drizzle_column_write(&state->result, &state->column);
316 if (ret == DRIZZLE_RETURN_IO_WAIT)
317 {
318 state->state = SERVER_STATE_RESULT_COLUMN_2;
319 return;
320 }
321 else if (ret != DRIZZLE_RETURN_OK)
322 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
323
324 drizzle_test("drizzle_column_free");
325 drizzle_column_free(&state->column);
326
327 drizzle_result_set_eof(&state->result, true);
328
329 case SERVER_STATE_RESULT_COLUMN_EOF:
330 drizzle_test("drizzle_handshake_result_write");
331 ret= drizzle_result_write(con, &state->result, false);
332 if (ret == DRIZZLE_RETURN_IO_WAIT)
333 {
334 state->state = SERVER_STATE_RESULT_COLUMN_EOF;
335 return;
336 }
337 else if (ret != DRIZZLE_RETURN_OK)
338 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
339
340 drizzle_result_calc_row_size(&state->result, fields, field_sizes);
341
342 case SERVER_STATE_RESULT_ROW_1:
343 ret= drizzle_row_write(&state->result);
344
345 case SERVER_STATE_RESULT_ROW_1_FIELD_1:
346 ret= drizzle_field_write(&state->result, fields[0], field_sizes[0],
347 field_sizes[0]);
348
349 case SERVER_STATE_RESULT_ROW_1_FIELD_2:
350 ret= drizzle_field_write(&state->result, fields[1], field_sizes[1],
351 field_sizes[1]);
352
353 case SERVER_STATE_RESULT_ROW_EOF:
354 drizzle_test("drizzle_handshake_result_write");
355 ret= drizzle_result_write(con, &state->result, true);
356 if (ret == DRIZZLE_RETURN_IO_WAIT)
357 {
358 state->state = SERVER_STATE_RESULT_ROW_EOF;
359 return;
360 }
361 else if (ret != DRIZZLE_RETURN_OK)
362 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
363
364 drizzle_result_free(&state->result);
365
366 state->state = SERVER_STATE_DONE;
367
368 case SERVER_STATE_DONE:
369 return;
370
371 default:
372 drizzle_test_error("invalid server state");
373 }
374}
375
376static void _client(drizzle_con_st *con, client_state_st *state)
377{
378 drizzle_return_t ret;
379 drizzle_column_st *column;
380 drizzle_row_t row;
381 size_t *field_sizes;
382
383 switch(state->state)
384 {
385 case CLIENT_STATE_START:
386 drizzle_test("drizzle_query_str");
387 (void)drizzle_query_str(con, &state->result, "SELECT", &ret);
388 if (ret == DRIZZLE_RETURN_IO_WAIT)
389 {
390 state->state = CLIENT_STATE_START;
391 return;
392 }
393 else if (ret != DRIZZLE_RETURN_OK)
394 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
395
396 case CLIENT_STATE_RESULT:
397 drizzle_test("drizzle_result_buffer");
398 ret = drizzle_result_buffer(&state->result);
399 if (ret == DRIZZLE_RETURN_IO_WAIT)
400 {
401 state->state = CLIENT_STATE_RESULT;
402 return;
403 }
404 else if (ret != DRIZZLE_RETURN_OK)
405 drizzle_test_error("returned %s (%d)", drizzle_con_error(con), ret);
406
407 drizzle_test("drizzle_con_protocol_version");
408 if (drizzle_con_protocol_version(con) != 10)
409 drizzle_test_error("no match");
410
411 drizzle_test("drizzle_con_server_version");
412 if (strcmp(drizzle_con_server_version(con), "test_version"))
413 drizzle_test_error("no match");
414
415 drizzle_test("drizzle_con_thread_id");
416 if (drizzle_con_thread_id(con) != 1)
417 drizzle_test_error("no match");
418
419 drizzle_test("drizzle_con_scramble");
420 if (memcmp(drizzle_con_scramble(con), "ABCDEFGHIJKLMNOPQRST",
421 DRIZZLE_MAX_SCRAMBLE_SIZE))
422 {
423 drizzle_test_error("no match");
424 }
425
426 /* We default to MySQL protocol right now, which sets this flag. */
427 drizzle_test("drizzle_con_capabilities");
428 if (drizzle_con_capabilities(con) != DRIZZLE_CAPABILITIES_PROTOCOL_41)
429 drizzle_test_error("no match");
430
431 drizzle_test("drizzle_con_charset");
432 if (drizzle_con_charset(con) != 8)
433 drizzle_test_error("no match");
434
435 drizzle_test("drizzle_con_status");
436 if (drizzle_con_status(con) != DRIZZLE_CON_STATUS_NONE)
437 drizzle_test_error("no match");
438
439 drizzle_test("drizzle_con_packet_size");
440 if (drizzle_con_max_packet_size(con) != DRIZZLE_MAX_PACKET_SIZE)
441 drizzle_test_error("no match");
442
443 drizzle_test("drizzle_column_next");
444 column= drizzle_column_next(&state->result);
445 if (column == NULL)
446 drizzle_test_error("column not found");
447
448 drizzle_test("drizzle_column_drizzle_result");
449 if (drizzle_column_drizzle_result(column) != &state->result)
450 drizzle_test_error("no match");
451
452 drizzle_test("drizzle_column_catalog");
453 if (strcmp(drizzle_column_catalog(column), "test_catalog"))
454 drizzle_test_error("no match");
455
456 drizzle_test("drizzle_column_db");
457 if (strcmp(drizzle_column_db(column), "test_db"))
458 drizzle_test_error("no match");
459
460 drizzle_test("drizzle_column_table");
461 if (strcmp(drizzle_column_table(column), "test_table"))
462 drizzle_test_error("no match");
463
464 drizzle_test("drizzle_column_orig_table");
465 if (strcmp(drizzle_column_orig_table(column), "test_orig_table"))
466 drizzle_test_error("no match");
467
468 drizzle_test("drizzle_column_name");
469 if (strcmp(drizzle_column_name(column), "test_column_1"))
470 drizzle_test_error("no match");
471
472 drizzle_test("drizzle_column_orig_name");
473 if (strcmp(drizzle_column_orig_name(column), "test_orig_column_1"))
474 drizzle_test_error("no match");
475
476 drizzle_test("drizzle_column_charset");
477 if (drizzle_column_charset(column) != 8)
478 drizzle_test_error("no match");
479
480 drizzle_test("drizzle_column_size");
481 if (drizzle_column_size(column) != 32)
482 drizzle_test_error("no match");
483
484 drizzle_test("drizzle_column_max_size");
485 if (drizzle_column_max_size(column) != 12)
486 drizzle_test_error("no match");
487
488 drizzle_test("drizzle_column_type_drizzle");
489 if (drizzle_column_type_drizzle(column) != DRIZZLE_COLUMN_TYPE_DRIZZLE_VARCHAR)
490 drizzle_test_error("no match");
491
492 drizzle_test("drizzle_column_flags");
493 if (drizzle_column_flags(column) != DRIZZLE_COLUMN_FLAGS_NONE)
494 drizzle_test_error("no match");
495
496 drizzle_test("drizzle_column_next");
497 column= drizzle_column_next(&state->result);
498 if (column == NULL)
499 drizzle_test_error("column not found");
500
501 drizzle_test("drizzle_column_name");
502 if (strcmp(drizzle_column_name(column), "test_column_2"))
503 drizzle_test_error("no match");
504
505 drizzle_test("drizzle_column_next");
506 column= drizzle_column_next(&state->result);
507 if (column != NULL)
508 drizzle_test_error("column found");
509
510 drizzle_test("drizzle_column_prev");
511 column= drizzle_column_prev(&state->result);
512 if (column == NULL)
513 drizzle_test_error("column not found");
514
515 drizzle_test("drizzle_column_name");
516 if (strcmp(drizzle_column_name(column), "test_column_2"))
517 drizzle_test_error("no match");
518
519 drizzle_test("drizzle_row_next");
520 row= drizzle_row_next(&state->result);
521 if (row == NULL)
522 drizzle_test_error("row not found");
523
524 if (strcmp(row[0], "test_field_1") || strcmp(row[1], "test_field_2"))
525 drizzle_test_error("no match");
526
527 drizzle_test("drizzle_row_field_sizes");
528 field_sizes= drizzle_row_field_sizes(&state->result);
529 if (field_sizes[0] != 12 || field_sizes[1] != 12)
530 drizzle_test_error("no match");
531
532 drizzle_test("drizzle_row_prev");
533 row = drizzle_row_prev(&state->result);
534 if (row == NULL)
535 drizzle_test_error("row not found");
536
537 if (strcmp(row[0], "test_field_1") || strcmp(row[1], "test_field_2"))
538 drizzle_test_error("no match");
539
540 drizzle_test("drizzle_row_next");
541 row = drizzle_row_next(&state->result);
542
543 drizzle_test("drizzle_row_index");
544 row = drizzle_row_index(&state->result, 0);
545 if (row == NULL)
546 drizzle_test_error("row not found");
547
548 if (strcmp(row[0], "test_field_1") || strcmp(row[1], "test_field_2"))
549 drizzle_test_error("no match");
550
551 drizzle_test("drizzle_row_index");
552 row = drizzle_row_index(&state->result, 1);
553 if (row != NULL)
554 drizzle_test_error("row found");
555
556 drizzle_test("drizzle_result_free");
557 drizzle_result_free(&state->result);
558
559 state->state = CLIENT_STATE_DONE;
560
561 case CLIENT_STATE_DONE:
562 return;
563
564 default:
565 drizzle_test_error("invalid client state");
566 }
567}
5680
=== added file 'unittests/constrained_value.cc'
--- unittests/constrained_value.cc 1970-01-01 00:00:00 +0000
+++ unittests/constrained_value.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,58 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Monty Taylor
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <string>
24
25#define BOOST_TEST_DYN_LINK
26#include <boost/test/unit_test.hpp>
27
28#include <drizzled/constrained_value.h>
29#include <boost/lexical_cast.hpp>
30
31using namespace drizzled;
32
33namespace po= boost::program_options;
34
35BOOST_AUTO_TEST_SUITE(ConstrainedValue)
36BOOST_AUTO_TEST_CASE(raw_usage)
37{
38 constrained_check<uint64_t,1024,1,10> val(1);
39
40 BOOST_REQUIRE_EQUAL(UINT64_C(1), (uint64_t)val);
41
42 BOOST_REQUIRE_THROW(val= 1025 , po::validation_error);
43 BOOST_REQUIRE_THROW(val= 0 , po::validation_error);
44
45 val= 25;
46
47 BOOST_REQUIRE_EQUAL(20, (uint64_t)val);
48}
49
50BOOST_AUTO_TEST_CASE(lexical_cast_usage)
51{
52 constrained_check<uint64_t,1024,1,10> val(1);
53
54 std::string string_val= boost::lexical_cast<std::string>(val);
55
56 BOOST_REQUIRE_EQUAL(std::string("1"), string_val);
57}
58BOOST_AUTO_TEST_SUITE_END()
059
=== removed file 'unittests/constrained_value.cc'
--- unittests/constrained_value.cc 2010-10-19 21:51:42 +0000
+++ unittests/constrained_value.cc 1970-01-01 00:00:00 +0000
@@ -1,57 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Monty Taylor
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <string>
24
25#include <gtest/gtest.h>
26
27#include <drizzled/constrained_value.h>
28#include <boost/lexical_cast.hpp>
29
30using namespace drizzled;
31
32namespace po= boost::program_options;
33
34TEST(constrained_value, raw_usage)
35{
36 constrained_check<uint64_t,1024,1,10> val(1);
37
38 EXPECT_EQ(UINT64_C(1), (uint64_t)val);
39
40 ASSERT_THROW(val= 1025 , po::validation_error);
41 ASSERT_THROW(val= 0 , po::validation_error);
42
43 val= 25;
44
45 EXPECT_EQ(20, (uint64_t)val);
46}
47
48TEST(constrained_value, lexical_cast_usage)
49{
50 constrained_check<uint64_t,1024,1,10> val(1);
51
52 std::string string_val= boost::lexical_cast<std::string>(val);
53
54 EXPECT_EQ(std::string("1"), string_val);
55}
56
57
580
=== added file 'unittests/date_test.cc'
--- unittests/date_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/date_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,562 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <drizzled/type/decimal.h>
27#include <drizzled/temporal.h>
28#include <drizzled/temporal_format.h>
29
30#include "temporal_generator.h"
31
32using namespace drizzled;
33
34class DateTestCompareOperators
35{
36 protected:
37 Date sample_date;
38 bool result;
39
40 Date identical_with_sample_date, before_sample_date, after_sample_date;
41
42 DateTestCompareOperators()
43 {
44 TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8);
45 TemporalGenerator::DateGen::make_date(&before_sample_date, 1980, 1, 1);
46 TemporalGenerator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8);
47 TemporalGenerator::DateGen::make_date(&after_sample_date, 2019, 5, 30);
48 }
49};
50
51class DateTimeTestCompareOperators
52{
53 protected:
54 Date sample_date;
55 bool result;
56
57 DateTime identical_with_sample_date, before_sample_date, after_sample_date;
58
59 DateTimeTestCompareOperators()
60 {
61 TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8);
62 TemporalGenerator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30);
63 TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
64 TemporalGenerator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4);
65 }
66};
67
68class TimestampTestCompareOperators
69{
70 protected:
71 Date sample_date;
72 bool result;
73
74 Timestamp identical_with_sample_date, before_sample_date, after_sample_date;
75
76 TimestampTestCompareOperators()
77 {
78 TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8);
79 TemporalGenerator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41);
80 TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
81 TemporalGenerator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13);
82 }
83};
84
85BOOST_AUTO_TEST_SUITE(DateTestCompare)
86BOOST_FIXTURE_TEST_CASE(operatorComparingDate, DateTestCompareOperators)
87{
88 result= (sample_date == identical_with_sample_date);
89 BOOST_REQUIRE(result);
90
91 result= (sample_date == before_sample_date);
92 BOOST_REQUIRE(not result);
93
94 result= (sample_date != identical_with_sample_date);
95 BOOST_REQUIRE(not result);
96
97 result= (sample_date != before_sample_date);
98 BOOST_REQUIRE(result);
99
100 result= (sample_date > identical_with_sample_date);
101 BOOST_REQUIRE(not this->result);
102
103 result= (sample_date > after_sample_date);
104 BOOST_REQUIRE(not result);
105
106 result= (sample_date > before_sample_date);
107 BOOST_REQUIRE(result);
108
109 result= (sample_date >= identical_with_sample_date);
110 BOOST_REQUIRE(result);
111
112 result= (sample_date >= after_sample_date);
113 BOOST_REQUIRE(not result);
114
115 result= (sample_date >= before_sample_date);
116 BOOST_REQUIRE(result);
117
118 result= (sample_date < identical_with_sample_date);
119
120 BOOST_REQUIRE(not result);
121
122 result= (sample_date < after_sample_date);
123 BOOST_REQUIRE(result);
124
125 result= (sample_date < before_sample_date);
126 BOOST_REQUIRE(not result);
127
128 result= (sample_date <= identical_with_sample_date);
129 BOOST_REQUIRE(result);
130
131 result= (sample_date <= after_sample_date);
132
133 BOOST_REQUIRE(result);
134
135 result= (sample_date <= before_sample_date);
136 BOOST_REQUIRE(not result);
137}
138
139BOOST_FIXTURE_TEST_CASE(operatorComparingDateTime, DateTimeTestCompareOperators)
140{
141 result= (sample_date == identical_with_sample_date);
142 BOOST_REQUIRE(result);
143
144 result= (sample_date == before_sample_date);
145 BOOST_REQUIRE(not result);
146
147 result= (sample_date != identical_with_sample_date);
148 BOOST_REQUIRE(not result);
149
150 result= (sample_date != before_sample_date);
151 BOOST_REQUIRE(result);
152
153 result= (sample_date > identical_with_sample_date);
154 BOOST_REQUIRE(not this->result);
155
156 result= (sample_date > after_sample_date);
157 BOOST_REQUIRE(not result);
158
159 result= (sample_date > before_sample_date);
160 BOOST_REQUIRE(result);
161
162 result= (sample_date >= identical_with_sample_date);
163 BOOST_REQUIRE(result);
164
165 result= (sample_date >= after_sample_date);
166 BOOST_REQUIRE(not result);
167
168 result= (sample_date >= before_sample_date);
169 BOOST_REQUIRE(result);
170
171 result= (sample_date < identical_with_sample_date);
172
173 BOOST_REQUIRE(not result);
174
175 result= (sample_date < after_sample_date);
176 BOOST_REQUIRE(result);
177
178 result= (sample_date < before_sample_date);
179 BOOST_REQUIRE(not result);
180
181 result= (sample_date <= identical_with_sample_date);
182 BOOST_REQUIRE(result);
183
184 result= (sample_date <= after_sample_date);
185
186 BOOST_REQUIRE(result);
187
188 result= (sample_date <= before_sample_date);
189 BOOST_REQUIRE(not result);
190}
191
192
193BOOST_FIXTURE_TEST_CASE(operatorComparingTimestamp, TimestampTestCompareOperators)
194{
195 result= (sample_date == identical_with_sample_date);
196 BOOST_REQUIRE(result);
197
198 result= (sample_date == before_sample_date);
199 BOOST_REQUIRE(not result);
200
201 result= (sample_date != identical_with_sample_date);
202 BOOST_REQUIRE(not result);
203
204 result= (sample_date != before_sample_date);
205 BOOST_REQUIRE(result);
206
207 result= (sample_date > identical_with_sample_date);
208 BOOST_REQUIRE(not this->result);
209
210 result= (sample_date > after_sample_date);
211 BOOST_REQUIRE(not result);
212
213 result= (sample_date > before_sample_date);
214 BOOST_REQUIRE(result);
215
216 result= (sample_date >= identical_with_sample_date);
217 BOOST_REQUIRE(result);
218
219 result= (sample_date >= after_sample_date);
220 BOOST_REQUIRE(not result);
221
222 result= (sample_date >= before_sample_date);
223 BOOST_REQUIRE(result);
224
225 result= (sample_date < identical_with_sample_date);
226
227 BOOST_REQUIRE(not result);
228
229 result= (sample_date < after_sample_date);
230 BOOST_REQUIRE(result);
231
232 result= (sample_date < before_sample_date);
233 BOOST_REQUIRE(not result);
234
235 result= (sample_date <= identical_with_sample_date);
236 BOOST_REQUIRE(result);
237
238 result= (sample_date <= after_sample_date);
239
240 BOOST_REQUIRE(result);
241
242 result= (sample_date <= before_sample_date);
243 BOOST_REQUIRE(not result);
244}
245BOOST_AUTO_TEST_SUITE_END()
246
247
248class DateTest
249{
250 protected:
251 Date date;
252 bool result;
253
254 DateTest()
255 {
256 TemporalGenerator::DateGen::make_valid_date(&date);
257 }
258};
259
260BOOST_AUTO_TEST_SUITE(CurrentDateValidationTest)
261BOOST_FIXTURE_TEST_CASE(operatorAssign_shouldCopyDateRelatadComponents, DateTest)
262{
263 Date copy= date;
264
265 BOOST_REQUIRE_EQUAL(date.years(), copy.years());
266 BOOST_REQUIRE_EQUAL(date.months(), copy.months());
267 BOOST_REQUIRE_EQUAL(date.days(), copy.days());
268}
269
270BOOST_FIXTURE_TEST_CASE(is_valid_onValidDate_shouldReturn_True, DateTest)
271{
272 result= date.is_valid();
273 BOOST_REQUIRE(result);
274}
275
276BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithYearBelowMinimum_shouldReturn_False, DateTest)
277{
278 date.set_years(DRIZZLE_MIN_YEARS_SQL - 1);
279
280 result= date.is_valid();
281
282 BOOST_REQUIRE(not result);
283}
284
285BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithYearAboveMaximum_shouldReturn_False, DateTest)
286{
287 date.set_years(DRIZZLE_MAX_YEARS_SQL + 1);
288
289 result= date.is_valid();
290
291 BOOST_REQUIRE(not result);
292}
293
294BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithMonthSetToZero_shouldReturn_False, DateTest)
295{
296 date.set_months(0);
297
298 result= date.is_valid();
299
300 BOOST_REQUIRE(not result);
301}
302
303
304BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithMonthAboveMaximum_shouldReturn_False, DateTest)
305{
306 date.set_months(13);
307
308 result= date.is_valid();
309
310 BOOST_REQUIRE(not result);
311}
312
313BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithDaySetToZero_shouldReturn_False, DateTest)
314{
315 date.set_days(0);
316
317 result= date.is_valid();
318
319 BOOST_REQUIRE(not result);
320}
321
322BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithDayAboveDaysInMonth_shouldReturn_False, DateTest)
323{
324 date.set_days(32);
325
326 result= date.is_valid();
327
328 BOOST_REQUIRE(not result);
329}
330
331BOOST_FIXTURE_TEST_CASE(is_valid_onInvalidDateWithLeapDayInNonLeapYear_shouldReturn_False, DateTest)
332{
333 TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&date);
334
335 result= date.is_valid();
336
337 BOOST_REQUIRE(not result);
338}
339
340BOOST_FIXTURE_TEST_CASE(is_valid_onValidDateWithLeapDayInLeapYear_shouldReturn_True, DateTest)
341{
342 TemporalGenerator::TemporalGen::leap_day_in_leap_year(&date);
343
344 result= date.is_valid();
345
346 BOOST_REQUIRE(result);
347}
348
349BOOST_FIXTURE_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements, DateTest)
350{
351 char expected[Date::MAX_STRING_LENGTH]= "2010-05-01";
352 char returned[Date::MAX_STRING_LENGTH];
353 TemporalGenerator::DateGen::make_date(&date, 2010, 5, 1);
354
355 date.to_string(returned, Date::MAX_STRING_LENGTH);
356
357 BOOST_REQUIRE_EQUAL(expected, returned);
358}
359
360BOOST_FIXTURE_TEST_CASE(to_string_nullBuffer_shouldReturnProperLengthAnyway, DateTest)
361{
362 int length= date.to_string(NULL, 0);
363
364 BOOST_REQUIRE_EQUAL(Date::MAX_STRING_LENGTH - 1, length);
365}
366
367BOOST_FIXTURE_TEST_CASE(from_string_validString_shouldPopulateCorrectly, DateTest)
368{
369 char valid_string[Date::MAX_STRING_LENGTH]= "2010-05-01";
370 uint32_t years, months, days;
371
372 init_temporal_formats();
373
374 result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1);
375 BOOST_REQUIRE(result);
376
377 years= date.years();
378 months= date.months();
379 days= date.days();
380
381 deinit_temporal_formats();
382
383 BOOST_REQUIRE_EQUAL(2010, years);
384 BOOST_REQUIRE_EQUAL(5, months);
385 BOOST_REQUIRE_EQUAL(1, days);
386}
387
388BOOST_FIXTURE_TEST_CASE(from_string_invalidString_shouldReturn_False, DateTest)
389{
390 char valid_string[Date::MAX_STRING_LENGTH]= "2x10-05-01";
391
392 init_temporal_formats();
393 result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1);
394 deinit_temporal_formats();
395
396 BOOST_REQUIRE(not result);
397}
398
399BOOST_FIXTURE_TEST_CASE(to_int64_t, DateTest)
400{
401 TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
402 int64_t representation;
403
404 date.to_int64_t(&representation);
405
406 BOOST_REQUIRE_EQUAL(20300817, representation);
407}
408
409BOOST_FIXTURE_TEST_CASE(to_int32_t, DateTest)
410{
411 TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
412 int32_t representation;
413
414 date.to_int32_t(&representation);
415
416 BOOST_REQUIRE_EQUAL(20300817, representation);
417}
418
419BOOST_FIXTURE_TEST_CASE(from_int32_t_shouldPopulateDateCorrectly, DateTest)
420{
421 uint32_t decoded_years, decoded_months, decoded_days;
422
423 date.from_int32_t(20300817);
424
425 decoded_years= date.years();
426 decoded_months= date.months();
427 decoded_days= date.days();
428
429 BOOST_REQUIRE_EQUAL(2030, decoded_years);
430 BOOST_REQUIRE_EQUAL(8, decoded_months);
431 BOOST_REQUIRE_EQUAL(17, decoded_days);
432}
433
434BOOST_FIXTURE_TEST_CASE(to_julian_day_number, DateTest)
435{
436 int64_t julian_day;
437 TemporalGenerator::DateGen::make_date(&date, 1999, 12, 31);
438
439 date.to_julian_day_number(&julian_day);
440
441 BOOST_REQUIRE_EQUAL(2451544, julian_day);
442}
443
444BOOST_FIXTURE_TEST_CASE(from_julian_day_number, DateTest)
445{
446 int64_t julian_day= 2451544;
447 uint32_t years, months, days;
448
449 date.from_julian_day_number(julian_day);
450
451 years= date.years();
452 months= date.months();
453 days= date.days();
454
455 BOOST_REQUIRE_EQUAL(1999, years);
456 BOOST_REQUIRE_EQUAL(12, months);
457 BOOST_REQUIRE_EQUAL(31, days);
458}
459
460BOOST_FIXTURE_TEST_CASE(to_tm, DateTest)
461{
462 uint32_t years= 2030, months= 8, days= 17;
463 TemporalGenerator::DateGen::make_date(&date, years, months, days);
464 struct tm filled;
465
466 date.to_tm(&filled);
467
468 BOOST_REQUIRE_EQUAL(130, filled.tm_year);
469 BOOST_REQUIRE_EQUAL(7, filled.tm_mon);
470 BOOST_REQUIRE_EQUAL(17, filled.tm_mday);
471 BOOST_REQUIRE_EQUAL(0, filled.tm_hour);
472 BOOST_REQUIRE_EQUAL(0, filled.tm_min);
473 BOOST_REQUIRE_EQUAL(0, filled.tm_sec);
474
475 /* TODO: these fail, shouldn't they also be set properly? */
476 /* From Andrew: These fail because Temporal::to_tm doesn't populate them.
477 Does it need to or would we be wasting cycles doing it? */
478
479 BOOST_WARN_EQUAL(228, filled.tm_yday);
480 BOOST_WARN_EQUAL(6, filled.tm_wday);
481 BOOST_WARN_EQUAL(-1, filled.tm_isdst);
482}
483
484BOOST_FIXTURE_TEST_CASE(from_tm, DateTest)
485{
486 uint32_t years, months, days;
487 struct tm from;
488 from.tm_year= 1956 - 1900;
489 from.tm_mon= 2;
490 from.tm_mday= 30;
491
492 date.from_tm(&from);
493
494 years= date.years();
495 months= date.months();
496 days= date.days();
497
498 BOOST_REQUIRE_EQUAL(1956, years);
499 BOOST_REQUIRE_EQUAL(3, months);
500 BOOST_REQUIRE_EQUAL(30, days);
501}
502
503BOOST_FIXTURE_TEST_CASE(to_time_t, DateTest)
504{
505 time_t time;
506 TemporalGenerator::DateGen::make_date(&date, 1990, 9, 9);
507
508 date.to_time_t(time);
509
510 BOOST_REQUIRE_EQUAL(652838400, time);
511}
512
513BOOST_FIXTURE_TEST_CASE(from_time_t, DateTest)
514{
515 uint32_t years, months, days;
516
517 date.from_time_t(652838400);
518
519 years= date.years();
520 months= date.months();
521 days= date.days();
522
523 BOOST_REQUIRE_EQUAL(1990, years);
524 BOOST_REQUIRE_EQUAL(9, months);
525 BOOST_REQUIRE_EQUAL(9, days);
526}
527
528BOOST_FIXTURE_TEST_CASE(to_decimal, DateTest)
529{
530 drizzled::type::Decimal to;
531 TemporalGenerator::DateGen::make_date(&date, 1987, 5, 6);
532
533 date.to_decimal(&to);
534
535 BOOST_REQUIRE_EQUAL(19870506, to.buf[0]);
536}
537BOOST_AUTO_TEST_SUITE_END()
538
539BOOST_AUTO_TEST_SUITE(DateStringTest)
540BOOST_AUTO_TEST_CASE(DateFromStringTest)
541{
542 Date date;
543 const char *valid_strings[]= {"20100607", /* YYYYMMDD */
544 "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/
545 "10.06.07",/* YY[-/.]MM[-/.]DD */
546 "10/6/7",/* YY[-/.][M]M[-/.][D]D */
547 "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */};
548
549 init_temporal_formats();
550 for (int it= 0; it < 5; it++)
551 {
552 const char *valid_string= valid_strings[it];
553 bool result= date.from_string(valid_string, strlen(valid_string));
554 BOOST_REQUIRE(result);
555
556 BOOST_REQUIRE_EQUAL(2010, date.years());
557 BOOST_REQUIRE_EQUAL(6, date.months());
558 BOOST_REQUIRE_EQUAL(7, date.days());
559 }
560 deinit_temporal_formats();
561}
562BOOST_AUTO_TEST_SUITE_END()
0563
=== removed file 'unittests/date_test.cc'
--- unittests/date_test.cc 2010-12-26 00:07:57 +0000
+++ unittests/date_test.cc 1970-01-01 00:00:00 +0000
@@ -1,522 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <drizzled/type/decimal.h>
25#include <drizzled/temporal.h>
26#include <drizzled/temporal_format.h>
27
28#include "temporal_generator.h"
29
30using namespace drizzled;
31
32template <typename TemporalType>
33class DateTestCompareOperators : public ::testing::Test
34{
35 protected:
36 Date sample_date;
37 bool result;
38
39 TemporalType identical_with_sample_date, before_sample_date, after_sample_date;
40
41 void initBeforeIdenticalAfter();
42
43 virtual void SetUp()
44 {
45 TemporalGenerator::DateGen::make_date(&sample_date, 2010, 9, 8);
46 initBeforeIdenticalAfter();
47 }
48};
49
50template<> void DateTestCompareOperators<Date>::initBeforeIdenticalAfter()
51{
52 TemporalGenerator::DateGen::make_date(&before_sample_date, 1980, 1, 1);
53 TemporalGenerator::DateGen::make_date(&identical_with_sample_date, 2010, 9, 8);
54 TemporalGenerator::DateGen::make_date(&after_sample_date, 2019, 5, 30);
55}
56
57template<> void DateTestCompareOperators<DateTime>::initBeforeIdenticalAfter()
58{
59 TemporalGenerator::DateTimeGen::make_datetime(&before_sample_date, 1990, 12, 31, 12, 12, 30);
60 TemporalGenerator::DateTimeGen::make_datetime(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
61 TemporalGenerator::DateTimeGen::make_datetime(&after_sample_date, 2020, 4, 4, 4, 4, 4);
62}
63
64template<> void DateTestCompareOperators<Timestamp>::initBeforeIdenticalAfter()
65{
66 TemporalGenerator::TimestampGen::make_timestamp(&before_sample_date, 1980, 1, 1, 13, 56, 41);
67 TemporalGenerator::TimestampGen::make_timestamp(&identical_with_sample_date, 2010, 9, 8, 0, 0, 0);
68 TemporalGenerator::TimestampGen::make_timestamp(&after_sample_date, 2019, 5, 30, 9, 10, 13);
69}
70
71typedef ::testing::Types<Date, DateTime, Timestamp> typesForDateTestCompareOperators;
72TYPED_TEST_CASE(DateTestCompareOperators, typesForDateTestCompareOperators);
73
74TYPED_TEST(DateTestCompareOperators, operatorEqual_ComparingWithIdencticalTemporal_ShouldReturn_True)
75{
76 this->result= (this->sample_date == this->identical_with_sample_date);
77
78 ASSERT_TRUE(this->result);
79}
80
81TYPED_TEST(DateTestCompareOperators, operatorEqual_ComparingWithDifferentTemporal_ShouldReturn_False)
82{
83 this->result= (this->sample_date == this->before_sample_date);
84
85 ASSERT_FALSE(this->result);
86}
87
88TYPED_TEST(DateTestCompareOperators, operatorNotEqual_ComparingWithIdencticalTemporal_ShouldReturn_False)
89{
90 this->result= (this->sample_date != this->identical_with_sample_date);
91
92 ASSERT_FALSE(this->result);
93}
94
95TYPED_TEST(DateTestCompareOperators, operatorNotEqual_ComparingWithDifferentTemporal_ShouldReturn_True)
96{
97 this->result= (this->sample_date != this->before_sample_date);
98
99 ASSERT_TRUE(this->result);
100}
101
102TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
103{
104 this->result= (this->sample_date > this->identical_with_sample_date);
105
106 ASSERT_FALSE(this->result);
107}
108
109TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithLaterTemporal_ShouldReturn_False)
110{
111 this->result= (this->sample_date > this->after_sample_date);
112
113 ASSERT_FALSE(this->result);
114}
115
116TYPED_TEST(DateTestCompareOperators, operatorGreaterThan_ComparingWithEarlierTemporal_ShouldReturn_True)
117{
118 this->result= (this->sample_date > this->before_sample_date);
119
120 ASSERT_TRUE(this->result);
121}
122
123TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
124{
125 this->result= (this->sample_date >= this->identical_with_sample_date);
126
127 ASSERT_TRUE(this->result);
128}
129
130TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_False)
131{
132 this->result= (this->sample_date >= this->after_sample_date);
133
134 ASSERT_FALSE(this->result);
135}
136
137TYPED_TEST(DateTestCompareOperators, operatorGreaterThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_True)
138{
139 this->result= (this->sample_date >= this->before_sample_date);
140
141 ASSERT_TRUE(this->result);
142}
143
144TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithIdenticalTemporal_ShouldReturn_False)
145{
146 this->result= (this->sample_date < this->identical_with_sample_date);
147
148 ASSERT_FALSE(this->result);
149}
150
151TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithLaterTemporal_ShouldReturn_True)
152{
153 this->result= (this->sample_date < this->after_sample_date);
154
155 ASSERT_TRUE(this->result);
156}
157
158TYPED_TEST(DateTestCompareOperators, operatorLessThan_ComparingWithEarlierTemporal_ShouldReturn_False)
159{
160 this->result= (this->sample_date < this->before_sample_date);
161
162 ASSERT_FALSE(this->result);
163}
164
165TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithIdenticalTemporal_ShouldReturn_True)
166{
167 this->result= (this->sample_date <= this->identical_with_sample_date);
168
169 ASSERT_TRUE(this->result);
170}
171
172TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithLaterTemporal_ShouldReturn_True)
173{
174 this->result= (this->sample_date <= this->after_sample_date);
175
176 ASSERT_TRUE(this->result);
177}
178
179TYPED_TEST(DateTestCompareOperators, operatorLessThanOrEqual_ComparingWithEarlierTemporal_ShouldReturn_False)
180{
181 this->result= (this->sample_date <= this->before_sample_date);
182
183 ASSERT_FALSE(this->result);
184}
185
186class DateTest : public ::testing::Test
187{
188 protected:
189 Date date;
190 bool result;
191
192 virtual void SetUp()
193 {
194 TemporalGenerator::DateGen::make_valid_date(&date);
195 }
196};
197
198TEST_F(DateTest, operatorAssign_shouldCopyDateRelatadComponents)
199{
200 Date copy= date;
201
202 EXPECT_EQ(date.years(), copy.years());
203 EXPECT_EQ(date.months(), copy.months());
204 EXPECT_EQ(date.days(), copy.days());
205}
206
207TEST_F(DateTest, is_valid_onValidDate_shouldReturn_True)
208{
209 result= date.is_valid();
210 ASSERT_TRUE(result);
211}
212
213TEST_F(DateTest, is_valid_onInvalidDateWithYearBelowMinimum_shouldReturn_False)
214{
215 date.set_years(DRIZZLE_MIN_YEARS_SQL - 1);
216
217 result= date.is_valid();
218
219 ASSERT_FALSE(result);
220}
221
222TEST_F(DateTest, is_valid_onInvalidDateWithYearAboveMaximum_shouldReturn_False)
223{
224 date.set_years(DRIZZLE_MAX_YEARS_SQL + 1);
225
226 result= date.is_valid();
227
228 ASSERT_FALSE(result);
229}
230
231TEST_F(DateTest, is_valid_onInvalidDateWithMonthSetToZero_shouldReturn_False)
232{
233 date.set_months(0);
234
235 result= date.is_valid();
236
237 ASSERT_FALSE(result);
238}
239
240
241TEST_F(DateTest, is_valid_onInvalidDateWithMonthAboveMaximum_shouldReturn_False)
242{
243 date.set_months(13);
244
245 result= date.is_valid();
246
247 ASSERT_FALSE(result);
248}
249
250TEST_F(DateTest, is_valid_onInvalidDateWithDaySetToZero_shouldReturn_False)
251{
252 date.set_days(0);
253
254 result= date.is_valid();
255
256 ASSERT_FALSE(result);
257}
258
259TEST_F(DateTest, is_valid_onInvalidDateWithDayAboveDaysInMonth_shouldReturn_False)
260{
261 date.set_days(32);
262
263 result= date.is_valid();
264
265 ASSERT_FALSE(result);
266}
267
268TEST_F(DateTest, is_valid_onInvalidDateWithLeapDayInNonLeapYear_shouldReturn_False)
269{
270 TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&date);
271
272 result= date.is_valid();
273
274 ASSERT_FALSE(result);
275}
276
277TEST_F(DateTest, is_valid_onValidDateWithLeapDayInLeapYear_shouldReturn_True)
278{
279 TemporalGenerator::TemporalGen::leap_day_in_leap_year(&date);
280
281 result= date.is_valid();
282
283 ASSERT_TRUE(result);
284}
285
286TEST_F(DateTest, to_string_shouldProduce_hyphenSeperatedDateElements)
287{
288 char expected[Date::MAX_STRING_LENGTH]= "2010-05-01";
289 char returned[Date::MAX_STRING_LENGTH];
290 TemporalGenerator::DateGen::make_date(&date, 2010, 5, 1);
291
292 date.to_string(returned, Date::MAX_STRING_LENGTH);
293
294 ASSERT_STREQ(expected, returned);
295}
296
297TEST_F(DateTest, to_string_nullBuffer_shouldReturnProperLengthAnyway)
298{
299 int length= date.to_string(NULL, 0);
300
301 ASSERT_EQ(Date::MAX_STRING_LENGTH - 1, length);
302}
303
304TEST_F(DateTest, from_string_validString_shouldPopulateCorrectly)
305{
306 char valid_string[Date::MAX_STRING_LENGTH]= "2010-05-01";
307 uint32_t years, months, days;
308
309 init_temporal_formats();
310
311 result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1);
312 ASSERT_TRUE(result);
313
314 years= date.years();
315 months= date.months();
316 days= date.days();
317
318 deinit_temporal_formats();
319
320 EXPECT_EQ(2010, years);
321 EXPECT_EQ(5, months);
322 EXPECT_EQ(1, days);
323}
324
325TEST_F(DateTest, from_string_invalidString_shouldReturn_False)
326{
327 char valid_string[Date::MAX_STRING_LENGTH]= "2x10-05-01";
328
329 init_temporal_formats();
330 result= date.from_string(valid_string, Date::MAX_STRING_LENGTH - 1);
331 deinit_temporal_formats();
332
333 ASSERT_FALSE(result);
334}
335
336TEST_F(DateTest, to_int64_t)
337{
338 TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
339 int64_t representation;
340
341 date.to_int64_t(&representation);
342
343 ASSERT_EQ(20300817, representation);
344}
345
346TEST_F(DateTest, to_int32_t)
347{
348 TemporalGenerator::DateGen::make_date(&date, 2030, 8, 17);
349 int32_t representation;
350
351 date.to_int32_t(&representation);
352
353 ASSERT_EQ(20300817, representation);
354}
355
356TEST_F(DateTest, from_int32_t_shouldPopulateDateCorrectly)
357{
358 uint32_t decoded_years, decoded_months, decoded_days;
359
360 date.from_int32_t(20300817);
361
362 decoded_years= date.years();
363 decoded_months= date.months();
364 decoded_days= date.days();
365
366 EXPECT_EQ(2030, decoded_years);
367 EXPECT_EQ(8, decoded_months);
368 EXPECT_EQ(17, decoded_days);
369}
370
371TEST_F(DateTest, to_julian_day_number)
372{
373 int64_t julian_day;
374 TemporalGenerator::DateGen::make_date(&date, 1999, 12, 31);
375
376 date.to_julian_day_number(&julian_day);
377
378 ASSERT_EQ(2451544, julian_day);
379}
380
381TEST_F(DateTest, from_julian_day_number)
382{
383 int64_t julian_day= 2451544;
384 uint32_t years, months, days;
385
386 date.from_julian_day_number(julian_day);
387
388 years= date.years();
389 months= date.months();
390 days= date.days();
391
392 EXPECT_EQ(1999, years);
393 EXPECT_EQ(12, months);
394 EXPECT_EQ(31, days);
395}
396
397TEST_F(DateTest, DISABLED_to_tm)
398{
399 uint32_t years= 2030, months= 8, days= 17;
400 TemporalGenerator::DateGen::make_date(&date, years, months, days);
401 struct tm filled;
402
403 date.to_tm(&filled);
404
405 EXPECT_EQ(130, filled.tm_year);
406 EXPECT_EQ(7, filled.tm_mon);
407 EXPECT_EQ(17, filled.tm_mday);
408 EXPECT_EQ(0, filled.tm_hour);
409 EXPECT_EQ(0, filled.tm_min);
410 EXPECT_EQ(0, filled.tm_sec);
411
412 /* TODO:these fail, shouldn't they also be set properly? */
413 EXPECT_EQ(228, filled.tm_yday);
414 EXPECT_EQ(6, filled.tm_wday);
415 EXPECT_EQ(-1, filled.tm_isdst);
416}
417
418TEST_F(DateTest, from_tm)
419{
420 uint32_t years, months, days;
421 struct tm from;
422 from.tm_year= 1956 - 1900;
423 from.tm_mon= 2;
424 from.tm_mday= 30;
425
426 date.from_tm(&from);
427
428 years= date.years();
429 months= date.months();
430 days= date.days();
431
432 EXPECT_EQ(1956, years);
433 EXPECT_EQ(3, months);
434 EXPECT_EQ(30, days);
435}
436
437TEST_F(DateTest, to_time_t)
438{
439 time_t time;
440 TemporalGenerator::DateGen::make_date(&date, 1990, 9, 9);
441
442 date.to_time_t(time);
443
444 ASSERT_EQ(652838400, time);
445}
446
447TEST_F(DateTest, from_time_t)
448{
449 uint32_t years, months, days;
450
451 date.from_time_t(652838400);
452
453 years= date.years();
454 months= date.months();
455 days= date.days();
456
457 EXPECT_EQ(1990, years);
458 EXPECT_EQ(9, months);
459 EXPECT_EQ(9, days);
460}
461
462TEST_F(DateTest, to_decimal)
463{
464 drizzled::type::Decimal to;
465 TemporalGenerator::DateGen::make_date(&date, 1987, 5, 6);
466
467 date.to_decimal(&to);
468
469 ASSERT_EQ(19870506, to.buf[0]);
470}
471
472class DateFromStringTest: public ::testing::TestWithParam<const char*>
473{
474 protected:
475 Date date;
476 bool result;
477 uint32_t years, months, days;
478
479 virtual void SetUp()
480 {
481 init_temporal_formats();
482 }
483
484 virtual void TearDown()
485 {
486 deinit_temporal_formats();
487 }
488
489 void assign_date_values()
490 {
491 years= date.years();
492 months= date.months();
493 days= date.days();
494 }
495};
496
497TEST_P(DateFromStringTest, from_string)
498{
499 const char *valid_string= GetParam();
500
501 result= date.from_string(valid_string, strlen(valid_string));
502 ASSERT_TRUE(result);
503
504 assign_date_values();
505
506 EXPECT_EQ(2010, years);
507 EXPECT_EQ(6, months);
508 EXPECT_EQ(7, days);
509}
510
511/* TODO:for some reason this was not declared by the macro, needs clarification*/
512testing::internal::ParamGenerator<const char*> gtest_ValidStringDateFromStringTest_EvalGenerator_();
513
514INSTANTIATE_TEST_CASE_P(ValidString, DateFromStringTest,
515 ::testing::Values("20100607", /* YYYYMMDD */
516 "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/
517 "10.06.07",/* YY[-/.]MM[-/.]DD */
518 "10/6/7",/* YY[-/.][M]M[-/.][D]D */
519 "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */));
520
521
522
5230
=== added file 'unittests/date_time_test.cc'
--- unittests/date_time_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/date_time_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,478 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3*
4* Copyright (C) 2010 Pawel Blokus
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <drizzled/type/decimal.h>
27#include <drizzled/temporal.h>
28#include <drizzled/temporal_format.h>
29
30#include "temporal_generator.h"
31
32using namespace drizzled;
33
34class DateTimeTest
35{
36 protected:
37 DateTime datetime;
38 bool result;
39 uint32_t years, months, days;
40 uint32_t hours, minutes, seconds;
41
42 DateTimeTest()
43 {
44 TemporalGenerator::DateTimeGen::make_valid_datetime(&datetime);
45 }
46
47 void assignDateTimeValues()
48 {
49 years= datetime.years();
50 months= datetime.months();
51 days= datetime.days();
52 hours= datetime.hours();
53 minutes= datetime.minutes();
54 seconds= datetime.seconds();
55 }
56};
57
58BOOST_FIXTURE_TEST_SUITE(DateTimeTestValidation, DateTimeTest)
59BOOST_AUTO_TEST_CASE(is_valid_onValidDateTime_shouldReturn_True)
60{
61 result= datetime.is_valid();
62 BOOST_REQUIRE(result);
63}
64
65BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithYearBelowMinimum_shouldReturn_False)
66{
67 datetime.set_years(DRIZZLE_MIN_YEARS_SQL - 1);
68
69 result= datetime.is_valid();
70
71 BOOST_REQUIRE(not result);
72}
73
74BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithYearAboveMaximum_shouldReturn_False)
75{
76 datetime.set_years(DRIZZLE_MAX_YEARS_SQL + 1);
77
78 result= datetime.is_valid();
79
80 BOOST_REQUIRE(not result);
81}
82
83BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithMonthSetToZero_shouldReturn_False)
84{
85 datetime.set_months(0);
86
87 result= datetime.is_valid();
88
89 BOOST_REQUIRE(not result);
90}
91
92
93BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithMonthAboveMaximum_shouldReturn_False)
94{
95 datetime.set_months(13);
96
97 result= datetime.is_valid();
98
99 BOOST_REQUIRE(not result);
100}
101
102BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithDaySetToZero_shouldReturn_False)
103{
104 datetime.set_days(0);
105
106 result= datetime.is_valid();
107
108 BOOST_REQUIRE(not result);
109}
110
111BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithDayAboveDaysInMonth_shouldReturn_False)
112{
113 datetime.set_days(32);
114
115 result= datetime.is_valid();
116
117 BOOST_REQUIRE(not result);
118}
119
120BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithLeapDayInNonLeapYear_shouldReturn_False)
121{
122 TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&datetime);
123
124 result= datetime.is_valid();
125
126 BOOST_REQUIRE(not result);
127}
128
129BOOST_AUTO_TEST_CASE(is_valid_onValidDateTimeWithLeapDayInLeapYear_shouldReturn_True)
130{
131 TemporalGenerator::TemporalGen::leap_day_in_leap_year(&datetime);
132
133 result= datetime.is_valid();
134
135 BOOST_REQUIRE(result);
136}
137
138BOOST_AUTO_TEST_CASE(is_valid_onValidMinimalTime_shouldReturn_True)
139{
140 TemporalGenerator::TemporalGen::make_min_time(&datetime);
141
142 result= datetime.is_valid();
143
144 BOOST_REQUIRE(result);
145}
146
147BOOST_AUTO_TEST_CASE(is_valid_onValidMaximalTime_shouldReturn_True)
148{
149 TemporalGenerator::TemporalGen::make_max_time(&datetime);
150
151 result= datetime.is_valid();
152
153 BOOST_REQUIRE(result);
154}
155
156BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithHourAboveMaximum23_shouldReturn_False)
157{
158 datetime.set_hours(24);
159
160 result= datetime.is_valid();
161
162 BOOST_REQUIRE(not result);
163}
164
165BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithMinutesAboveMaximum59_shouldReturn_False)
166{
167 datetime.set_minutes(60);
168
169 result= datetime.is_valid();
170
171 BOOST_REQUIRE(not result);
172}
173
174BOOST_AUTO_TEST_CASE(is_valid_onInvalidDateTimeWithSecondsAboveMaximum61_shouldReturn_False)
175{
176 datetime.set_seconds(62);
177
178 result= datetime.is_valid();
179
180 BOOST_REQUIRE(not result);
181}
182
183BOOST_AUTO_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements)
184{
185 char expected[DateTime::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.123456";
186 char returned[DateTime::MAX_STRING_LENGTH];
187 TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2010, 5, 1, 8, 7, 6, 123456);
188
189 datetime.to_string(returned, DateTime::MAX_STRING_LENGTH);
190
191 BOOST_REQUIRE_EQUAL(expected, returned);
192}
193
194BOOST_AUTO_TEST_CASE(to_string_nullBuffer_noMicroSeconds_shouldReturnProperLengthAnyway)
195{
196 int length= datetime.to_string(NULL, 0);
197
198 BOOST_REQUIRE_EQUAL(DateTime::MAX_STRING_LENGTH - 1 - 7, length);
199}
200
201BOOST_AUTO_TEST_CASE(to_int64_t)
202{
203 TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2030, 8, 7, 14, 5, 13);
204 int64_t representation;
205
206 datetime.to_int64_t(&representation);
207
208 BOOST_REQUIRE_EQUAL(20300807140513LL, representation);
209}
210
211BOOST_AUTO_TEST_CASE(from_int64_t_no_conversion_format_YYYYMMDDHHMMSSshouldPopulateDateTimeCorrectly)
212{
213 datetime.from_int64_t(20300807140513LL, false);
214
215 assignDateTimeValues();
216
217 BOOST_REQUIRE_EQUAL(2030, years);
218 BOOST_REQUIRE_EQUAL(8, months);
219 BOOST_REQUIRE_EQUAL(7, days);
220 BOOST_REQUIRE_EQUAL(14, hours);
221 BOOST_REQUIRE_EQUAL(5, minutes);
222 BOOST_REQUIRE_EQUAL(13, seconds);
223}
224
225BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearOver2000)
226{
227 datetime.from_int64_t(20300807140513LL, true);
228
229 assignDateTimeValues();
230
231 BOOST_REQUIRE_EQUAL(2030, years);
232 BOOST_REQUIRE_EQUAL(8, months);
233 BOOST_REQUIRE_EQUAL(7, days);
234 BOOST_REQUIRE_EQUAL(14, hours);
235 BOOST_REQUIRE_EQUAL(5, minutes);
236 BOOST_REQUIRE_EQUAL(13, seconds);
237}
238
239BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearBelow2000)
240{
241 datetime.from_int64_t(19900807140513LL, true);
242
243 assignDateTimeValues();
244
245 BOOST_REQUIRE_EQUAL(1990, years);
246 BOOST_REQUIRE_EQUAL(8, months);
247 BOOST_REQUIRE_EQUAL(7, days);
248 BOOST_REQUIRE_EQUAL(14, hours);
249 BOOST_REQUIRE_EQUAL(5, minutes);
250 BOOST_REQUIRE_EQUAL(13, seconds);
251}
252
253BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearOver2000)
254{
255 datetime.from_int64_t(300807140513LL, true);
256
257 assignDateTimeValues();
258
259 BOOST_REQUIRE_EQUAL(2030, years);
260 BOOST_REQUIRE_EQUAL(8, months);
261 BOOST_REQUIRE_EQUAL(7, days);
262 BOOST_REQUIRE_EQUAL(14, hours);
263 BOOST_REQUIRE_EQUAL(5, minutes);
264 BOOST_REQUIRE_EQUAL(13, seconds);
265}
266
267BOOST_AUTO_TEST_CASE(from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearBelow2000)
268{
269 datetime.from_int64_t(900807140513LL, true);
270
271 assignDateTimeValues();
272
273 BOOST_REQUIRE_EQUAL(1990, years);
274 BOOST_REQUIRE_EQUAL(8, months);
275 BOOST_REQUIRE_EQUAL(7, days);
276 BOOST_REQUIRE_EQUAL(14, hours);
277 BOOST_REQUIRE_EQUAL(5, minutes);
278 BOOST_REQUIRE_EQUAL(13, seconds);
279}
280
281BOOST_AUTO_TEST_CASE(to_tm)
282{
283 years= 2030, months= 8, days= 17, hours= 14, minutes= 45, seconds= 13;
284 TemporalGenerator::DateTimeGen::make_datetime(&datetime, years, months, days, hours, minutes, seconds);
285 struct tm filled;
286
287 datetime.to_tm(&filled);
288
289 BOOST_REQUIRE_EQUAL(2030 - 1900, filled.tm_year);
290 BOOST_REQUIRE_EQUAL(8 - 1, filled.tm_mon);
291 BOOST_REQUIRE_EQUAL(17, filled.tm_mday);
292 BOOST_REQUIRE_EQUAL(14, filled.tm_hour);
293 BOOST_REQUIRE_EQUAL(45, filled.tm_min);
294 BOOST_REQUIRE_EQUAL(13, filled.tm_sec);
295
296 /* TODO:these fail, shouldn't they also be set properly? */
297 BOOST_WARN_EQUAL(228, filled.tm_yday);
298 BOOST_WARN_EQUAL(6, filled.tm_wday);
299 BOOST_WARN_EQUAL(-1, filled.tm_isdst);
300}
301
302BOOST_AUTO_TEST_CASE(to_decimal)
303{
304 drizzled::type::Decimal to;
305 TemporalGenerator::DateTimeGen::make_datetime(&datetime, 1987, 6, 13, 5, 10, 13, 456);
306
307 datetime.to_decimal(&to);
308
309 BOOST_REQUIRE_EQUAL(19870,to.buf[0]);
310 BOOST_REQUIRE_EQUAL(613051013,to.buf[1]);
311 BOOST_REQUIRE_EQUAL(456000,to.buf[2]);
312}
313BOOST_AUTO_TEST_SUITE_END()
314
315
316class DateTimeFromStringTest
317{
318 protected:
319 static const char* allStrings[];
320 DateTime datetime;
321 bool result;
322 uint32_t years, months, days;
323 uint32_t hours, minutes, seconds;
324
325 DateTimeFromStringTest()
326 {
327 init_temporal_formats();
328 }
329
330 virtual ~DateTimeFromStringTest()
331 {
332 deinit_temporal_formats();
333 }
334
335 virtual int stringCount() { return 0; }
336 virtual const char** strings() { return NULL; }
337
338 void assignDateTimeValues()
339 {
340 years= datetime.years();
341 months= datetime.months();
342 days= datetime.days();
343 hours= datetime.hours();
344 minutes= datetime.minutes();
345 seconds= datetime.seconds();
346 }
347};
348
349const char* DateTimeFromStringTest::allStrings[]= {"NULL"};
350
351
352class DateTimeFromStringFullFormatTest : public DateTimeFromStringTest
353{
354 protected:
355 static const char* allStrings[];
356
357 const char** strings()
358 {
359 return allStrings;
360 }
361
362 int stringCount()
363 {
364 return 7;
365 }
366};
367
368const char* DateTimeFromStringFullFormatTest::allStrings[]= {"20100501080706",
369 "2010-05-01 08:07:06",
370 "2010/05/01T08:07:06",
371 "2010.5.1 08:07:06",
372 "10-05-01 08:07:06",
373 "10/5/1 08:07:06",
374 "10.5.1 08:07:06"};
375
376class DateTimeFromStringNoSecondFormatTest : public DateTimeFromStringTest
377{
378 protected:
379 static const char* allStrings[];
380
381 const char** strings()
382 {
383 return allStrings;
384 }
385
386 int stringCount()
387 {
388 return 6;
389 }
390};
391
392const char* DateTimeFromStringNoSecondFormatTest::allStrings[]= {"2010-05-01 08:07",
393 "2010/05/01 08:07",
394 "2010.5.1 08:07",
395 "10-05-01 08:07",
396 "10/5/1 08:07",
397 "10.5.1 08:07"};
398
399class DateTimeFromStringDateOnlyTest: public DateTimeFromStringTest
400{
401 protected:
402 static const char* allStrings[];
403
404 const char** strings()
405 {
406 return allStrings;
407 }
408
409 int stringCount()
410 {
411 return 5;
412 }
413};
414
415const char* DateTimeFromStringDateOnlyTest::allStrings[]= {"20100607", /* YYYYMMDD */
416 "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/
417 "10.06.07",/* YY[-/.]MM[-/.]DD */
418 "10/6/7",/* YY[-/.][M]M[-/.][D]D */
419 "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */};
420
421BOOST_AUTO_TEST_SUITE(DateTimeFromStringTestSuite)
422BOOST_FIXTURE_TEST_CASE(from_string_validStringFull, DateTimeFromStringFullFormatTest)
423{
424 for (int it= 0; it < stringCount(); it++)
425 {
426 const char *valid_string= strings()[it];
427
428 result= datetime.from_string(valid_string, strlen(valid_string));
429 BOOST_REQUIRE(result);
430
431 assignDateTimeValues();
432
433 BOOST_REQUIRE_EQUAL(2010, years);
434 BOOST_REQUIRE_EQUAL(5, months);
435 BOOST_REQUIRE_EQUAL(1, days);
436 BOOST_REQUIRE_EQUAL(8, hours);
437 BOOST_REQUIRE_EQUAL(7, minutes);
438 BOOST_REQUIRE_EQUAL(6, seconds);
439 }
440}
441
442BOOST_FIXTURE_TEST_CASE(from_string_validStringNoSecond, DateTimeFromStringNoSecondFormatTest)
443{
444 for (int it= 0; it < stringCount(); it++)
445 {
446 const char *valid_string= strings()[it];
447
448 result= datetime.from_string(valid_string, strlen(valid_string));
449 BOOST_REQUIRE(result);
450
451 assignDateTimeValues();
452
453 BOOST_REQUIRE_EQUAL(2010, years);
454 BOOST_REQUIRE_EQUAL(5, months);
455 BOOST_REQUIRE_EQUAL(1, days);
456 BOOST_REQUIRE_EQUAL(8, hours);
457 BOOST_REQUIRE_EQUAL(7, minutes);
458 }
459}
460
461BOOST_FIXTURE_TEST_CASE(from_string_validStringDateOnly, DateTimeFromStringDateOnlyTest)
462{
463 for (int it= 0; it < stringCount(); it++)
464 {
465 const char *valid_string= strings()[it];
466
467 result= datetime.from_string(valid_string, strlen(valid_string));
468 BOOST_REQUIRE(result);
469
470 assignDateTimeValues();
471
472 BOOST_REQUIRE_EQUAL(2010, years);
473 BOOST_REQUIRE_EQUAL(6, months);
474 BOOST_REQUIRE_EQUAL(7, days);
475 }
476}
477
478BOOST_AUTO_TEST_SUITE_END()
0479
=== removed file 'unittests/date_time_test.cc'
--- unittests/date_time_test.cc 2010-12-26 00:07:57 +0000
+++ unittests/date_time_test.cc 1970-01-01 00:00:00 +0000
@@ -1,460 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3*
4* Copyright (C) 2010 Pawel Blokus
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <drizzled/type/decimal.h>
25#include <drizzled/temporal.h>
26#include <drizzled/temporal_format.h>
27
28#include "temporal_generator.h"
29
30using namespace drizzled;
31
32class DateTimeTest: public ::testing::Test
33{
34 protected:
35 DateTime datetime;
36 bool result;
37 uint32_t years, months, days;
38 uint32_t hours, minutes, seconds;
39
40 virtual void SetUp()
41 {
42 TemporalGenerator::DateTimeGen::make_valid_datetime(&datetime);
43 }
44
45 void assignDateTimeValues()
46 {
47 years= datetime.years();
48 months= datetime.months();
49 days= datetime.days();
50 hours= datetime.hours();
51 minutes= datetime.minutes();
52 seconds= datetime.seconds();
53 }
54};
55
56TEST_F(DateTimeTest, is_valid_onValidDateTime_shouldReturn_True)
57{
58 result= datetime.is_valid();
59 ASSERT_TRUE(result);
60}
61
62TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithYearBelowMinimum_shouldReturn_False)
63{
64 datetime.set_years(DRIZZLE_MIN_YEARS_SQL - 1);
65
66 result= datetime.is_valid();
67
68 ASSERT_FALSE(result);
69}
70
71TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithYearAboveMaximum_shouldReturn_False)
72{
73 datetime.set_years(DRIZZLE_MAX_YEARS_SQL + 1);
74
75 result= datetime.is_valid();
76
77 ASSERT_FALSE(result);
78}
79
80TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithMonthSetToZero_shouldReturn_False)
81{
82 datetime.set_months(0);
83
84 result= datetime.is_valid();
85
86 ASSERT_FALSE(result);
87}
88
89
90TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithMonthAboveMaximum_shouldReturn_False)
91{
92 datetime.set_months(13);
93
94 result= datetime.is_valid();
95
96 ASSERT_FALSE(result);
97}
98
99TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithDaySetToZero_shouldReturn_False)
100{
101 datetime.set_days(0);
102
103 result= datetime.is_valid();
104
105 ASSERT_FALSE(result);
106}
107
108TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithDayAboveDaysInMonth_shouldReturn_False)
109{
110 datetime.set_days(32);
111
112 result= datetime.is_valid();
113
114 ASSERT_FALSE(result);
115}
116
117TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithLeapDayInNonLeapYear_shouldReturn_False)
118{
119 TemporalGenerator::TemporalGen::leap_day_in_non_leap_year(&datetime);
120
121 result= datetime.is_valid();
122
123 ASSERT_FALSE(result);
124}
125
126TEST_F(DateTimeTest, is_valid_onValidDateTimeWithLeapDayInLeapYear_shouldReturn_True)
127{
128 TemporalGenerator::TemporalGen::leap_day_in_leap_year(&datetime);
129
130 result= datetime.is_valid();
131
132 ASSERT_TRUE(result);
133}
134
135TEST_F(DateTimeTest, is_valid_onValidMinimalTime_shouldReturn_True)
136{
137 TemporalGenerator::TemporalGen::make_min_time(&datetime);
138
139 result= datetime.is_valid();
140
141 ASSERT_TRUE(result);
142}
143
144TEST_F(DateTimeTest, is_valid_onValidMaximalTime_shouldReturn_True)
145{
146 TemporalGenerator::TemporalGen::make_max_time(&datetime);
147
148 result= datetime.is_valid();
149
150 ASSERT_TRUE(result);
151}
152
153TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithHourAboveMaximum23_shouldReturn_False)
154{
155 datetime.set_hours(24);
156
157 result= datetime.is_valid();
158
159 ASSERT_FALSE(result);
160}
161
162TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithMinutesAboveMaximum59_shouldReturn_False)
163{
164 datetime.set_minutes(60);
165
166 result= datetime.is_valid();
167
168 ASSERT_FALSE(result);
169}
170
171TEST_F(DateTimeTest, is_valid_onInvalidDateTimeWithSecondsAboveMaximum61_shouldReturn_False)
172{
173 datetime.set_seconds(62);
174
175 result= datetime.is_valid();
176
177 ASSERT_FALSE(result);
178}
179
180TEST_F(DateTimeTest, to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements)
181{
182 char expected[DateTime::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.123456";
183 char returned[DateTime::MAX_STRING_LENGTH];
184 TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2010, 5, 1, 8, 7, 6, 123456);
185
186 datetime.to_string(returned, DateTime::MAX_STRING_LENGTH);
187
188 ASSERT_STREQ(expected, returned);
189}
190
191TEST_F(DateTimeTest, to_string_nullBuffer_noMicroSeconds_shouldReturnProperLengthAnyway)
192{
193 int length= datetime.to_string(NULL, 0);
194
195 ASSERT_EQ(DateTime::MAX_STRING_LENGTH - 1 - 7, length);
196}
197
198TEST_F(DateTimeTest, to_int64_t)
199{
200 TemporalGenerator::DateTimeGen::make_datetime(&datetime, 2030, 8, 7, 14, 5, 13);
201 int64_t representation;
202
203 datetime.to_int64_t(&representation);
204
205 ASSERT_EQ(20300807140513LL, representation);
206}
207
208TEST_F(DateTimeTest, from_int64_t_no_conversion_format_YYYYMMDDHHMMSSshouldPopulateDateTimeCorrectly)
209{
210 datetime.from_int64_t(20300807140513LL, false);
211
212 assignDateTimeValues();
213
214 EXPECT_EQ(2030, years);
215 EXPECT_EQ(8, months);
216 EXPECT_EQ(7, days);
217 EXPECT_EQ(14, hours);
218 EXPECT_EQ(5, minutes);
219 EXPECT_EQ(13, seconds);
220}
221
222TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearOver2000)
223{
224 datetime.from_int64_t(20300807140513LL, true);
225
226 assignDateTimeValues();
227
228 EXPECT_EQ(2030, years);
229 EXPECT_EQ(8, months);
230 EXPECT_EQ(7, days);
231 EXPECT_EQ(14, hours);
232 EXPECT_EQ(5, minutes);
233 EXPECT_EQ(13, seconds);
234}
235
236TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYYYMMDDHHMMSS_yearBelow2000)
237{
238 datetime.from_int64_t(19900807140513LL, true);
239
240 assignDateTimeValues();
241
242 EXPECT_EQ(1990, years);
243 EXPECT_EQ(8, months);
244 EXPECT_EQ(7, days);
245 EXPECT_EQ(14, hours);
246 EXPECT_EQ(5, minutes);
247 EXPECT_EQ(13, seconds);
248}
249
250TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearOver2000)
251{
252 datetime.from_int64_t(300807140513LL, true);
253
254 assignDateTimeValues();
255
256 EXPECT_EQ(2030, years);
257 EXPECT_EQ(8, months);
258 EXPECT_EQ(7, days);
259 EXPECT_EQ(14, hours);
260 EXPECT_EQ(5, minutes);
261 EXPECT_EQ(13, seconds);
262}
263
264TEST_F(DateTimeTest, from_int64_t_with_conversion_format_YYMMDDHHMMSS_yearBelow2000)
265{
266 datetime.from_int64_t(900807140513LL, true);
267
268 assignDateTimeValues();
269
270 EXPECT_EQ(1990, years);
271 EXPECT_EQ(8, months);
272 EXPECT_EQ(7, days);
273 EXPECT_EQ(14, hours);
274 EXPECT_EQ(5, minutes);
275 EXPECT_EQ(13, seconds);
276}
277
278TEST_F(DateTimeTest, DISABLED_to_tm)
279{
280 years= 2030, months= 8, days= 17, hours= 14, minutes= 45, seconds= 13;
281 TemporalGenerator::DateTimeGen::make_datetime(&datetime, years, months, days, hours, minutes, seconds);
282 struct tm filled;
283
284 datetime.to_tm(&filled);
285
286 EXPECT_EQ(2030 - 1900, filled.tm_year);
287 EXPECT_EQ(8 - 1, filled.tm_mon);
288 EXPECT_EQ(17, filled.tm_mday);
289 EXPECT_EQ(14, filled.tm_hour);
290 EXPECT_EQ(45, filled.tm_min);
291 EXPECT_EQ(13, filled.tm_sec);
292
293 /* TODO:these fail, shouldn't they also be set properly? */
294 EXPECT_EQ(228, filled.tm_yday);
295 EXPECT_EQ(6, filled.tm_wday);
296 EXPECT_EQ(-1, filled.tm_isdst);
297}
298
299TEST_F(DateTimeTest, to_decimal)
300{
301 drizzled::type::Decimal to;
302 TemporalGenerator::DateTimeGen::make_datetime(&datetime, 1987, 6, 13, 5, 10, 13, 456);
303
304 datetime.to_decimal(&to);
305
306 EXPECT_EQ(19870,to.buf[0]);
307 EXPECT_EQ(613051013,to.buf[1]);
308 EXPECT_EQ(456000,to.buf[2]);
309}
310
311
312
313class DateTimeFromStringTest
314{
315 protected:
316 DateTime datetime;
317 bool result;
318 uint32_t years, months, days;
319 uint32_t hours, minutes, seconds;
320
321 void init()
322 {
323 init_temporal_formats();
324 }
325
326 void deinit()
327 {
328 deinit_temporal_formats();
329 }
330
331 void assignDateTimeValues()
332 {
333 years= datetime.years();
334 months= datetime.months();
335 days= datetime.days();
336 hours= datetime.hours();
337 minutes= datetime.minutes();
338 seconds= datetime.seconds();
339 }
340};
341
342class DateTimeFromStringFullFormatTest: public ::testing::TestWithParam<const char*>, public DateTimeFromStringTest
343{
344 virtual void SetUp()
345 {
346 init();
347 }
348
349 virtual void TearDown()
350 {
351 deinit();
352 }
353};
354
355class DateTimeFromStringNoSecondFormatTest: public ::testing::TestWithParam<const char*>, public DateTimeFromStringTest
356{
357 virtual void SetUp()
358 {
359 init();
360 }
361
362 virtual void TearDown()
363 {
364 deinit();
365 }
366};
367
368class DateTimeFromStringDateOnlyTest: public ::testing::TestWithParam<const char*>, public DateTimeFromStringTest
369{
370 virtual void SetUp()
371 {
372 init();
373 }
374
375 virtual void TearDown()
376 {
377 deinit();
378 }
379};
380
381TEST_P(DateTimeFromStringFullFormatTest, from_string_validString)
382{
383 const char *valid_string= GetParam();
384
385 result= datetime.from_string(valid_string, strlen(valid_string));
386 ASSERT_TRUE(result);
387
388 assignDateTimeValues();
389
390 EXPECT_EQ(2010, years);
391 EXPECT_EQ(5, months);
392 EXPECT_EQ(1, days);
393 EXPECT_EQ(8, hours);
394 EXPECT_EQ(7, minutes);
395 EXPECT_EQ(6, seconds);
396}
397/* TODO:for some reason this was not declared by the macro, needs clarification*/
398testing::internal::ParamGenerator<const char*> gtest_ValidStringDateTimeFromStringFullFormatTest_EvalGenerator_();
399INSTANTIATE_TEST_CASE_P(ValidString, DateTimeFromStringFullFormatTest,
400 ::testing::Values("20100501080706",
401 "2010-05-01 08:07:06",
402 "2010/05/01T08:07:06",
403 "2010.5.1 08:07:06",
404 "10-05-01 08:07:06",
405 "10/5/1 08:07:06",
406 "10.5.1 08:07:06"));
407
408
409TEST_P(DateTimeFromStringNoSecondFormatTest, from_string_validString)
410{
411 const char *valid_string= GetParam();
412
413 result= datetime.from_string(valid_string, strlen(valid_string));
414 ASSERT_TRUE(result);
415
416 assignDateTimeValues();
417
418 EXPECT_EQ(2010, years);
419 EXPECT_EQ(5, months);
420 EXPECT_EQ(1, days);
421 EXPECT_EQ(8, hours);
422 EXPECT_EQ(7, minutes);
423}
424
425/* TODO:for some reason this was not declared by the macro, needs clarification*/
426testing::internal::ParamGenerator<const char*> gtest_ValidStringDateTimeFromStringNoSecondFormatTest_EvalGenerator_();
427INSTANTIATE_TEST_CASE_P(ValidString, DateTimeFromStringNoSecondFormatTest,
428 ::testing::Values("2010-05-01 08:07",
429 "2010/05/01 08:07",
430 "2010.5.1 08:07",
431 "10-05-01 08:07",
432 "10/5/1 08:07",
433 "10.5.1 08:07"));
434
435
436
437TEST_P(DateTimeFromStringDateOnlyTest, from_string_validString)
438{
439 const char *valid_string= GetParam();
440
441 result= datetime.from_string(valid_string, strlen(valid_string));
442 ASSERT_TRUE(result);
443
444 assignDateTimeValues();
445
446 EXPECT_EQ(2010, years);
447 EXPECT_EQ(6, months);
448 EXPECT_EQ(7, days);
449}
450
451/* TODO:for some reason this was not declared by the macro, needs clarification*/
452testing::internal::ParamGenerator<const char*> gtest_ValidStringDateTimeFromStringDateOnlyTest_EvalGenerator_();
453INSTANTIATE_TEST_CASE_P(ValidString, DateTimeFromStringDateOnlyTest,
454 ::testing::Values("20100607", /* YYYYMMDD */
455 "06/07/2010",/* MM[-/.]DD[-/.]YYYY (US common format)*/
456 "10.06.07",/* YY[-/.]MM[-/.]DD */
457 "10/6/7",/* YY[-/.][M]M[-/.][D]D */
458 "2010-6-7"/* YYYY[-/.][M]M[-/.][D]D */));
459
460
4610
=== removed file 'unittests/generators.cc'
--- unittests/generators.cc 2010-07-09 17:59:07 +0000
+++ unittests/generators.cc 1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Brian Aker
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24
25#include <drizzled/generator.h>
26#include <drizzled/plugin/listen.h>
27
28/*
29 These will not work currently because of init issues for the server.
30*/
31#if 0
32TEST(generator_test, schema)
33{
34 drizzled::Session session(drizzled::plugin::Listen::getNullClient());
35 drizzled::generator::Schema generator(session);
36
37 const drizzled::message::Schema *schema_ptr;
38 if ((schema_ptr= generator))
39 ASSERT_TRUE(0);
40}
41
42TEST(generator_test, table)
43{
44 drizzled::Session session(drizzled::plugin::Listen::getNullClient());
45 drizzled::SchemaIdentifier schema("foo");
46 drizzled::generator::Table generator(session, schema);
47 const drizzled::message::Table *table_ptr;
48
49 if ((table_ptr= generator))
50 ASSERT_TRUE(0);
51}
52
53TEST(generator_test, all_tables)
54{
55 drizzled::Session session(drizzled::plugin::Listen::getNullClient());
56 drizzled::generator::AllTables generator(session);
57 const drizzled::message::Table *table_ptr;
58
59 if ((table_ptr= generator))
60 ASSERT_TRUE(0);
61}
62
63TEST(generator_test, all_fields)
64{
65 drizzled::Session session(drizzled::plugin::Listen::getNullClient());
66 drizzled::generator::AllFields generator(session);
67 const drizzled::message::Table::Field *field_ptr;
68
69 if ((field_ptr= generator))
70 ASSERT_TRUE(0);
71}
72#endif
730
=== added file 'unittests/global_buffer_test.cc'
--- unittests/global_buffer_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/global_buffer_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,64 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Andrew Hutchings
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include "drizzled/global_buffer.h"
27
28BOOST_AUTO_TEST_SUITE(GlobalBufferTests)
29BOOST_AUTO_TEST_CASE(overflow)
30{
31 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
32
33 BOOST_REQUIRE(test_buffer.add(512));
34 BOOST_REQUIRE(test_buffer.add(512));
35 BOOST_REQUIRE(not test_buffer.add(1));
36}
37
38BOOST_AUTO_TEST_CASE(subtract)
39{
40 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
41
42 BOOST_REQUIRE(test_buffer.add(1024));
43 BOOST_REQUIRE(test_buffer.sub(512));
44 BOOST_REQUIRE(test_buffer.add(512));
45 BOOST_REQUIRE(not test_buffer.add(1));
46}
47
48BOOST_AUTO_TEST_CASE(underflow)
49{
50 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
51
52 BOOST_REQUIRE(test_buffer.add(10));
53 BOOST_REQUIRE(not test_buffer.sub(11));
54}
55
56BOOST_AUTO_TEST_CASE(change_max)
57{
58 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
59
60 test_buffer.setMaxSize(512);
61
62 BOOST_REQUIRE(not test_buffer.add(513));
63}
64BOOST_AUTO_TEST_SUITE_END()
065
=== removed file 'unittests/global_buffer_test.cc'
--- unittests/global_buffer_test.cc 2010-10-20 09:34:21 +0000
+++ unittests/global_buffer_test.cc 1970-01-01 00:00:00 +0000
@@ -1,60 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Andrew Hutchings
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include "drizzled/global_buffer.h"
25
26TEST(global_buffer, overflow)
27{
28 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
29
30 ASSERT_TRUE(test_buffer.add(512));
31 ASSERT_TRUE(test_buffer.add(512));
32 ASSERT_FALSE(test_buffer.add(1));
33}
34
35TEST(global_buffer, subtract)
36{
37 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
38
39 ASSERT_TRUE(test_buffer.add(1024));
40 ASSERT_TRUE(test_buffer.sub(512));
41 ASSERT_TRUE(test_buffer.add(512));
42 ASSERT_FALSE(test_buffer.add(1));
43}
44
45TEST(global_buffer, underflow)
46{
47 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
48
49 ASSERT_TRUE(test_buffer.add(10));
50 ASSERT_FALSE(test_buffer.sub(11));
51}
52
53TEST(global_buffer, change_max)
54{
55 drizzled::global_buffer_constraint<uint64_t> test_buffer(1024);
56
57 test_buffer.setMaxSize(512);
58
59 ASSERT_FALSE(test_buffer.add(513));
60}
610
=== modified file 'unittests/include.am'
--- unittests/include.am 2010-12-28 20:54:15 +0000
+++ unittests/include.am 2011-01-24 09:18:02 +0000
@@ -17,8 +17,7 @@
17# along with this program; if not, write to the Free Software17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
2020if HAVE_BOOST_TEST
21if HAVE_LIBGTEST
22check_PROGRAMS += unittests/unittests21check_PROGRAMS += unittests/unittests
23endif22endif
2423
@@ -26,9 +25,6 @@
26 unittests/plugin/plugin_stubs.h \25 unittests/plugin/plugin_stubs.h \
27 unittests/temporal_generator.h26 unittests/temporal_generator.h
2827
29EXTRA_DIST += \
30 unittests/client_server.c
31
32unit: unittests/unittests28unit: unittests/unittests
33 unittests/unittests29 unittests/unittests
3430
@@ -38,30 +34,26 @@
38# 34#
3935
40unittests_unittests_SOURCES = \36unittests_unittests_SOURCES = \
37 unittests/main.cc \
41 unittests/atomics_test.cc \38 unittests/atomics_test.cc \
42 unittests/calendar_test.cc \39 unittests/calendar_test.cc \
43 unittests/constrained_value.cc \40 unittests/constrained_value.cc \
44 unittests/date_test.cc \41 unittests/date_test.cc \
45 unittests/date_time_test.cc \42 unittests/date_time_test.cc \
46 unittests/generators.cc \43 unittests/global_buffer_test.cc \
47 unittests/global_buffer_test.cc \44 unittests/libdrizzle_test.cc \
48 unittests/libdrizzle_test.cc \
49 unittests/main.cc \
50 unittests/micro_timestamp_test.cc \45 unittests/micro_timestamp_test.cc \
51 unittests/nano_timestamp_test.cc \46 unittests/nano_timestamp_test.cc \
52 unittests/option_context.cc \47 unittests/option_context.cc \
53 unittests/plugin/authentication_test.cc \
54 unittests/plugin/client_test.cc \
55 unittests/plugin/error_message_test.cc \
56 unittests/pthread_atomics_test.cc \48 unittests/pthread_atomics_test.cc \
57 unittests/table_identifier.cc \49 unittests/table_identifier.cc \
58 unittests/temporal_format_test.cc \50 unittests/temporal_format_test.cc \
59 unittests/temporal_generator.cc \51 unittests/temporal_generator.cc \
52 unittests/timestamp_test.cc \
60 unittests/time_test.cc \53 unittests/time_test.cc \
61 unittests/timestamp_test.cc \
62 unittests/utf8_test.cc54 unittests/utf8_test.cc
6355
64unittests_unittests_LDADD= \56unittests_unittests_LDADD= \
65 $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \57 $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \
66 ${drizzled_drizzled_LDADD} ${LTLIBGTEST} ${BOOST_LIBS} \58 ${drizzled_drizzled_LDADD} ${BOOST_LIBS} libdrizzle/libdrizzle.la \
67 libdrizzle/libdrizzle.la59 ${LTLIBBOOST_UNIT_TEST_FRAMEWORK} ${LTLIBBOOST_UNIT_TEST_FRAMEWORK_MT}
6860
=== added file 'unittests/libdrizzle_test.cc'
--- unittests/libdrizzle_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/libdrizzle_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,63 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Andrew Hutchings
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <libdrizzle/drizzle_client.h>
27#include <libdrizzle/drizzle_server.h>
28
29BOOST_AUTO_TEST_SUITE(LibDrizzle)
30BOOST_AUTO_TEST_CASE(drizzleEscapeString)
31{
32 const char* orig= "hello \"world\"\n";
33 char out[255];
34 size_t out_len;
35
36 out_len= drizzle_escape_string(out, orig, strlen(orig));
37
38 BOOST_REQUIRE_EQUAL(17, out_len);
39 BOOST_REQUIRE_EQUAL("hello \\\"world\\\"\\n", out);
40}
41
42BOOST_AUTO_TEST_CASE(drizzleHexString)
43{
44 const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF};
45 char out[255];
46 size_t out_len;
47
48 out_len= drizzle_hex_string(out, (char*) orig, 5);
49
50 BOOST_REQUIRE_EQUAL(10, out_len);
51 BOOST_REQUIRE_EQUAL("34268099FF", out);
52}
53
54BOOST_AUTO_TEST_CASE(drizzleMysqlPasswordHash)
55{
56 const char* orig= "test password";
57 char out[255];
58
59 drizzle_mysql_password_hash(out, orig, strlen(orig));
60
61 BOOST_REQUIRE_EQUAL("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out);
62}
63BOOST_AUTO_TEST_SUITE_END()
064
=== removed file 'unittests/libdrizzle_test.cc'
--- unittests/libdrizzle_test.cc 2010-10-17 16:04:42 +0000
+++ unittests/libdrizzle_test.cc 1970-01-01 00:00:00 +0000
@@ -1,59 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Andrew Hutchings
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <libdrizzle/drizzle_client.h>
25#include <libdrizzle/drizzle_server.h>
26
27TEST(libdrizzle, drizzle_escape_string)
28{
29 const char* orig= "hello \"world\"\n";
30 char out[255];
31 size_t out_len;
32
33 out_len= drizzle_escape_string(out, orig, strlen(orig));
34
35 EXPECT_EQ(17, out_len);
36 ASSERT_STREQ("hello \\\"world\\\"\\n", out);
37}
38
39TEST(libdrizzle, drizzle_hex_string)
40{
41 const unsigned char orig[5]= {0x34, 0x26, 0x80, 0x99, 0xFF};
42 char out[255];
43 size_t out_len;
44
45 out_len= drizzle_hex_string(out, (char*) orig, 5);
46
47 EXPECT_EQ(10, out_len);
48 ASSERT_STREQ("34268099FF", out);
49}
50
51TEST(libdrizzle, drizzle_mysql_password_hash)
52{
53 const char* orig= "test password";
54 char out[255];
55
56 drizzle_mysql_password_hash(out, orig, strlen(orig));
57
58 ASSERT_STREQ("3B942720DACACBBA7E3838AF03C5B6B5A6DFE0AB", out);
59}
600
=== modified file 'unittests/main.cc'
--- unittests/main.cc 2010-06-06 20:55:30 +0000
+++ unittests/main.cc 2011-01-24 09:18:02 +0000
@@ -1,7 +1,7 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *3 *
4 * Copyright (C) 2010 Stewart Smith4 * Copyright (C) 2011 Andrew Hutchings
5 *5 *
6 * This program is free software; you can redistribute it and/or modify6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by7 * it under the terms of the GNU General Public License as published by
@@ -18,15 +18,26 @@
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */19 */
2020
21#include "config.h"21#define BOOST_TEST_DYN_LINK
2222#define BOOST_TEST_MAIN
23#include <gtest/gtest.h>23#include <boost/test/unit_test.hpp>
2424#include <iostream>
25#include <drizzled/internal/my_sys.h>25
2626struct MyConfig
27int main(int argc, char **argv)27{
28{28 MyConfig()
29 MY_INIT(argv[0]);29 {
30 ::testing::InitGoogleTest(&argc, argv);30 boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages);
31 return RUN_ALL_TESTS();31 }
32
33 ~MyConfig()
34 {
35 }
36};
37
38BOOST_GLOBAL_FIXTURE( MyConfig )
39
40BOOST_AUTO_TEST_CASE(MainInit)
41{
42 BOOST_REQUIRE(true);
32}43}
3344
=== added file 'unittests/micro_timestamp_test.cc'
--- unittests/micro_timestamp_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/micro_timestamp_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,112 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <drizzled/temporal.h>
27
28#include "temporal_generator.h"
29
30using namespace drizzled;
31
32class MicroTimestampTest
33{
34 protected:
35 MicroTimestamp micro_timestamp;
36 bool result;
37};
38
39BOOST_FIXTURE_TEST_SUITE(MicroTimestampTestSuite, MicroTimestampTest)
40BOOST_AUTO_TEST_CASE(is_valid_minOfMicroTimestampRange_shouldReturn_True)
41{
42 uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, microsecond= 0;
43 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
44
45 result= micro_timestamp.is_valid();
46
47 BOOST_REQUIRE(result);
48}
49
50BOOST_AUTO_TEST_CASE(is_valid_maxOfMicroTimestampRange_shouldReturn_True)
51{
52 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, microsecond= 0;
53 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
54
55 result= micro_timestamp.is_valid();
56
57 BOOST_REQUIRE(result);
58}
59
60BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondBeforeMicroTimestampMinOfRange_shouldReturn_False)
61{
62 uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, microsecond= 999999;
63 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
64
65 result= micro_timestamp.is_valid();
66
67 BOOST_REQUIRE(not result);
68}
69
70BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondAfterMicroTimestampMaxOfRange_shouldReturn_False)
71{
72 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, microsecond= 1;
73 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
74
75 result= micro_timestamp.is_valid();
76
77 BOOST_REQUIRE(not result);
78}
79
80BOOST_AUTO_TEST_CASE(is_valid_InsideOfMicroTimestampRange_shouldReturn_True)
81{
82 uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, microsecond= 18263;
83 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
84
85 result= micro_timestamp.is_valid();
86
87 BOOST_REQUIRE(result);
88}
89
90BOOST_AUTO_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements)
91{
92 char expected[MicroTimestamp::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.007654";
93 char returned[MicroTimestamp::MAX_STRING_LENGTH];
94 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, 2010, 5, 1, 8, 7, 6, 7654);
95
96 micro_timestamp.to_string(returned, MicroTimestamp::MAX_STRING_LENGTH);
97
98 BOOST_REQUIRE_EQUAL(expected, returned);
99}
100
101BOOST_AUTO_TEST_CASE(to_timeval)
102{
103 struct timeval filled;
104 uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, microsecond= 675;
105 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
106
107 micro_timestamp.to_timeval(filled);
108
109 BOOST_REQUIRE_EQUAL(1244005141, filled.tv_sec);
110 BOOST_REQUIRE_EQUAL(675, filled.tv_usec);
111}
112BOOST_AUTO_TEST_SUITE_END()
0113
=== removed file 'unittests/micro_timestamp_test.cc'
--- unittests/micro_timestamp_test.cc 2011-01-20 07:24:29 +0000
+++ unittests/micro_timestamp_test.cc 1970-01-01 00:00:00 +0000
@@ -1,108 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <drizzled/temporal.h>
25
26#include "temporal_generator.h"
27
28using namespace drizzled;
29
30class MicroTimestampTest : public ::testing::Test
31{
32 protected:
33 MicroTimestamp micro_timestamp;
34 bool result;
35};
36
37TEST_F(MicroTimestampTest, is_valid_minOfMicroTimestampRange_shouldReturn_True)
38{
39 uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, microsecond= 0;
40 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
41
42 result= micro_timestamp.is_valid();
43
44 ASSERT_TRUE(result);
45}
46
47TEST_F(MicroTimestampTest, is_valid_maxOfMicroTimestampRange_shouldReturn_True)
48{
49 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, microsecond= 0;
50 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
51
52 result= micro_timestamp.is_valid();
53
54 ASSERT_TRUE(result);
55}
56
57TEST_F(MicroTimestampTest, is_valid_oneMicroSecondBeforeMicroTimestampMinOfRange_shouldReturn_False)
58{
59 uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, microsecond= 999999;
60 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
61
62 result= micro_timestamp.is_valid();
63
64 ASSERT_FALSE(result);
65}
66
67TEST_F(MicroTimestampTest, is_valid_oneMicroSecondAfterMicroTimestampMaxOfRange_shouldReturn_False)
68{
69 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, microsecond= 1;
70 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
71
72 result= micro_timestamp.is_valid();
73
74 ASSERT_FALSE(result);
75}
76
77TEST_F(MicroTimestampTest, is_valid_InsideOfMicroTimestampRange_shouldReturn_True)
78{
79 uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, microsecond= 18263;
80 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
81
82 result= micro_timestamp.is_valid();
83
84 ASSERT_TRUE(result);
85}
86
87TEST_F(MicroTimestampTest, to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements)
88{
89 char expected[MicroTimestamp::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.007654";
90 char returned[MicroTimestamp::MAX_STRING_LENGTH];
91 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, 2010, 5, 1, 8, 7, 6, 7654);
92
93 micro_timestamp.to_string(returned, MicroTimestamp::MAX_STRING_LENGTH);
94
95 ASSERT_STREQ(expected, returned);
96}
97
98TEST_F(MicroTimestampTest, to_timeval)
99{
100 struct timeval filled;
101 uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, microsecond= 675;
102 TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
103
104 micro_timestamp.to_timeval(filled);
105
106 EXPECT_EQ(1244005141, filled.tv_sec);
107 EXPECT_EQ(675, filled.tv_usec);
108}
1090
=== added file 'unittests/nano_timestamp_test.cc'
--- unittests/nano_timestamp_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/nano_timestamp_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,101 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <drizzled/temporal.h>
27
28#include "temporal_generator.h"
29
30using namespace drizzled;
31
32class NanoTimestampTest
33{
34 protected:
35 NanoTimestamp nano_timestamp;
36 bool result;
37};
38
39BOOST_FIXTURE_TEST_SUITE(NanoTimestampTestSuite, NanoTimestampTest)
40BOOST_AUTO_TEST_CASE(is_valid_minOfNanoTimestampRange_shouldReturn_True)
41{
42 uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, nanosecond= 0;
43 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
44
45 result= nano_timestamp.is_valid();
46
47 BOOST_REQUIRE(result);
48}
49
50BOOST_AUTO_TEST_CASE(is_valid_maxOfNanoTimestampRange_shouldReturn_True)
51{
52 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, nanosecond= 0;
53 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
54
55 result= nano_timestamp.is_valid();
56
57 BOOST_REQUIRE(result);
58}
59
60BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondBeforeNanoTimestampMinOfRange_shouldReturn_False)
61{
62 uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, nanosecond= 999999999;
63 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
64
65 result= nano_timestamp.is_valid();
66
67 BOOST_REQUIRE(not result);
68}
69
70BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondAfterNanoTimestampMaxOfRange_shouldReturn_False)
71{
72 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, nanosecond= 1;
73 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
74
75 result= nano_timestamp.is_valid();
76
77 BOOST_REQUIRE(not result);
78}
79
80BOOST_AUTO_TEST_CASE(is_valid_InsideOfNanoTimestampRange_shouldReturn_True)
81{
82 uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, nanosecond= 3265832;
83 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
84
85 result= nano_timestamp.is_valid();
86
87 BOOST_REQUIRE(result);
88}
89
90BOOST_AUTO_TEST_CASE(to_timespec)
91{
92 struct timespec filled;
93 uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, nanosecond= 675;
94 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
95
96 nano_timestamp.to_timespec(&filled);
97
98 BOOST_REQUIRE_EQUAL(1244005141, filled.tv_sec);
99 BOOST_REQUIRE_EQUAL(675, filled.tv_nsec);
100}
101BOOST_AUTO_TEST_SUITE_END()
0102
=== removed file 'unittests/nano_timestamp_test.cc'
--- unittests/nano_timestamp_test.cc 2011-01-20 07:24:29 +0000
+++ unittests/nano_timestamp_test.cc 1970-01-01 00:00:00 +0000
@@ -1,97 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <drizzled/temporal.h>
25
26#include "temporal_generator.h"
27
28using namespace drizzled;
29
30class NanoTimestampTest : public ::testing::Test
31{
32 protected:
33 NanoTimestamp nano_timestamp;
34 bool result;
35};
36
37TEST_F(NanoTimestampTest, is_valid_minOfNanoTimestampRange_shouldReturn_True)
38{
39 uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, nanosecond= 0;
40 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
41
42 result= nano_timestamp.is_valid();
43
44 ASSERT_TRUE(result);
45}
46
47TEST_F(NanoTimestampTest, is_valid_maxOfNanoTimestampRange_shouldReturn_True)
48{
49 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, nanosecond= 0;
50 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
51
52 result= nano_timestamp.is_valid();
53
54 ASSERT_TRUE(result);
55}
56
57TEST_F(NanoTimestampTest, is_valid_oneMicroSecondBeforeNanoTimestampMinOfRange_shouldReturn_False)
58{
59 uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, nanosecond= 999999999;
60 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
61
62 result= nano_timestamp.is_valid();
63
64 ASSERT_FALSE(result);
65}
66
67TEST_F(NanoTimestampTest, is_valid_oneMicroSecondAfterNanoTimestampMaxOfRange_shouldReturn_False)
68{
69 uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, nanosecond= 1;
70 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
71
72 result= nano_timestamp.is_valid();
73
74 ASSERT_FALSE(result);
75}
76
77TEST_F(NanoTimestampTest, is_valid_InsideOfNanoTimestampRange_shouldReturn_True)
78{
79 uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, nanosecond= 3265832;
80 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
81
82 result= nano_timestamp.is_valid();
83
84 ASSERT_TRUE(result);
85}
86
87TEST_F(NanoTimestampTest, to_timespec)
88{
89 struct timespec filled;
90 uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, nanosecond= 675;
91 TemporalGenerator::TimestampGen::make_nano_timestamp(&nano_timestamp, year, month, day, hour, minute, second, nanosecond);
92
93 nano_timestamp.to_timespec(&filled);
94
95 EXPECT_EQ(1244005141, filled.tv_sec);
96 EXPECT_EQ(675, filled.tv_nsec);
97}
980
=== added file 'unittests/option_context.cc'
--- unittests/option_context.cc 1970-01-01 00:00:00 +0000
+++ unittests/option_context.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,60 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Monty Taylor
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <boost/program_options.hpp>
27
28#include "drizzled/module/option_context.h"
29
30namespace po=boost::program_options;
31
32using namespace drizzled;
33
34BOOST_AUTO_TEST_SUITE(OptionContext)
35BOOST_AUTO_TEST_CASE(parsing)
36{
37 const std::string module_name("test");
38 po::options_description command_line_options("Test prefix injection");
39 module::option_context ctx(module_name, command_line_options.add_options());
40
41 ctx("option", po::value<std::string>(), "Test option name prefix injection");
42
43 po::variables_map vm;
44
45 const char *options[]= {
46 "test", "--test.option=foo"
47 };
48
49 // Disable allow_guessing
50 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
51
52 po::store(po::command_line_parser(2, (char **)options).style(style).
53 options(command_line_options).run(), vm);
54 po::notify(vm);
55
56 BOOST_REQUIRE_EQUAL(0, vm.count("option"));
57 BOOST_REQUIRE_EQUAL(1, vm.count("test.option"));
58 BOOST_REQUIRE_EQUAL(0, vm["test.option"].as<std::string>().compare("foo"));
59}
60BOOST_AUTO_TEST_SUITE_END()
061
=== removed file 'unittests/option_context.cc'
--- unittests/option_context.cc 2010-09-26 08:33:47 +0000
+++ unittests/option_context.cc 1970-01-01 00:00:00 +0000
@@ -1,56 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Monty Taylor
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24#include <boost/program_options.hpp>
25
26#include "drizzled/module/option_context.h"
27
28namespace po=boost::program_options;
29
30using namespace drizzled;
31
32TEST(option_context, parsing)
33{
34 const std::string module_name("test");
35 po::options_description command_line_options("Test prefix injection");
36 module::option_context ctx(module_name, command_line_options.add_options());
37
38 ctx("option", po::value<std::string>(), "Test option name prefix injection");
39
40 po::variables_map vm;
41
42 const char *options[]= {
43 "test", "--test.option=foo"
44 };
45
46 // Disable allow_guessing
47 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
48
49 po::store(po::command_line_parser(2, (char **)options).style(style).
50 options(command_line_options).run(), vm);
51 po::notify(vm);
52
53 EXPECT_EQ(0, vm.count("option"));
54 EXPECT_EQ(1, vm.count("test.option"));
55 EXPECT_EQ(0, vm["test.option"].as<std::string>().compare("foo"));
56}
570
=== added file 'unittests/pthread_atomics_test.cc'
--- unittests/pthread_atomics_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/pthread_atomics_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,130 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Stewart Smith
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26# if defined(__SUNPRO_CC)
27# include <drizzled/atomic/sun_studio.h>
28# endif
29
30# if !defined(__ICC) && (defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC))
31# include <drizzled/atomic/gcc_traits.h>
32# define ATOMIC_TRAITS internal::gcc_traits
33# else /* use pthread impl */
34# define ATOMIC_TRAITS internal::pthread_traits
35# endif
36
37#include <pthread.h>
38#include <drizzled/atomic/pthread_traits.h>
39
40#include <drizzled/atomics.h>
41
42using namespace drizzled;
43
44template<typename T>
45struct atomic_pthread {
46};
47
48# define __DRIZZLE_DECL_ATOMIC_PTHREAD(T) \
49 template<> struct atomic_pthread<T> \
50 : internal::atomic_impl<T,T, internal::pthread_traits<T,T> > { \
51 atomic_pthread<T>() \
52 : internal::atomic_impl<T,T, internal::pthread_traits<T,T> >() {} \
53 T operator=( T rhs ) { return store_with_release(rhs); } \
54 };
55
56__DRIZZLE_DECL_ATOMIC_PTHREAD(unsigned int)
57
58BOOST_AUTO_TEST_SUITE(PthreadAtomicOperations)
59BOOST_AUTO_TEST_CASE(fetch_and_store)
60{
61 atomic_pthread<uint32_t> u235;
62
63 BOOST_REQUIRE_EQUAL(0, u235.fetch_and_store(1));
64
65 u235.fetch_and_store(15);
66
67 BOOST_REQUIRE_EQUAL(15, u235.fetch_and_store(100));
68 BOOST_REQUIRE_EQUAL(100, u235);
69}
70
71BOOST_AUTO_TEST_CASE(fetch_and_increment)
72{
73 atomic_pthread<uint32_t> u235;
74
75 BOOST_REQUIRE_EQUAL(0, u235.fetch_and_increment());
76 BOOST_REQUIRE_EQUAL(1, u235);
77}
78
79BOOST_AUTO_TEST_CASE(fetch_and_add)
80{
81 atomic_pthread<uint32_t> u235;
82
83 BOOST_REQUIRE_EQUAL(0, u235.fetch_and_add(2));
84 BOOST_REQUIRE_EQUAL(2, u235);
85}
86
87BOOST_AUTO_TEST_CASE(add_and_fetch)
88{
89 atomic_pthread<uint32_t> u235;
90
91 BOOST_REQUIRE_EQUAL(10, u235.add_and_fetch(10));
92 BOOST_REQUIRE_EQUAL(10, u235);
93}
94
95BOOST_AUTO_TEST_CASE(fetch_and_decrement)
96{
97 atomic_pthread<uint32_t> u235;
98
99 u235.fetch_and_store(15);
100
101 BOOST_REQUIRE_EQUAL(15, u235.fetch_and_decrement());
102 BOOST_REQUIRE_EQUAL(14, u235);
103}
104
105BOOST_AUTO_TEST_CASE(compare_and_swap)
106{
107 atomic_pthread<uint32_t> u235;
108
109 u235.fetch_and_store(100);
110
111 BOOST_REQUIRE(not u235.compare_and_swap(42, 200));
112 BOOST_REQUIRE(u235.compare_and_swap(200, 100));
113 BOOST_REQUIRE_EQUAL(200, u235);
114}
115
116BOOST_AUTO_TEST_CASE(increment)
117{
118 atomic_pthread<uint32_t> u235;
119 u235.fetch_and_store(200);
120 BOOST_REQUIRE_EQUAL(201, u235.increment());
121}
122
123BOOST_AUTO_TEST_CASE(decrement)
124{
125 atomic_pthread<uint32_t> u235;
126 u235.fetch_and_store(200);
127
128 BOOST_REQUIRE_EQUAL(199, u235.decrement());
129}
130BOOST_AUTO_TEST_SUITE_END()
0131
=== removed file 'unittests/pthread_atomics_test.cc'
--- unittests/pthread_atomics_test.cc 2010-10-20 09:36:04 +0000
+++ unittests/pthread_atomics_test.cc 1970-01-01 00:00:00 +0000
@@ -1,134 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Stewart Smith
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24
25# if defined(__SUNPRO_CC)
26# include <drizzled/atomic/sun_studio.h>
27# endif
28
29# if !defined(__ICC) && (defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC))
30# include <drizzled/atomic/gcc_traits.h>
31# define ATOMIC_TRAITS internal::gcc_traits
32# else /* use pthread impl */
33# define ATOMIC_TRAITS internal::pthread_traits
34# endif
35
36#include <pthread.h>
37#include <drizzled/atomic/pthread_traits.h>
38
39#include <drizzled/atomics.h>
40
41using namespace drizzled;
42
43template<typename T>
44struct atomic_pthread {
45};
46
47# define __DRIZZLE_DECL_ATOMIC_PTHREAD(T) \
48 template<> struct atomic_pthread<T> \
49 : internal::atomic_impl<T,T, internal::pthread_traits<T,T> > { \
50 atomic_pthread<T>() \
51 : internal::atomic_impl<T,T, internal::pthread_traits<T,T> >() {} \
52 T operator=( T rhs ) { return store_with_release(rhs); } \
53 };
54
55__DRIZZLE_DECL_ATOMIC_PTHREAD(unsigned int)
56
57TEST(pthread_atomic_operations, fetch_and_store)
58{
59 atomic_pthread<uint32_t> u235;
60
61 EXPECT_EQ(0, u235.fetch_and_store(1));
62
63 u235.fetch_and_store(15);
64
65 EXPECT_EQ(15, u235.fetch_and_store(100));
66 EXPECT_EQ(100, u235);
67}
68
69TEST(pthread_atomic_operations, fetch_and_increment)
70{
71 atomic_pthread<uint32_t> u235;
72
73 EXPECT_EQ(0, u235.fetch_and_increment());
74 EXPECT_EQ(1, u235);
75}
76
77TEST(pthread_atomic_operations, fetch_and_add)
78{
79 atomic_pthread<uint32_t> u235;
80
81 EXPECT_EQ(0, u235.fetch_and_add(2));
82 EXPECT_EQ(2, u235);
83}
84
85TEST(pthread_atomic_operations, add_and_fetch)
86{
87 atomic_pthread<uint32_t> u235;
88
89 EXPECT_EQ(10, u235.add_and_fetch(10));
90 EXPECT_EQ(10, u235);
91}
92
93TEST(pthread_atomic_operations, fetch_and_decrement)
94{
95 atomic_pthread<uint32_t> u235;
96
97 u235.fetch_and_store(15);
98
99 EXPECT_EQ(15, u235.fetch_and_decrement());
100 EXPECT_EQ(14, u235);
101}
102
103TEST(pthread_atomic_operations, compare_and_swap)
104{
105 atomic_pthread<uint32_t> u235;
106
107 u235.fetch_and_store(100);
108
109 ASSERT_FALSE(u235.compare_and_swap(42, 200));
110 ASSERT_TRUE(u235.compare_and_swap(200, 100));
111 EXPECT_EQ(200, u235);
112}
113
114TEST(pthread_atomic_operations, increment)
115{
116 atomic_pthread<uint32_t> u235;
117 u235.fetch_and_store(200);
118 EXPECT_EQ(201, u235.increment());
119}
120
121TEST(pthread_atomic_operations, decrement)
122{
123 atomic_pthread<uint32_t> u235;
124 u235.fetch_and_store(200);
125
126 EXPECT_EQ(199, u235.decrement());
127}
128
129// these don't build for whatever reason
130// EXPECT_EQ(242, u235+=42);
131// EXPECT_EQ(200, u235-=42);
132
133
134
1350
=== added file 'unittests/table_identifier.cc'
--- unittests/table_identifier.cc 1970-01-01 00:00:00 +0000
+++ unittests/table_identifier.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,91 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Brian Aker
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
25
26#include <drizzled/identifier.h>
27
28using namespace drizzled;
29
30BOOST_AUTO_TEST_SUITE(TableIdentifierTest)
31BOOST_AUTO_TEST_CASE(CreateStandard)
32{
33 identifier::Table identifier("test", "a");
34 BOOST_REQUIRE_EQUAL("test/a", identifier.getPath());
35 std::string path;
36 identifier.getSQLPath(path);
37 BOOST_REQUIRE_EQUAL("test.a", path);
38}
39
40BOOST_AUTO_TEST_CASE(CreateTemporary)
41{
42 identifier::Table identifier("test", "a", message::Table::TEMPORARY);
43 BOOST_REQUIRE_EQUAL("/#sql", identifier.getPath().substr(0, 5));
44 std::string path;
45 identifier.getSQLPath(path);
46 BOOST_REQUIRE_EQUAL("test.#a", path);
47}
48
49BOOST_AUTO_TEST_CASE(CreateInternal)
50{
51 identifier::Table identifier("test", "a", message::Table::TEMPORARY);
52 BOOST_REQUIRE_EQUAL("/#sql", identifier.getPath().substr(0, 5));
53 std::string path;
54 identifier.getSQLPath(path);
55 BOOST_REQUIRE_EQUAL("test.#a", path);
56}
57
58BOOST_AUTO_TEST_CASE(StaticTmpTable)
59{
60 std::vector<char> pathname;
61
62 identifier::Table::build_tmptable_filename(pathname);
63
64 BOOST_REQUIRE_GT(pathname.size(), 0);
65 BOOST_REQUIRE_GT(strlen(&pathname[0]), 0);
66}
67
68BOOST_AUTO_TEST_CASE(Key)
69{
70 identifier::Table identifier("test", "a");
71
72 const identifier::Table::Key key= identifier.getKey();
73
74 BOOST_REQUIRE_EQUAL(key.size(), 7);
75 BOOST_REQUIRE_EQUAL(key.vector()[0], 't');
76 BOOST_REQUIRE_EQUAL(key.vector()[1], 'e');
77 BOOST_REQUIRE_EQUAL(key.vector()[2], 's');
78 BOOST_REQUIRE_EQUAL(key.vector()[3], 't');
79 BOOST_REQUIRE_EQUAL(key.vector()[4], 0);
80 BOOST_REQUIRE_EQUAL(key.vector()[5], 'a');
81 BOOST_REQUIRE_EQUAL(key.vector()[6], 0);
82}
83
84BOOST_AUTO_TEST_CASE(KeyCompare)
85{
86 identifier::Table identifier("test", "a");
87 identifier::Table identifier2("test", "a");
88
89 BOOST_REQUIRE_EQUAL((identifier.getKey() == identifier.getKey()), true);
90}
91BOOST_AUTO_TEST_SUITE_END()
092
=== removed file 'unittests/table_identifier.cc'
--- unittests/table_identifier.cc 2011-01-17 04:15:23 +0000
+++ unittests/table_identifier.cc 1970-01-01 00:00:00 +0000
@@ -1,88 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Brian Aker
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <gtest/gtest.h>
24
25#include <drizzled/identifier.h>
26
27using namespace drizzled;
28
29TEST(table_identifier_test_standard, Create)
30{
31 identifier::Table identifier("test", "a");
32 EXPECT_EQ("test/a", identifier.getPath());
33 std::string path;
34 identifier.getSQLPath(path);
35 EXPECT_EQ("test.a", path);
36}
37
38TEST(table_identifier_test_temporary, Create)
39{
40 identifier::Table identifier("test", "a", message::Table::TEMPORARY);
41 EXPECT_EQ("/#sql", identifier.getPath().substr(0, 5));
42 std::string path;
43 identifier.getSQLPath(path);
44 EXPECT_EQ("test.#a", path);
45}
46
47TEST(table_identifier_test_internal, Create)
48{
49 identifier::Table identifier("test", "a", message::Table::TEMPORARY);
50 EXPECT_EQ("/#sql", identifier.getPath().substr(0, 5));
51 std::string path;
52 identifier.getSQLPath(path);
53 EXPECT_EQ("test.#a", path);
54}
55
56TEST(table_identifier_test_build_tmptable_filename, Static)
57{
58 std::vector<char> pathname;
59
60 identifier::Table::build_tmptable_filename(pathname);
61
62 EXPECT_GT(pathname.size(), 0);
63 EXPECT_GT(strlen(&pathname[0]), 0);
64}
65
66TEST(table_identifier_test_key, Key)
67{
68 identifier::Table identifier("test", "a");
69
70 const identifier::Table::Key key= identifier.getKey();
71
72 EXPECT_EQ(key.size(), 7);
73 EXPECT_EQ(key.vector()[0], 't');
74 EXPECT_EQ(key.vector()[1], 'e');
75 EXPECT_EQ(key.vector()[2], 's');
76 EXPECT_EQ(key.vector()[3], 't');
77 EXPECT_EQ(key.vector()[4], 0);
78 EXPECT_EQ(key.vector()[5], 'a');
79 EXPECT_EQ(key.vector()[6], 0);
80}
81
82TEST(table_identifier_test_key, KeyCompare)
83{
84 identifier::Table identifier("test", "a");
85 identifier::Table identifier2("test", "a");
86
87 EXPECT_EQ((identifier.getKey() == identifier.getKey()), true);
88}
890
=== added file 'unittests/temporal_format_test.cc'
--- unittests/temporal_format_test.cc 1970-01-01 00:00:00 +0000
+++ unittests/temporal_format_test.cc 2011-01-24 09:18:02 +0000
@@ -0,0 +1,157 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <drizzled/temporal.h>
24#include <drizzled/temporal_format.h>
25
26#define BOOST_TEST_DYN_LINK
27#include <boost/test/unit_test.hpp>
28
29#include <vector>
30
31#include "temporal_generator.h"
32
33using namespace drizzled;
34
35class TemporalFormatTest
36{
37 protected:
38 TemporalFormat *tf;
39 Temporal *temporal;
40 bool result;
41
42 TemporalFormatTest()
43 {
44 tf= NULL;
45 temporal= NULL;
46 }
47
48 ~TemporalFormatTest()
49 {
50 if (tf != NULL)
51 delete tf;
52 if (temporal != NULL)
53 delete temporal;
54 }
55};
56
57BOOST_FIXTURE_TEST_SUITE(TemporalFormatTestSuite, TemporalFormatTest)
58BOOST_AUTO_TEST_CASE(constructor_WithValidRegExp_shouldCompile)
59{
60 tf= new TemporalFormat("^(\\d{4})[-/.]$");
61
62 result= tf->is_valid();
63
64 BOOST_REQUIRE(result);
65}
66
67BOOST_AUTO_TEST_CASE(constructor_WithInvalidRegExp_shouldNotCompile)
68{
69 tf= new TemporalFormat("^\\d{4)[-/.]$");
70
71 result= tf->is_valid();
72
73 BOOST_REQUIRE(not result);
74}
75
76BOOST_AUTO_TEST_CASE(matches_OnNotMatchingString_shouldReturn_False)
77{
78 tf= new TemporalFormat("^(\\d{4})[-/.]$");
79 char matched[] ="1234/ABC";
80
81 result= tf->matches(matched, sizeof(matched) - sizeof(char), NULL);
82
83 BOOST_REQUIRE(not result);
84}
85
86BOOST_AUTO_TEST_CASE(matches_OnMatchingString_FormatWithIndexesSet_shouldPopulateTemporal)
87{
88 char regexp[]= "^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$";
89 char matched[]= "1999/9/14T23:29:05";
90 tf= TemporalGenerator::TemporalFormatGen::make_temporal_format(regexp, 1, 2, 3, 4, 5, 6, 0, 0);
91 temporal= new DateTime();
92
93
94 result= tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
95 BOOST_REQUIRE(result);
96
97 BOOST_REQUIRE_EQUAL(1999, temporal->years());
98 BOOST_REQUIRE_EQUAL(9, temporal->months());
99 BOOST_REQUIRE_EQUAL(14, temporal->days());
100 BOOST_REQUIRE_EQUAL(23, temporal->hours());
101 BOOST_REQUIRE_EQUAL(29, temporal->minutes());
102 BOOST_REQUIRE_EQUAL(5, temporal->seconds());
103}
104
105BOOST_AUTO_TEST_CASE(matches_FormatWithMicroSecondIndexSet_shouldAddTrailingZeros)
106{
107 tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,6})$", 0, 0, 0, 0, 0, 0, 1, 0);
108 char matched[]= "560";
109 temporal= new Time();
110
111 tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
112
113 BOOST_REQUIRE_EQUAL(560000, temporal->useconds());
114}
115
116BOOST_AUTO_TEST_CASE(matches_FormatWithNanoSecondIndexSet_shouldAddTrailingZeros)
117{
118 tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,9})$", 0, 0, 0, 0, 0, 0, 0, 1);
119 char matched[]= "4321";
120 temporal= new Time();
121
122 tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
123
124 BOOST_REQUIRE_EQUAL(432100000, temporal->nseconds());
125}
126BOOST_AUTO_TEST_SUITE_END()
127
128namespace drizzled
129{
130extern std::vector<TemporalFormat *> known_datetime_formats;
131extern std::vector<TemporalFormat *> known_date_formats;
132extern std::vector<TemporalFormat *> known_time_formats;
133extern std::vector<TemporalFormat *> all_temporal_formats;
134}
135
136BOOST_AUTO_TEST_SUITE(TemporalFormatTestSuite)
137BOOST_AUTO_TEST_CASE(init_temporal_formats_vectorsWithKnownFormats_shouldHaveExpectedLengths)
138{
139 init_temporal_formats();
140
141 BOOST_REQUIRE_EQUAL(13, known_datetime_formats.size());
142 BOOST_REQUIRE_EQUAL(8, known_date_formats.size());
143 BOOST_REQUIRE_EQUAL(11, known_time_formats.size());
144 BOOST_REQUIRE_EQUAL(19, all_temporal_formats.size());
145}
146
147BOOST_AUTO_TEST_CASE(deinit_temporal_formats_vectorsWithKnownFormats_shouldHaveZeroLengths)
148{
149 init_temporal_formats();
150 deinit_temporal_formats();
151
152 BOOST_REQUIRE_EQUAL(0, known_datetime_formats.size());
153 BOOST_REQUIRE_EQUAL(0, known_date_formats.size());
154 BOOST_REQUIRE_EQUAL(0, known_time_formats.size());
155 BOOST_REQUIRE_EQUAL(0, all_temporal_formats.size());
156}
157BOOST_AUTO_TEST_SUITE_END()
0158
=== removed file 'unittests/temporal_format_test.cc'
--- unittests/temporal_format_test.cc 2010-12-22 19:43:00 +0000
+++ unittests/temporal_format_test.cc 1970-01-01 00:00:00 +0000
@@ -1,151 +0,0 @@
1/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Pawel Blokus
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "config.h"
22
23#include <drizzled/temporal.h>
24#include <drizzled/temporal_format.h>
25#include <gtest/gtest.h>
26#include <vector>
27
28#include "temporal_generator.h"
29
30using namespace drizzled;
31
32class TemporalFormatTest : public ::testing::Test
33{
34 protected:
35 TemporalFormat *tf;
36 Temporal *temporal;
37 bool result;
38
39 virtual void SetUp()
40 {
41 tf= NULL;
42 temporal= NULL;
43 }
44
45 virtual void TearDown()
46 {
47 if (tf != NULL)
48 delete tf;
49 if (temporal != NULL)
50 delete temporal;
51 }
52};
53
54
55TEST_F(TemporalFormatTest, constructor_WithValidRegExp_shouldCompile)
56{
57 tf= new TemporalFormat("^(\\d{4})[-/.]$");
58
59 result= tf->is_valid();
60
61 ASSERT_TRUE(result);
62}
63
64TEST_F(TemporalFormatTest, constructor_WithInvalidRegExp_shouldNotCompile)
65{
66 tf= new TemporalFormat("^\\d{4)[-/.]$");
67
68 result= tf->is_valid();
69
70 ASSERT_FALSE(result);
71}
72
73TEST_F(TemporalFormatTest, matches_OnNotMatchingString_shouldReturn_False)
74{
75 tf= new TemporalFormat("^(\\d{4})[-/.]$");
76 char matched[] ="1234/ABC";
77
78 result= tf->matches(matched, sizeof(matched) - sizeof(char), NULL);
79
80 ASSERT_FALSE(result);
81}
82
83TEST_F(TemporalFormatTest, matches_OnMatchingString_FormatWithIndexesSet_shouldPopulateTemporal)
84{
85 char regexp[]= "^(\\d{4})[-/.](\\d{1,2})[-/.](\\d{1,2})[T|\\s+](\\d{2}):(\\d{2}):(\\d{2})$";
86 char matched[]= "1999/9/14T23:29:05";
87 tf= TemporalGenerator::TemporalFormatGen::make_temporal_format(regexp, 1, 2, 3, 4, 5, 6, 0, 0);
88 temporal= new DateTime();
89
90
91 result= tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
92 ASSERT_TRUE(result);
93
94 EXPECT_EQ(1999, temporal->years());
95 EXPECT_EQ(9, temporal->months());
96 EXPECT_EQ(14, temporal->days());
97 EXPECT_EQ(23, temporal->hours());
98 EXPECT_EQ(29, temporal->minutes());
99 EXPECT_EQ(5, temporal->seconds());
100}
101
102TEST_F(TemporalFormatTest, matches_FormatWithMicroSecondIndexSet_shouldAddTrailingZeros)
103{
104 tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,6})$", 0, 0, 0, 0, 0, 0, 1, 0);
105 char matched[]= "560";
106 temporal= new Time();
107
108 tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
109
110 ASSERT_EQ(560000, temporal->useconds());
111}
112
113TEST_F(TemporalFormatTest, matches_FormatWithNanoSecondIndexSet_shouldAddTrailingZeros)
114{
115 tf= TemporalGenerator::TemporalFormatGen::make_temporal_format("^(\\d{1,9})$", 0, 0, 0, 0, 0, 0, 0, 1);
116 char matched[]= "4321";
117 temporal= new Time();
118
119 tf->matches(matched, sizeof(matched) - sizeof(char), temporal);
120
121 ASSERT_EQ(432100000, temporal->nseconds());
122}
123
124namespace drizzled
125{
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches