From e2704bd823e44000b81e42fc05b58b8d0bc9ddda Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 9 Mar 2009 15:10:26 +0000 Subject: 2009-03-10 Tatsuhiro Tsujikawa FileEntry::getPath() contains store(top level) directory to simplify path handling operation. In the previous implementation, store directory is concatenated to FileEntry::getPath() in DownloadContext. * src/BtDependency.cc * src/BtPostDownloadHandler.cc * src/CopyDiskAdaptor.cc * src/DefaultBtContext.cc * src/DirectDiskAdaptor.cc * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpResponse.cc * src/HttpResponseCommand.cc * src/Metalink2RequestGroup.cc * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/RequestGroup.cc * src/SingleFileDownloadContext.cc * src/SingleFileDownloadContext.h * src/download_helper.cc * test/BtDependencyTest.cc * test/CopyDiskAdaptorTest.cc * test/DefaultBtContextTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DirectDiskAdaptorTest.cc * test/DownloadHelperTest.cc * test/FileEntryTest.cc * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/RequestGroupTest.cc * test/SingleFileDownloadContextTest.cc --- test/MultiFileAllocationIteratorTest.cc | 86 ++++++++++++++++----------------- 1 file changed, 41 insertions(+), 45 deletions(-) (limited to 'test/MultiFileAllocationIteratorTest.cc') diff --git a/test/MultiFileAllocationIteratorTest.cc b/test/MultiFileAllocationIteratorTest.cc index 90c7e74c..822d838a 100644 --- a/test/MultiFileAllocationIteratorTest.cc +++ b/test/MultiFileAllocationIteratorTest.cc @@ -35,18 +35,21 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MultiFileAllocationIteratorTest ); void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries() { + std::string storeDir = "/tmp/aria2_MultiFileAllocationIteratorTest" + "_testMakeDiskWriterEntries"; + SharedHandle fs[] = { - SharedHandle(new FileEntry("file1", 1536, 0)), - SharedHandle(new FileEntry("file2", 2048, 1536)),// req no - SharedHandle(new FileEntry("file3", 1024, 3584)), - SharedHandle(new FileEntry("file4", 1024, 4608)),// req no - SharedHandle(new FileEntry("file5", 1024, 5632)),// req no - SharedHandle(new FileEntry("file6", 1024, 6656)),// req no - SharedHandle(new FileEntry("file7", 256, 7680)),// req no - SharedHandle(new FileEntry("file8", 255, 7936)), - SharedHandle(new FileEntry("file9", 1025, 8191)),// req no - SharedHandle(new FileEntry("fileA", 1024, 9216)),// req no - SharedHandle(new FileEntry("fileB", 1024, 10240)), + SharedHandle(new FileEntry(storeDir+"/file1", 1536, 0)), + SharedHandle(new FileEntry(storeDir+"/file2", 2048, 1536)),// req no + SharedHandle(new FileEntry(storeDir+"/file3", 1024, 3584)), + SharedHandle(new FileEntry(storeDir+"/file4", 1024, 4608)),// req no + SharedHandle(new FileEntry(storeDir+"/file5", 1024, 5632)),// req no + SharedHandle(new FileEntry(storeDir+"/file6", 1024, 6656)),// req no + SharedHandle(new FileEntry(storeDir+"/file7", 256, 7680)),// req no + SharedHandle(new FileEntry(storeDir+"/file8", 255, 7936)), + SharedHandle(new FileEntry(storeDir+"/file9", 1025, 8191)),// req no + SharedHandle(new FileEntry(storeDir+"/fileA", 1024, 9216)),// req no + SharedHandle(new FileEntry(storeDir+"/fileB", 1024, 10240)), }; fs[1]->setRequested(false); // file2 fs[3]->setRequested(false); // file4 @@ -56,8 +59,6 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries() fs[8]->setRequested(false); // file9 fs[9]->setRequested(false); // fileA - std::string storeDir = "/tmp/aria2_MultiFileAllocationIteratorTest" - "_testMakeDiskWriterEntries"; // create empty file4 createFile(storeDir+std::string("/file4"), 0); @@ -79,57 +80,57 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries() // file1 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file1"), - entries[0]->getFilePath(storeDir)); + entries[0]->getFilePath()); CPPUNIT_ASSERT(entries[0]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[0]->getDiskWriter().isNull()); // file2 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file2"), - entries[1]->getFilePath(storeDir)); + entries[1]->getFilePath()); CPPUNIT_ASSERT(entries[1]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[1]->getDiskWriter().isNull()); // file3 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file3"), - entries[2]->getFilePath(storeDir)); + entries[2]->getFilePath()); CPPUNIT_ASSERT(entries[2]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[2]->getDiskWriter().isNull()); // file4, diskWriter is not null, because file exists. CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file4"), - entries[3]->getFilePath(storeDir)); + entries[3]->getFilePath()); CPPUNIT_ASSERT(!entries[3]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[3]->getDiskWriter().isNull()); // file5 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file5"), - entries[4]->getFilePath(storeDir)); + entries[4]->getFilePath()); CPPUNIT_ASSERT(!entries[4]->needsFileAllocation()); CPPUNIT_ASSERT(entries[4]->getDiskWriter().isNull()); // file6 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file6"), - entries[5]->getFilePath(storeDir)); + entries[5]->getFilePath()); CPPUNIT_ASSERT(entries[5]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[5]->getDiskWriter().isNull()); // file7 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file7"), - entries[6]->getFilePath(storeDir)); + entries[6]->getFilePath()); CPPUNIT_ASSERT(entries[6]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[6]->getDiskWriter().isNull()); // file8 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file8"), - entries[7]->getFilePath(storeDir)); + entries[7]->getFilePath()); CPPUNIT_ASSERT(entries[7]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[7]->getDiskWriter().isNull()); // file9 CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file9"), - entries[8]->getFilePath(storeDir)); + entries[8]->getFilePath()); CPPUNIT_ASSERT(!entries[8]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[8]->getDiskWriter().isNull()); // fileA CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/fileA"), - entries[9]->getFilePath(storeDir)); + entries[9]->getFilePath()); CPPUNIT_ASSERT(!entries[9]->needsFileAllocation()); CPPUNIT_ASSERT(entries[9]->getDiskWriter().isNull()); // fileB CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/fileB"), - entries[10]->getFilePath(storeDir)); + entries[10]->getFilePath()); CPPUNIT_ASSERT(entries[10]->needsFileAllocation()); CPPUNIT_ASSERT(!entries[10]->getDiskWriter().isNull()); } @@ -158,32 +159,32 @@ void MultiFileAllocationIteratorTest::testAllocate() diskAdaptor->setPieceLength(1); int64_t offset = 0; - SharedHandle fileEntry1(new FileEntry(fname1, + SharedHandle fileEntry1(new FileEntry(storeDir+"/"+fname1, length1, offset)); offset += length1; - SharedHandle fileEntry2(new FileEntry(fname2, + SharedHandle fileEntry2(new FileEntry(storeDir+"/"+fname2, length2, offset)); offset += length2; - SharedHandle fileEntry3(new FileEntry(fname3, + SharedHandle fileEntry3(new FileEntry(storeDir+"/"+fname3, length3, offset)); offset += length3; - SharedHandle fileEntry4(new FileEntry(fname4, + SharedHandle fileEntry4(new FileEntry(storeDir+"/"+fname4, length4, offset)); fileEntry4->setRequested(false); offset += length4; - SharedHandle fileEntry5(new FileEntry(fname5, + SharedHandle fileEntry5(new FileEntry(storeDir+"/"+fname5, length5, offset)); offset += length5; - SharedHandle fileEntry6(new FileEntry(fname6, + SharedHandle fileEntry6(new FileEntry(storeDir+"/"+fname6, length6, offset)); fileEntry6->setRequested(false); @@ -197,13 +198,10 @@ void MultiFileAllocationIteratorTest::testAllocate() fs.push_back(fileEntry6); diskAdaptor->setFileEntries(fs); - - File(storeDir+"/"+fname1).remove(); - File(storeDir+"/"+fname2).remove(); - File(storeDir+"/"+fname3).remove(); - File(storeDir+"/"+fname4).remove(); - File(storeDir+"/"+fname5).remove(); - File(storeDir+"/"+fname6).remove(); + for(std::deque >::const_iterator i = fs.begin(); + i != fs.end(); ++i) { + File((*i)->getPath()).remove(); + } // we have to open file first. diskAdaptor->initAndOpenFile(); @@ -213,14 +211,12 @@ void MultiFileAllocationIteratorTest::testAllocate() while(!itr->finished()) { itr->allocateChunk(); } - 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(storeDir+"/"+fname5).size()); - CPPUNIT_ASSERT(!File(storeDir+"/"+fname6).isFile()); - + CPPUNIT_ASSERT_EQUAL((uint64_t)length1, File(fileEntry1->getPath()).size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length2, File(fileEntry2->getPath()).size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length3, File(fileEntry3->getPath()).size()); + CPPUNIT_ASSERT(!File(fileEntry4->getPath()).isFile()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length5, File(fileEntry5->getPath()).size()); + CPPUNIT_ASSERT(!File(fileEntry6->getPath()).isFile()); } catch(Exception& e) { CPPUNIT_FAIL(e.stackTrace()); } -- cgit