add test to make sure magnet links that fail to be parsed report errors

This commit is contained in:
arvidn 2017-02-16 17:07:57 -05:00 committed by Arvid Norberg
parent a12bfe3164
commit f01801339c
2 changed files with 23 additions and 0 deletions

View File

@ -161,5 +161,13 @@ extern int EXPORT _g_test_failures;
TEST_ERROR("Exception thrown: " #x); \ TEST_ERROR("Exception thrown: " #x); \
} }
#define TEST_THROW(x) \
try \
{ \
x; \
TEST_ERROR("No exception thrown: " #x); \
} \
catch (...) {}
#endif // TEST_HPP #endif // TEST_HPP

View File

@ -395,3 +395,18 @@ TORRENT_TEST(make_magnet_uri2)
TEST_CHECK(magnet.find("&ws=http%3a%2f%2ffoo.com%2fbar") != std::string::npos); TEST_CHECK(magnet.find("&ws=http%3a%2f%2ffoo.com%2fbar") != std::string::npos);
} }
TORRENT_TEST(trailing_whitespace)
{
session ses(settings());
add_torrent_params p;
p.save_path = ".";
p.url = "magnet:?xt=urn:btih:abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n";
// invalid hash
TEST_THROW(ses.add_torrent(p));
p.url = "magnet:?xt=urn:btih:abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
// now it's valid, because there's no trailing whitespace
torrent_handle h = ses.add_torrent(p);
TEST_CHECK(h.is_valid());
}