1 #include "libtorrent/session.hpp"
2 #include "libtorrent/session_settings.hpp"
3 #include "libtorrent/hasher.hpp"
4 #include "libtorrent/create_torrent.hpp"
5 #include <boost/thread.hpp>
6 #include <boost/tuple/tuple.hpp>
9 #include "setup_transfer.hpp"
11 using namespace libtorrent
;
13 void test_running_torrent(boost::intrusive_ptr
<torrent_info
> info
, size_type file_size
)
15 session
ses(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48130, 48140));
20 torrent_handle h
= ses
.add_torrent(p
);
23 torrent_status st
= h
.status();
25 std::cout
<< "total_wanted: " << st
.total_wanted
<< " : " << file_size
* 3 << std::endl
;
26 TEST_CHECK(st
.total_wanted
== file_size
* 3);
27 std::cout
<< "total_wanted_done: " << st
.total_wanted_done
<< " : 0" << std::endl
;
28 TEST_CHECK(st
.total_wanted_done
== 0);
30 std::vector
<int> prio(3, 1);
32 h
.prioritize_files(prio
);
37 std::cout
<< "total_wanted: " << st
.total_wanted
<< " : " << file_size
* 2 << std::endl
;
38 TEST_CHECK(st
.total_wanted
== file_size
* 2);
39 std::cout
<< "total_wanted_done: " << st
.total_wanted_done
<< " : 0" << std::endl
;
40 TEST_CHECK(st
.total_wanted_done
== 0);
43 h
.prioritize_files(prio
);
48 std::cout
<< "total_wanted: " << st
.total_wanted
<< " : " << file_size
<< std::endl
;
49 TEST_CHECK(st
.total_wanted
== file_size
);
50 std::cout
<< "total_wanted_done: " << st
.total_wanted_done
<< " : 0" << std::endl
;
51 TEST_CHECK(st
.total_wanted_done
== 0);
58 size_type file_size
= 1 * 1024 * 1024 * 1024;
59 fs
.add_file("test_torrent/tmp1", file_size
);
60 fs
.add_file("test_torrent/tmp2", file_size
);
61 fs
.add_file("test_torrent/tmp3", file_size
);
62 libtorrent::create_torrent
t(fs
, 4 * 1024 * 1024);
63 t
.add_tracker("http://non-existing.com/announce");
65 std::vector
<char> piece(4 * 1024 * 1024);
66 for (int i
= 0; i
< int(piece
.size()); ++i
)
67 piece
[i
] = (i
% 26) + 'A';
69 // calculate the hash for all pieces
70 sha1_hash ph
= hasher(&piece
[0], piece
.size()).final();
71 int num
= t
.num_pieces();
72 for (int i
= 0; i
< num
; ++i
)
75 std::vector
<char> tmp
;
76 std::back_insert_iterator
<std::vector
<char> > out(tmp
);
77 bencode(out
, t
.generate());
78 boost::intrusive_ptr
<torrent_info
> info(new torrent_info(&tmp
[0], tmp
.size()));
80 test_running_torrent(info
, file_size
);
86 fs
.add_file("test_torrent/tmp1", 0);
87 libtorrent::create_torrent
t(fs
, 4 * 1024 * 1024);
88 t
.add_tracker("http://non-existing.com/announce");
90 std::vector
<char> tmp
;
91 std::back_insert_iterator
<std::vector
<char> > out(tmp
);
92 bencode(out
, t
.generate());
93 boost::intrusive_ptr
<torrent_info
> info(new torrent_info(&tmp
[0], tmp
.size()));
94 test_running_torrent(info
, 0);