8 #ifndef SOCI_COMMON_TESTS_H_INCLUDED 9 #define SOCI_COMMON_TESTS_H_INCLUDED 11 #include "soci/soci.h" 15 #include <boost/version.hpp> 16 #include "soci/boost-optional.h" 17 #include "soci/boost-tuple.h" 18 #include "soci/boost-gregorian-date.h" 19 #if defined(BOOST_VERSION) && BOOST_VERSION >= 103500 20 #include "soci/boost-fusion.h" 21 #endif // BOOST_VERSION 26 #define CATCH_CONFIG_RUNNER 57 size_t const len = expected_str.length();
58 std::string
const start_str(padded_str, 0, len);
60 if (start_str != expected_str)
62 throw soci::soci_error(
63 "Expected string \"" + expected_str +
"\" " 64 "is different from the padded string \"" + padded_str +
"\"" 68 if (padded_str.length() > len)
70 std::string
const end_str(padded_str, len);
71 if (end_str != std::string(padded_str.length() - len,
' '))
73 throw soci::soci_error(
74 "\"" + padded_str +
"\" starts with \"" + padded_str +
75 "\" but non-space characater(s) are found aftewards" 81 #define CHECK_EQUAL_PADDED(padded_str, expected_str) \ 82 CHECK_NOTHROW(checkEqualPadded(padded_str, expected_str)); 98 void setName(std::string
const & n) { name_ = n; }
99 std::string
getName()
const {
return name_; }
101 void setPhone(std::string
const & p) { phone_ = p; }
115 void set(
int i) { i_ = i; }
116 int get()
const {
return i_; }
125 template<>
struct type_conversion<
MyInt>
152 pe.
name = v.get<std::string>(
"NAME");
153 pe.
phone = v.get<std::string>(
"PHONE",
"<NULL>");
158 v.set(
"NAME", pe.
name);
159 v.set(
"PHONE", pe.
phone, pe.
phone.empty() ? i_null : i_ok);
173 pe.
name = v.get<std::string>(
"NAME");
174 indicator ind = v.get_indicator(
"PHONE");
175 pe.
phone = ind == i_null ?
"<NULL>" : v.get<std::string>(
"PHONE");
180 v.set(
"NAME", pe.
name);
181 v.set(
"PHONE", pe.
phone, pe.
phone.empty() ? i_null : i_ok);
194 pe.
setName(v.get<std::string>(
"NAME"));
195 pe.
setPhone(v.get<std::string>(
"PHONE",
"<NULL>"));
219 : msession(sql) { drop(); }
227 msession <<
"drop table if exists soci_test";
229 catch (soci_error
const& e)
244 : msession(sql) { drop(); }
250 try { msession <<
"drop procedure soci_test"; }
catch (soci_error&) {}
261 : msession(sql) { drop(); }
268 return "drop function soci_test";
274 try { msession << dropstatement(); }
catch (soci_error&) {}
287 std::string
const &connectString)
288 : backEndFactory_(backEnd),
289 connectString_(connectString)
293 assert(!the_test_context_);
295 the_test_context_ =
this;
301 if (std::getenv(
"SOCI_TEST_USE_LC_ALL"))
302 std::setlocale(LC_ALL,
"");
309 return *the_test_context_;
314 return backEndFactory_;
319 return connectString_;
322 virtual std::string to_date_time(std::string
const &dateTime)
const = 0;
357 the_test_context_ = NULL;
361 backend_factory
const &backEndFactory_;
362 std::string
const connectString_;
389 double const epsilon(std::numeric_limits<float>::epsilon() * 100);
390 double const scale(1.0);
391 return std::fabs(a - b) < epsilon * (scale + (std::max)(std::fabs(a), std::fabs(b)));
398 #define ASSERT_EQUAL_APPROX(a, b) \ 400 if (!are_doubles_approx_equal((a), (b))) { \ 401 FAIL( "Approximate equality check failed: " \ 403 << std::setprecision(std::numeric_limits<double>::digits10 + 1) \ 404 << (a) << " != " << (b) ); \ 406 } while ( (void)0, 0 ) 422 #define ASSERT_EQUAL_EXACT(a, b) \ 424 if (!are_doubles_exactly_equal((a), (b))) { \ 425 FAIL( "Exact equality check failed: " \ 427 << std::setprecision(std::numeric_limits<double>::digits10 + 1) \ 428 << (a) << " != " << (b) ); \ 430 } while ( (void)0, 0 ) 452 #define ASSERT_EQUAL(a, b) \ 454 if (!are_doubles_equal(tc_, (a), (b))) { \ 455 FAIL( "Equality check failed: " \ 457 << std::setprecision(std::numeric_limits<double>::digits10 + 1) \ 458 << (a) << " != " << (b) ); \ 460 } while ( (void)0, 0 ) 468 backEndFactory_(tc_.get_backend_factory()),
469 connectString_(tc_.get_connect_string())
488 #endif // SOCI_COMMON_TESTS_H_INCLUDED virtual bool has_silent_truncate_bug(session &) const
Definition: common-tests.h:344
Definition: common-tests.h:215
std::string name_
Definition: common-tests.h:105
static void to_base(PhonebookEntry2 const &pe, values &v, indicator &ind)
Definition: common-tests.h:178
Definition: common-tests.h:283
static void from_base(int i, indicator ind, MyInt &mi)
Definition: common-tests.h:129
static void from_base(values const &v, indicator, PhonebookEntry3 &pe)
Definition: common-tests.h:190
test_context_base const & tc_
Definition: common-tests.h:473
Definition: common-tests.h:91
static void to_base(PhonebookEntry const &pe, values &v, indicator &ind)
Definition: common-tests.h:156
void setPhone(std::string const &p)
Definition: common-tests.h:101
void setName(std::string const &n)
Definition: common-tests.h:98
virtual void on_after_ddl(session &) const
Definition: common-tests.h:348
soci::values base_type
Definition: common-tests.h:147
virtual bool has_multiple_select_bug() const
Definition: common-tests.h:337
virtual ~function_creator_base()
Definition: common-tests.h:263
table_creator_base(session &sql)
Definition: common-tests.h:218
soci::values base_type
Definition: common-tests.h:167
soci::values base_type
Definition: common-tests.h:188
int base_type
Definition: common-tests.h:127
virtual ~procedure_creator_base()
Definition: common-tests.h:246
int get() const
Definition: common-tests.h:116
Definition: common-tests.h:240
virtual bool has_fp_bug() const
Definition: common-tests.h:332
std::string const connectString_
Definition: common-tests.h:475
Definition: common-tests.h:85
virtual bool has_transactions_support(session &) const
Definition: common-tests.h:340
static void to_base(MyInt const &mi, int &i, indicator &ind)
Definition: common-tests.h:137
MyInt(int i)
Definition: common-tests.h:114
MyInt()
Definition: common-tests.h:113
Definition: common-tests.h:95
std::string get_connect_string() const
Definition: common-tests.h:317
static test_context_base const & get_instance()
Definition: common-tests.h:305
std::string getPhone() const
Definition: common-tests.h:102
Definition: common-tests.h:463
Definition: common-tests.h:110
backend_factory const & get_backend_factory() const
Definition: common-tests.h:312
Definition: common-tests.h:257
virtual ~table_creator_base()
Definition: common-tests.h:221
common_tests()
Definition: common-tests.h:466
bool are_doubles_equal(test_context_base const &tc, double a, double b)
Definition: common-tests.h:436
virtual ~test_context_base()
Definition: common-tests.h:355
static void to_base(PhonebookEntry3 const &pe, values &v, indicator &ind)
Definition: common-tests.h:198
void set(int i)
Definition: common-tests.h:115
bool are_doubles_approx_equal(double const a, double const b)
Definition: common-tests.h:384
static void from_base(values const &v, indicator, PhonebookEntry2 &pe)
Definition: common-tests.h:169
virtual bool enable_std_char_padding(session &) const
Definition: common-tests.h:353
std::auto_ptr< table_creator_base > auto_table_creator
Definition: common-tests.h:480
std::string phone_
Definition: common-tests.h:106
std::string name
Definition: common-tests.h:87
procedure_creator_base(session &sql)
Definition: common-tests.h:243
bool are_doubles_exactly_equal(double a, double b)
Definition: common-tests.h:412
test_context_base(backend_factory const &backEnd, std::string const &connectString)
Definition: common-tests.h:286
void checkEqualPadded(const std::string &padded_str, const std::string &expected_str)
Definition: common-tests.h:55
function_creator_base(session &sql)
Definition: common-tests.h:260
std::string phone
Definition: common-tests.h:88
Definition: HorizonTestDBTable1.h:104
static void from_base(values const &v, indicator, PhonebookEntry &pe)
Definition: common-tests.h:149
std::string getName() const
Definition: common-tests.h:99
backend_factory const & backEndFactory_
Definition: common-tests.h:474
virtual std::string dropstatement()
Definition: common-tests.h:266