From 092163ffe44f64387508a0770948636f79ae139d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Jan 2012 14:34:06 +0200 Subject: Add support for configuring test suite with additional macros --- INSTALL | 43 ++++++++++++++++++++++++++++ boost/mssql/date-time/driver.cxx | 6 ++++ boost/mssql/date-time/test.hxx | 33 ++++++++++++++-------- mssql/types/driver.cxx | 8 ++++++ mssql/types/test.hxx | 34 +++++++++++++--------- qt/mssql/date-time/driver.cxx | 4 +++ qt/mssql/date-time/test.hxx | 61 +++++++++++++++++++++++++--------------- 7 files changed, 141 insertions(+), 48 deletions(-) diff --git a/INSTALL b/INSTALL index af84129..6a59aee 100644 --- a/INSTALL +++ b/INSTALL @@ -163,3 +163,46 @@ odb-tests\ directory. Once this is done, you can run the tests by executing the following command from the command prompt: test.bat + + +Test Suite Configuration +======================== + +The test suite supports additional configuration via the following +preprocessor macros: + +HOST_WIN32 Specifies that the tests will run on Windows. This + macro is only needed when cross-compiling for Windows + using, for example, a cross-compiler to MinGW. + +MSSQL_SERVER_VERSION Specifies the SQL Server version that will be used to + run the tests. The version is specified as XXYY where + XX is the major and YY is the minor SQL Server versions, + for example, 900 (SQL Server 2005/9.0), 1000 (2008/10.0), + 1050 (2008R2/10.5), 1100 (2012/11.0). If this macro is + not defined, then the test suite assumes SQL Server 2008. + +To define any of these macros when building on UNIX operating systems you +can use the CPPFLAGS configure variable, for example: + +./configure CPPFLAGS=-DMSSQL_SERVER_VERSION=900 + +When building on Windows with Visual Studio the extra macros have to be +specified in two places: in the default.options ODB configuration file +(located in the odb-X.Y.Z-i686-windows\etc\odb\ directory) as well as +in the CL environment variable. For example, to specify the SQL Server +version add the following line to the default.options file: + +-DMSSQL_SERVER_VERSION=900 + +As well as set the CL environment variable before running the build.bat +batch file: + +SET CL=-DMSSQL_SERVER_VERSION=900 + +If you are using the Visual Studio IDE to build the tests, then you will +need to start the IDE from a command prompt after setting the CL variable, +for example: + +SET CL=-DMSSQL_SERVER_VERSION=900 +C:\Program Files (x86)\Microsoft Visual Studio \Common7\IDE\devenv.com diff --git a/boost/mssql/date-time/driver.cxx b/boost/mssql/date-time/driver.cxx index d48f90b..55cbdb0 100644 --- a/boost/mssql/date-time/driver.cxx +++ b/boost/mssql/date-time/driver.cxx @@ -44,6 +44,7 @@ main (int argc, char* argv[]) // Test all valid date-time mappings. // +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.dates.push_back (day_clock::local_day ()); o.dates.push_back (date (not_a_date_time)); o.dates.push_back (date (max_date_time)); @@ -53,6 +54,7 @@ main (int argc, char* argv[]) o.times.push_back (not_a_date_time); o.times.push_back (min_date_time); o.times.push_back (ptime (max_date_time)); +#endif // In DATETIME fractional seconds are rounded to .000, .003, or .007. // @@ -64,8 +66,10 @@ main (int argc, char* argv[]) o.times_sdt.push_back (ptime (date (2012, 1, 13), time_duration (11, 57, 0, 0))); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.durations.push_back (time_duration (1, 2, 3, 123456)); o.durations.push_back (not_a_date_time); +#endif { transaction t (db->begin ()); @@ -81,6 +85,7 @@ main (int argc, char* argv[]) assert (*ol == o); } +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 // Test invalid date mappings. // { @@ -130,6 +135,7 @@ main (int argc, char* argv[]) t.commit (); } +#endif } catch (const odb::exception& e) { diff --git a/boost/mssql/date-time/test.hxx b/boost/mssql/date-time/test.hxx index 7bbd15d..ddf38f6 100644 --- a/boost/mssql/date-time/test.hxx +++ b/boost/mssql/date-time/test.hxx @@ -20,24 +20,14 @@ struct object { } - bool - operator== (const object& x) const - { - return - id == x.id && - dates == x.dates && - times == x.times && - times_dt == x.times_dt && - times_sdt == x.times_sdt && - durations == x.durations; - } - #pragma db id auto unsigned long id; +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 std::vector dates; std::vector times; +#endif #pragma db value_type("DATETIME") std::vector times_dt; @@ -45,7 +35,26 @@ struct object #pragma db value_type("SMALLDATETIME") std::vector times_sdt; +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 std::vector durations; +#endif + + bool + operator== (const object& x) const + { + return + id == x.id +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && dates == x.dates + && times == x.times +#endif + && times_dt == x.times_dt + && times_sdt == x.times_sdt +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && durations == x.durations +#endif + ; + } }; #endif // TEST_HXX diff --git a/mssql/types/driver.cxx b/mssql/types/driver.cxx index 3cef5ad..db814e2 100644 --- a/mssql/types/driver.cxx +++ b/mssql/types/driver.cxx @@ -78,14 +78,18 @@ main (int argc, char* argv[]) o.mvbin_.assign (ldata.begin (), ldata.end ()); o.image_.assign (ldata.begin (), ldata.end ()); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.date_ = date_time (2011, 12, 20, 0, 0, 0, 0, 0, 0); o.time7_ = date_time (0, 0, 0, 13, 34, 39, 123456789, 0, 0); o.time4_ = date_time (0, 0, 0, 13, 34, 39, 123456700, 0, 0); +#endif o.sdt_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 0, 0); o.dt_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 0, 0); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.dt2_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 0, 0); o.dto7_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 2, 0); o.dto0_ = date_time (2011, 12, 20, 15, 44, 29, 123456700, 2, 0); +#endif #ifdef _WIN32 // 6F846D41-C89A-4E4D-B22F-56443CFA543F @@ -103,11 +107,15 @@ main (int argc, char* argv[]) t.commit (); } +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.time7_ = date_time (0, 0, 0, 13, 34, 39, 123456700, 0, 0); o.time4_ = date_time (0, 0, 0, 13, 34, 39, 123400000, 0, 0); +#endif o.sdt_ = date_time (2011, 12, 20, 15, 44, 0, 0, 0, 0); o.dt_ = date_time (2011, 12, 20, 15, 44, 29, 123000000, 0, 0); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.dto0_ = date_time (2011, 12, 20, 15, 44, 29, 0, 2, 0); +#endif // Load. // diff --git a/mssql/types/test.hxx b/mssql/types/test.hxx index 7653ec6..57bc7b2 100644 --- a/mssql/types/test.hxx +++ b/mssql/types/test.hxx @@ -11,7 +11,7 @@ # define WIN32_LEAN_AND_MEAN # endif # include // GUID -#elif defined(WIN32_CROSS) +#elif defined(HOST_WIN32) typedef struct _GUID { unsigned int Data1; @@ -205,8 +205,9 @@ struct object #pragma db type ("IMAGE") std::vector image_; - // Date-time. + // Date-time. SQL Server 2005 (9.0) only has DATETIME and SMALLDATETIME. // +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 #pragma db type ("DATE") date_time date_; @@ -215,6 +216,7 @@ struct object #pragma db type ("TIME(4)") date_time time4_; +#endif #pragma db type ("SMALLDATETIME") date_time sdt_; @@ -222,6 +224,7 @@ struct object #pragma db type ("DATETIME") date_time dt_; +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 #pragma db type ("DATETIME2") date_time dt2_; @@ -230,10 +233,11 @@ struct object #pragma db type ("DATETIMEOFFSET(0)") date_time dto0_; +#endif // Other types. // -#if defined(_WIN32) || defined(WIN32_CROSS) +#if defined(_WIN32) || defined(HOST_WIN32) //#pragma db type ("UNIQUEIDENTIFIER") GUID guid_; #endif @@ -280,16 +284,20 @@ struct object std::memcmp (lbin_, y.lbin_, sizeof (lbin_)) == 0 && lvbin_ == y.lvbin_ && mvbin_ == y.mvbin_ && - image_ == y.image_ && - - date_ == y.date_ && - time7_ == y.time7_ && - time4_ == y.time4_ && - sdt_ == y.sdt_ && - dt_ == y.dt_ && - dt2_ == y.dt2_ && - dto7_ == y.dto7_ && - dto0_ == y.dto0_ + image_ == y.image_ + +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && date_ == y.date_ + && time7_ == y.time7_ + && time4_ == y.time4_ +#endif + && sdt_ == y.sdt_ + && dt_ == y.dt_ +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && dt2_ == y.dt2_ + && dto7_ == y.dto7_ + && dto0_ == y.dto0_ +#endif #ifdef _WIN32 && std::memcmp (&guid_, &y.guid_, sizeof (guid_)) == 0 diff --git a/qt/mssql/date-time/driver.cxx b/qt/mssql/date-time/driver.cxx index 66d6b67..0e7681a 100644 --- a/qt/mssql/date-time/driver.cxx +++ b/qt/mssql/date-time/driver.cxx @@ -53,10 +53,12 @@ main (int argc, char* argv[]) // Check persistence of valid dates and times. // +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 QDateTime t (QDateTime::currentDateTime ()); o.date = t.date (); o.date_time = t; +#endif // In DATETIME fractional seconds are rounded to .000, .003, or .007. // @@ -68,7 +70,9 @@ main (int argc, char* argv[]) o.date_time_sdt = QDateTime (QDate (2012, 1, 14), QTime (11, 57, 0, 0)); +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 o.time = t.time (); +#endif { transaction t (db->begin ()); diff --git a/qt/mssql/date-time/test.hxx b/qt/mssql/date-time/test.hxx index c494efb..218baaa 100644 --- a/qt/mssql/date-time/test.hxx +++ b/qt/mssql/date-time/test.hxx @@ -13,35 +13,14 @@ #pragma db object struct object { - bool - operator== (const object& x) const - { - return - id == x.id && - date == x.date && - date_time == x.date_time && - date_time_dt == x.date_time_dt && - date_time_sdt == x.date_time_sdt && - time == x.time; - } - - bool - is_null () const - { - return - date.isNull () && - date_time.isNull () && - date_time_dt.isNull () && - date_time_sdt.isNull () && - time.isNull (); - } - #pragma db id auto unsigned long id; +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 QDate date; QDateTime date_time; +#endif #pragma db type ("DATETIME") QDateTime date_time_dt; @@ -49,7 +28,43 @@ struct object #pragma db type ("SMALLDATETIME") QDateTime date_time_sdt; +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 QTime time; +#endif + + bool + operator== (const object& x) const + { + return + id == x.id +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && date == x.date + && date_time == x.date_time +#endif + && date_time_dt == x.date_time_dt + && date_time_sdt == x.date_time_sdt +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && time == x.time +#endif + ; + } + + bool + is_null () const + { + return + true +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && date.isNull () + && date_time.isNull () +#endif + && date_time_dt.isNull () + && date_time_sdt.isNull () +#if !defined(MSSQL_SERVER_VERSION) || MSSQL_SERVER_VERSION >= 1000 + && time.isNull () +#endif + ; + } }; #endif // TEST_HXX -- cgit v1.1