summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-12-03 13:08:22 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-12-03 13:08:22 +0900
commit0a2b1660fa282da899cba35f7105b9d424f915ca (patch)
tree5283e683278fac7660204bf3619ff6dc53a2183d /test
parent479f71efaffb8cbed3c4c22ad6e7b02869e8784f (diff)
Removed DownloadContext::dir_. Use PREF_DIR value instead.
Diffstat (limited to 'test')
-rw-r--r--test/BittorrentHelperTest.cc89
-rw-r--r--test/BtDependencyTest.cc4
-rw-r--r--test/DefaultBtMessageDispatcherTest.cc3
-rw-r--r--test/DefaultBtProgressInfoFileTest.cc1
-rw-r--r--test/DefaultPieceStorageTest.cc46
-rw-r--r--test/DownloadContextTest.cc3
-rw-r--r--test/DownloadHelperTest.cc9
-rw-r--r--test/Metalink2RequestGroupTest.cc3
-rw-r--r--test/UTMetadataPostDownloadHandlerTest.cc1
-rw-r--r--test/XmlRpcMethodTest.cc7
10 files changed, 75 insertions, 91 deletions
diff --git a/test/BittorrentHelperTest.cc b/test/BittorrentHelperTest.cc
index 0be90738..34f51223 100644
--- a/test/BittorrentHelperTest.cc
+++ b/test/BittorrentHelperTest.cc
@@ -75,7 +75,12 @@ class BittorrentHelperTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testAdjustAnnounceUri);
CPPUNIT_TEST_SUITE_END();
public:
- void setUp() {
+ SharedHandle<Option> option_;
+
+ void setUp()
+ {
+ option_.reset(new Option());
+ option_->put(PREF_DIR, ".");
}
void testGetInfoHash();
@@ -132,7 +137,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BittorrentHelperTest);
void BittorrentHelperTest::testGetInfoHash() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
std::string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
@@ -141,7 +146,7 @@ void BittorrentHelperTest::testGetInfoHash() {
void BittorrentHelperTest::testGetPieceHash() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(util::toHex("AAAAAAAAAAAAAAAAAAAA", 20),
dctx->getPieceHash(0));
@@ -157,7 +162,7 @@ void BittorrentHelperTest::testGetPieceHash() {
void BittorrentHelperTest::testGetFileEntries() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
// This is multi-file torrent.
std::vector<SharedHandle<FileEntry> > fileEntries = dctx->getFileEntries();
// There are 2 file entries.
@@ -177,7 +182,7 @@ void BittorrentHelperTest::testGetFileEntries() {
void BittorrentHelperTest::testGetFileEntriesSingle() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", dctx);
+ load(A2_TEST_DIR"/single.torrent", dctx, option_);
// This is multi-file torrent.
std::vector<SharedHandle<FileEntry> > fileEntries = dctx->getFileEntries();
// There is 1 file entry.
@@ -193,42 +198,42 @@ void BittorrentHelperTest::testGetFileEntriesSingle() {
void BittorrentHelperTest::testGetTotalLength() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL((uint64_t)384ULL, dctx->getTotalLength());
}
void BittorrentHelperTest::testGetTotalLengthSingle() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", dctx);
+ load(A2_TEST_DIR"/single.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL((uint64_t)384ULL, dctx->getTotalLength());
}
void BittorrentHelperTest::testGetFileModeMulti() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(MULTI, getTorrentAttrs(dctx)->mode);
}
void BittorrentHelperTest::testGetFileModeSingle() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", dctx);
+ load(A2_TEST_DIR"/single.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(SINGLE, getTorrentAttrs(dctx)->mode);
}
void BittorrentHelperTest::testGetNameMulti() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test"), getTorrentAttrs(dctx)->name);
}
void BittorrentHelperTest::testGetNameSingle() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", dctx);
+ load(A2_TEST_DIR"/single.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-0.8.2.tar.bz2"),
dctx->getBasePath());
@@ -239,7 +244,7 @@ void BittorrentHelperTest::testGetNameSingle() {
void BittorrentHelperTest::testOverrideName()
{
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx, "aria2-override.name");
+ load(A2_TEST_DIR"/test.torrent", dctx, option_, "aria2-override.name");
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-override.name"),
dctx->getBasePath());
CPPUNIT_ASSERT_EQUAL(std::string("aria2-override.name"),
@@ -249,7 +254,7 @@ void BittorrentHelperTest::testOverrideName()
void BittorrentHelperTest::testGetAnnounceTier() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", dctx);
+ load(A2_TEST_DIR"/single.torrent", dctx, option_);
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
// There is 1 tier.
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->announceList.size());
@@ -261,7 +266,7 @@ void BittorrentHelperTest::testGetAnnounceTier() {
void BittorrentHelperTest::testGetAnnounceTierAnnounceList() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
// There are 3 tiers.
CPPUNIT_ASSERT_EQUAL((size_t)3, attrs->announceList.size());
@@ -281,14 +286,14 @@ void BittorrentHelperTest::testGetAnnounceTierAnnounceList() {
void BittorrentHelperTest::testGetPieceLength() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL((size_t)128, dctx->getPieceLength());
}
void BittorrentHelperTest::testGetInfoHashAsString() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
getInfoHashString(dctx));
@@ -336,7 +341,7 @@ void BittorrentHelperTest::testComputeFastSet()
void BittorrentHelperTest::testGetFileEntries_multiFileUrlList() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/url-list-multiFile.torrent", dctx);
+ load(A2_TEST_DIR"/url-list-multiFile.torrent", dctx, option_);
// This is multi-file torrent.
const std::vector<SharedHandle<FileEntry> >& fileEntries =
dctx->getFileEntries();
@@ -369,7 +374,7 @@ void BittorrentHelperTest::testGetFileEntries_multiFileUrlList() {
void BittorrentHelperTest::testGetFileEntries_singleFileUrlList() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/url-list-singleFile.torrent", dctx);
+ load(A2_TEST_DIR"/url-list-singleFile.torrent", dctx, option_);
// This is single-file torrent.
const std::vector<SharedHandle<FileEntry> >& fileEntries =
dctx->getFileEntries();
@@ -387,7 +392,7 @@ void BittorrentHelperTest::testGetFileEntries_singleFileUrlList() {
void BittorrentHelperTest::testGetFileEntries_singleFileUrlListEndsWithSlash() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/url-list-singleFileEndsWithSlash.torrent", dctx);
+ load(A2_TEST_DIR"/url-list-singleFileEndsWithSlash.torrent", dctx, option_);
// This is single-file torrent.
const std::vector<SharedHandle<FileEntry> >& fileEntries =
dctx->getFileEntries();
@@ -421,7 +426,7 @@ void BittorrentHelperTest::testLoadFromMemory_multiFileNonUtf8Path()
Dict dict;
dict.put("info", info);
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(bencode2::encode(&dict), dctx, "default");
+ loadFromMemory(bencode2::encode(&dict), dctx, option_, "default");
const SharedHandle<FileEntry>& fe = dctx->getFirstFileEntry();
CPPUNIT_ASSERT_EQUAL
@@ -441,7 +446,7 @@ void BittorrentHelperTest::testLoadFromMemory_singleFileNonUtf8Path()
Dict dict;
dict.put("info", info);
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(bencode2::encode(&dict), dctx, "default");
+ loadFromMemory(bencode2::encode(&dict), dctx, option_, "default");
const SharedHandle<FileEntry>& fe = dctx->getFirstFileEntry();
CPPUNIT_ASSERT_EQUAL(std::string("./%90%A2%8AE"), fe->getPath());
@@ -452,7 +457,7 @@ void BittorrentHelperTest::testLoadFromMemory()
std::string memory = "d8:announce36:http://aria.rednoah.com/announce.php13:announce-listll16:http://tracker1 el15:http://tracker2el15:http://tracker3ee7:comment17:REDNOAH.COM RULES13:creation datei1123456789e4:infod5:filesld6:lengthi284e4:pathl5:aria23:src6:aria2ceed6:lengthi100e4:pathl19:aria2-0.2.2.tar.bz2eee4:name10:aria2-test12:piece lengthi128e6:pieces60:AAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
std::string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
@@ -465,7 +470,7 @@ void BittorrentHelperTest::testLoadFromMemory_somethingMissing()
try {
std::string memory = "d8:announce36:http://aria.rednoah.com/announce.php4:infod4:name13:aria2.tar.bz26:lengthi262144eee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
// OK
@@ -477,7 +482,7 @@ void BittorrentHelperTest::testLoadFromMemory_overrideName()
std::string memory = "d8:announce36:http://aria.rednoah.com/announce.php13:announce-listll16:http://tracker1 el15:http://tracker2el15:http://tracker3ee7:comment17:REDNOAH.COM RULES13:creation datei1123456789e4:infod5:filesld6:lengthi284e4:pathl5:aria23:src6:aria2ceed6:lengthi100e4:pathl19:aria2-0.2.2.tar.bz2eee4:name10:aria2-test12:piece lengthi128e6:pieces60:AAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default", "aria2-override.name");
+ loadFromMemory(memory, dctx, option_, "default", "aria2-override.name");
CPPUNIT_ASSERT_EQUAL(std::string("aria2-override.name"),
getTorrentAttrs(dctx)->name);
@@ -489,9 +494,8 @@ void BittorrentHelperTest::testLoadFromMemory_multiFileDirTraversal()
"d8:announce27:http://example.com/announce4:infod5:filesld6:lengthi262144e4:pathl7:../dir14:dir28:file.imgeee4:name14:../name1/name212:piece lengthi262144e6:pieces20:00000000000000000000ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- dctx->setDir("/tmp");
try {
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
CPPUNIT_FAIL("Exception must be thrown.");
} catch(RecoverableException& e) {
// success
@@ -504,9 +508,8 @@ void BittorrentHelperTest::testLoadFromMemory_singleFileDirTraversal()
"d8:announce27:http://example.com/announce4:infod4:name14:../name1/name26:lengthi262144e12:piece lengthi262144e6:pieces20:00000000000000000000ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- dctx->setDir("/tmp");
try {
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
} catch(RecoverableException& e) {
// success
}
@@ -524,7 +527,7 @@ void BittorrentHelperTest::testGetNodes()
"6:pieces20:AAAAAAAAAAAAAAAAAAAA"
"ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->nodes.size());
@@ -544,7 +547,7 @@ void BittorrentHelperTest::testGetNodes()
"6:pieces20:AAAAAAAAAAAAAAAAAAAA"
"ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
@@ -562,7 +565,7 @@ void BittorrentHelperTest::testGetNodes()
"6:pieces20:AAAAAAAAAAAAAAAAAAAA"
"ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
@@ -580,7 +583,7 @@ void BittorrentHelperTest::testGetNodes()
"6:pieces20:AAAAAAAAAAAAAAAAAAAA"
"ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
@@ -597,7 +600,7 @@ void BittorrentHelperTest::testGetNodes()
"6:pieces20:AAAAAAAAAAAAAAAAAAAA"
"ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)0, attrs->nodes.size());
@@ -613,7 +616,7 @@ void BittorrentHelperTest::testGetNodes()
"6:pieces20:AAAAAAAAAAAAAAAAAAAA"
"ee";
SharedHandle<DownloadContext> dctx(new DownloadContext());
- loadFromMemory(memory, dctx, "default");
+ loadFromMemory(memory, dctx, option_, "default");
SharedHandle<TorrentAttribute> attrs = getTorrentAttrs(dctx);
CPPUNIT_ASSERT_EQUAL((size_t)1, attrs->nodes.size());
@@ -625,13 +628,13 @@ void BittorrentHelperTest::testGetNodes()
void BittorrentHelperTest::testGetBasePath()
{
SharedHandle<DownloadContext> singleCtx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", singleCtx);
+ load(A2_TEST_DIR"/single.torrent", singleCtx, option_);
singleCtx->setFilePathWithIndex(1, "new-path");
CPPUNIT_ASSERT_EQUAL(std::string("new-path"), singleCtx->getBasePath());
+ option_->put(PREF_DIR, "downloads");
SharedHandle<DownloadContext> multiCtx(new DownloadContext());
- multiCtx->setDir("downloads");
- load(A2_TEST_DIR"/test.torrent", multiCtx);
+ load(A2_TEST_DIR"/test.torrent", multiCtx, option_);
CPPUNIT_ASSERT_EQUAL(std::string("downloads/aria2-test"),
multiCtx->getBasePath());
}
@@ -639,7 +642,7 @@ void BittorrentHelperTest::testGetBasePath()
void BittorrentHelperTest::testSetFileFilter_single()
{
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/single.torrent", dctx);
+ load(A2_TEST_DIR"/single.torrent", dctx, option_);
CPPUNIT_ASSERT(dctx->getFirstFileEntry()->isRequested());
@@ -658,7 +661,7 @@ void BittorrentHelperTest::testSetFileFilter_single()
void BittorrentHelperTest::testSetFileFilter_multi()
{
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT(dctx->getFileEntries()[0]->isRequested());
CPPUNIT_ASSERT(dctx->getFileEntries()[1]->isRequested());
@@ -683,7 +686,7 @@ void BittorrentHelperTest::testSetFileFilter_multi()
void BittorrentHelperTest::testUTF8Torrent()
{
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/utf8.torrent", dctx);
+ load(A2_TEST_DIR"/utf8.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(std::string("name in utf-8"),
getTorrentAttrs(dctx)->name);
CPPUNIT_ASSERT_EQUAL(std::string("./name in utf-8/path in utf-8"),
@@ -695,7 +698,7 @@ void BittorrentHelperTest::testUTF8Torrent()
void BittorrentHelperTest::testEtc()
{
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(std::string("REDNOAH.COM RULES"),
getTorrentAttrs(dctx)->comment);
CPPUNIT_ASSERT_EQUAL(std::string("aria2"),
@@ -726,7 +729,7 @@ void BittorrentHelperTest::testCheckBitfield()
void BittorrentHelperTest::testMetadata() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
std::string torrentData = readFile(A2_TEST_DIR"/test.torrent");
SharedHandle<ValueBase> tr = bencode2::decode(torrentData);
SharedHandle<ValueBase> infoDic = asDict(tr)->get("info");
@@ -796,7 +799,7 @@ void BittorrentHelperTest::testMetadata2Torrent()
void BittorrentHelperTest::testTorrent2Magnet()
{
SharedHandle<DownloadContext> dctx(new DownloadContext());
- load(A2_TEST_DIR"/test.torrent", dctx);
+ load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL
(std::string("magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C"
diff --git a/test/BtDependencyTest.cc b/test/BtDependencyTest.cc
index 7e0c8af8..433acf12 100644
--- a/test/BtDependencyTest.cc
+++ b/test/BtDependencyTest.cc
@@ -17,6 +17,7 @@
#include "DirectDiskAdaptor.h"
#include "ByteArrayDiskWriter.h"
#include "MockPieceStorage.h"
+#include "prefs.h"
namespace aria2 {
@@ -38,7 +39,6 @@ class BtDependencyTest:public CppUnit::TestFixture {
SharedHandle<RequestGroup> dependant(new RequestGroup(option));
SharedHandle<DownloadContext> dctx
(new DownloadContext(0, 0, "/tmp/outfile.path"));
- dctx->setDir("/tmp");
std::vector<std::string> uris;
uris.push_back("http://localhost/outfile.path");
SharedHandle<FileEntry> fileEntry = dctx->getFirstFileEntry();
@@ -57,7 +57,6 @@ class BtDependencyTest:public CppUnit::TestFixture {
SharedHandle<RequestGroup> dependee(new RequestGroup(option));
SharedHandle<DownloadContext> dctx
(new DownloadContext(1024*1024, length, torrentFile));
- dctx->setDir(".");
dependee->setDownloadContext(dctx);
dependee->initPieceStorage();
return dependee;
@@ -68,6 +67,7 @@ public:
void setUp()
{
option_.reset(new Option());
+ option_->put(PREF_DIR, "/tmp");
}
void testResolve();
diff --git a/test/DefaultBtMessageDispatcherTest.cc b/test/DefaultBtMessageDispatcherTest.cc
index ef3f0fe8..88257d62 100644
--- a/test/DefaultBtMessageDispatcherTest.cc
+++ b/test/DefaultBtMessageDispatcherTest.cc
@@ -136,11 +136,12 @@ public:
void setUp() {
option_.reset(new Option());
+ option_->put(PREF_DIR, ".");
rg_.reset(new RequestGroup(option_));
dctx_.reset(new DownloadContext());
- bittorrent::load(A2_TEST_DIR"/test.torrent", dctx_);
+ bittorrent::load(A2_TEST_DIR"/test.torrent", dctx_, option_);
rg_->setDownloadContext(dctx_);
diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc
index d3d2cb4e..50dad43a 100644
--- a/test/DefaultBtProgressInfoFileTest.cc
+++ b/test/DefaultBtProgressInfoFileTest.cc
@@ -73,7 +73,6 @@ public:
SharedHandle<TorrentAttribute> torrentAttrs(new TorrentAttribute());
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
dctx_->setAttribute(bittorrent::BITTORRENT, torrentAttrs);
- dctx_->setDir(option_->get(PREF_DIR));
const SharedHandle<FileEntry> fileEntries[] = {
SharedHandle<FileEntry>(new FileEntry("/path/to/file",totalLength,0))
};
diff --git a/test/DefaultPieceStorageTest.cc b/test/DefaultPieceStorageTest.cc
index 980671ce..fc38f84d 100644
--- a/test/DefaultPieceStorageTest.cc
+++ b/test/DefaultPieceStorageTest.cc
@@ -15,6 +15,7 @@
#include "DiskAdaptor.h"
#include "DiskWriterFactory.h"
#include "PieceStatMan.h"
+#include "prefs.h"
namespace aria2 {
@@ -41,25 +42,20 @@ class DefaultPieceStorageTest:public CppUnit::TestFixture {
private:
SharedHandle<DownloadContext> dctx_;
SharedHandle<Peer> peer;
- Option* option;
+ SharedHandle<Option> option_;
SharedHandle<PieceSelector> pieceSelector_;
public:
void setUp() {
+ option_.reset(new Option());
+ option_->put(PREF_DIR, ".");
dctx_.reset(new DownloadContext());
- bittorrent::load(A2_TEST_DIR"/test.torrent", dctx_);
+ bittorrent::load(A2_TEST_DIR"/test.torrent", dctx_, option_);
peer.reset(new Peer("192.168.0.1", 6889));
peer->allocateSessionResource(dctx_->getPieceLength(),
dctx_->getTotalLength());
- option = new Option();
pieceSelector_.reset(new InOrderPieceSelector());
}
- void tearDown()
- {
- delete option;
- option = 0;
- }
-
void testGetTotalLength();
void testGetMissingPiece();
void testGetMissingPiece_many();
@@ -82,13 +78,13 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultPieceStorageTest);
void DefaultPieceStorageTest::testGetTotalLength() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
CPPUNIT_ASSERT_EQUAL((uint64_t)384ULL, pss.getTotalLength());
}
void DefaultPieceStorageTest::testGetMissingPiece() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
peer->setAllBitfield();
@@ -106,7 +102,7 @@ void DefaultPieceStorageTest::testGetMissingPiece() {
}
void DefaultPieceStorageTest::testGetMissingPiece_many() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
peer->setAllBitfield();
std::vector<SharedHandle<Piece> > pieces;
@@ -125,7 +121,7 @@ void DefaultPieceStorageTest::testGetMissingPiece_many() {
void DefaultPieceStorageTest::testGetMissingPiece_excludedIndexes()
{
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
pss.setEndGamePieceNum(0);
@@ -147,7 +143,7 @@ void DefaultPieceStorageTest::testGetMissingPiece_excludedIndexes()
}
void DefaultPieceStorageTest::testGetMissingPiece_manyWithExcludedIndexes() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
peer->setAllBitfield();
std::vector<size_t> excludedIndexes;
@@ -165,7 +161,7 @@ void DefaultPieceStorageTest::testGetMissingPiece_manyWithExcludedIndexes() {
}
void DefaultPieceStorageTest::testGetMissingFastPiece() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
pss.setEndGamePieceNum(0);
@@ -182,7 +178,7 @@ void DefaultPieceStorageTest::testGetMissingFastPiece() {
void DefaultPieceStorageTest::testGetMissingFastPiece_excludedIndexes()
{
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
pss.setEndGamePieceNum(0);
@@ -202,7 +198,7 @@ void DefaultPieceStorageTest::testGetMissingFastPiece_excludedIndexes()
}
void DefaultPieceStorageTest::testHasMissingPiece() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
CPPUNIT_ASSERT(!pss.hasMissingPiece(peer));
@@ -212,7 +208,7 @@ void DefaultPieceStorageTest::testHasMissingPiece() {
}
void DefaultPieceStorageTest::testCompletePiece() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
pss.setPieceSelector(pieceSelector_);
pss.setEndGamePieceNum(0);
@@ -234,7 +230,7 @@ void DefaultPieceStorageTest::testCompletePiece() {
}
void DefaultPieceStorageTest::testGetPiece() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
SharedHandle<Piece> pieceGot = pss.getPiece(0);
CPPUNIT_ASSERT_EQUAL((size_t)0, pieceGot->getIndex());
@@ -243,7 +239,7 @@ void DefaultPieceStorageTest::testGetPiece() {
}
void DefaultPieceStorageTest::testGetPieceInUsedPieces() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
SharedHandle<Piece> piece = SharedHandle<Piece>(new Piece(0, 128));
piece->completeBlock(0);
pss.addUsedPiece(piece);
@@ -254,7 +250,7 @@ void DefaultPieceStorageTest::testGetPieceInUsedPieces() {
}
void DefaultPieceStorageTest::testGetPieceCompletedPiece() {
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
SharedHandle<Piece> piece = SharedHandle<Piece>(new Piece(0, 128));
pss.completePiece(piece);
SharedHandle<Piece> pieceGot = pss.getPiece(0);
@@ -274,7 +270,7 @@ void DefaultPieceStorageTest::testCancelPiece()
SharedHandle<DownloadContext> dctx
(new DownloadContext(pieceLength, totalLength, "src/file1.txt"));
- SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, option));
+ SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, option_.get()));
SharedHandle<Piece> p = ps->getMissingPiece(0);
p->completeBlock(0);
@@ -293,7 +289,7 @@ void DefaultPieceStorageTest::testMarkPiecesDone()
SharedHandle<DownloadContext> dctx
(new DownloadContext(pieceLength, totalLength));
- DefaultPieceStorage ps(dctx, option);
+ DefaultPieceStorage ps(dctx, option_.get());
ps.markPiecesDone(pieceLength*10+16*1024*2+1);
@@ -320,7 +316,7 @@ void DefaultPieceStorageTest::testGetCompletedLength()
SharedHandle<DownloadContext> dctx
(new DownloadContext(1024*1024, 256*1024*1024));
- DefaultPieceStorage ps(dctx, option);
+ DefaultPieceStorage ps(dctx, option_.get());
CPPUNIT_ASSERT_EQUAL((uint64_t)0, ps.getCompletedLength());
@@ -347,7 +343,7 @@ void DefaultPieceStorageTest::testGetCompletedLength()
void DefaultPieceStorageTest::testGetNextUsedIndex()
{
- DefaultPieceStorage pss(dctx_, option);
+ DefaultPieceStorage pss(dctx_, option_.get());
CPPUNIT_ASSERT_EQUAL((size_t)3, pss.getNextUsedIndex(0));
SharedHandle<Piece> piece = pss.getMissingPiece(2);
CPPUNIT_ASSERT_EQUAL((size_t)2, pss.getNextUsedIndex(0));
diff --git a/test/DownloadContextTest.cc b/test/DownloadContextTest.cc
index cda4e5ed..04aaf5cb 100644
--- a/test/DownloadContextTest.cc
+++ b/test/DownloadContextTest.cc
@@ -71,9 +71,6 @@ void DownloadContextTest::testGetBasePath()
CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getBasePath());
ctx.getFirstFileEntry()->setPath("aria2.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), ctx.getBasePath());
- ctx.setDir("/tmp");
- // See dir doesn't effect getBasePath().
- CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), ctx.getBasePath());
}
} // namespace aria2
diff --git a/test/DownloadHelperTest.cc b/test/DownloadHelperTest.cc
index 6db4d493..1fae01e1 100644
--- a/test/DownloadHelperTest.cc
+++ b/test/DownloadHelperTest.cc
@@ -91,7 +91,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
}
CPPUNIT_ASSERT_EQUAL((unsigned int)7, group->getNumConcurrentCommand());
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"), ctx->getBasePath());
}
option_->put(PREF_SPLIT, "5");
@@ -136,7 +135,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
CPPUNIT_ASSERT_EQUAL((unsigned int)2,
alphaGroup->getNumConcurrentCommand());
SharedHandle<DownloadContext> alphaCtx = alphaGroup->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), alphaCtx->getDir());
// See filename is not assigned yet
CPPUNIT_ASSERT_EQUAL(std::string(""), alphaCtx->getBasePath());
}
@@ -171,7 +169,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
CPPUNIT_ASSERT_EQUAL((unsigned int)3, group->getNumConcurrentCommand());
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"), ctx->getBasePath());
}
}
@@ -207,7 +204,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
CPPUNIT_ASSERT_EQUAL((unsigned int)3, group->getNumConcurrentCommand());
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
ctx->getBasePath());
@@ -218,7 +214,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
CPPUNIT_ASSERT_EQUAL((unsigned int)3,
torrentGroup->getNumConcurrentCommand());
SharedHandle<DownloadContext> btctx = torrentGroup->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), btctx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-test"),
btctx->getBasePath());
}
@@ -262,7 +257,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
}
CPPUNIT_ASSERT_EQUAL((unsigned int)3, group->getNumConcurrentCommand());
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
ctx->getBasePath());
@@ -271,7 +265,6 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
aria2052Group->getNumConcurrentCommand());
SharedHandle<DownloadContext> aria2052Ctx =
aria2052Group->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), aria2052Ctx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-0.5.2.tar.bz2"),
aria2052Ctx->getBasePath());
@@ -304,13 +297,11 @@ void DownloadHelperTest::testCreateRequestGroupForUriList()
CPPUNIT_ASSERT_EQUAL(std::string("http://charlie/file"), fileURIs[2]);
CPPUNIT_ASSERT_EQUAL((unsigned int)3, fileGroup->getNumConcurrentCommand());
SharedHandle<DownloadContext> fileCtx = fileGroup->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/mydownloads"), fileCtx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/mydownloads/myfile.out"),
fileCtx->getBasePath());
SharedHandle<RequestGroup> fileISOGroup = result[1];
SharedHandle<DownloadContext> fileISOCtx = fileISOGroup->getDownloadContext();
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), fileISOCtx->getDir());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
fileISOCtx->getBasePath());
}
diff --git a/test/Metalink2RequestGroupTest.cc b/test/Metalink2RequestGroupTest.cc
index 2348a9a7..2e64283a 100644
--- a/test/Metalink2RequestGroupTest.cc
+++ b/test/Metalink2RequestGroupTest.cc
@@ -59,7 +59,6 @@ void Metalink2RequestGroupTest::testGenerate()
CPPUNIT_ASSERT(dctx);
CPPUNIT_ASSERT_EQUAL((uint64_t)0ULL, dctx->getTotalLength());
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), dctx->getDir());
#ifdef ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getChecksumHashAlgo());
CPPUNIT_ASSERT_EQUAL
@@ -79,7 +78,6 @@ void Metalink2RequestGroupTest::testGenerate()
const SharedHandle<DownloadContext>& dctx = rg->getDownloadContext();
CPPUNIT_ASSERT(dctx);
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), dctx->getDir());
#ifdef ENABLE_MESSAGE_DIGEST
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getPieceHashAlgo());
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
@@ -124,7 +122,6 @@ void Metalink2RequestGroupTest::testGenerate()
const SharedHandle<DownloadContext>& dctx = rg->getDownloadContext();
CPPUNIT_ASSERT(dctx);
- CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), dctx->getDir());
}
}
diff --git a/test/UTMetadataPostDownloadHandlerTest.cc b/test/UTMetadataPostDownloadHandlerTest.cc
index 006b3c11..38ecb3bb 100644
--- a/test/UTMetadataPostDownloadHandlerTest.cc
+++ b/test/UTMetadataPostDownloadHandlerTest.cc
@@ -33,7 +33,6 @@ public:
void setUp()
{
option_.reset(new Option());
- option_->put("HELLO", "WORLD");
option_->put(PREF_DIR, A2_TEST_OUT_DIR);
dctx_.reset(new DownloadContext(0, 0, A2_TEST_OUT_DIR"/something"));
requestGroup_.reset(new RequestGroup(option_));
diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc
index df45d282..f33b42cc 100644
--- a/test/XmlRpcMethodTest.cc
+++ b/test/XmlRpcMethodTest.cc
@@ -177,7 +177,7 @@ void XmlRpcMethodTest::testAddUri()
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL(std::string("/sink"),
e_->getRequestGroupMan()->findReservedGroup(2)->
- getDownloadContext()->getDir());
+ getOption()->get(PREF_DIR));
}
}
@@ -747,7 +747,6 @@ void XmlRpcMethodTest::testGatherProgressCommon()
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0,"aria2.tar.bz2"));
std::string uris[] = { "http://localhost/aria2.tar.bz2" };
dctx->getFirstFileEntry()->addUris(vbegin(uris), vend(uris));
- dctx->setDir(option_->get(PREF_DIR));
SharedHandle<RequestGroup> group(new RequestGroup(option_));
group->setDownloadContext(dctx);
std::vector<SharedHandle<RequestGroup> > followedBy;
@@ -794,8 +793,10 @@ void XmlRpcMethodTest::testGatherProgressCommon()
#ifdef ENABLE_BITTORRENT
void XmlRpcMethodTest::testGatherBitTorrentMetadata()
{
+ SharedHandle<Option> option(new Option());
+ option->put(PREF_DIR, ".");
SharedHandle<DownloadContext> dctx(new DownloadContext());
- bittorrent::load(A2_TEST_DIR"/test.torrent", dctx);
+ bittorrent::load(A2_TEST_DIR"/test.torrent", dctx, option);
SharedHandle<Dict> btDict = Dict::g();
gatherBitTorrentMetadata(btDict, bittorrent::getTorrentAttrs(dctx));
CPPUNIT_ASSERT_EQUAL(std::string("REDNOAH.COM RULES"),