From b3e26d08f031ceedc5f6f152653f8060ccb1e295 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 20 Jul 2018 13:04:57 +0200 Subject: [PATCH] fix GCC 7 warnings and improve test_primitives a bit --- test/test_primitives.cpp | 70 +++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index bb7119ef7..f645599ea 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -42,10 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; -TORRENT_TEST(primitives) +TORRENT_TEST(retry_interval) { - error_code ec; - // make sure the retry interval keeps growing // on failing announces announce_entry ae("dummy"); @@ -61,8 +59,10 @@ TORRENT_TEST(primitives) std::printf("%d, ", delay); } std::printf("\n"); +} - // test error codes +TORRENT_TEST(error_code) +{ TEST_CHECK(error_code(errors::http_error).message() == "HTTP error"); TEST_CHECK(error_code(errors::missing_file_sizes).message() == "missing or invalid 'file sizes' entry"); @@ -78,32 +78,46 @@ TORRENT_TEST(primitives) == "401 Unauthorized"); TEST_CHECK(error_code(errors::service_unavailable, http_category()).message() == "503 Service Unavailable"); +} - // test std::snprintf +#if defined __GNUC__ && __GNUC__ >= 7 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation=" +#endif +TORRENT_TEST(snprintf) +{ char msg[10]; std::snprintf(msg, sizeof(msg), "too %s format string", "long"); TEST_CHECK(strcmp(msg, "too long ") == 0); +} - if (supports_ipv6()) +#if defined __GNUC__ && __GNUC__ >= 7 +#pragma GCC diagnostic pop +#endif + +TORRENT_TEST(address_to_from_string) +{ + if (!supports_ipv6()) return; + + error_code ec; + // make sure the assumption we use in peer list hold + std::multimap peers; + std::multimap::iterator i; + peers.insert(std::make_pair(address::from_string("::1", ec), 0)); + peers.insert(std::make_pair(address::from_string("::2", ec), 3)); + peers.insert(std::make_pair(address::from_string("::3", ec), 5)); + i = peers.find(address::from_string("::2", ec)); + TEST_CHECK(i != peers.end()); + if (i != peers.end()) { - // make sure the assumption we use in policy's peer list hold - std::multimap peers; - std::multimap::iterator i; - peers.insert(std::make_pair(address::from_string("::1", ec), 0)); - peers.insert(std::make_pair(address::from_string("::2", ec), 3)); - peers.insert(std::make_pair(address::from_string("::3", ec), 5)); - i = peers.find(address::from_string("::2", ec)); - TEST_CHECK(i != peers.end()); - if (i != peers.end()) - { - TEST_CHECK(i->first == address::from_string("::2", ec)); - TEST_CHECK(i->second == 3); - } + TEST_CHECK(i->first == address::from_string("::2", ec)); + TEST_CHECK(i->second == 3); } +} - // test network functions - +TORRENT_TEST(address_endpoint_io) +{ // test print_endpoint, print_address TEST_EQUAL(print_endpoint(ep("127.0.0.1", 23)), "127.0.0.1:23"); TEST_EQUAL(print_address(addr4("241.124.23.5")), "241.124.23.5"); @@ -120,8 +134,10 @@ TORRENT_TEST(primitives) // test endpoint_to_bytes TEST_EQUAL(endpoint_to_bytes(uep("10.11.12.13", 8080)), "\x0a\x0b\x0c\x0d\x1f\x90"); TEST_EQUAL(endpoint_to_bytes(uep("16.5.127.1", 12345)), "\x10\x05\x7f\x01\x30\x39"); +} - // test gen_fingerprint +TORRENT_TEST(gen_fingerprint) +{ TEST_EQUAL(generate_fingerprint("AB", 1, 2, 3, 4), "-AB1234-"); TEST_EQUAL(generate_fingerprint("AB", 1, 2), "-AB1200-"); TEST_EQUAL(generate_fingerprint("..", 1, 10), "-..1A00-"); @@ -145,6 +161,11 @@ TORRENT_TEST(printf_uint64) TEST_EQUAL(buffer, std::string("18446744073709551615 end")) } +#if defined __GNUC__ && __GNUC__ >= 7 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation=" +#endif + TORRENT_TEST(printf_trunc) { char buffer[4]; @@ -153,6 +174,11 @@ TORRENT_TEST(printf_trunc) TEST_EQUAL(buffer, std::string("184")) } +#if defined __GNUC__ && __GNUC__ >= 7 +#pragma GCC diagnostic pop +#endif + + TORRENT_TEST(error_condition) { #ifdef TORRENT_WINDOWS