Removed DownloadContext::dir_. Use PREF_DIR value instead.

pull/1/head
Tatsuhiro Tsujikawa 2010-12-03 13:08:22 +09:00
parent 479f71efaf
commit 0a2b1660fa
24 changed files with 117 additions and 127 deletions

View File

@ -81,7 +81,6 @@ bool BtDependency::resolve()
// cut reference here
dependee_.reset();
SharedHandle<DownloadContext> context(new DownloadContext());
context->setDir(dependant_->getDownloadContext()->getDir());
try {
SharedHandle<DiskAdaptor> diskAdaptor =
dependee->getPieceStorage()->getDiskAdaptor();
@ -91,12 +90,14 @@ bool BtDependency::resolve()
SharedHandle<TorrentAttribute> attrs =
bittorrent::getTorrentAttrs(dependee->getDownloadContext());
bittorrent::loadFromMemory
(bittorrent::metadata2Torrent(content, attrs), context, "default");
(bittorrent::metadata2Torrent(content, attrs), context,
dependant_->getOption(), "default");
// We don't call bittorrent::adjustAnnounceUri() because it
// has already been called with attrs.
} else {
bittorrent::loadFromMemory
(content, context, File(dependee->getFirstFilePath()).getBasename());
(content, context, dependant_->getOption(),
File(dependee->getFirstFilePath()).getBasename());
bittorrent::adjustAnnounceUri(bittorrent::getTorrentAttrs(context),
dependant_->getOption());
}

View File

@ -48,7 +48,6 @@
namespace aria2 {
DownloadContext::DownloadContext():
dir_(A2STR::DOT_C),
pieceLength_(0),
checksumVerified_(false),
knowsTotalLength_(true),
@ -59,7 +58,6 @@ DownloadContext::DownloadContext():
DownloadContext::DownloadContext(size_t pieceLength,
uint64_t totalLength,
const std::string& path):
dir_(A2STR::DOT_C),
pieceLength_(pieceLength),
checksumVerified_(false),
knowsTotalLength_(true),
@ -259,11 +257,6 @@ void DownloadContext::setBasePath(const std::string& basePath)
basePath_ = basePath;
}
void DownloadContext::setDir(const std::string& dir)
{
dir_ = dir;
}
void DownloadContext::setSignature(const SharedHandle<Signature>& signature)
{
signature_ = signature;

View File

@ -59,8 +59,6 @@ class DownloadContext
private:
std::vector<SharedHandle<FileEntry> > fileEntries_;
std::string dir_;
std::vector<std::string> pieceHashes_;
size_t pieceLength_;
@ -161,10 +159,6 @@ public:
void setBasePath(const std::string& basePath);
const std::string& getDir() const { return dir_; }
void setDir(const std::string& dir);
const SharedHandle<Signature>& getSignature() const { return signature_; }
void setSignature(const SharedHandle<Signature>& signature);

View File

@ -367,7 +367,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
if(getFileEntry()->getPath().empty()) {
getFileEntry()->setPath
(util::createSafePath
(getDownloadContext()->getDir(),
(getOption()->get(PREF_DIR),
util::percentDecode(getRequest()->getFile())));
}
getRequestGroup()->preDownloadProcessing();

View File

@ -158,7 +158,7 @@ bool HttpRequestCommand::executeInternal() {
if(getFileEntry()->getPath().empty()) {
getFileEntry()->setPath
(util::createSafePath
(getDownloadContext()->getDir(),
(getOption()->get(PREF_DIR),
util::percentDecode(getRequest()->getFile())));
}
File ctrlfile(getFileEntry()->getPath()+

View File

@ -207,7 +207,7 @@ bool HttpResponseCommand::executeInternal()
if(getFileEntry()->getPath().empty()) {
getFileEntry()->setPath
(util::createSafePath
(getDownloadContext()->getDir(), httpResponse->determinFilename()));
(getOption()->get(PREF_DIR), httpResponse->determinFilename()));
}
getFileEntry()->setContentType(httpResponse->getContentType());
getRequestGroup()->preDownloadProcessing();

View File

@ -309,7 +309,6 @@ Metalink2RequestGroup::createRequestGroup
dctx->setFileEntries(fileEntries.begin(), fileEntries.end());
rg->setNumConcurrentCommand(option->getAsInt(PREF_METALINK_SERVERS));
}
dctx->setDir(option->get(PREF_DIR));
rg->setDownloadContext(dctx);
// remove "metalink" from Accept Type list to avoid loop in
// tranparent metalink

View File

@ -1189,7 +1189,7 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
#endif // ENABLE_BITTORRENT
res->pieceLength = downloadContext_->getPieceLength();
res->numPieces = downloadContext_->getNumPieces();
res->dir = downloadContext_->getDir();
res->dir = option_->get(PREF_DIR);
return res;
}

View File

@ -238,7 +238,6 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
(new DownloadContext(getOption()->getAsInt(PREF_SEGMENT_SIZE),
0,
TRACKER_ANNOUNCE_FILE));
dctx->setDir(A2STR::NIL);
dctx->getFileEntries().front()->setUris(uris);
rg->setDownloadContext(dctx);
SharedHandle<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory());

View File

@ -611,7 +611,7 @@ void gatherProgressCommon
entryDict->put(KEY_FILES, files);
}
if(requested_key(keys, KEY_DIR)) {
entryDict->put(KEY_DIR, dctx->getDir());
entryDict->put(KEY_DIR, group->getOption()->get(PREF_DIR));
}
}

View File

@ -193,6 +193,7 @@ void extractFileEntries
(const SharedHandle<DownloadContext>& ctx,
const SharedHandle<TorrentAttribute>& torrent,
const Dict* infoDict,
const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName,
const std::vector<std::string>& urlList)
@ -284,7 +285,8 @@ void extractFileEntries
std::vector<std::string> uris;
createUri(urlList.begin(), urlList.end(),std::back_inserter(uris),pePath);
SharedHandle<FileEntry> fileEntry
(new FileEntry(util::applyDir(ctx->getDir(),util::escapePath(utf8Path)),
(new FileEntry(util::applyDir(option->get(PREF_DIR),
util::escapePath(utf8Path)),
fileLengthData->i(), offset, uris));
fileEntry->setOriginalName(path);
fileEntries.push_back(fileEntry);
@ -312,14 +314,15 @@ void extractFileEntries
}
}
SharedHandle<FileEntry> fileEntry
(new FileEntry(util::applyDir(ctx->getDir(), util::escapePath(utf8Name)),
(new FileEntry(util::applyDir(option->get(PREF_DIR),
util::escapePath(utf8Name)),
totalLength, 0, uris));
fileEntry->setOriginalName(name);
fileEntries.push_back(fileEntry);
}
ctx->setFileEntries(fileEntries.begin(), fileEntries.end());
if(torrent->mode == MULTI) {
ctx->setBasePath(util::applyDir(ctx->getDir(), utf8Name));
ctx->setBasePath(util::applyDir(option->get(PREF_DIR), utf8Name));
}
}
} // namespace
@ -392,6 +395,7 @@ namespace {
void processRootDictionary
(const SharedHandle<DownloadContext>& ctx,
const SharedHandle<ValueBase>& root,
const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName,
const std::vector<std::string>& uris)
@ -466,7 +470,7 @@ void processRootDictionary
// retrieve file entries
extractFileEntries
(ctx, torrent, infoDict, defaultName, overrideName, urlList);
(ctx, torrent, infoDict, option, defaultName, overrideName, urlList);
if((ctx->getTotalLength()+pieceLength-1)/pieceLength != numPieces) {
throw DL_ABORT_EX2("Too few/many piece hash.",
error_code::BITTORRENT_PARSE_ERROR);
@ -500,10 +504,12 @@ void processRootDictionary
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decodeFromFile(torrentFile),
option,
torrentFile,
overrideName,
std::vector<std::string>());
@ -511,11 +517,13 @@ void load(const std::string& torrentFile,
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decodeFromFile(torrentFile),
option,
torrentFile,
overrideName,
uris);
@ -524,11 +532,13 @@ void load(const std::string& torrentFile,
void loadFromMemory(const unsigned char* content,
size_t length,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decode(content, length),
option,
defaultName,
overrideName,
std::vector<std::string>());
@ -537,12 +547,14 @@ void loadFromMemory(const unsigned char* content,
void loadFromMemory(const unsigned char* content,
size_t length,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode2::decode(content, length),
option,
defaultName,
overrideName,
uris);
@ -550,18 +562,21 @@ void loadFromMemory(const unsigned char* content,
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary
(ctx,
bencode2::decode(context),
option,
defaultName, overrideName,
std::vector<std::string>());
}
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
@ -569,6 +584,7 @@ void loadFromMemory(const std::string& context,
processRootDictionary
(ctx,
bencode2::decode(context),
option,
defaultName, overrideName,
uris);
}

View File

@ -66,31 +66,37 @@ extern const std::string BITTORRENT;
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::string& overrideName = "");
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
const SharedHandle<Option>& option,
const std::vector<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");

View File

@ -222,7 +222,6 @@ SharedHandle<RequestGroup> createRequestGroup
0,
useOutOption&&!option->blank(PREF_OUT)?
util::applyDir(option->get(PREF_DIR), option->get(PREF_OUT)):A2STR::NIL));
dctx->setDir(option->get(PREF_DIR));
dctx->getFirstFileEntry()->setUris(uris);
dctx->getFirstFileEntry()->setMaxConnectionPerServer
(option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER));
@ -259,14 +258,13 @@ createBtRequestGroup(const std::string& torrentFilePath,
{
SharedHandle<RequestGroup> rg(new RequestGroup(option));
SharedHandle<DownloadContext> dctx(new DownloadContext());
dctx->setDir(option->get(PREF_DIR));
if(torrentData.empty()) {
bittorrent::load(torrentFilePath, dctx, auxUris);// may throw exception
// may throw exception
bittorrent::load(torrentFilePath, dctx, option, auxUris);
rg->setMetadataInfo(createMetadataInfo(torrentFilePath));
} else {
bittorrent::loadFromMemory(torrentData, dctx, auxUris, "default"); // may
// throw
// exception
// may throw exception
bittorrent::loadFromMemory(torrentData, dctx, option, auxUris, "default");
rg->setMetadataInfo(createMetadataInfoDataOnly());
}
if(adjustAnnounceUri) {
@ -279,7 +277,7 @@ createBtRequestGroup(const std::string& torrentFilePath,
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin(),
eoi = indexPathMap.end(); i != eoi; ++i) {
dctx->setFilePathWithIndex
((*i).first, util::applyDir(dctx->getDir(), (*i).second));
((*i).first, util::applyDir(option->get(PREF_DIR), (*i).second));
}
rg->setDownloadContext(dctx);
// Remove "metalink" from Accept Type list to avoid server from
@ -299,7 +297,6 @@ createBtMagnetRequestGroup(const std::string& magnetLink,
SharedHandle<DownloadContext> dctx
(new DownloadContext(METADATA_PIECE_SIZE, 0,
A2STR::NIL));
dctx->setDir(A2STR::NIL);
// We only know info hash. Total Length is unknown at this moment.
dctx->markTotalLengthIsUnknown();
rg->setFileAllocationEnabled(false);

View File

@ -113,8 +113,9 @@ std::ostream& getSummaryOut(const SharedHandle<Option>& op)
namespace {
void showTorrentFile(const std::string& uri)
{
SharedHandle<Option> op(new Option());
SharedHandle<DownloadContext> dctx(new DownloadContext());
bittorrent::load(uri, dctx);
bittorrent::load(uri, dctx, op);
bittorrent::print(std::cout, dctx);
}
} // namespace

View File

@ -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"

View File

@ -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();

View File

@ -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_);

View File

@ -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))
};

View File

@ -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));

View File

@ -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

View File

@ -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());
}

View File

@ -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());
}
}

View File

@ -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_));

View File

@ -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"),