aria2/test/SingleFileDownloadContextTest.cc
Tatsuhiro Tsujikawa e2704bd823 2009-03-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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
2009-03-09 15:10:26 +00:00

58 lines
1.7 KiB
C++

#include "SingleFileDownloadContext.h"
#include "FileEntry.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
class SingleFileDownloadContextTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(SingleFileDownloadContextTest);
CPPUNIT_TEST(testGetPieceHash);
CPPUNIT_TEST(testGetNumPieces);
CPPUNIT_TEST(testGetActualBasePath);
CPPUNIT_TEST_SUITE_END();
public:
SingleFileDownloadContextTest() {}
void setUp() {}
void testGetPieceHash();
void testGetNumPieces();
void testGetActualBasePath();
};
CPPUNIT_TEST_SUITE_REGISTRATION( SingleFileDownloadContextTest );
void SingleFileDownloadContextTest::testGetPieceHash()
{
SingleFileDownloadContext ctx(0, 0, "");
std::deque<std::string> pieceHashes;
pieceHashes.push_back("0000");
pieceHashes.push_back("0001");
pieceHashes.push_back("0002");
ctx.setPieceHashes(pieceHashes);
CPPUNIT_ASSERT_EQUAL(std::string("0000"), ctx.getPieceHash(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getPieceHash(3));
}
void SingleFileDownloadContextTest::testGetNumPieces()
{
SingleFileDownloadContext ctx(345, 9889, "");
CPPUNIT_ASSERT_EQUAL((size_t)29, ctx.getNumPieces());
}
void SingleFileDownloadContextTest::testGetActualBasePath()
{
SingleFileDownloadContext ctx(0, 0, "");
CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getActualBasePath());
ctx.setFilename("aria2.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), ctx.getActualBasePath());
ctx.setUFilename("/t/aria.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("/t/aria.tar.bz2"), ctx.getActualBasePath());
ctx.setDir("/tmp");
// See dir doesn't effect getActualBasePath().
CPPUNIT_ASSERT_EQUAL(std::string("/t/aria.tar.bz2"), ctx.getActualBasePath());
}
} // namespace aria2