2014-07-06 21:18:00 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2012, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libtorrent/session.hpp"
|
|
|
|
#include "libtorrent/session_settings.hpp"
|
|
|
|
#include "libtorrent/hasher.hpp"
|
|
|
|
#include "libtorrent/alert_types.hpp"
|
|
|
|
#include "libtorrent/bencode.hpp"
|
|
|
|
#include "libtorrent/time.hpp"
|
|
|
|
#include "libtorrent/file.hpp"
|
|
|
|
#include "libtorrent/error_code.hpp"
|
2016-06-20 17:32:06 +02:00
|
|
|
#include <tuple>
|
2016-05-25 06:31:52 +02:00
|
|
|
#include <functional>
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
#include "test.hpp"
|
|
|
|
#include "setup_transfer.hpp"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
namespace lt = libtorrent;
|
|
|
|
|
|
|
|
const int mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification);
|
|
|
|
|
|
|
|
void wait_for_complete(lt::session& ses, torrent_handle h)
|
|
|
|
{
|
2016-03-03 03:35:08 +01:00
|
|
|
int last_progress = 0;
|
|
|
|
clock_type::time_point last_change = clock_type::now();
|
|
|
|
for (int i = 0; i < 400; ++i)
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
|
|
|
print_alerts(ses, "ses1");
|
|
|
|
torrent_status st = h.status();
|
2016-05-17 15:24:06 +02:00
|
|
|
std::fprintf(stderr, "%f %%\n", st.progress_ppm / 10000.f);
|
2014-07-06 21:18:00 +02:00
|
|
|
if (st.progress_ppm == 1000000) return;
|
2016-03-03 03:35:08 +01:00
|
|
|
if (st.progress_ppm != last_progress)
|
|
|
|
{
|
|
|
|
last_progress = st.progress_ppm;
|
|
|
|
last_change = clock_type::now();
|
|
|
|
}
|
|
|
|
if (clock_type::now() - last_change > seconds(10)) break;
|
2014-07-06 21:18:00 +02:00
|
|
|
test_sleep(500);
|
|
|
|
}
|
2015-05-30 23:46:59 +02:00
|
|
|
TEST_ERROR("torrent did not finish");
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-30 06:31:23 +02:00
|
|
|
TORRENT_TEST(recheck)
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
|
|
|
error_code ec;
|
2015-06-05 08:31:52 +02:00
|
|
|
settings_pack sett;
|
|
|
|
sett.set_str(settings_pack::listen_interfaces, "0.0.0.0:48675");
|
|
|
|
sett.set_int(settings_pack::alert_mask, mask);
|
2015-07-28 14:04:51 +02:00
|
|
|
sett.set_bool(settings_pack::enable_upnp, false);
|
|
|
|
sett.set_bool(settings_pack::enable_natpmp, false);
|
|
|
|
sett.set_bool(settings_pack::enable_lsd, false);
|
|
|
|
sett.set_bool(settings_pack::enable_dht, false);
|
2015-06-05 08:31:52 +02:00
|
|
|
lt::session ses1(sett);
|
2014-07-06 21:18:00 +02:00
|
|
|
create_directory("tmp1_recheck", ec);
|
2016-05-17 15:24:06 +02:00
|
|
|
if (ec) std::fprintf(stderr, "create_directory: %s\n", ec.message().c_str());
|
2014-07-06 21:18:00 +02:00
|
|
|
std::ofstream file("tmp1_recheck/temporary");
|
2015-09-20 03:06:56 +02:00
|
|
|
boost::shared_ptr<torrent_info> t = ::create_torrent(&file, "temporary", 4 * 1024 * 1024
|
2015-07-29 01:18:15 +02:00
|
|
|
, 7, false);
|
2014-07-06 21:18:00 +02:00
|
|
|
file.close();
|
|
|
|
|
|
|
|
add_torrent_params param;
|
|
|
|
param.flags &= ~add_torrent_params::flag_paused;
|
|
|
|
param.flags &= ~add_torrent_params::flag_auto_managed;
|
|
|
|
param.ti = t;
|
|
|
|
param.save_path = "tmp1_recheck";
|
|
|
|
param.flags |= add_torrent_params::flag_seed_mode;
|
|
|
|
torrent_handle tor1 = ses1.add_torrent(param, ec);
|
2016-05-17 15:24:06 +02:00
|
|
|
if (ec) std::fprintf(stderr, "add_torrent: %s\n", ec.message().c_str());
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
wait_for_listen(ses1, "ses1");
|
|
|
|
|
|
|
|
tor1.force_recheck();
|
|
|
|
|
|
|
|
torrent_status st1 = tor1.status();
|
|
|
|
TEST_CHECK(st1.progress_ppm <= 1000000);
|
|
|
|
wait_for_complete(ses1, tor1);
|
|
|
|
|
|
|
|
tor1.force_recheck();
|
|
|
|
|
|
|
|
st1 = tor1.status();
|
|
|
|
TEST_CHECK(st1.progress_ppm <= 1000000);
|
|
|
|
wait_for_complete(ses1, tor1);
|
|
|
|
}
|
2016-03-03 03:35:08 +01:00
|
|
|
|