Changeset 1374
- Timestamp:
- 08/10/08 10:11:13 (3 months ago)
- Files:
-
- trunk/ChangeLog (modified) (2 diffs)
- trunk/test/test_helpers.hxx (modified) (4 diffs)
- trunk/test/unit/test_escape.cxx (modified) (1 diff)
- trunk/test/unit/test_float.cxx (modified) (3 diffs)
- trunk/test/unit/test_pipeline.cxx (modified) (1 diff)
- trunk/test/unit/test_simultaneous_transactions.cxx (modified) (1 diff)
- trunk/test/unit/test_stateless_cursor.cxx (modified) (1 diff)
- trunk/test/unit/test_test_helpers.cxx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r1372 r1374 2 2 include/pqxx/connection.hxx, src/connection.cxx: 3 3 - Doc/comment update 4 include/pqxx/util.hxx: 5 - Fixed broken is_null for C-style strings 4 6 test/test000.cxx, test/test001.cxx, test/test002.cxx, test/test004.cxx, 5 7 test/test005.cxx, test/test006.cxx, test/test007.cxx, test/test008.cxx, … … 10 12 - New TestCase::run() so normal tests don't need pqxx::test::pqxxtest() 11 13 - Rigged up test setup so it runs with nullconnection 12 - Consistently use TestCase for tests14 - Standard main() macro for tests, so later we can do all tests in 1 program 13 15 - Improved PQXX_CHECK_THROWS 14 16 - More thorough testing of test helpers trunk/test/test_helpers.hxx
r1372 r1374 29 29 int line() const throw () { return m_line; } 30 30 }; 31 32 33 // Run a libpqxx test function.34 template<typename TESTFUNC>35 inline int pqxxtest(TESTFUNC &func)36 {37 try38 {39 func();40 }41 catch (const test_failure &e)42 {43 PGSTD::cerr << "Test failure in " + e.file() + " line " +44 to_string(e.line()) << ": " << e.what() << PGSTD::endl;45 return 1;46 }47 catch (const PGSTD::bad_alloc &)48 {49 PGSTD::cerr << "Out of memory!" << PGSTD::endl;50 return 50;51 }52 catch (const sql_error &e)53 {54 PGSTD::cerr << "SQL error: " << e.what() << PGSTD::endl55 << "Query was: " << e.query() << PGSTD::endl;56 return 1;57 }58 catch (const PGSTD::exception &e)59 {60 PGSTD::cerr << "Exception: " << e.what() << PGSTD::endl;61 return 2;62 }63 catch (...)64 {65 PGSTD::cerr << "Unknown exception" << PGSTD::endl;66 return 100;67 }68 69 return 0;70 } // pqxxtest()71 31 72 32 … … 139 99 140 100 // Run test, catching errors & returning Unix-style success value 141 int run() { return pqxxtest(*this); } 101 int run() 102 { 103 try 104 { 105 (*this)(); 106 } 107 catch (const test_failure &e) 108 { 109 PGSTD::cerr << "Test failure in " + e.file() + " line " + 110 to_string(e.line()) << ": " << e.what() << PGSTD::endl; 111 return 1; 112 } 113 catch (const PGSTD::bad_alloc &) 114 { 115 PGSTD::cerr << "Out of memory!" << PGSTD::endl; 116 return 50; 117 } 118 catch (const sql_error &e) 119 { 120 PGSTD::cerr << "SQL error: " << e.what() << PGSTD::endl 121 << "Query was: " << e.query() << PGSTD::endl; 122 return 1; 123 } 124 catch (const PGSTD::exception &e) 125 { 126 PGSTD::cerr << "Exception: " << e.what() << PGSTD::endl; 127 return 2; 128 } 129 catch (...) 130 { 131 PGSTD::cerr << "Unknown exception" << PGSTD::endl; 132 return 100; 133 } 134 135 return 0; 136 } 142 137 143 138 private: … … 146 141 testfunc m_func; 147 142 }; 143 144 145 // Register a function taking (connection_base &, transaction_base &) as a test. 146 #define PQXX_REGISTER_TEST(function) \ 147 int main() \ 148 { \ 149 pqxx::test::TestCase<> test(#function, (function)); \ 150 return test.run(); \ 151 } 152 153 154 // Register test function that doesn't access the database. 155 #define PQXX_REGISTER_TEST_NODB(function) \ 156 int main() \ 157 { \ 158 pqxx::test::TestCase<nullconnection, nontransaction> \ 159 test(#function, (function)); \ 160 return test.run(); \ 161 } 148 162 149 163 … … 298 312 } // namespace pqxx 299 313 314 trunk/test/unit/test_escape.cxx
r1370 r1374 63 63 "Connection and transaction quote differently."); 64 64 } 65 66 67 void test_escaping(connection_base &c, transaction_base &t) 68 { 69 test_esc(c, t); 70 test_quote(c, t); 71 } 65 72 } // namespace 66 73 67 int main() 68 { 69 test::TestCase<> test1("test_esc", test_esc); 70 return test1.run(); 71 } 72 74 PQXX_REGISTER_TEST(test_escaping) trunk/test/unit/test_float.cxx
r1368 r1374 4 4 using namespace pqxx; 5 5 6 namespace 7 { 6 8 template<typename T> T make_infinity() 7 9 { … … 14 16 } 15 17 16 namespace 17 { 18 void infinity_test() 18 void infinity_test(connection_base &, transaction_base &) 19 19 { 20 20 double inf = make_infinity<double>(); … … 22 22 PQXX_CHECK_EQUAL(to_string(-inf), "-infinity", "Negative infinity is broken"); 23 23 } 24 } 24 } // namespace 25 25 26 int main() 27 { 28 return pqxx::test::pqxxtest(infinity_test); 29 } 30 26 PQXX_REGISTER_TEST_NODB(infinity_test) trunk/test/unit/test_pipeline.cxx
r1370 r1374 51 51 } // namespace 52 52 53 int main() 54 { 55 test::TestCase<> test("pipeline_detach", test_pipeline_detach); 56 return test.run(); 57 } 58 53 PQXX_REGISTER_TEST(test_pipeline_detach) trunk/test/unit/test_simultaneous_transactions.cxx
r1370 r1374 18 18 } // namespace 19 19 20 int main() 21 { 22 test::TestCase<> test("simultaneous_trans", test_simultaneous_transactions); 23 return test.run(); 24 } 25 20 PQXX_REGISTER_TEST(test_simultaneous_transactions) trunk/test/unit/test_stateless_cursor.cxx
r1371 r1374 85 85 } // namespace 86 86 87 int main() 88 { 89 test::TestCase<> test("stateless_cursor", test_stateless_cursor); 90 return test.run(); 91 } 92 87 PQXX_REGISTER_TEST(test_stateless_cursor) trunk/test/unit/test_test_helpers.cxx
r1372 r1374 142 142 143 143 144 int main() 145 { 146 TestCase<nullconnection, nontransaction> test( 147 "test_test_helpers", 148 test_test_helpers); 149 return test.run(); 150 } 151 144 PQXX_REGISTER_TEST_NODB(test_test_helpers)
