From 7bcf0f48b21c1f75ba2b658805ca85912cb04b5b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 14 Nov 2008 12:32:54 +0000 Subject: [PATCH] 2008-11-14 Tatsuhiro Tsujikawa Instead of creating special filename in createDownloadResult() if inMemoryDownload() is true, now it is done in getFilePath(). * src/RequestGroup.cc * test/RequestGroupTest.cc --- ChangeLog | 7 +++++++ src/RequestGroup.cc | 15 ++++----------- test/RequestGroupTest.cc | 26 +++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9aaee194..86b41a95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-11-14 Tatsuhiro Tsujikawa + + Instead of creating special filename in createDownloadResult() if + inMemoryDownload() is true, now it is done in getFilePath(). + * src/RequestGroup.cc + * test/RequestGroupTest.cc + 2008-11-14 Tatsuhiro Tsujikawa Print "[MEMORY]" and filename if a file is not saved in disk and just diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 26622274..49307046 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -556,8 +556,9 @@ void RequestGroup::createNextCommand(std::deque& commands, std::string RequestGroup::getFilePath() const { assert(!_downloadContext.isNull()); - if(_downloadContext.isNull()) { - return A2STR::NIL; + if(inMemoryDownload()) { + static const std::string DIR_MEMORY("[MEMORY]"); + return DIR_MEMORY+File(_downloadContext->getActualBasePath()).getBasename(); } else { return _downloadContext->getActualBasePath(); } @@ -893,18 +894,10 @@ DownloadResultHandle RequestGroup::createDownloadResult() const _segmentMan->calculateSessionDownloadLength(); } - std::string path; - if(inMemoryDownload()) { - static const std::string DIR_MEMORY("[MEMORY]"); - path = DIR_MEMORY+File(getFilePath()).getBasename(); - } else { - path = getFilePath(); - } - return SharedHandle (new DownloadResult(_gid, - path, + getFilePath(), getTotalLength(), uris.empty() ? A2STR::NIL:uris.front(), uris.size(), diff --git a/test/RequestGroupTest.cc b/test/RequestGroupTest.cc index 8b6893ed..da14ef4a 100644 --- a/test/RequestGroupTest.cc +++ b/test/RequestGroupTest.cc @@ -1,7 +1,11 @@ #include "RequestGroup.h" + +#include + #include "ServerHost.h" #include "Option.h" -#include +#include "SingleFileDownloadContext.h" +#include "FileEntry.h" namespace aria2 { @@ -10,6 +14,7 @@ class RequestGroupTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RequestGroupTest); CPPUNIT_TEST(testRegisterSearchRemove); CPPUNIT_TEST(testRemoveURIWhoseHostnameIs); + CPPUNIT_TEST(testGetFilePath); CPPUNIT_TEST_SUITE_END(); private: @@ -18,6 +23,7 @@ public: void testRegisterSearchRemove(); void testRemoveURIWhoseHostnameIs(); + void testGetFilePath(); }; @@ -69,4 +75,22 @@ void RequestGroupTest::testRemoveURIWhoseHostnameIs() rg.getRemainingUris()[0]); } +void RequestGroupTest::testGetFilePath() +{ + SharedHandle ctx + (new SingleFileDownloadContext(1024, 1024, "myfile")); + ctx->setDir("/tmp"); + Option op; + std::deque uris; + + RequestGroup group(&op, uris); + group.setDownloadContext(ctx); + + CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), group.getFilePath()); + + group.markInMemoryDownload(); + + CPPUNIT_ASSERT_EQUAL(std::string("[MEMORY]myfile"), group.getFilePath()); +} + } // namespace aria2