msvc fixes
This commit is contained in:
parent
91197005e9
commit
c8443d0c7c
|
@ -460,7 +460,7 @@ namespace libtorrent
|
|||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
template <class Fun>
|
||||
TORRENT_DEPRECATED
|
||||
void TORRENT_DEPRECATED set_piece_hashes(create_torrent& t
|
||||
void set_piece_hashes(create_torrent& t
|
||||
, std::wstring const& p, Fun f)
|
||||
{
|
||||
error_code ec;
|
||||
|
@ -469,7 +469,7 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
TORRENT_DEPRECATED
|
||||
inline void TORRENT_DEPRECATED set_piece_hashes(create_torrent& t
|
||||
inline void set_piece_hashes(create_torrent& t
|
||||
, std::wstring const& p)
|
||||
{
|
||||
error_code ec;
|
||||
|
@ -479,7 +479,7 @@ namespace libtorrent
|
|||
#endif
|
||||
|
||||
TORRENT_DEPRECATED
|
||||
inline void TORRENT_DEPRECATED set_piece_hashes(create_torrent& t
|
||||
inline void set_piece_hashes(create_torrent& t
|
||||
, std::wstring const& p, error_code& ec)
|
||||
{
|
||||
set_piece_hashes_deprecated(t, p, detail::nop, ec);
|
||||
|
|
|
@ -50,6 +50,7 @@ rule link_libtorrent ( properties * )
|
|||
|
||||
lib libtorrent_test
|
||||
: # sources
|
||||
test.cpp
|
||||
setup_transfer.cpp
|
||||
dht_server.cpp
|
||||
udp_tracker.cpp
|
||||
|
@ -83,7 +84,6 @@ lib advapi32 : : <name>Advapi32 ;
|
|||
project
|
||||
: requirements
|
||||
<source>main.cpp
|
||||
<source>test.cpp
|
||||
<conditional>@link_test
|
||||
<conditional>@link_libtorrent
|
||||
: default-build
|
||||
|
|
|
@ -66,9 +66,9 @@ struct unit_test_t
|
|||
FILE* output;
|
||||
};
|
||||
|
||||
extern unit_test_t _g_unit_tests[1024];
|
||||
extern int _g_num_unit_tests;
|
||||
extern int _g_test_failures;
|
||||
extern unit_test_t EXPORT _g_unit_tests[1024];
|
||||
extern int EXPORT _g_num_unit_tests;
|
||||
extern int EXPORT _g_test_failures;
|
||||
|
||||
#define TORRENT_TEST(test_name) \
|
||||
void BOOST_PP_CAT(unit_test_, test_name)(); \
|
||||
|
@ -76,14 +76,14 @@ extern int _g_test_failures;
|
|||
BOOST_PP_CAT(register_class, __LINE__) () { \
|
||||
unit_test_t& t = _g_unit_tests[_g_num_unit_tests]; \
|
||||
t.fun = &BOOST_PP_CAT(unit_test_, test_name); \
|
||||
t.name = #test_name; \
|
||||
t.name = __FILE__ "." #test_name; \
|
||||
t.num_failures = 0; \
|
||||
t.run = false; \
|
||||
t.output = NULL; \
|
||||
_g_num_unit_tests++; \
|
||||
} \
|
||||
} BOOST_PP_CAT(_static_registrar, __LINE__); \
|
||||
void BOOST_PP_CAT(unit_test_, test_name)()
|
||||
static void BOOST_PP_CAT(unit_test_, test_name)()
|
||||
|
||||
#define TEST_REPORT_AUX(x, line, file) \
|
||||
report_failure(x, line, file)
|
||||
|
|
|
@ -44,7 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace libtorrent;
|
||||
|
||||
void test_limit()
|
||||
TORRENT_TEST(limit)
|
||||
{
|
||||
alert_manager mgr(500, 0xffffffff);
|
||||
|
||||
|
@ -81,7 +81,7 @@ void test_limit()
|
|||
TEST_EQUAL(alerts.size(), 200);
|
||||
}
|
||||
|
||||
void test_priority_limit()
|
||||
TORRENT_TEST(priority_limit)
|
||||
{
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
||||
|
@ -109,7 +109,7 @@ void test_dispatch_fun(int& cnt, std::auto_ptr<alert> a)
|
|||
++cnt;
|
||||
}
|
||||
|
||||
void test_dispatch_function()
|
||||
TORRENT_TEST(dispatch_function)
|
||||
{
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
int cnt = 0;
|
||||
|
@ -142,7 +142,7 @@ void test_notify_fun(int& cnt)
|
|||
++cnt;
|
||||
}
|
||||
|
||||
void test_notify_function()
|
||||
TORRENT_TEST(notify_function)
|
||||
{
|
||||
int cnt = 0;
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
@ -200,7 +200,7 @@ struct test_plugin : libtorrent::plugin
|
|||
|
||||
#endif
|
||||
|
||||
void test_extensions()
|
||||
TORRENT_TEST(extensions)
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
@ -231,7 +231,7 @@ void post_torrent_added(alert_manager* mgr)
|
|||
mgr->emplace_alert<torrent_added_alert>(torrent_handle());
|
||||
}
|
||||
|
||||
void test_wait_for_alert()
|
||||
TORRENT_TEST(wait_for_alert)
|
||||
{
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
||||
|
@ -267,7 +267,7 @@ void test_wait_for_alert()
|
|||
posting_thread.join();
|
||||
}
|
||||
|
||||
void test_queued_resume()
|
||||
TORRENT_TEST(queued_resume)
|
||||
{
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
||||
|
@ -301,7 +301,7 @@ void test_queued_resume()
|
|||
TEST_EQUAL(mgr.num_queued_resume(), 0);
|
||||
}
|
||||
|
||||
void test_alert_mask()
|
||||
TORRENT_TEST(alert_mask)
|
||||
{
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
||||
|
@ -314,17 +314,3 @@ void test_alert_mask()
|
|||
TEST_CHECK(!mgr.should_post<torrent_paused_alert>());
|
||||
}
|
||||
|
||||
TORRENT_TEST(alert_manager)
|
||||
{
|
||||
test_limit();
|
||||
test_priority_limit();
|
||||
test_dispatch_function();
|
||||
test_notify_function();
|
||||
test_extensions();
|
||||
test_wait_for_alert();
|
||||
test_queued_resume();
|
||||
test_alert_mask();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -457,10 +457,8 @@ void test_no_starvation(int limit)
|
|||
TEST_CHECK(close_to(p->m_quota / sample_time, limit / 200 / num_peers, 5));
|
||||
}
|
||||
|
||||
TORRENT_TEST(bandwidth_limiter)
|
||||
TORRENT_TEST(equal_connection)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
test_equal_connections(2, 20);
|
||||
test_equal_connections(2, 2000);
|
||||
test_equal_connections(2, 20000);
|
||||
|
@ -470,11 +468,19 @@ TORRENT_TEST(bandwidth_limiter)
|
|||
test_equal_connections(33, 60000);
|
||||
test_equal_connections(33, 500000);
|
||||
test_equal_connections(1, 100000000);
|
||||
}
|
||||
|
||||
TORRENT_TEST(conn_var_rate)
|
||||
{
|
||||
test_connections_variable_rate(2, 20, 0);
|
||||
test_connections_variable_rate(5, 20000, 0);
|
||||
test_connections_variable_rate(3, 2000, 6000);
|
||||
test_connections_variable_rate(5, 2000, 30000);
|
||||
test_connections_variable_rate(33, 500000, 0);
|
||||
}
|
||||
|
||||
TORRENT_TEST(torrents)
|
||||
{
|
||||
test_torrents(2, 400, 400, 0);
|
||||
test_torrents(2, 100, 500, 0);
|
||||
test_torrents(2, 3000, 3000, 6000);
|
||||
|
@ -483,15 +489,29 @@ TORRENT_TEST(bandwidth_limiter)
|
|||
test_torrents(5, 6000, 6000, 3000);
|
||||
test_torrents(5, 6000, 5000, 4000);
|
||||
test_torrents(5, 20000, 20000, 30000);
|
||||
}
|
||||
|
||||
TORRENT_TEST(torrent_var_rate)
|
||||
{
|
||||
test_torrents_variable_rate(5, 6000, 3000);
|
||||
test_torrents_variable_rate(5, 20000, 30000);
|
||||
}
|
||||
|
||||
TORRENT_TEST(bandwidth_limiter)
|
||||
{
|
||||
test_single_peer(40000, true);
|
||||
test_single_peer(40000, false);
|
||||
}
|
||||
|
||||
TORRENT_TEST(peer_priority)
|
||||
{
|
||||
test_peer_priority(40000, false);
|
||||
test_peer_priority(40000, true);
|
||||
test_no_starvation(40000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TORRENT_TEST(no_starvation)
|
||||
{
|
||||
test_no_starvation(40000);
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -586,7 +586,5 @@ TORRENT_TEST(bencoding)
|
|||
TEST_CHECK(ec == bdecode_errors::expected_colon);
|
||||
}
|
||||
#endif // TORRENT_NO_DEPRECATE
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -187,6 +187,4 @@ TORRENT_TEST(bitfield)
|
|||
TEST_EQUAL(test1.count(), 32 + 8 + 2);
|
||||
TEST_EQUAL(test1.all_set(), true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/bloom_filter.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/sha1_hash.hpp"
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -100,7 +101,7 @@ void test_count_zeroes()
|
|||
|
||||
void test_to_from_string()
|
||||
{
|
||||
uint8_t bits[4] = { 0x10, 0xff, 0x55, 0xaa};
|
||||
boost::uint8_t bits[4] = { 0x10, 0xff, 0x55, 0xaa};
|
||||
|
||||
bloom_filter<4> filter;
|
||||
filter.from_string(reinterpret_cast<char*>(bits));
|
||||
|
|
|
@ -60,6 +60,5 @@ TORRENT_TEST(crc32)
|
|||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32);
|
||||
out = crc32c(buf, 4);
|
||||
TEST_EQUAL(out, htonl(0x4e79dd46));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1954,16 +1954,12 @@ TORRENT_TEST(dht)
|
|||
|
||||
target_id = item_target_id(test_content);
|
||||
TEST_EQUAL(to_hex(target_id.to_string()), "e5f96f6f38320f0f33959cb4d3d656452117aadb");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
TORRENT_TEST(dht)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
{}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -91,7 +91,5 @@ TORRENT_TEST(dos_blocker)
|
|||
|
||||
TEST_EQUAL(b.incoming(spammer, now, &l), false);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
using namespace libtorrent;
|
||||
|
||||
void test_disk_job_empty_fence()
|
||||
TORRENT_TEST(empty_fence)
|
||||
{
|
||||
libtorrent::disk_job_fence fence;
|
||||
counters cnt;
|
||||
|
@ -42,7 +42,7 @@ void test_disk_job_empty_fence()
|
|||
fence.job_complete(&test_job[8], jobs);
|
||||
}
|
||||
|
||||
void test_disk_job_fence()
|
||||
TORRENT_TEST(job_fence)
|
||||
{
|
||||
counters cnt;
|
||||
libtorrent::disk_job_fence fence;
|
||||
|
@ -115,7 +115,7 @@ void test_disk_job_fence()
|
|||
fence.job_complete(&test_job[8], jobs);
|
||||
}
|
||||
|
||||
void test_disk_job_double_fence()
|
||||
TORRENT_TEST(double_fence)
|
||||
{
|
||||
counters cnt;
|
||||
libtorrent::disk_job_fence fence;
|
||||
|
@ -203,11 +203,3 @@ void test_disk_job_double_fence()
|
|||
fence.job_complete(&test_job[9], jobs);
|
||||
}
|
||||
|
||||
TORRENT_TEST(fence)
|
||||
{
|
||||
test_disk_job_fence();
|
||||
test_disk_job_double_fence();
|
||||
test_disk_job_empty_fence();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -75,147 +75,148 @@ void setup_test_storage(file_storage& st)
|
|||
TEST_EQUAL(st.num_pieces(), (100000 + 0x3fff) / 0x4000);
|
||||
}
|
||||
|
||||
TORRENT_TEST(file_storage)
|
||||
TORRENT_TEST(rename_file)
|
||||
{
|
||||
{
|
||||
// test rename_file
|
||||
file_storage st;
|
||||
setup_test_storage(st);
|
||||
// test rename_file
|
||||
file_storage st;
|
||||
setup_test_storage(st);
|
||||
|
||||
st.rename_file(0, combine_path("test", combine_path("c", "d")));
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test"
|
||||
, combine_path("c", "d"))));
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test"
|
||||
, combine_path("c", "d")));
|
||||
st.rename_file(0, combine_path("test", combine_path("c", "d")));
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test"
|
||||
, combine_path("c", "d"))));
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test"
|
||||
, combine_path("c", "d")));
|
||||
|
||||
// files with absolute paths should ignore the save_path argument
|
||||
// passed in to file_path()
|
||||
// files with absolute paths should ignore the save_path argument
|
||||
// passed in to file_path()
|
||||
#ifdef TORRENT_WINDOWS
|
||||
st.rename_file(0, "c:\\tmp\\a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "c:\\tmp\\a");
|
||||
st.rename_file(0, "c:\\tmp\\a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "c:\\tmp\\a");
|
||||
#else
|
||||
st.rename_file(0, "/tmp/a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "/tmp/a");
|
||||
st.rename_file(0, "/tmp/a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "/tmp/a");
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
// test set_name. Make sure the name of the torrent is not encoded
|
||||
// in the paths of each individual file. When changing the name of the
|
||||
// torrent, the path of the files should change too
|
||||
file_storage st;
|
||||
setup_test_storage(st);
|
||||
|
||||
st.set_name("test_2");
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test_2"
|
||||
, "a")));
|
||||
}
|
||||
|
||||
{
|
||||
// test rename_file
|
||||
file_storage st;
|
||||
st.add_file("a", 10000);
|
||||
TEST_EQUAL(st.file_path(0, ""), "a");
|
||||
|
||||
st.rename_file(0, combine_path("test", combine_path("c", "d")));
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test", combine_path("c", "d"))));
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test", combine_path("c", "d")));
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
st.rename_file(0, "c:\\tmp\\a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "c:\\tmp\\a");
|
||||
TEST_EQUAL(st.file_path(0, "c:\\test-1\\test2"), "c:\\tmp\\a");
|
||||
#else
|
||||
st.rename_file(0, "/tmp/a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "/tmp/a");
|
||||
TEST_EQUAL(st.file_path(0, "/usr/local/temp"), "/tmp/a");
|
||||
#endif
|
||||
|
||||
st.rename_file(0, combine_path("tmp", "a"));
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path("tmp", "a"));
|
||||
}
|
||||
|
||||
{
|
||||
// test applying pointer offset
|
||||
file_storage st;
|
||||
char const filename[] = "test1fooba";
|
||||
|
||||
st.add_file_borrow(filename, 5, combine_path("test-torrent-1", "test1")
|
||||
, 10);
|
||||
|
||||
// test filename_ptr and filename_len
|
||||
TEST_EQUAL(st.file_name_ptr(0), filename);
|
||||
TEST_EQUAL(st.file_name_len(0), 5);
|
||||
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test-torrent-1", "test1"));
|
||||
TEST_EQUAL(st.file_path(0, "tmp"), combine_path("tmp"
|
||||
, combine_path("test-torrent-1", "test1")));
|
||||
|
||||
// apply a pointer offset of 5 bytes. The name of the file should
|
||||
// change to "fooba".
|
||||
|
||||
st.apply_pointer_offset(5);
|
||||
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test-torrent-1", "fooba"));
|
||||
TEST_EQUAL(st.file_path(0, "tmp"), combine_path("tmp"
|
||||
, combine_path("test-torrent-1", "fooba")));
|
||||
|
||||
// test filename_ptr and filename_len
|
||||
TEST_EQUAL(st.file_name_ptr(0), filename + 5);
|
||||
TEST_EQUAL(st.file_name_len(0), 5);
|
||||
}
|
||||
|
||||
{
|
||||
// test map_file
|
||||
file_storage fs;
|
||||
fs.set_piece_length(512);
|
||||
fs.add_file(combine_path("temp_storage", "test1.tmp"), 17);
|
||||
fs.add_file(combine_path("temp_storage", "test2.tmp"), 612);
|
||||
fs.add_file(combine_path("temp_storage", "test3.tmp"), 0);
|
||||
fs.add_file(combine_path("temp_storage", "test4.tmp"), 0);
|
||||
fs.add_file(combine_path("temp_storage", "test5.tmp"), 3253);
|
||||
// size: 3882
|
||||
fs.add_file(combine_path("temp_storage", "test6.tmp"), 841);
|
||||
// size: 4723
|
||||
|
||||
peer_request rq = fs.map_file(0, 0, 10);
|
||||
TEST_EQUAL(rq.piece, 0);
|
||||
TEST_EQUAL(rq.start, 0);
|
||||
TEST_EQUAL(rq.length, 10);
|
||||
rq = fs.map_file(5, 0, 10);
|
||||
TEST_EQUAL(rq.piece, 7);
|
||||
TEST_EQUAL(rq.start, 298);
|
||||
TEST_EQUAL(rq.length, 10);
|
||||
rq = fs.map_file(5, 0, 1000);
|
||||
TEST_EQUAL(rq.piece, 7);
|
||||
TEST_EQUAL(rq.start, 298);
|
||||
TEST_EQUAL(rq.length, 841);
|
||||
}
|
||||
|
||||
{
|
||||
// test file_path_hash and path_hash. Make sure we can detect a path
|
||||
// whose name collides with
|
||||
file_storage fs;
|
||||
fs.set_piece_length(512);
|
||||
fs.add_file(combine_path("temp_storage", "Foo"), 17);
|
||||
fs.add_file(combine_path("temp_storage", "foo"), 612);
|
||||
|
||||
fprintf(stderr, "path: %s\n", fs.file_path(0).c_str());
|
||||
fprintf(stderr, "file: %s\n", fs.file_path(1).c_str());
|
||||
boost::uint32_t file_hash0 = fs.file_path_hash(0, "a");
|
||||
boost::uint32_t file_hash1 = fs.file_path_hash(1, "a");
|
||||
TEST_EQUAL(file_hash0, file_hash1);
|
||||
}
|
||||
|
||||
// TODO: test file_storage::optimize too
|
||||
// TODO: test map_block
|
||||
// TODO: test piece_size(int piece)
|
||||
// TODO: test file_index_at_offset
|
||||
// TODO: test file attributes
|
||||
// TODO: test symlinks
|
||||
// TODO: test pad_files
|
||||
// TODO: test reorder_file (make sure internal_file_entry::swap() is used)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
TORRENT_TEST(set_name)
|
||||
{
|
||||
// test set_name. Make sure the name of the torrent is not encoded
|
||||
// in the paths of each individual file. When changing the name of the
|
||||
// torrent, the path of the files should change too
|
||||
file_storage st;
|
||||
setup_test_storage(st);
|
||||
|
||||
st.set_name("test_2");
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test_2"
|
||||
, "a")));
|
||||
}
|
||||
|
||||
TORRENT_TEST(rename_file2)
|
||||
{
|
||||
// test rename_file
|
||||
file_storage st;
|
||||
st.add_file("a", 10000);
|
||||
TEST_EQUAL(st.file_path(0, ""), "a");
|
||||
|
||||
st.rename_file(0, combine_path("test", combine_path("c", "d")));
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test", combine_path("c", "d"))));
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test", combine_path("c", "d")));
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
st.rename_file(0, "c:\\tmp\\a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "c:\\tmp\\a");
|
||||
TEST_EQUAL(st.file_path(0, "c:\\test-1\\test2"), "c:\\tmp\\a");
|
||||
#else
|
||||
st.rename_file(0, "/tmp/a");
|
||||
TEST_EQUAL(st.file_path(0, "."), "/tmp/a");
|
||||
TEST_EQUAL(st.file_path(0, "/usr/local/temp"), "/tmp/a");
|
||||
#endif
|
||||
|
||||
st.rename_file(0, combine_path("tmp", "a"));
|
||||
TEST_EQUAL(st.file_path(0, "."), combine_path("tmp", "a"));
|
||||
}
|
||||
|
||||
TORRENT_TEST(pointer_offset)
|
||||
{
|
||||
// test applying pointer offset
|
||||
file_storage st;
|
||||
char const filename[] = "test1fooba";
|
||||
|
||||
st.add_file_borrow(filename, 5, combine_path("test-torrent-1", "test1")
|
||||
, 10);
|
||||
|
||||
// test filename_ptr and filename_len
|
||||
TEST_EQUAL(st.file_name_ptr(0), filename);
|
||||
TEST_EQUAL(st.file_name_len(0), 5);
|
||||
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test-torrent-1", "test1"));
|
||||
TEST_EQUAL(st.file_path(0, "tmp"), combine_path("tmp"
|
||||
, combine_path("test-torrent-1", "test1")));
|
||||
|
||||
// apply a pointer offset of 5 bytes. The name of the file should
|
||||
// change to "fooba".
|
||||
|
||||
st.apply_pointer_offset(5);
|
||||
|
||||
TEST_EQUAL(st.file_path(0, ""), combine_path("test-torrent-1", "fooba"));
|
||||
TEST_EQUAL(st.file_path(0, "tmp"), combine_path("tmp"
|
||||
, combine_path("test-torrent-1", "fooba")));
|
||||
|
||||
// test filename_ptr and filename_len
|
||||
TEST_EQUAL(st.file_name_ptr(0), filename + 5);
|
||||
TEST_EQUAL(st.file_name_len(0), 5);
|
||||
}
|
||||
|
||||
TORRENT_TEST(map_file)
|
||||
{
|
||||
// test map_file
|
||||
file_storage fs;
|
||||
fs.set_piece_length(512);
|
||||
fs.add_file(combine_path("temp_storage", "test1.tmp"), 17);
|
||||
fs.add_file(combine_path("temp_storage", "test2.tmp"), 612);
|
||||
fs.add_file(combine_path("temp_storage", "test3.tmp"), 0);
|
||||
fs.add_file(combine_path("temp_storage", "test4.tmp"), 0);
|
||||
fs.add_file(combine_path("temp_storage", "test5.tmp"), 3253);
|
||||
// size: 3882
|
||||
fs.add_file(combine_path("temp_storage", "test6.tmp"), 841);
|
||||
// size: 4723
|
||||
|
||||
peer_request rq = fs.map_file(0, 0, 10);
|
||||
TEST_EQUAL(rq.piece, 0);
|
||||
TEST_EQUAL(rq.start, 0);
|
||||
TEST_EQUAL(rq.length, 10);
|
||||
rq = fs.map_file(5, 0, 10);
|
||||
TEST_EQUAL(rq.piece, 7);
|
||||
TEST_EQUAL(rq.start, 298);
|
||||
TEST_EQUAL(rq.length, 10);
|
||||
rq = fs.map_file(5, 0, 1000);
|
||||
TEST_EQUAL(rq.piece, 7);
|
||||
TEST_EQUAL(rq.start, 298);
|
||||
TEST_EQUAL(rq.length, 841);
|
||||
}
|
||||
|
||||
TORRENT_TEST(file_path_hash)
|
||||
{
|
||||
// test file_path_hash and path_hash. Make sure we can detect a path
|
||||
// whose name collides with
|
||||
file_storage fs;
|
||||
fs.set_piece_length(512);
|
||||
fs.add_file(combine_path("temp_storage", "Foo"), 17);
|
||||
fs.add_file(combine_path("temp_storage", "foo"), 612);
|
||||
|
||||
fprintf(stderr, "path: %s\n", fs.file_path(0).c_str());
|
||||
fprintf(stderr, "file: %s\n", fs.file_path(1).c_str());
|
||||
boost::uint32_t file_hash0 = fs.file_path_hash(0, "a");
|
||||
boost::uint32_t file_hash1 = fs.file_path_hash(1, "a");
|
||||
TEST_EQUAL(file_hash0, file_hash1);
|
||||
}
|
||||
|
||||
// TODO: test file_storage::optimize
|
||||
// TODO: test map_block
|
||||
// TODO: test piece_size(int piece)
|
||||
// TODO: test file_index_at_offset
|
||||
// TODO: test file attributes
|
||||
// TODO: test symlinks
|
||||
// TODO: test pad_files
|
||||
// TODO: test reorder_file (make sure internal_file_entry::swap() is used)
|
||||
|
||||
|
|
|
@ -57,7 +57,5 @@ TORRENT_TEST(gzip)
|
|||
TEST_CHECK(inflated.size() > 0);
|
||||
for (int i = 0; i < int(inflated.size()); ++i)
|
||||
TEST_EQUAL(inflated[i], 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,5 @@ TORRENT_TEST(hasher)
|
|||
from_hex(result_array[test], 40, (char*)&result[0]);
|
||||
TEST_CHECK(result == h.final());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ private:
|
|||
|
||||
// test push_back of heterogeneous types
|
||||
// and retrieval of their pointers
|
||||
TORRENT_TEST(heterogeneuous_queue_push_back)
|
||||
TORRENT_TEST(push_back)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -188,7 +188,7 @@ TORRENT_TEST(heterogeneuous_queue_push_back)
|
|||
}
|
||||
|
||||
// test swap
|
||||
TORRENT_TEST(heterogeneuous_queue_swap)
|
||||
TORRENT_TEST(swap)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -237,7 +237,7 @@ TORRENT_TEST(heterogeneuous_queue_swap)
|
|||
}
|
||||
|
||||
// test destruction
|
||||
TORRENT_TEST(heterogeneuous_queue_destruction)
|
||||
TORRENT_TEST(destruction)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -259,7 +259,7 @@ TORRENT_TEST(heterogeneuous_queue_destruction)
|
|||
}
|
||||
|
||||
// test copy/move
|
||||
TORRENT_TEST(heterogeneuous_queue_copy_move)
|
||||
TORRENT_TEST(copy_move)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -285,7 +285,7 @@ TORRENT_TEST(heterogeneuous_queue_copy_move)
|
|||
q.clear();
|
||||
}
|
||||
|
||||
TORRENT_TEST(heterogeneuous_queue_nontrivial)
|
||||
TORRENT_TEST(nontrivial)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
|
|
|
@ -474,7 +474,5 @@ TORRENT_TEST(http_parser)
|
|||
TEST_EQUAL(is_redirect(300), true);
|
||||
TEST_EQUAL(is_redirect(399), true);
|
||||
TEST_EQUAL(is_redirect(400), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,5 @@ TORRENT_TEST(ip_filter)
|
|||
TEST_CHECK(pf.access(301) == 0);
|
||||
TEST_CHECK(pf.access(6881) == 0);
|
||||
TEST_CHECK(pf.access(65535) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ bool cast_vote(ip_voter& ipv, address ext_ip, address voter)
|
|||
|
||||
// test the case where every time we get a new IP. Make sure
|
||||
// we don't flap
|
||||
TORRENT_TEST(ip_voter_test_random)
|
||||
TORRENT_TEST(test_random)
|
||||
{
|
||||
ip_voter ipv;
|
||||
|
||||
|
@ -73,7 +73,7 @@ TORRENT_TEST(ip_voter_test_random)
|
|||
TEST_CHECK(ipv.external_address() == addr1);
|
||||
}
|
||||
|
||||
TORRENT_TEST(ip_voter_two_ips)
|
||||
TORRENT_TEST(two_ips)
|
||||
{
|
||||
ip_voter ipv;
|
||||
|
||||
|
@ -98,16 +98,18 @@ TORRENT_TEST(ip_voter_two_ips)
|
|||
}
|
||||
}
|
||||
|
||||
TORRENT_TEST(ip_voter_one_ip)
|
||||
TORRENT_TEST(one_ip)
|
||||
{
|
||||
ip_voter ipv;
|
||||
|
||||
address_v4 start_addr(address_v4::from_string("93.12.63.174"));
|
||||
address_v4 addr1(address_v4::from_string("51.1.1.1"));
|
||||
address_v4 addr2(address_v4::from_string("53.3.3.3"));
|
||||
|
||||
bool new_ip = cast_vote(ipv, rand_v4(), rand_v4());
|
||||
bool new_ip = cast_vote(ipv, start_addr, rand_v4());
|
||||
TEST_CHECK(new_ip);
|
||||
TEST_CHECK(ipv.external_address() != addr1);
|
||||
TEST_CHECK(ipv.external_address() == start_addr);
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
new_ip = cast_vote(ipv, addr2, rand_v4());
|
||||
|
|
|
@ -307,7 +307,5 @@ TORRENT_TEST(magnet)
|
|||
|
||||
test_remove_url("magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567");
|
||||
test_remove_url("http://non-existent.com/test.torrent");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,5 @@ TORRENT_TEST(merkle)
|
|||
TEST_EQUAL(merkle_num_nodes(4), 7);
|
||||
TEST_EQUAL(merkle_num_nodes(8), 15);
|
||||
TEST_EQUAL(merkle_num_nodes(16), 31);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,129 +35,127 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using libtorrent::packet_buffer;
|
||||
|
||||
// test packet_buffer
|
||||
TORRENT_TEST(packet_buffer)
|
||||
{
|
||||
// test packet_buffer
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.capacity(), 0);
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
TEST_EQUAL(pb.span(), 0);
|
||||
|
||||
pb.insert(123, (void*)123);
|
||||
TEST_EQUAL(pb.at(123 + 16), 0);
|
||||
|
||||
TEST_CHECK(pb.at(123) == (void*)123);
|
||||
TEST_CHECK(pb.capacity() > 0);
|
||||
TEST_EQUAL(pb.size(), 1);
|
||||
TEST_EQUAL(pb.span(), 1);
|
||||
TEST_EQUAL(pb.cursor(), 123);
|
||||
|
||||
pb.insert(125, (void*)125);
|
||||
|
||||
TEST_CHECK(pb.at(125) == (void*)125);
|
||||
TEST_EQUAL(pb.size(), 2);
|
||||
TEST_EQUAL(pb.span(), 3);
|
||||
TEST_EQUAL(pb.cursor(), 123);
|
||||
|
||||
pb.insert(500, (void*)500);
|
||||
TEST_EQUAL(pb.size(), 3);
|
||||
TEST_EQUAL(pb.span(), 501 - 123);
|
||||
TEST_EQUAL(pb.capacity(), 512);
|
||||
|
||||
pb.insert(500, (void*)501);
|
||||
TEST_EQUAL(pb.size(), 3);
|
||||
pb.insert(500, (void*)500);
|
||||
TEST_EQUAL(pb.size(), 3);
|
||||
|
||||
TEST_CHECK(pb.remove(123) == (void*)123);
|
||||
TEST_EQUAL(pb.size(), 2);
|
||||
TEST_EQUAL(pb.span(), 501 - 125);
|
||||
TEST_EQUAL(pb.cursor(), 125);
|
||||
TEST_CHECK(pb.remove(125) == (void*)125);
|
||||
TEST_EQUAL(pb.size(), 1);
|
||||
TEST_EQUAL(pb.span(), 1);
|
||||
TEST_EQUAL(pb.cursor(), 500);
|
||||
|
||||
TEST_CHECK(pb.remove(500) == (void*)500);
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
TEST_EQUAL(pb.span(), 0);
|
||||
|
||||
for (int i = 0; i < 0xff; ++i)
|
||||
{
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.capacity(), 0);
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
TEST_EQUAL(pb.span(), 0);
|
||||
|
||||
pb.insert(123, (void*)123);
|
||||
TEST_EQUAL(pb.at(123 + 16), 0);
|
||||
|
||||
TEST_CHECK(pb.at(123) == (void*)123);
|
||||
TEST_CHECK(pb.capacity() > 0);
|
||||
TEST_EQUAL(pb.size(), 1);
|
||||
TEST_EQUAL(pb.span(), 1);
|
||||
TEST_EQUAL(pb.cursor(), 123);
|
||||
|
||||
pb.insert(125, (void*)125);
|
||||
|
||||
TEST_CHECK(pb.at(125) == (void*)125);
|
||||
TEST_EQUAL(pb.size(), 2);
|
||||
TEST_EQUAL(pb.span(), 3);
|
||||
TEST_EQUAL(pb.cursor(), 123);
|
||||
|
||||
pb.insert(500, (void*)500);
|
||||
TEST_EQUAL(pb.size(), 3);
|
||||
TEST_EQUAL(pb.span(), 501 - 123);
|
||||
int index = (i + 0xfff0) & 0xffff;
|
||||
pb.insert(index, (void*)(index + 1));
|
||||
fprintf(stderr, "insert: %u (mask: %x)\n", index, int(pb.capacity() - 1));
|
||||
TEST_EQUAL(pb.capacity(), 512);
|
||||
|
||||
pb.insert(500, (void*)501);
|
||||
TEST_EQUAL(pb.size(), 3);
|
||||
pb.insert(500, (void*)500);
|
||||
TEST_EQUAL(pb.size(), 3);
|
||||
|
||||
TEST_CHECK(pb.remove(123) == (void*)123);
|
||||
TEST_EQUAL(pb.size(), 2);
|
||||
TEST_EQUAL(pb.span(), 501 - 125);
|
||||
TEST_EQUAL(pb.cursor(), 125);
|
||||
TEST_CHECK(pb.remove(125) == (void*)125);
|
||||
TEST_EQUAL(pb.size(), 1);
|
||||
TEST_EQUAL(pb.span(), 1);
|
||||
TEST_EQUAL(pb.cursor(), 500);
|
||||
|
||||
TEST_CHECK(pb.remove(500) == (void*)500);
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
TEST_EQUAL(pb.span(), 0);
|
||||
|
||||
for (int i = 0; i < 0xff; ++i)
|
||||
if (i >= 14)
|
||||
{
|
||||
int index = (i + 0xfff0) & 0xffff;
|
||||
pb.insert(index, (void*)(index + 1));
|
||||
fprintf(stderr, "insert: %u (mask: %x)\n", index, int(pb.capacity() - 1));
|
||||
TEST_EQUAL(pb.capacity(), 512);
|
||||
if (i >= 14)
|
||||
{
|
||||
index = (index - 14) & 0xffff;
|
||||
fprintf(stderr, "remove: %u\n", index);
|
||||
TEST_CHECK(pb.remove(index) == (void*)(index + 1));
|
||||
TEST_EQUAL(pb.size(), 14);
|
||||
}
|
||||
index = (index - 14) & 0xffff;
|
||||
fprintf(stderr, "remove: %u\n", index);
|
||||
TEST_CHECK(pb.remove(index) == (void*)(index + 1));
|
||||
TEST_EQUAL(pb.size(), 14);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// test wrapping the indices
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
|
||||
pb.insert(0xfffe, (void*)1);
|
||||
TEST_CHECK(pb.at(0xfffe) == (void*)1);
|
||||
|
||||
pb.insert(2, (void*)2);
|
||||
TEST_CHECK(pb.at(2) == (void*)2);
|
||||
|
||||
pb.remove(0xfffe);
|
||||
TEST_CHECK(pb.at(0xfffe) == (void*)0);
|
||||
TEST_CHECK(pb.at(2) == (void*)2);
|
||||
}
|
||||
|
||||
{
|
||||
// test wrapping the indices
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
|
||||
pb.insert(0xfff3, (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)1);
|
||||
|
||||
int new_index = (0xfff3 + pb.capacity()) & 0xffff;
|
||||
pb.insert(new_index, (void*)2);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
|
||||
void* old = pb.remove(0xfff3);
|
||||
TEST_CHECK(old == (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)0);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
}
|
||||
|
||||
{
|
||||
// test wrapping the indices backwards
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
|
||||
pb.insert(0xfff3, (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)1);
|
||||
|
||||
int new_index = (0xfff3 + pb.capacity()) & 0xffff;
|
||||
pb.insert(new_index, (void*)2);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
|
||||
void* old = pb.remove(0xfff3);
|
||||
TEST_CHECK(old == (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)0);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
|
||||
pb.insert(0xffff, (void*)0xffff);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
TORRENT_TEST(packet_buffer_wrap)
|
||||
{
|
||||
// test wrapping the indices
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
|
||||
pb.insert(0xfffe, (void*)1);
|
||||
TEST_CHECK(pb.at(0xfffe) == (void*)1);
|
||||
|
||||
pb.insert(2, (void*)2);
|
||||
TEST_CHECK(pb.at(2) == (void*)2);
|
||||
|
||||
pb.remove(0xfffe);
|
||||
TEST_CHECK(pb.at(0xfffe) == (void*)0);
|
||||
TEST_CHECK(pb.at(2) == (void*)2);
|
||||
}
|
||||
|
||||
TORRENT_TEST(packet_buffer_wrap2)
|
||||
{
|
||||
// test wrapping the indices
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
|
||||
pb.insert(0xfff3, (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)1);
|
||||
|
||||
int new_index = (0xfff3 + pb.capacity()) & 0xffff;
|
||||
pb.insert(new_index, (void*)2);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
|
||||
void* old = pb.remove(0xfff3);
|
||||
TEST_CHECK(old == (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)0);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
}
|
||||
|
||||
TORRENT_TEST(packet_buffer_reverse_wrap)
|
||||
{
|
||||
// test wrapping the indices backwards
|
||||
packet_buffer pb;
|
||||
|
||||
TEST_EQUAL(pb.size(), 0);
|
||||
|
||||
pb.insert(0xfff3, (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)1);
|
||||
|
||||
int new_index = (0xfff3 + pb.capacity()) & 0xffff;
|
||||
pb.insert(new_index, (void*)2);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
|
||||
void* old = pb.remove(0xfff3);
|
||||
TEST_CHECK(old == (void*)1);
|
||||
TEST_CHECK(pb.at(0xfff3) == (void*)0);
|
||||
TEST_CHECK(pb.at(new_index) == (void*)2);
|
||||
|
||||
pb.insert(0xffff, (void*)0xffff);
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,5 @@ TORRENT_TEST(part_file)
|
|||
for (int i = 0; i < 1024; ++i)
|
||||
TEST_CHECK(buf[i] == char(i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -104,7 +104,5 @@ TORRENT_TEST(peer_priority)
|
|||
"\xff\xff\x0f\xff\x55\x55\x55\x55\x00\x00\x00\x00\x00\x00\x00\x01"
|
||||
"\xff\xff\xff\xff\x55\x55\x55\x55\x00\x00\x00\x00\x00\x00\x00\x01", 32));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -274,6 +274,7 @@ int test_pick(boost::shared_ptr<piece_picker> const& p
|
|||
return picked[0].piece_index;
|
||||
}
|
||||
|
||||
// TODO: 2 split this up into smaller tests (where we print_title)
|
||||
TORRENT_TEST(piece_picker)
|
||||
{
|
||||
tcp::endpoint endp;
|
||||
|
@ -1857,7 +1858,5 @@ TORRENT_TEST(piece_picker)
|
|||
TEST_EQUAL(picked.size(), blocks_per_piece);
|
||||
for (int i = 0; i < int(picked.size()); ++i)
|
||||
TEST_EQUAL(picked[0].piece_index, 4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,5 @@ TORRENT_TEST(random)
|
|||
TEST_CHECK(abs(buckets[i] - expected) < expected / 6);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,5 @@ TORRENT_TEST(resolve_links)
|
|||
|
||||
}
|
||||
#endif // TORRENT_DISABLE_MUTABLE_TORRENTS
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,5 @@ TORRENT_TEST(settings_pack)
|
|||
p.set_str(settings_pack::peer_fingerprint, "hij");
|
||||
|
||||
TEST_EQUAL(p.get_str(settings_pack::peer_fingerprint), "hij");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,52 +44,54 @@ int samples[] = {
|
|||
67, 51, 66, 52, 48, 57, 30, 51, 72, 65, 78, 56, 74, 68, 49, 66,
|
||||
63, 57, 61, 62, 64, 62, 61, 52, 67, 64, 59, 61, 69, 60, 54, 69 };
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
TORRENT_TEST(sliding_average)
|
||||
// make sure we react quickly for the first few samples
|
||||
TORRENT_TEST(reaction_time)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
sliding_average<10> avg;
|
||||
|
||||
// make sure we react quickly for the first few samples
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
avg.add_sample(-10);
|
||||
avg.add_sample(10);
|
||||
|
||||
avg.add_sample(-10);
|
||||
avg.add_sample(10);
|
||||
|
||||
TEST_EQUAL(avg.mean(), 0);
|
||||
}
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
|
||||
avg.add_sample(10);
|
||||
avg.add_sample(20);
|
||||
|
||||
TEST_EQUAL(avg.mean(), 15);
|
||||
}
|
||||
|
||||
// make sure we converge
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
avg.add_sample(100);
|
||||
for (int i = 0; i < 20; ++i)
|
||||
avg.add_sample(10);
|
||||
TEST_CHECK(abs(avg.mean() - 10) <= 3);
|
||||
}
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
avg.add_sample(-100);
|
||||
for (int i = 0; i < 20; ++i)
|
||||
avg.add_sample(-10);
|
||||
TEST_CHECK(abs(avg.mean() + 10) <= 3);
|
||||
}
|
||||
|
||||
// test with a more realistic input
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
for (int i = 0; i < int(sizeof(samples)/sizeof(samples[0])); ++i)
|
||||
avg.add_sample(samples[i]);
|
||||
TEST_CHECK(abs(avg.mean() - 60) <= 3);
|
||||
}
|
||||
return 0;
|
||||
TEST_EQUAL(avg.mean(), 0);
|
||||
}
|
||||
|
||||
TORRENT_TEST(reaction_time2)
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
|
||||
avg.add_sample(10);
|
||||
avg.add_sample(20);
|
||||
|
||||
TEST_EQUAL(avg.mean(), 15);
|
||||
}
|
||||
|
||||
// make sure we converge
|
||||
TORRENT_TEST(converge)
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
avg.add_sample(100);
|
||||
for (int i = 0; i < 20; ++i)
|
||||
avg.add_sample(10);
|
||||
TEST_CHECK(abs(avg.mean() - 10) <= 3);
|
||||
}
|
||||
|
||||
TORRENT_TEST(converge2)
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
avg.add_sample(-100);
|
||||
for (int i = 0; i < 20; ++i)
|
||||
avg.add_sample(-10);
|
||||
TEST_CHECK(abs(avg.mean() + 10) <= 3);
|
||||
}
|
||||
|
||||
// test with a more realistic input
|
||||
TORRENT_TEST(random_converge)
|
||||
{
|
||||
sliding_average<10> avg;
|
||||
for (int i = 0; i < int(sizeof(samples)/sizeof(samples[0])); ++i)
|
||||
avg.add_sample(samples[i]);
|
||||
TEST_CHECK(abs(avg.mean() - 60) <= 3);
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,5 @@ TORRENT_TEST(socket_io)
|
|||
TEST_EQUAL(list.size(), 1);
|
||||
#endif
|
||||
TEST_EQUAL(list[0], udp::endpoint(address_v4::from_string("16.5.128.1"), 1337));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -303,7 +303,5 @@ TORRENT_TEST(string)
|
|||
|
||||
TEST_EQUAL(convert_to_native("foobar")
|
||||
, convert_to_native("foo") + convert_to_native("bar"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,5 @@ TORRENT_TEST(tailqueue)
|
|||
|
||||
free_chain(t1);
|
||||
free_chain(t2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,5 @@ TORRENT_TEST(threads)
|
|||
}
|
||||
|
||||
TEST_CHECK(c == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,5 @@ TORRENT_TEST(time)
|
|||
t2.join();
|
||||
t3.join();
|
||||
t4.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace libtorrent;
|
||||
|
||||
void test_mutable_torrents()
|
||||
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
|
||||
TORRENT_TEST(mutable_torrents)
|
||||
{
|
||||
file_storage fs;
|
||||
|
||||
|
@ -82,6 +83,7 @@ void test_mutable_torrents()
|
|||
TEST_CHECK(similar == ti.similar_torrents());
|
||||
TEST_CHECK(collections == ti.collections());
|
||||
}
|
||||
#endif
|
||||
|
||||
struct test_torrent_t
|
||||
{
|
||||
|
@ -176,7 +178,7 @@ test_failing_torrent_t test_error_torrents[] =
|
|||
// TODO: torrent_info constructor that takes an invalid bencoded buffer
|
||||
// TODO: verify_encoding with a string that triggers character replacement
|
||||
|
||||
void test_sanitize_path()
|
||||
TORRENT_TEST(sanitize_path)
|
||||
{
|
||||
// test sanitize_append_path_element
|
||||
|
||||
|
@ -286,7 +288,7 @@ void test_sanitize_path()
|
|||
|
||||
}
|
||||
|
||||
void test_torrent_parse()
|
||||
TORRENT_TEST(parse)
|
||||
{
|
||||
error_code ec;
|
||||
|
||||
|
@ -567,8 +569,6 @@ void test_torrent_parse()
|
|||
, test_error_torrents[i].error.message().c_str());
|
||||
TEST_CHECK(ec.message() == test_error_torrents[i].error.message());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_resolve_duplicates(int test_case)
|
||||
|
@ -660,7 +660,13 @@ void test_resolve_duplicates(int test_case)
|
|||
}
|
||||
}
|
||||
|
||||
void test_copy()
|
||||
TORRENT_TEST(resolve_duplicates)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
test_resolve_duplicates(i);
|
||||
}
|
||||
|
||||
TORRENT_TEST(copy)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -715,18 +721,4 @@ void test_copy()
|
|||
}
|
||||
}
|
||||
|
||||
TORRENT_TEST(torrent_info)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
test_resolve_duplicates(i);
|
||||
|
||||
test_copy();
|
||||
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
|
||||
test_mutable_torrents();
|
||||
#endif
|
||||
test_torrent_parse();
|
||||
test_sanitize_path();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -387,7 +387,5 @@ TORRENT_TEST(transfer)
|
|||
remove_all("tmp2_transfer", ec);
|
||||
remove_all("tmp1_transfer_moved", ec);
|
||||
remove_all("tmp2_transfer_moved", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ void callback(int mapping, address const& ip, int port, error_code const& err)
|
|||
<< ", error: \"" << err.message() << "\"\n";
|
||||
}
|
||||
|
||||
int run_upnp_test(char const* root_filename, char const* router_model, char const* control_name)
|
||||
void run_upnp_test(char const* root_filename, char const* router_model, char const* control_name)
|
||||
{
|
||||
libtorrent::io_service ios;
|
||||
|
||||
|
@ -135,7 +135,7 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
|
|||
{
|
||||
fprintf(stderr, "failed to open file 'upnp.xml': %s\n", strerror(errno));
|
||||
TEST_CHECK(false);
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
fprintf(xml_file, &buf[0], g_port);
|
||||
fclose(xml_file);
|
||||
|
@ -225,13 +225,11 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
|
|||
callbacks.clear();
|
||||
|
||||
delete sock;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TORRENT_TEST(upnp)
|
||||
{
|
||||
run_upnp_test(combine_path("..", "root1.xml").c_str(), "Xtreme N GIGABIT Router", "wipconn");
|
||||
run_upnp_test(combine_path("..", "root2.xml").c_str(), "D-Link Router", "WANIPConnection");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -424,7 +424,5 @@ TORRENT_TEST(xml)
|
|||
std::cerr << out << std::endl;
|
||||
TEST_CHECK(out == "Punexpected end of file");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue