fix GCC 7 warnings and improve test_primitives a bit

This commit is contained in:
arvidn 2018-07-20 13:04:57 +02:00 committed by Arvid Norberg
parent f4b0dbf115
commit b3e26d08f0
1 changed files with 48 additions and 22 deletions

View File

@ -42,10 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
TORRENT_TEST(primitives) TORRENT_TEST(retry_interval)
{ {
error_code ec;
// make sure the retry interval keeps growing // make sure the retry interval keeps growing
// on failing announces // on failing announces
announce_entry ae("dummy"); announce_entry ae("dummy");
@ -61,8 +59,10 @@ TORRENT_TEST(primitives)
std::printf("%d, ", delay); std::printf("%d, ", delay);
} }
std::printf("\n"); 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::http_error).message() == "HTTP error");
TEST_CHECK(error_code(errors::missing_file_sizes).message() TEST_CHECK(error_code(errors::missing_file_sizes).message()
== "missing or invalid 'file sizes' entry"); == "missing or invalid 'file sizes' entry");
@ -78,16 +78,30 @@ TORRENT_TEST(primitives)
== "401 Unauthorized"); == "401 Unauthorized");
TEST_CHECK(error_code(errors::service_unavailable, http_category()).message() TEST_CHECK(error_code(errors::service_unavailable, http_category()).message()
== "503 Service Unavailable"); == "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]; char msg[10];
std::snprintf(msg, sizeof(msg), "too %s format string", "long"); std::snprintf(msg, sizeof(msg), "too %s format string", "long");
TEST_CHECK(strcmp(msg, "too long ") == 0); 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)
{ {
// make sure the assumption we use in policy's peer list hold if (!supports_ipv6()) return;
error_code ec;
// make sure the assumption we use in peer list hold
std::multimap<address, int> peers; std::multimap<address, int> peers;
std::multimap<address, int>::iterator i; std::multimap<address, int>::iterator i;
peers.insert(std::make_pair(address::from_string("::1", ec), 0)); peers.insert(std::make_pair(address::from_string("::1", ec), 0));
@ -102,8 +116,8 @@ TORRENT_TEST(primitives)
} }
} }
// test network functions TORRENT_TEST(address_endpoint_io)
{
// test print_endpoint, print_address // test print_endpoint, print_address
TEST_EQUAL(print_endpoint(ep("127.0.0.1", 23)), "127.0.0.1:23"); 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"); 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 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("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_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, 3, 4), "-AB1234-");
TEST_EQUAL(generate_fingerprint("AB", 1, 2), "-AB1200-"); TEST_EQUAL(generate_fingerprint("AB", 1, 2), "-AB1200-");
TEST_EQUAL(generate_fingerprint("..", 1, 10), "-..1A00-"); TEST_EQUAL(generate_fingerprint("..", 1, 10), "-..1A00-");
@ -145,6 +161,11 @@ TORRENT_TEST(printf_uint64)
TEST_EQUAL(buffer, std::string("18446744073709551615 end")) 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) TORRENT_TEST(printf_trunc)
{ {
char buffer[4]; char buffer[4];
@ -153,6 +174,11 @@ TORRENT_TEST(printf_trunc)
TEST_EQUAL(buffer, std::string("184")) TEST_EQUAL(buffer, std::string("184"))
} }
#if defined __GNUC__ && __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
TORRENT_TEST(error_condition) TORRENT_TEST(error_condition)
{ {
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS