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"
13 using namespace libtorrent
;
15 session
ses(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48130, 48140));
18 size_type file_size
= 1 * 1024 * 1024 * 1024;
19 fs
.add_file("test_torrent/tmp1", file_size
);
20 fs
.add_file("test_torrent/tmp2", file_size
);
21 fs
.add_file("test_torrent/tmp3", file_size
);
22 libtorrent::create_torrent
t(fs
, 4 * 1024 * 1024);
23 t
.add_tracker("http://non-existing.com/announce");
25 std::vector
<char> piece(4 * 1024 * 1024);
26 for (int i
= 0; i
< int(piece
.size()); ++i
)
27 piece
[i
] = (i
% 26) + 'A';
29 // calculate the hash for all pieces
30 sha1_hash ph
= hasher(&piece
[0], piece
.size()).final();
31 int num
= t
.num_pieces();
32 for (int i
= 0; i
< num
; ++i
)
35 std::vector
<char> tmp
;
36 std::back_insert_iterator
<std::vector
<char> > out(tmp
);
37 bencode(out
, t
.generate());
38 boost::intrusive_ptr
<torrent_info
> info(new torrent_info(&tmp
[0], tmp
.size()));
43 torrent_handle h
= ses
.add_torrent(p
);
46 torrent_status st
= h
.status();
48 std::cout
<< "total_wanted: " << st
.total_wanted
<< " : " << file_size
* 3 << std::endl
;
49 TEST_CHECK(st
.total_wanted
== file_size
* 3);
50 std::cout
<< "total_wanted_done: " << st
.total_wanted_done
<< " : 0" << std::endl
;
51 TEST_CHECK(st
.total_wanted_done
== 0);
53 std::vector
<int> prio(3, 1);
55 h
.prioritize_files(prio
);
60 std::cout
<< "total_wanted: " << st
.total_wanted
<< " : " << file_size
* 2 << std::endl
;
61 TEST_CHECK(st
.total_wanted
== file_size
* 2);
62 std::cout
<< "total_wanted_done: " << st
.total_wanted_done
<< " : 0" << std::endl
;
63 TEST_CHECK(st
.total_wanted_done
== 0);
66 h
.prioritize_files(prio
);
71 std::cout
<< "total_wanted: " << st
.total_wanted
<< " : " << file_size
<< std::endl
;
72 TEST_CHECK(st
.total_wanted
== file_size
);
73 std::cout
<< "total_wanted_done: " << st
.total_wanted_done
<< " : 0" << std::endl
;
74 TEST_CHECK(st
.total_wanted_done
== 0);