Ver código fonte

2008-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Instead of creating special filename in createDownloadResult()
	if inMemoryDownload() is true, now it is done in getFilePath().
	* src/RequestGroup.cc
	* test/RequestGroupTest.cc
Tatsuhiro Tsujikawa 17 anos atrás
pai
commit
7bcf0f48b2
3 arquivos alterados com 36 adições e 12 exclusões
  1. 7 0
      ChangeLog
  2. 4 11
      src/RequestGroup.cc
  3. 25 1
      test/RequestGroupTest.cc

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-11-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	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  <t-tujikawa@users.sourceforge.net>
 
 	Print "[MEMORY]" and filename if a file is not saved in disk and just

+ 4 - 11
src/RequestGroup.cc

@@ -556,8 +556,9 @@ void RequestGroup::createNextCommand(std::deque<Command*>& 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<DownloadResult>
     (new DownloadResult(_gid,
-			path,
+			getFilePath(),
 			getTotalLength(),
 			uris.empty() ? A2STR::NIL:uris.front(),
 			uris.size(),

+ 25 - 1
test/RequestGroupTest.cc

@@ -1,7 +1,11 @@
 #include "RequestGroup.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
 #include "ServerHost.h"
 #include "Option.h"
-#include <cppunit/extensions/HelperMacros.h>
+#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<SingleFileDownloadContext> ctx
+    (new SingleFileDownloadContext(1024, 1024, "myfile"));
+  ctx->setDir("/tmp");
+  Option op;
+  std::deque<std::string> 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