~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to test/test_trackers_extension.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (c) 2008, Arvid Norberg
 
4
All rights reserved.
 
5
 
 
6
Redistribution and use in source and binary forms, with or without
 
7
modification, are permitted provided that the following conditions
 
8
are met:
 
9
 
 
10
    * Redistributions of source code must retain the above copyright
 
11
      notice, this list of conditions and the following disclaimer.
 
12
    * Redistributions in binary form must reproduce the above copyright
 
13
      notice, this list of conditions and the following disclaimer in
 
14
      the documentation and/or other materials provided with the distribution.
 
15
    * Neither the name of the author nor the names of its
 
16
      contributors may be used to endorse or promote products derived
 
17
      from this software without specific prior written permission.
 
18
 
 
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
20
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
21
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
22
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
23
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
24
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
25
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
26
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
27
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
28
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
29
POSSIBILITY OF SUCH DAMAGE.
 
30
 
 
31
*/
 
32
 
 
33
#include "libtorrent/session.hpp"
 
34
#include "libtorrent/hasher.hpp"
 
35
#include <boost/thread.hpp>
 
36
#include <boost/tuple/tuple.hpp>
 
37
#include <boost/filesystem/operations.hpp>
 
38
#include <boost/filesystem/convenience.hpp>
 
39
 
 
40
#include "test.hpp"
 
41
#include "setup_transfer.hpp"
 
42
#include "libtorrent/extensions/metadata_transfer.hpp"
 
43
#include "libtorrent/extensions/ut_metadata.hpp"
 
44
#include "libtorrent/extensions/lt_trackers.hpp"
 
45
 
 
46
using boost::filesystem::remove_all;
 
47
using boost::tuples::ignore;
 
48
 
 
49
int test_main()
 
50
{
 
51
        using namespace libtorrent;
 
52
 
 
53
        session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48130, 49000), "0.0.0.0", 0);
 
54
        session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49130, 50000), "0.0.0.0", 0);
 
55
        ses1.add_extension(create_lt_trackers_plugin);
 
56
        ses2.add_extension(create_lt_trackers_plugin);
 
57
 
 
58
        add_torrent_params atp;
 
59
        atp.info_hash = sha1_hash("12345678901234567890");
 
60
        atp.save_path = "./";
 
61
        torrent_handle tor1 = ses1.add_torrent(atp);
 
62
        atp.tracker_url = "http://test.non-existent.com/announce";
 
63
        torrent_handle tor2 = ses2.add_torrent(atp);
 
64
        tor2.connect_peer(tcp::endpoint(address_v4::from_string("127.0.0.1"), ses1.listen_port()));
 
65
 
 
66
        for (int i = 0; i < 130; ++i)
 
67
        {
 
68
                // make sure this function can be called on
 
69
                // torrents without metadata
 
70
                print_alerts(ses1, "ses1", false, true);
 
71
                print_alerts(ses2, "ses2", false, true);
 
72
 
 
73
                if (tor1.trackers().size() == 1) break;
 
74
                test_sleep(1000);
 
75
        }
 
76
 
 
77
        TEST_CHECK(tor1.trackers().size() == 1);
 
78
        return 0;
 
79
}
 
80