summaryrefslogtreecommitdiff
path: root/test/MultiFileAllocationIteratorTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-03-07 03:10:53 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-03-07 03:10:53 +0000
commitf44554a6346605468f5fbc221746e32735db44ca (patch)
tree308ddd0b6173cc1aa72c291fa64fe6a204ef1de7 /test/MultiFileAllocationIteratorTest.cc
parent4aae48c9b2e9b1280f724df50ac71dd64fe1c0df (diff)
2009-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --index-out option to specify each file path for torrent. Here index shown in --show-files option is used to specify which file path should be altered. For example, to change the file path with index=2, use --index-out=2=aria2.tar.bz2. You can use this option multiple times: --index-out=1=aria2.tar.bz2 --index-out=2=aria2-opt.tar.bz2. The short hand form -O is also available. This option can be specified in -i list. * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/OptionHandlerFactory.cc * src/OptionHandlerImpl.h * src/Util.cc * src/Util.h * src/download_helper.cc * src/prefs.cc * src/prefs.h * src/usage_text.h * test/DefaultBtContextTest.cc * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/UtilTest.cc
Diffstat (limited to 'test/MultiFileAllocationIteratorTest.cc')
-rw-r--r--test/MultiFileAllocationIteratorTest.cc91
1 files changed, 45 insertions, 46 deletions
diff --git a/test/MultiFileAllocationIteratorTest.cc b/test/MultiFileAllocationIteratorTest.cc
index 1ca3dfb0..90c7e74c 100644
--- a/test/MultiFileAllocationIteratorTest.cc
+++ b/test/MultiFileAllocationIteratorTest.cc
@@ -1,4 +1,10 @@
#include "MultiFileAllocationIterator.h"
+
+#include <algorithm>
+#include <iostream>
+
+#include <cppunit/extensions/HelperMacros.h>
+
#include "File.h"
#include "MultiDiskAdaptor.h"
#include "FileEntry.h"
@@ -6,9 +12,6 @@
#include "array_fun.h"
#include "TestUtil.h"
#include "DiskWriter.h"
-#include <algorithm>
-#include <iostream>
-#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@@ -53,20 +56,17 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries()
fs[8]->setRequested(false); // file9
fs[9]->setRequested(false); // fileA
- std::string topDir = "top";
std::string storeDir = "/tmp/aria2_MultiFileAllocationIteratorTest"
"_testMakeDiskWriterEntries";
- std::string prefix = storeDir+"/"+topDir;
// create empty file4
- createFile(prefix+std::string("/file4"), 0);
+ createFile(storeDir+std::string("/file4"), 0);
SharedHandle<MultiDiskAdaptor> diskAdaptor(new MultiDiskAdaptor());
diskAdaptor->setFileEntries
(std::deque<SharedHandle<FileEntry> >(&fs[0], &fs[arrayLength(fs)]));
diskAdaptor->setPieceLength(1024);
diskAdaptor->setStoreDir(storeDir);
- diskAdaptor->setTopDir(topDir);
diskAdaptor->openFile();
SharedHandle<MultiFileAllocationIterator> itr
@@ -78,67 +78,67 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries()
CPPUNIT_ASSERT_EQUAL((size_t)11, entries.size());
// file1
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file1"),
- entries[0]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file1"),
+ entries[0]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[0]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[0]->getDiskWriter().isNull());
// file2
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file2"),
- entries[1]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file2"),
+ entries[1]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[1]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[1]->getDiskWriter().isNull());
// file3
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file3"),
- entries[2]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file3"),
+ entries[2]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[2]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[2]->getDiskWriter().isNull());
// file4, diskWriter is not null, because file exists.
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file4"),
- entries[3]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file4"),
+ entries[3]->getFilePath(storeDir));
CPPUNIT_ASSERT(!entries[3]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[3]->getDiskWriter().isNull());
// file5
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file5"),
- entries[4]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file5"),
+ entries[4]->getFilePath(storeDir));
CPPUNIT_ASSERT(!entries[4]->needsFileAllocation());
CPPUNIT_ASSERT(entries[4]->getDiskWriter().isNull());
// file6
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file6"),
- entries[5]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file6"),
+ entries[5]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[5]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[5]->getDiskWriter().isNull());
// file7
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file7"),
- entries[6]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file7"),
+ entries[6]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[6]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[6]->getDiskWriter().isNull());
// file8
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file8"),
- entries[7]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file8"),
+ entries[7]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[7]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[7]->getDiskWriter().isNull());
// file9
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/file9"),
- entries[8]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file9"),
+ entries[8]->getFilePath(storeDir));
CPPUNIT_ASSERT(!entries[8]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[8]->getDiskWriter().isNull());
// fileA
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/fileA"),
- entries[9]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/fileA"),
+ entries[9]->getFilePath(storeDir));
CPPUNIT_ASSERT(!entries[9]->needsFileAllocation());
CPPUNIT_ASSERT(entries[9]->getDiskWriter().isNull());
// fileB
- CPPUNIT_ASSERT_EQUAL(prefix+std::string("/fileB"),
- entries[10]->getFilePath(prefix));
+ CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/fileB"),
+ entries[10]->getFilePath(storeDir));
CPPUNIT_ASSERT(entries[10]->needsFileAllocation());
CPPUNIT_ASSERT(!entries[10]->getDiskWriter().isNull());
}
void MultiFileAllocationIteratorTest::testAllocate()
{
- std::string dir = "/tmp";
- std::string topDir = "aria2_MultiFileAllocationIteratorTest_testAllocate";
- std::string prefix = dir+"/"+topDir;
+ std::string storeDir =
+ "/tmp/aria2_MultiFileAllocationIteratorTest_testAllocate";
+
std::string fname1 = "file1";
std::string fname2 = "file2";
std::string fname3 = "file3";
@@ -154,8 +154,7 @@ void MultiFileAllocationIteratorTest::testAllocate()
try {
SharedHandle<MultiDiskAdaptor> diskAdaptor(new MultiDiskAdaptor());
- diskAdaptor->setStoreDir(dir);
- diskAdaptor->setTopDir(topDir);
+ diskAdaptor->setStoreDir(storeDir);
diskAdaptor->setPieceLength(1);
int64_t offset = 0;
@@ -199,12 +198,12 @@ void MultiFileAllocationIteratorTest::testAllocate()
diskAdaptor->setFileEntries(fs);
- File(prefix+"/"+fname1).remove();
- File(prefix+"/"+fname2).remove();
- File(prefix+"/"+fname3).remove();
- File(prefix+"/"+fname4).remove();
- File(prefix+"/"+fname5).remove();
- File(prefix+"/"+fname6).remove();
+ File(storeDir+"/"+fname1).remove();
+ File(storeDir+"/"+fname2).remove();
+ File(storeDir+"/"+fname3).remove();
+ File(storeDir+"/"+fname4).remove();
+ File(storeDir+"/"+fname5).remove();
+ File(storeDir+"/"+fname6).remove();
// we have to open file first.
diskAdaptor->initAndOpenFile();
@@ -214,13 +213,13 @@ void MultiFileAllocationIteratorTest::testAllocate()
while(!itr->finished()) {
itr->allocateChunk();
}
- CPPUNIT_ASSERT_EQUAL((uint64_t)length1, File(prefix+"/"+fname1).size());
- CPPUNIT_ASSERT_EQUAL((uint64_t)length2, File(prefix+"/"+fname2).size());
- CPPUNIT_ASSERT_EQUAL((uint64_t)length3, File(prefix+"/"+fname3).size());
- CPPUNIT_ASSERT(!File(prefix+"/"+fname4).isFile());
+ CPPUNIT_ASSERT_EQUAL((uint64_t)length1, File(storeDir+"/"+fname1).size());
+ CPPUNIT_ASSERT_EQUAL((uint64_t)length2, File(storeDir+"/"+fname2).size());
+ CPPUNIT_ASSERT_EQUAL((uint64_t)length3, File(storeDir+"/"+fname3).size());
+ CPPUNIT_ASSERT(!File(storeDir+"/"+fname4).isFile());
- CPPUNIT_ASSERT_EQUAL((uint64_t)length5, File(prefix+"/"+fname5).size());
- CPPUNIT_ASSERT(!File(prefix+"/"+fname6).isFile());
+ CPPUNIT_ASSERT_EQUAL((uint64_t)length5, File(storeDir+"/"+fname5).size());
+ CPPUNIT_ASSERT(!File(storeDir+"/"+fname6).isFile());
} catch(Exception& e) {
CPPUNIT_FAIL(e.stackTrace());