From 1774e989f0dbfe4d1b7e5a130db25c73cfeeee7a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 17 Jun 2013 00:45:17 +0000 Subject: [PATCH] make tests run in separate directories, to have them never interfere with eachother --- clean.py | 3 ++- test/main.cpp | 18 ++++++++++++++++++ test/setup_transfer.cpp | 1 + test/test_rss.cpp | 10 +++++----- test/test_torrent_parse.cpp | 4 ++-- test/test_upnp.cpp | 4 ++-- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/clean.py b/clean.py index 2c2b47770..300437a7d 100644 --- a/clean.py +++ b/clean.py @@ -7,7 +7,8 @@ to_delete = [ 'dht.log', 'upnp.log', 'natpmp.log', - 'bin' + 'bin', + 'test_tmp_*' ] directories = [ diff --git a/test/main.cpp b/test/main.cpp index 52a65a502..591cc233a 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -41,6 +41,7 @@ int test_main(); extern bool tests_failure; #include "libtorrent/assert.hpp" +#include "libtorrent/file.hpp" #include void sig_handler(int sig) @@ -74,6 +75,8 @@ void sig_handler(int sig) exit(138); } +using namespace libtorrent; + int main() { #ifdef O_NONBLOCK @@ -97,6 +100,18 @@ int main() signal(SIGSYS, &sig_handler); #endif + char dir[40]; + snprintf(dir, sizeof(dir), "test_tmp_%u", rand()); + std::string test_dir = complete(dir); + error_code ec; + create_directory(test_dir, ec); + if (ec) + { + fprintf(stderr, "Failed to create test directory: %s\n", ec.message().c_str()); + return 1; + } + chdir(dir); + #ifndef BOOST_NO_EXCEPTIONS try { @@ -117,6 +132,9 @@ int main() #endif fflush(stdout); fflush(stderr); + remove_all(test_dir, ec); + if (ec) + fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str()); return tests_failure ? 1 : 0; } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index b0765c606..80f69f8ef 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -650,6 +650,7 @@ void stop_web_server() web_server->join(); web_server.reset(); } + remove("server.pem"); fprintf(stderr, "done\n"); } diff --git a/test/test_rss.cpp b/test/test_rss.cpp index 7767f8200..a2a4fed18 100644 --- a/test/test_rss.cpp +++ b/test/test_rss.cpp @@ -133,11 +133,11 @@ void test_feed(std::string const& filename, rss_expect const& expect) int test_main() { - test_feed("eztv.xml", rss_expect(30, "http://torrent.zoink.it/The.Daily.Show.2012.02.16.(HDTV-LMAO)[VTV].torrent", "The Daily Show 2012-02-16 [HDTV - LMAO]", 183442338)); - test_feed("cb.xml", rss_expect(50, "http://www.clearbits.net/get/1911-norbergfestival-2011.torrent", "Norbergfestival 2011", 1160773632)); - test_feed("kat.xml", rss_expect(25, "http://kat.ph/torrents/benito-di-paula-1975-benito-di-paula-lp-rip-ogg-at-500-jarax4u-t6194897/", "Benito Di Paula - 1975 - Benito Di Paula (LP Rip OGG at 500) [jarax4u]", 168773863)); - test_feed("mn.xml", rss_expect(20, "http://www.mininova.org/get/13203100", "Dexcell - January TwentyTwelve Mix", 137311179)); - test_feed("pb.xml", rss_expect(60, "magnet:?xt=urn:btih:FD4CDDB7BBE722D17A018EFD875EB0695ED7159C&dn=Thompson+Twins+-+1989+-+Big+Trash+%5BMP3%5D", "Thompson Twins - 1989 - Big Trash [MP3]", 100160904)); + test_feed(combine_path("..", "eztv.xml"), rss_expect(30, "http://torrent.zoink.it/The.Daily.Show.2012.02.16.(HDTV-LMAO)[VTV].torrent", "The Daily Show 2012-02-16 [HDTV - LMAO]", 183442338)); + test_feed(combine_path("..", "cb.xml"), rss_expect(50, "http://www.clearbits.net/get/1911-norbergfestival-2011.torrent", "Norbergfestival 2011", 1160773632)); + test_feed(combine_path("..", "kat.xml"), rss_expect(25, "http://kat.ph/torrents/benito-di-paula-1975-benito-di-paula-lp-rip-ogg-at-500-jarax4u-t6194897/", "Benito Di Paula - 1975 - Benito Di Paula (LP Rip OGG at 500) [jarax4u]", 168773863)); + test_feed(combine_path("..", "mn.xml"), rss_expect(20, "http://www.mininova.org/get/13203100", "Dexcell - January TwentyTwelve Mix", 137311179)); + test_feed(combine_path("..", "pb.xml"), rss_expect(60, "magnet:?xt=urn:btih:FD4CDDB7BBE722D17A018EFD875EB0695ED7159C&dn=Thompson+Twins+-+1989+-+Big+Trash+%5BMP3%5D", "Thompson Twins - 1989 - Big Trash [MP3]", 100160904)); return 0; } diff --git a/test/test_torrent_parse.cpp b/test/test_torrent_parse.cpp index 981aa7639..0b73ace0f 100644 --- a/test/test_torrent_parse.cpp +++ b/test/test_torrent_parse.cpp @@ -114,7 +114,7 @@ int test_main() { error_code ec; fprintf(stderr, "loading %s\n", test_torrents[i].file); - boost::intrusive_ptr ti(new torrent_info(combine_path("test_torrents", test_torrents[i].file), ec)); + boost::intrusive_ptr ti(new torrent_info(combine_path(combine_path("..", "test_torrents"), test_torrents[i].file), ec)); TEST_CHECK(!ec); if (ec) fprintf(stderr, " -> failed %s\n", ec.message().c_str()); @@ -215,7 +215,7 @@ int test_main() { error_code ec; fprintf(stderr, "loading %s\n", test_error_torrents[i].file); - boost::intrusive_ptr ti(new torrent_info(combine_path("test_torrents", test_error_torrents[i].file), ec)); + boost::intrusive_ptr ti(new torrent_info(combine_path(combine_path("..", "test_torrents"), test_error_torrents[i].file), ec)); fprintf(stderr, "E: %s\nexpected: %s\n", ec.message().c_str(), test_error_torrents[i].error.message().c_str()); TEST_EQUAL(ec, test_error_torrents[i].error); } diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index 5c273cb73..e85a66699 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -194,8 +194,8 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons int test_main() { - run_upnp_test("root1.xml", "Xtreme N GIGABIT Router", "wipconn"); - run_upnp_test("root2.xml", "D-Link Router", "WANIPConnection"); + run_upnp_test(combine_path("..", "root1.xml").c_str(), "Xtreme N GIGABIT Router", "wipconn"); + run_upnp_test(combine_path("..", "root2.xml").c_str(), "D-Link Router", "WANIPConnection"); return 0; }