fix clang warning on empty statements by fixing the test macros

This commit is contained in:
arvidn 2019-09-23 08:32:14 +02:00 committed by Arvid Norberg
parent 3168de21f9
commit 9c970550e3
12 changed files with 43 additions and 40 deletions

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -517,7 +517,7 @@ TORRENT_TEST(chunked_encoding)
std::tuple<int, int, bool> 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());

View File

@ -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";

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -104,7 +104,7 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
}
aux::vector<download_priority_t, file_index_t> 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<torrent_info> info, std::int64_t file_
aux::vector<download_priority_t, file_index_t> 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<torrent_info> 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);