Changeset 1380
- Timestamp:
- 08/18/08 23:57:21 (5 months ago)
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/test/test000.cxx (modified) (6 diffs)
- trunk/test/test001.cxx (modified) (1 diff)
- trunk/test/test002.cxx (modified) (1 diff)
- trunk/test/test004.cxx (modified) (1 diff)
- trunk/test/test006.cxx (modified) (1 diff)
- trunk/test/test007.cxx (modified) (1 diff)
- trunk/test/test020.cxx (modified) (1 diff)
- trunk/test/test023.cxx (modified) (1 diff)
- trunk/test/test075.cxx (modified) (1 diff)
- trunk/test/test079.cxx (modified) (1 diff)
- trunk/test/test084.cxx (modified) (3 diffs)
- trunk/test/test087.cxx (modified) (1 diff)
- trunk/test/test089.cxx (modified) (1 diff)
- trunk/test/test092.cxx (modified) (1 diff)
- trunk/test/test094.cxx (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r1379 r1380 1 2008-08-19 Jeroen T. Vermeulen <jtv@xs4all.nl> 2 test/test000.cxx, test/test001.cxx, test/test002.cxx, test/test004.cxx, 3 test/test006.cxx, test/test007.cxx, test/test020.cxx, test/test023.cxx, 4 test/test075.cxx, test/test079.cxx, test/test084.cxx, test/test087.cxx, 5 test/test089.cxx, test/test092.cxx, test/test094.cxx: 6 - Replaced throws with test helpers. 1 7 2008-08-15 Jeroen T. Vermeulen <jtv@xs4all.nl> 2 8 test/Makefile.am.template, test/runner.cxx, test/test027.cxx, trunk/test/test000.cxx
r1375 r1380 89 89 "cause problems in libpqxx."); 90 90 91 if (cursor_base::prior() >= 0 || cursor_base::backward_all() >= 0) 92 throw logic_error("cursor_base::difference_type appears to be unsigned"); 91 PQXX_CHECK( 92 cursor_base::prior() < 0 && cursor_base::backward_all() < 0, 93 "cursor_base::difference_type appears to be unsigned."); 93 94 94 95 cout << "Testing items template..." << endl; … … 106 107 testitems(I5,5); 107 108 const string l = separated_list(",",I5.begin(),I5.end(),intderef()); 108 if (l != "1,2,3,4,5") throw logic_error("Separated list was '" + l + "'");109 PQXX_CHECK_EQUAL(l, "1,2,3,4,5", "separated_list is broken."); 109 110 vector<int> V2(I2); 110 111 testitems(items<int>(V2),2); … … 170 171 string zero; 171 172 from_string(zerobuf, zero, sizeof(zerobuf)-1); 172 if (zero != zerobuf) 173 throw logic_error("Converting \"0\" with explicit length failed!"); 173 PQXX_CHECK_EQUAL( 174 zero, 175 zerobuf, 176 "Converting \"0\" with explicit length failed."); 174 177 175 178 const char nulbuf[] = "\0string\0with\0nuls\0"; … … 177 180 string nully_parsed; 178 181 from_string(nulbuf, nully_parsed, sizeof(nulbuf)-1); 179 if (nully_parsed != nully) 180 throw logic_error("String with nuls now " + 181 to_string(nully_parsed.size()) + " bytes!"); 182 PQXX_CHECK_EQUAL(nully_parsed.size(), nully.size(), "Nul truncates string."); 183 PQXX_CHECK_EQUAL(nully_parsed, nully, "String conversion breaks on nuls."); 182 184 from_string(nully.c_str(), nully_parsed, nully.size()); 183 if (nully_parsed != nully) 184 throw logic_error("Nul conversion worked, but not on strings!"); 185 PQXX_CHECK_EQUAL(nully_parsed, nully, "Nul conversion breaks on strings."); 185 186 186 187 stringstream ss; … … 193 194 #ifdef PQXX_HAVE_PQENCRYPTPASSWORD 194 195 const string pw = encrypt_password("foo", "bar"); 195 if (pw.empty()) 196 throw logic_error("Encrypting a password returned no data"); 197 if (pw == encrypt_password("splat", "blub")) 198 throw logic_error("Password encryption does not work"); 199 if (pw.find("bar") != string::npos) 200 throw logic_error("Encrypted password contains original"); 196 PQXX_CHECK(!pw.empty(), "Encrypting a password returned no data."); 197 PQXX_CHECK_NOT_EQUAL( 198 pw, 199 encrypt_password("splat", "blub"), 200 "Password encryption is broken."); 201 PQXX_CHECK( 202 pw.find("bar") == string::npos, 203 "Encrypted password contains original."); 201 204 #endif 202 205 203 206 cout << "Testing error handling for failed connections..." << endl; 204 try205 207 { 206 208 nullconnection nc; 207 work w(nc); 208 throw logic_error("nullconnection failed to fail!"); 209 } 210 catch (broken_connection &c) 211 { 212 cout << "(Expected) " << c.what() << endl; 213 } 214 try 209 PQXX_CHECK_THROWS( 210 work w(nc), 211 broken_connection, 212 "nullconnection fails to fail."); 213 } 215 214 { 216 215 nullconnection nc(""); 217 work w(nc); 218 throw logic_error("nullconnection(const char[]) failed to fail!"); 219 } 220 catch (broken_connection &c) 221 { 222 cout << "(Expected) " << c.what() << endl; 223 } 224 try 216 PQXX_CHECK_THROWS( 217 work w(nc), 218 broken_connection, 219 "nullconnection(const char[]) is broken."); 220 } 225 221 { 226 222 string n; 227 223 nullconnection nc(n); 228 work w(nc); 229 throw logic_error("nullconnection(const std::string &) failed to fail!"); 230 } 231 catch (broken_connection &c) 232 { 233 cout << "(Expected) " << c.what() << endl; 224 PQXX_CHECK_THROWS( 225 work w(nc), 226 broken_connection, 227 "nullconnection(const string &) is broken."); 234 228 } 235 229 … … 243 237 catch (const pqxx_exception &e) 244 238 { 245 if (!dynamic_cast<const broken_connection *>(&e.base())) 246 throw logic_error("Downcast pqxx_exception is not a broken_connection"); 239 PQXX_CHECK( 240 dynamic_cast<const broken_connection *>(&e.base()), 241 "Downcast pqxx_exception is not a broken_connection"); 247 242 cout << "(Expected) " << e.base().what() << endl; 248 if (dynamic_cast<const broken_connection &>(e.base()).what() != 249 e.base().what()) 250 throw logic_error("Inconsistent what() message in exception!"); 243 PQXX_CHECK_EQUAL( 244 dynamic_cast<const broken_connection &>(e.base()).what(), 245 e.base().what(), 246 "Inconsistent what() message in exception."); 251 247 } 252 248 } trunk/test/test001.cxx
r1377 r1380 31 31 32 32 // We're expecting to find some tables... 33 if (R.empty()) throw logic_error("No tables found!");33 PQXX_CHECK(!R.empty(), "No tables found. Cannot test."); 34 34 35 35 // Process each successive result tuple trunk/test/test002.cxx
r1375 r1380 80 80 #ifdef PQXX_HAVE_PQFTABLE 81 81 const oid ftable = R[i][0].table(); 82 if (ftable != rtable) 83 throw logic_error("Field says it comes from '" + to_string(ftable) + "'; " 84 "expected '" + to_string(rtable) + "'"); 82 PQXX_CHECK_EQUAL(ftable, rtable, "result::field::table() is broken."); 83 85 84 const oid ttable = R[i].column_table(0); 86 if (ttable != R[i].column_table(result::tuple::size_type(0))) 87 throw logic_error("Inconsistent result::tuple::column_table()"); 88 if (ttable != rtable) 89 throw logic_error("Tuple says field comes from " 90 "'" + to_string(ttable) + "'; " 91 "expected '" + to_string(rtable) + "'"); 85 86 PQXX_CHECK_EQUAL( 87 ttable, 88 R[i].column_table(result::tuple::size_type(0)), 89 "Inconsistent result::tuple::column_table()."); 90 91 PQXX_CHECK_EQUAL(ttable, rtable, "Inconsistent result::column_table()."); 92 92 93 const oid cttable = R[i].column_table(rcol); 93 if (cttable != rtable) 94 throw logic_error("Field comes from '" + to_string(rtable) + "', " 95 "but by name, tuple says it's from '" + 96 to_string(cttable) + "'"); 94 95 PQXX_CHECK_EQUAL( 96 cttable, 97 rtable, 98 "result::tuple::column_table() is broken."); 97 99 #endif 98 100 } trunk/test/test004.cxx
r1375 r1380 35 35 { 36 36 m_Done = true; 37 if (be_pid != Backend_PID) 38 throw logic_error("Expected notification from backend process " + 39 to_string(Backend_PID) + 40 ", but got one from " + 41 to_string(be_pid)); 37 PQXX_CHECK_EQUAL( 38 be_pid, 39 Backend_PID, 40 "Notification came from wrong backend process."); 42 41 43 42 cout << "Received notification: " << name() << " pid=" << be_pid << endl; trunk/test/test006.cxx
r1375 r1380 58 58 void CheckState(tablereader &R) 59 59 { 60 PQXX_CHECK_EQUAL( 61 !R, 62 !bool(R), 63 "tablereader " + R.name() + " is in inconsistent state."); 60 64 if (!R != !bool(R)) 61 65 throw logic_error("tablereader " + R.name() + " in inconsistent state!"); trunk/test/test007.cxx
r1375 r1380 90 90 // See if type identifiers are consistent 91 91 const oid tctype = r->column_type(0); 92 if (tctype != r->column_type(result::tuple::size_type(0))) 93 throw logic_error("Inconsistent result::tuple::column_type()"); 94 if (tctype != rctype) 95 throw logic_error("Column has type " + rct + ", " 96 "but tuple says it's " + to_string(tctype)); 92 93 PQXX_CHECK_EQUAL( 94 tctype, 95 r->column_type(result::tuple::size_type(0)), 96 "Inconsistent result::tuple::column_type()"); 97 98 PQXX_CHECK_EQUAL( 99 tctype, 100 rctype, 101 "tuple::column_type() is inconsistent with result::column_type()."); 102 97 103 const oid ctctype = r->column_type(rcol); 98 if (ctctype != rctype) 99 throw logic_error("Column has type " + rct + ", " 100 "but by name, tuple says it's " + to_string(ctctype)); 104 105 PQXX_CHECK_EQUAL( 106 ctctype, 107 rctype, 108 "Column type lookup by column name is broken."); 109 101 110 const oid rawctctype = r->column_type(rcol.c_str()); 102 if (rawctctype != rctype) 103 throw logic_error("Column has type " + rct + ", " 104 "but by C-style name, tuple says it's " + 105 to_string(rawctctype)); 111 112 PQXX_CHECK_EQUAL( 113 rawctctype, 114 rctype, 115 "Column type lookup by C-style name is broken."); 116 106 117 const oid fctype = r[0].type(); 107 if (fctype != rctype) 108 throw logic_error("Column has type " + rct + ", " 109 "but field says it's " + to_string(fctype)); 118 PQXX_CHECK_EQUAL( 119 fctype, 120 rctype, 121 "Field type lookup is broken."); 110 122 } 111 123 trunk/test/test020.cxx
r1377 r1380 27 27 result R( T1.exec(("SELECT * FROM " + Table + " " 28 28 "WHERE year=" + to_string(BoringYear)).c_str()) ); 29 if (R.size() != 0)30 throw runtime_error("There is already a record for " + 31 to_string(BoringYear) + ". "32 "Can't runtest.");29 PQXX_CHECK_EQUAL( 30 R.size(), 31 0u, 32 "Already have a row for " + to_string(BoringYear) + ", cannot test."); 33 33 34 34 // (Not needed, but verify that clear() works on empty containers) 35 35 R.clear(); 36 if (!R.empty()) 37 throw logic_error("Result non-empty after clear()!"); 36 PQXX_CHECK(R.empty(), "result::clear() is broken."); 38 37 39 38 // OK. Having laid that worry to rest, add a record for 1977. trunk/test/test023.cxx
r1377 r1380 32 32 { 33 33 m_Done = true; 34 if (be_pid != Conn().backendpid()) 35 throw logic_error("Expected notification from backend process " + 36 to_string(Conn().backendpid()) + 37 ", but got one from " + 38 to_string(be_pid)); 34 PQXX_CHECK_EQUAL( 35 be_pid, 36 Conn().backendpid(), 37 "Notification came from wrong backend process."); 39 38 40 39 cout << "Received notification: " << name() << " pid=" << be_pid << endl; trunk/test/test075.cxx
r1378 r1380 21 21 { 22 22 const result R( W.exec("SELECT year FROM pqxxevents") ); 23 24 if (R.empty()) throw runtime_error("No events found, can't test!"); 23 PQXX_CHECK(!R.empty(), "No events found, cannot test."); 25 24 26 25 PQXX_CHECK_EQUAL(R[0], R.at(0), "Inconsistent result indexing."); trunk/test/test079.cxx
r1378 r1380 32 32 { 33 33 m_Done = true; 34 if (be_pid != Conn().backendpid()) 35 throw logic_error("Expected notification from backend process " + 36 to_string(Conn().backendpid()) + 37 ", but got one from " + 38 to_string(be_pid)); 34 PQXX_CHECK_EQUAL( 35 be_pid, 36 Conn().backendpid(), 37 "Notification came from wrong backend."); 39 38 40 39 cout << "Received notification: " << name() << " pid=" << be_pid << endl; trunk/test/test084.cxx
r1378 r1380 29 29 cerr << '\t' << f; 30 30 cerr << endl; 31 }32 }33 34 35 void compare_results(const result &lhs, const result &rhs, string desc)36 {37 if (lhs != rhs)38 {39 cerr << "Outputs at " << desc << ':' << endl;40 cerr << "lhs:" << endl;41 dump(lhs);42 cerr << "rhs:" << endl;43 dump(rhs);44 throw logic_error("Different results at " + desc);45 31 } 46 32 } … … 105 91 "Got unexpected number of rows."); 106 92 107 compare_results(R, R2, "[1]");93 PQXX_CHECK_EQUAL(R, R2, "Unexpected result at [1]"); 108 94 109 95 C.get(R); 110 96 R2 = *i2; 111 compare_results(R, R2, "[2]");97 PQXX_CHECK_EQUAL(R, R2, "Unexpected result at [2]"); 112 98 i2 += 1; 113 99 … … 116 102 R2 = *++i2; 117 103 118 compare_results(R, R2, "[3]");104 PQXX_CHECK_EQUAL(R, R2, "Unexpected result at [3]"); 119 105 120 106 ++i2; 121 107 R2 = *i2++; 122 108 for (int i=1; C.get(R) && i2 != iend; R2 = *i2++, ++i) 123 compare_results(R, R2, "iteration " + to_string(i)); 109 PQXX_CHECK_EQUAL( 110 R, 111 R2, 112 "Unexpected result in iteration at " + to_string(i)); 124 113 125 114 PQXX_CHECK(i2 == iend, "Adopted cursor terminated early."); trunk/test/test087.cxx
r1378 r1380 50 50 { 51 51 m_Done = true; 52 if (be_pid != Conn().backendpid()) 53 throw logic_error("Expected notification from backend process " + 54 to_string(Conn().backendpid()) + 55 ", but got one from " + 56 to_string(be_pid)); 52 PQXX_CHECK_EQUAL( 53 be_pid, 54 Conn().backendpid(), 55 "Notification came from wrong backend process."); 57 56 58 57 cout << "Received notification: " << name() << " pid=" << be_pid << endl; trunk/test/test089.cxx
r1378 r1380 98 98 catch (const exception &) 99 99 { 100 throw logic_error(100 PQXX_CHECK_NOTREACHED( 101 101 "First asyncconnection supported nested " 102 102 "transactions, but second one doesn't!"); trunk/test/test092.cxx
r1378 r1380 67 67 68 68 const result t( T.exec("SELECT * FROM tuple") ); 69 if (t.size() != 1) 70 throw logic_error("Expected 1 tuple, got " + to_string(t.size())); 71 if (t[0][0].as<string>() != "6") 72 throw logic_error("Expected value 6, got " + t[0][0].as<string>()); 73 if (t[0][1].c_str() != f) 74 throw logic_error("Expected string '" + f + "', " 75 "got '" + t[0][1].c_str() + "'"); 69 PQXX_CHECK_EQUAL(t.size(), 1u, "Wrong result size."); 70 PQXX_CHECK_EQUAL(t[0][0].as<string>(), "6", "Unexpected result value."); 71 PQXX_CHECK_EQUAL(t[0][1].c_str(), f, "Unexpected string result."); 76 72 } 77 73 } // namespace trunk/test/test094.cxx
r1378 r1380 43 43 if (conn().is_open()) 44 44 { 45 if (simulate_failure) 46 throw logic_error("Connection did not simulate failure"); 45 PQXX_CHECK(!simulate_failure, "Connection did not simulate failure."); 47 46 cerr << "Unexpected exception (connection still open)" << endl; 48 47 throw; … … 121 120 122 121 123 void simulate(connection_base &C, int failures, int attempts)124 {125 bool failed = true;126 try127 {128 C.perform(FlakyTransactor(failures), attempts);129 failed = false;130 }131 catch (const in_doubt_error &e)132 {133 if (!failures) throw;134 cout << "(Expected) " << e.what() << endl;135 }136 if (failures && !failed)137 throw logic_error("Simulated failure did not lead to in-doubt error");138 }139 140 141 122 void test_094(connection_base &C, transaction_base &orgT) 142 123 { … … 145 126 // Run without simulating failure 146 127 cout << "Playing transactor without simulating failure..." << endl; 147 simulate(C, 0, 1);128 C.perform(FlakyTransactor(0), 1); 148 129 149 // Simulate one failure, but succeed on retry 130 // Simulate one failure. The transactor will succeed on a second attempt, but 131 // since this is an in-doubt error, the framework does not retry. 150 132 cout << "Playing transactor with simulated failure..." << endl; 151 simulate(C, 1, 2); 133 PQXX_CHECK_THROWS( 134 C.perform(FlakyTransactor(1), 2), 135 in_doubt_error, 136 "Simulated failure did not lead to in-doubt error."); 152 137 } 153 138 } // namespace
