From e8d691eed9c830fa7a945add7fcee5c60ae138a9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 17 Aug 2008 11:42:57 +0000 Subject: [PATCH] extended the test_torrent to torrents with 0 bytes --- test/Makefile.am | 3 ++ test/test_torrent.cpp | 74 ++++++++++++++++++++++++++++--------------- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index 25b34b63b..eb0728d28 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -58,6 +58,9 @@ test_primitives_LDADD = $(top_builddir)/src/libtorrent-rasterbar.la test_bandwidth_limiter_SOURCES = main.cpp test_bandwidth_limiter.cpp test_bandwidth_limiter_LDADD = $(top_builddir)/src/libtorrent-rasterbar.la +test_torrent_SOURCES = main.cpp test_torrent.cpp +test_torrent_LDADD = $(top_builddir)/src/libtorrent-rasterbar.la + noinst_HEADERS = test.hpp setup_transfer.hpp AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/include/libtorrent @DEBUGFLAGS@ @PTHREAD_CFLAGS@ -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index aaa66a520..25d6d387e 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -8,35 +8,12 @@ #include "test.hpp" #include "setup_transfer.hpp" -int test_main() +using namespace libtorrent; + +void test_running_torrent(boost::intrusive_ptr info, size_type file_size) { - using namespace libtorrent; - session ses(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48130, 48140)); - file_storage fs; - size_type file_size = 1 * 1024 * 1024 * 1024; - fs.add_file("test_torrent/tmp1", file_size); - fs.add_file("test_torrent/tmp2", file_size); - fs.add_file("test_torrent/tmp3", file_size); - libtorrent::create_torrent t(fs, 4 * 1024 * 1024); - t.add_tracker("http://non-existing.com/announce"); - - std::vector piece(4 * 1024 * 1024); - for (int i = 0; i < int(piece.size()); ++i) - piece[i] = (i % 26) + 'A'; - - // calculate the hash for all pieces - sha1_hash ph = hasher(&piece[0], piece.size()).final(); - int num = t.num_pieces(); - for (int i = 0; i < num; ++i) - t.set_hash(i, ph); - - std::vector tmp; - std::back_insert_iterator > out(tmp); - bencode(out, t.generate()); - boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size())); - add_torrent_params p; p.ti = info; p.save_path = "."; @@ -72,6 +49,51 @@ int test_main() TEST_CHECK(st.total_wanted == file_size); std::cout << "total_wanted_done: " << st.total_wanted_done << " : 0" << std::endl; TEST_CHECK(st.total_wanted_done == 0); +} + +int test_main() +{ + { + file_storage fs; + size_type file_size = 1 * 1024 * 1024 * 1024; + fs.add_file("test_torrent/tmp1", file_size); + fs.add_file("test_torrent/tmp2", file_size); + fs.add_file("test_torrent/tmp3", file_size); + libtorrent::create_torrent t(fs, 4 * 1024 * 1024); + t.add_tracker("http://non-existing.com/announce"); + + std::vector piece(4 * 1024 * 1024); + for (int i = 0; i < int(piece.size()); ++i) + piece[i] = (i % 26) + 'A'; + + // calculate the hash for all pieces + sha1_hash ph = hasher(&piece[0], piece.size()).final(); + int num = t.num_pieces(); + for (int i = 0; i < num; ++i) + t.set_hash(i, ph); + + std::vector tmp; + std::back_insert_iterator > out(tmp); + bencode(out, t.generate()); + boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size())); + + test_running_torrent(info, file_size); + } + + { + file_storage fs; + + fs.add_file("test_torrent/tmp1", 0); + libtorrent::create_torrent t(fs, 4 * 1024 * 1024); + t.add_tracker("http://non-existing.com/announce"); + + std::vector tmp; + std::back_insert_iterator > out(tmp); + bencode(out, t.generate()); + boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size())); + test_running_torrent(info, 0); + } + return 0; }