2007-10-11 16:58:24 +00:00
|
|
|
#include "SingleFileDownloadContext.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
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, "");
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> pieceHashes;
|
2007-10-11 16:58:24 +00:00
|
|
|
pieceHashes.push_back("0000");
|
|
|
|
pieceHashes.push_back("0001");
|
|
|
|
pieceHashes.push_back("0002");
|
|
|
|
ctx.setPieceHashes(pieceHashes);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0000"), ctx.getPieceHash(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getPieceHash(3));
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SingleFileDownloadContextTest::testGetNumPieces()
|
|
|
|
{
|
|
|
|
SingleFileDownloadContext ctx(345, 9889, "");
|
2008-03-08 10:33:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)29, ctx.getNumPieces());
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SingleFileDownloadContextTest::testGetActualBasePath()
|
|
|
|
{
|
|
|
|
SingleFileDownloadContext ctx(0, 0, "");
|
2009-03-09 15:10:26 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getActualBasePath());
|
2007-10-11 16:58:24 +00:00
|
|
|
ctx.setFilename("aria2.tar.bz2");
|
2009-03-09 15:10:26 +00:00
|
|
|
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());
|
2007-10-11 16:58:24 +00:00
|
|
|
ctx.setDir("/tmp");
|
2009-03-09 15:10:26 +00:00
|
|
|
// See dir doesn't effect getActualBasePath().
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/t/aria.tar.bz2"), ctx.getActualBasePath());
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|