forked from premiere/premiere-libtorrent
polish unit tests
This commit is contained in:
parent
fe10128d53
commit
fd20958e3d
|
@ -77,6 +77,7 @@ enum flags_t
|
|||
expect_dht_msg = 32,
|
||||
expect_peer_connection = 64,
|
||||
expect_possible_udp_connection = 128,
|
||||
expect_possible_dht_msg = 256,
|
||||
};
|
||||
|
||||
session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
||||
|
@ -194,6 +195,15 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
|||
{
|
||||
TEST_EQUAL(num_udp_announces(), prev_udp_announces + bool(flags & expect_udp_connection));
|
||||
}
|
||||
|
||||
if (flags & expect_possible_udp_connection)
|
||||
{
|
||||
// this flag is true if we may fail open, but also might not have had
|
||||
// enough time to fail yet
|
||||
TEST_CHECK(num_dht_hits() == 0 || num_dht_hits() == 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flags & expect_dht_msg)
|
||||
{
|
||||
TEST_CHECK(num_dht_hits() > 0);
|
||||
|
@ -202,6 +212,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
|||
{
|
||||
TEST_EQUAL(num_dht_hits(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & expect_peer_connection)
|
||||
{
|
||||
|
@ -237,8 +248,8 @@ int test_main()
|
|||
// or if the proxy doesn't support UDP
|
||||
pr[0] = test_proxy(settings_pack::none, expect_udp_connection | expect_http_connection | expect_dht_msg | expect_peer_connection);
|
||||
pr[1] = test_proxy(settings_pack::socks4, expect_udp_connection | expect_dht_msg);
|
||||
pr[2] = test_proxy(settings_pack::socks5, expect_possible_udp_connection | expect_dht_msg);
|
||||
pr[3] = test_proxy(settings_pack::socks5_pw,expect_possible_udp_connection | expect_dht_msg);
|
||||
pr[2] = test_proxy(settings_pack::socks5, expect_possible_udp_connection | expect_possible_dht_msg);
|
||||
pr[3] = test_proxy(settings_pack::socks5_pw,expect_possible_udp_connection | expect_possible_dht_msg);
|
||||
pr[4] = test_proxy(settings_pack::http, expect_udp_connection | expect_dht_msg);
|
||||
pr[5] = test_proxy(settings_pack::http_pw, expect_udp_connection | expect_dht_msg);
|
||||
pr[6] = test_proxy(settings_pack::i2p_proxy, expect_udp_connection | expect_dht_msg);
|
||||
|
|
|
@ -43,8 +43,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace libtorrent;
|
||||
|
||||
ptime g_start_time;
|
||||
|
||||
boost::shared_ptr<torrent_info> generate_torrent()
|
||||
{
|
||||
file_storage fs;
|
||||
|
@ -69,7 +67,6 @@ boost::shared_ptr<torrent_info> generate_torrent()
|
|||
|
||||
std::vector<char> generate_resume_data(torrent_info* ti)
|
||||
{
|
||||
g_start_time = libtorrent::time_now();
|
||||
entry rd;
|
||||
|
||||
rd["file-format"] = "libtorrent resume file";
|
||||
|
@ -159,12 +156,19 @@ torrent_status test_resume_flags(int flags)
|
|||
|
||||
void default_tests(torrent_status const& s)
|
||||
{
|
||||
int offset = total_seconds(libtorrent::time_now() - g_start_time);
|
||||
// allow some slack in the time stamps since they are reported as
|
||||
// relative times. If the computer is busy while running the unit test
|
||||
// or running under valgrind it may take several seconds
|
||||
TEST_CHECK(s.last_scrape >= 1349);
|
||||
TEST_CHECK(s.time_since_download >= 1350);
|
||||
TEST_CHECK(s.time_since_upload >= 1351);
|
||||
TEST_CHECK(s.active_time >= 1339);
|
||||
|
||||
TEST_CHECK(s.last_scrape < 1349 + 10);
|
||||
TEST_CHECK(s.time_since_download < 1350 + 10);
|
||||
TEST_CHECK(s.time_since_upload < 1351 + 10);
|
||||
TEST_CHECK(s.active_time < 1339 + 10);
|
||||
|
||||
TEST_EQUAL(s.last_scrape, 1349 + offset);
|
||||
TEST_EQUAL(s.time_since_download, 1350 + offset);
|
||||
TEST_EQUAL(s.time_since_upload, 1351 + offset);
|
||||
TEST_EQUAL(s.active_time, 1339 + offset);
|
||||
TEST_EQUAL(s.finished_time, 1352);
|
||||
TEST_EQUAL(s.seeding_time, 1340);
|
||||
TEST_EQUAL(s.added_time, 1347);
|
||||
|
|
|
@ -95,7 +95,13 @@ void test_transfer()
|
|||
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0
|
||||
, true, false, true, "_utp", 0, &t, false, &atp);
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
#ifdef TORRENT_USE_VALGRIND
|
||||
const int timeout = 12;
|
||||
#else
|
||||
const int timeout = 6;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < timeout; ++i)
|
||||
{
|
||||
print_alerts(ses1, "ses1", true, true, true);
|
||||
print_alerts(ses2, "ses2", true, true, true);
|
||||
|
|
Loading…
Reference in New Issue