updates to test_storage

This commit is contained in:
Arvid Norberg 2009-01-02 09:42:51 +00:00
parent dacb1ac48d
commit 090502390f
3 changed files with 24 additions and 6 deletions

View File

@ -51,9 +51,11 @@ using boost::filesystem::create_directory;
using namespace libtorrent; using namespace libtorrent;
namespace sf = boost::filesystem; namespace sf = boost::filesystem;
void print_alerts(libtorrent::session& ses, char const* name bool print_alerts(libtorrent::session& ses, char const* name
, bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume) , bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume
, bool (*predicate)(libtorrent::alert*))
{ {
bool ret = false;
std::vector<torrent_handle> handles = ses.get_torrents(); std::vector<torrent_handle> handles = ses.get_torrents();
TEST_CHECK(!handles.empty() || allow_no_torrents); TEST_CHECK(!handles.empty() || allow_no_torrents);
torrent_handle h; torrent_handle h;
@ -62,6 +64,7 @@ void print_alerts(libtorrent::session& ses, char const* name
a = ses.pop_alert(); a = ses.pop_alert();
while (a.get()) while (a.get())
{ {
if (predicate && predicate(a.get())) ret = true;
if (peer_disconnected_alert* p = dynamic_cast<peer_disconnected_alert*>(a.get())) if (peer_disconnected_alert* p = dynamic_cast<peer_disconnected_alert*>(a.get()))
{ {
std::cerr << name << "(" << p->ip << "): " << p->message() << "\n"; std::cerr << name << "(" << p->ip << "): " << p->message() << "\n";
@ -85,6 +88,7 @@ void print_alerts(libtorrent::session& ses, char const* name
|| (allow_disconnects && a->message() == "End of file.")); || (allow_disconnects && a->message() == "End of file."));
a = ses.pop_alert(); a = ses.pop_alert();
} }
return ret;
} }
void test_sleep(int millisec) void test_sleep(int millisec)

View File

@ -36,11 +36,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session.hpp" #include "libtorrent/session.hpp"
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
namespace libtorrent
{
class alert;
}
void print_alerts(libtorrent::session& ses, char const* name bool print_alerts(libtorrent::session& ses, char const* name
, bool allow_disconnects = false , bool allow_disconnects = false
, bool allow_no_torrents = false , bool allow_no_torrents = false
, bool allow_failed_fastresume = false); , bool allow_failed_fastresume = false
, bool (*)(libtorrent::alert*) = 0);
void test_sleep(int millisec); void test_sleep(int millisec);
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0, int piece_size = 16 * 1024, int num_pieces = 1024 / 8); boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0, int piece_size = 16 * 1024, int num_pieces = 1024 / 8);

View File

@ -478,6 +478,12 @@ void test_fastresume()
remove_all("tmp1"); remove_all("tmp1");
} }
bool got_file_rename_alert(alert* a)
{
return dynamic_cast<libtorrent::file_renamed_alert*>(a)
|| dynamic_cast<libtorrent::file_rename_failed_alert*>(a);
}
void test_rename_file_in_fastresume() void test_rename_file_in_fastresume()
{ {
std::cout << "\n\n=== test rename file in fastresume ===" << std::endl; std::cout << "\n\n=== test rename file in fastresume ===" << std::endl;
@ -498,12 +504,14 @@ void test_rename_file_in_fastresume()
, storage_mode_compact); , storage_mode_compact);
h.rename_file(0, "testing_renamed_files"); h.rename_file(0, "testing_renamed_files");
for (int i = 0; i < 10; ++i) std::cout << "renaming file" << std::endl;
for (int i = 0; i < 100; ++i)
{ {
print_alerts(ses, "ses"); if (print_alerts(ses, "ses", true, true, true, &got_file_rename_alert)) break;
test_sleep(1000); test_sleep(1000);
torrent_status s = h.status(); torrent_status s = h.status();
} }
std::cout << "stop loop" << std::endl;
resume = h.write_resume_data(); resume = h.write_resume_data();
ses.remove_torrent(h); ses.remove_torrent(h);
} }