Skip to content

Commit

Permalink
Move macros and ensure_approx function.
Browse files Browse the repository at this point in the history
Allow use of ensure_approx as free function.
  • Loading branch information
mloskot committed Feb 27, 2013
1 parent dadd276 commit 44054c7
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/core/test/common-tests.h
Expand Up @@ -158,6 +158,34 @@ namespace soci
namespace tests
{

// ensure connection is checked, no crash occurs

#define SOCI_TEST_ENSURE_CONNECTED(sql, method) { \
std::string msg; \
try { \
(sql.method)(); \
assert(!"exception expected"); \
} catch (soci_error const &e) { msg = e.what(); } \
assert(msg.empty() == false); } (void)sql

#define SOCI_TEST_ENSURE_CONNECTED2(sql, method) { \
std::string msg; \
try { std::string seq; long v(0); \
(sql.method)(seq, v); \
assert(!"exception expected"); \
} catch (soci_error const &e) { msg = e.what(); } \
assert(msg.empty() == false); } (void)sql

inline bool equal_approx(double const a, double const b)
{
// The formula taken from CATCH test framework
// https://github.com/philsquared/Catch/
// Thanks to Richard Harris for his help refining this formula
double const epsilon(std::numeric_limits<float>::epsilon() * 100);
double const scale(1.0);
return std::fabs(a - b) < epsilon * (scale + (std::max)(std::fabs(a), std::fabs(b)));
}

// TODO: improve cleanup capabilities by subtypes, soci_test name may be omitted --mloskot
// i.e. optional ctor param accepting custom table name
class table_creator_base
Expand Down Expand Up @@ -319,35 +347,6 @@ class common_tests

typedef std::auto_ptr<table_creator_base> auto_table_creator;


inline bool equal_approx(double const a, double const b)
{
// The formula taken from CATCH test framework
// https://github.com/philsquared/Catch/
// Thanks to Richard Harris for his help refining this formula
double const epsilon(std::numeric_limits<float>::epsilon() * 100);
double const scale(1.0);
return std::fabs(a - b) < epsilon * (scale + (std::max)(std::fabs(a), std::fabs(b)));
}

// ensure connection is checked, no crash occurs

#define SOCI_TEST_ENSURE_CONNECTED(sql, method) { \
std::string msg; \
try { \
(sql.method)(); \
assert(!"exception expected"); \
} catch (soci_error const &e) { msg = e.what(); } \
assert(msg.empty() == false); } (void)sql

#define SOCI_TEST_ENSURE_CONNECTED2(sql, method) { \
std::string msg; \
try { std::string seq; long v(0); \
(sql.method)(seq, v); \
assert(!"exception expected"); \
} catch (soci_error const &e) { msg = e.what(); } \
assert(msg.empty() == false); } (void)sql

void test0()
{
{
Expand Down

0 comments on commit 44054c7

Please sign in to comment.