diff --git a/simulation/test_session.cpp b/simulation/test_session.cpp index 684a3c51a..fa7dfda21 100644 --- a/simulation/test_session.cpp +++ b/simulation/test_session.cpp @@ -171,7 +171,7 @@ TORRENT_TEST(add_extension_while_transfer) }); TEST_CHECK(done); - TEST_CHECK(p->m_new_connection) + TEST_CHECK(p->m_new_connection); TEST_CHECK(p->m_files_checked); } #endif // TORRENT_DISABLE_EXTENSIONS diff --git a/test/main.cpp b/test/main.cpp index 288f0d1cb..cde3d57f3 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -197,7 +197,7 @@ LONG WINAPI seh_exception_handler(LPEXCEPTION_POINTERS p) SIG(SIGSYS); #endif #undef SIG - }; + } std::printf("signal: (%d) %s caught:\n%s\n" , sig, name, stack_text); @@ -246,7 +246,7 @@ void change_directory(std::string const& f, error_code& ec) struct unit_directory_guard { - std::string dir; + explicit unit_directory_guard(std::string d) : dir(std::move(d)) {} unit_directory_guard(unit_directory_guard const&) = delete; unit_directory_guard& operator=(unit_directory_guard const&) = delete; ~unit_directory_guard() @@ -273,6 +273,8 @@ struct unit_directory_guard #endif if (ec) std::cerr << "Failed to remove unit test directory: " << ec.message() << "\n"; } +private: + std::string dir; }; void EXPORT reset_output() diff --git a/test/test.hpp b/test/test.hpp index 939fa6882..abd160789 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -114,23 +114,24 @@ extern int _g_test_idx; #ifdef BOOST_NO_EXCEPTIONS #define TEST_CHECK(x) \ - if (!(x)) \ + do if (!(x)) { \ TEST_REPORT_AUX("TEST_ERROR: check failed: \"" #x "\"", __FILE__, __LINE__); + } while (false) #define TEST_EQUAL(x, y) \ - if ((x) != (y)) { \ + do if ((x) != (y)) { \ std::stringstream s__; \ s__ << "TEST_ERROR: equal check failed:\n" #x ": " << (x) << "\nexpected: " << (y); \ TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \ - } + } while (false) #define TEST_NE(x, y) \ - if ((x) == (y)) { \ + do if ((x) == (y)) { \ std::stringstream s__; \ s__ << "TEST_ERROR: not equal check failed:\n" #x ": " << (x) << "\nexpected not equal to: " << (y); \ TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \ - } + } while (false) #else #define TEST_CHECK(x) \ - try \ + do try \ { \ if (!(x)) \ TEST_REPORT_AUX("TEST_ERROR: check failed: \"" #x "\"", __FILE__, __LINE__); \ @@ -142,10 +143,10 @@ extern int _g_test_idx; catch (...) \ { \ TEST_ERROR("TEST_ERROR: Exception thrown: " #x); \ - } + } while (false) #define TEST_EQUAL(x, y) \ - try { \ + do try { \ if ((x) != (y)) { \ std::stringstream s__; \ s__ << "TEST_ERROR: " #x ": " << (x) << " expected: " << (y); \ @@ -159,9 +160,9 @@ extern int _g_test_idx; catch (...) \ { \ TEST_ERROR("TEST_ERROR: Exception thrown: " #x); \ - } + } while (false) #define TEST_NE(x, y) \ - try { \ + do try { \ if ((x) == (y)) { \ std::stringstream s__; \ s__ << "TEST_ERROR: " #x ": " << (x) << " expected not equal to: " << (y); \ @@ -175,29 +176,29 @@ extern int _g_test_idx; catch (...) \ { \ TEST_ERROR("TEST_ERROR: Exception thrown: " #x); \ - } + } while (false) #endif #define TEST_ERROR(x) \ TEST_REPORT_AUX((std::string("TEST_ERROR: \"") + (x) + "\"").c_str(), __FILE__, __LINE__) #define TEST_NOTHROW(x) \ - try \ + do try \ { \ x; \ } \ catch (...) \ { \ TEST_ERROR("TEST_ERROR: Exception thrown: " #x); \ - } + } while (false) #define TEST_THROW(x) \ - try \ + do try \ { \ x; \ TEST_ERROR("No exception thrown: " #x); \ } \ - catch (...) {} + catch (...) {} while (false) #endif // TEST_HPP diff --git a/test/test_alert_types.cpp b/test/test_alert_types.cpp index 169edf3d5..22eecd872 100644 --- a/test/test_alert_types.cpp +++ b/test/test_alert_types.cpp @@ -60,7 +60,7 @@ TORRENT_TEST(alerts_types) TEST_EQUAL(name::static_category, cat); \ TEST_EQUAL(count_alert_types, seq); \ TEST_EQUAL(std::string(alert_name(name::alert_type)) + "_alert", #name); \ - count_alert_types++; + count_alert_types++ #if TORRENT_ABI_VERSION == 1 TEST_ALERT_TYPE(torrent_added_alert, 3, 0, alert::status_notification); diff --git a/test/test_dht_storage.cpp b/test/test_dht_storage.cpp index f5481f203..c6eac4637 100644 --- a/test/test_dht_storage.cpp +++ b/test/test_dht_storage.cpp @@ -101,7 +101,7 @@ TORRENT_TEST(announce_peer) entry peers; s->get_peers(n1, false, false, address(), peers); - TEST_CHECK(peers["n"].string().empty()) + TEST_CHECK(peers["n"].string().empty()); TEST_CHECK(peers["values"].list().empty()); tcp::endpoint const p1 = ep("124.31.75.21", 1); @@ -112,8 +112,8 @@ TORRENT_TEST(announce_peer) s->announce_peer(n1, p1, "torrent_name", false); peers = entry(); s->get_peers(n1, false, false, address(), peers); - TEST_EQUAL(peers["n"].string(), "torrent_name") - TEST_EQUAL(peers["values"].list().size(), 1) + TEST_EQUAL(peers["n"].string(), "torrent_name"); + TEST_EQUAL(peers["values"].list().size(), 1); s->announce_peer(n2, p2, "torrent_name1", false); s->announce_peer(n2, p3, "torrent_name1", false); @@ -453,7 +453,7 @@ TORRENT_TEST(infohashes_sample) entry item; int r = s->get_infohashes_sample(item); TEST_EQUAL(r, 2); - TEST_EQUAL(item["interval"].integer(), 10) + TEST_EQUAL(item["interval"].integer(), 10); TEST_EQUAL(item["num"].integer(), 4); TEST_EQUAL(item["samples"].string().size(), 2 * 20); @@ -463,7 +463,7 @@ TORRENT_TEST(infohashes_sample) item = entry(); r = s->get_infohashes_sample(item); TEST_EQUAL(r, 4); - TEST_EQUAL(item["interval"].integer(), 10) + TEST_EQUAL(item["interval"].integer(), 10); TEST_EQUAL(item["num"].integer(), 4); TEST_EQUAL(item["samples"].string().size(), 4 * 20); @@ -494,7 +494,7 @@ TORRENT_TEST(infohashes_sample_dist) entry item; int r = s->get_infohashes_sample(item); TEST_EQUAL(r, 1); - TEST_EQUAL(item["interval"].integer(), 0) + TEST_EQUAL(item["interval"].integer(), 0); TEST_EQUAL(item["num"].integer(), 1000); TEST_EQUAL(item["samples"].string().size(), 20); diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index a934f3113..ac32dd2c5 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -517,7 +517,7 @@ TORRENT_TEST(chunked_encoding) std::tuple const received = feed_bytes(parser, chunked_input); - TEST_EQUAL(strlen(chunked_input), 24 + 94) + TEST_EQUAL(strlen(chunked_input), 24 + 94); TEST_CHECK(received == std::make_tuple(24, 94, false)); TEST_CHECK(parser.finished()); diff --git a/test/test_pex.cpp b/test/test_pex.cpp index fea8fa594..1522edade 100644 --- a/test/test_pex.cpp +++ b/test/test_pex.cpp @@ -135,7 +135,7 @@ void test_pex() std::this_thread::sleep_for(lt::milliseconds(100)); } - TEST_CHECK(st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2) + TEST_CHECK(st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2); if (!tor2.status().is_seeding && tor3.status().is_seeding) std::cout << "done\n"; diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index a8aa06c80..5c9a75c37 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -1341,7 +1341,7 @@ TORRENT_TEST(prefer_aligned_whole_pieces) TEST_CHECK(picked_pieces.size() == 4); piece_index_t expected_pieces[] = {piece_index_t(4),piece_index_t(5),piece_index_t(6),piece_index_t(7)}; - TEST_CHECK(std::equal(picked_pieces.begin(), picked_pieces.end(), expected_pieces)) + TEST_CHECK(std::equal(picked_pieces.begin(), picked_pieces.end(), expected_pieces)); } TORRENT_TEST(parole_mode) @@ -1645,20 +1645,20 @@ TORRENT_TEST(dont_have_but_passed_hash_check) TEST_EQUAL(p->has_piece_passed(piece_index_t(0)), true); TEST_EQUAL(p->has_piece_passed(piece_index_t(1)), false); - TEST_EQUAL(p->have_piece(piece_index_t(0)), true) - TEST_EQUAL(p->have_piece(piece_index_t(1)), false) + TEST_EQUAL(p->have_piece(piece_index_t(0)), true); + TEST_EQUAL(p->have_piece(piece_index_t(1)), false); p->piece_passed(piece_index_t(1)); TEST_EQUAL(p->has_piece_passed(piece_index_t(0)), true); TEST_EQUAL(p->has_piece_passed(piece_index_t(1)), true); - TEST_EQUAL(p->have_piece(piece_index_t(1)), false) + TEST_EQUAL(p->have_piece(piece_index_t(1)), false); p->we_dont_have(piece_index_t(1)); TEST_EQUAL(p->has_piece_passed(piece_index_t(0)), true); TEST_EQUAL(p->has_piece_passed(piece_index_t(1)), false); - TEST_EQUAL(p->have_piece(piece_index_t(1)), false) + TEST_EQUAL(p->have_piece(piece_index_t(1)), false); } TORRENT_TEST(write_failed) diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index 6c0c6636c..69aaa51e3 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -148,7 +148,7 @@ TORRENT_TEST(printf_int64) char buffer[100]; std::int64_t val = 345678901234567ll; std::snprintf(buffer, sizeof(buffer), "%" PRId64 " %s", val, "end"); - TEST_EQUAL(buffer, std::string("345678901234567 end")) + TEST_EQUAL(buffer, std::string("345678901234567 end")); } TORRENT_TEST(printf_uint64) @@ -156,7 +156,7 @@ TORRENT_TEST(printf_uint64) char buffer[100]; std::uint64_t val = 18446744073709551615ull; std::snprintf(buffer, sizeof(buffer), "%" PRIu64 " %s", val, "end"); - TEST_EQUAL(buffer, std::string("18446744073709551615 end")) + TEST_EQUAL(buffer, std::string("18446744073709551615 end")); } #if defined __GNUC__ && __GNUC__ >= 7 @@ -169,7 +169,7 @@ TORRENT_TEST(printf_trunc) char buffer[4]; int val = 184; std::snprintf(buffer, sizeof(buffer), "%d %s", val, "end"); - TEST_EQUAL(buffer, std::string("184")) + TEST_EQUAL(buffer, std::string("184")); } #if defined __GNUC__ && __GNUC__ >= 7 diff --git a/test/test_session.cpp b/test/test_session.cpp index dfe5819c7..492f8016d 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -203,7 +203,7 @@ TORRENT_TEST(load_empty_file) torrent_handle h = ses.add_torrent(std::move(atp), ec); TEST_CHECK(!h.is_valid()); - TEST_CHECK(ec == error_code(errors::no_metadata)) + TEST_CHECK(ec == error_code(errors::no_metadata)); } TORRENT_TEST(session_stats) diff --git a/test/test_settings_pack.cpp b/test/test_settings_pack.cpp index 278a9c83b..8a2e7a577 100644 --- a/test/test_settings_pack.cpp +++ b/test/test_settings_pack.cpp @@ -117,7 +117,7 @@ TORRENT_TEST(sparse_pack) TORRENT_TEST(test_name) { #define TEST_NAME(n) \ - TEST_EQUAL(setting_by_name(#n), settings_pack:: n) \ + TEST_EQUAL(setting_by_name(#n), settings_pack:: n); \ TEST_EQUAL(name_for_setting(settings_pack:: n), std::string(#n)) #if TORRENT_ABI_VERSION == 1 diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index a0ca5e721..1bf511a4b 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -104,7 +104,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ } aux::vector ones(std::size_t(info->num_files()), 1_pri); - TEST_CHECK(prioritize_files(h, ones)) + TEST_CHECK(prioritize_files(h, ones)); torrent_status st = h.status(); @@ -113,7 +113,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ aux::vector prio(std::size_t(info->num_files()), 1_pri); prio[file_index_t(0)] = 0_pri; - TEST_CHECK(prioritize_files(h, prio)) + TEST_CHECK(prioritize_files(h, prio)); st = h.status(); st = h.status(); @@ -124,7 +124,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ if (info->num_files() > 1) { prio[file_index_t{1}] = 0_pri; - TEST_CHECK(prioritize_files(h, prio)) + TEST_CHECK(prioritize_files(h, prio)); st = h.status(); TEST_EQUAL(st.total_wanted, file_size);