2007-08-28 15:48:05 +00:00
|
|
|
#include "RequestGroup.h"
|
2008-11-14 12:32:54 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2007-12-12 13:53:33 +00:00
|
|
|
#include "Option.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2008-11-14 12:32:54 +00:00
|
|
|
#include "FileEntry.h"
|
2009-01-12 12:27:34 +00:00
|
|
|
#include "PieceStorage.h"
|
2009-06-29 08:42:58 +00:00
|
|
|
#include "DownloadResult.h"
|
2007-08-28 15:48:05 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-08-28 15:48:05 +00:00
|
|
|
|
|
|
|
class RequestGroupTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(RequestGroupTest);
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_TEST(testGetFirstFilePath);
|
2009-01-12 12:27:34 +00:00
|
|
|
CPPUNIT_TEST(testCreateDownloadResult);
|
2007-08-28 15:48:05 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Option> option_;
|
2007-08-28 15:48:05 +00:00
|
|
|
public:
|
2009-05-08 16:41:21 +00:00
|
|
|
void setUp()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
option_.reset(new Option());
|
2009-05-08 16:41:21 +00:00
|
|
|
}
|
2007-12-12 13:53:33 +00:00
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
void testGetFirstFilePath();
|
2009-01-12 12:27:34 +00:00
|
|
|
void testCreateDownloadResult();
|
2007-08-28 15:48:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest );
|
2007-12-12 13:53:33 +00:00
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
void RequestGroupTest::testGetFirstFilePath()
|
2008-11-14 12:32:54 +00:00
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> ctx
|
2009-06-28 10:37:15 +00:00
|
|
|
(new DownloadContext(1024, 1024, "/tmp/myfile"));
|
2008-11-14 12:32:54 +00:00
|
|
|
|
2012-12-16 07:00:18 +00:00
|
|
|
RequestGroup group(GroupId::create(), option_);
|
2008-11-14 12:32:54 +00:00
|
|
|
group.setDownloadContext(ctx);
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), group.getFirstFilePath());
|
2008-11-14 12:32:54 +00:00
|
|
|
|
|
|
|
group.markInMemoryDownload();
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("[MEMORY]myfile"), group.getFirstFilePath());
|
2008-11-14 12:32:54 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 12:27:34 +00:00
|
|
|
void RequestGroupTest::testCreateDownloadResult()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> ctx
|
2009-06-28 10:37:15 +00:00
|
|
|
(new DownloadContext(1024, 1024*1024, "/tmp/myfile"));
|
2012-12-16 07:00:18 +00:00
|
|
|
RequestGroup group(GroupId::create(), option_);
|
2009-01-12 12:27:34 +00:00
|
|
|
group.setDownloadContext(ctx);
|
|
|
|
group.initPieceStorage();
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadResult> result = group.createDownloadResult();
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2009-05-12 15:16:11 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"),
|
2010-01-05 16:01:46 +00:00
|
|
|
result->fileEntries[0]->getPath());
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)1024*1024,
|
2010-01-05 16:01:46 +00:00
|
|
|
result->fileEntries.back()->getLastOffset());
|
2009-01-12 12:27:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)0, result->sessionDownloadLength);
|
2009-01-15 15:39:05 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)0, result->sessionTime);
|
2009-01-12 12:27:34 +00:00
|
|
|
// result is UNKNOWN_ERROR if download has not completed and no specific
|
|
|
|
// error has been reported
|
2010-11-28 07:52:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(error_code::UNKNOWN_ERROR, result->result);
|
2009-05-09 04:11:31 +00:00
|
|
|
|
|
|
|
// if haltReason is set to RequestGroup::USER_REQUEST, download
|
2011-05-29 11:59:45 +00:00
|
|
|
// result will become REMOVED.
|
2009-05-09 04:11:31 +00:00
|
|
|
group.setHaltRequested(true, RequestGroup::USER_REQUEST);
|
|
|
|
result = group.createDownloadResult();
|
2011-05-29 11:59:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(error_code::REMOVED, result->result);
|
|
|
|
// if haltReason is set to RequestGroup::SHUTDOWN_SIGNAL, download
|
|
|
|
// result will become IN_PROGRESS.
|
|
|
|
group.setHaltRequested(true, RequestGroup::SHUTDOWN_SIGNAL);
|
|
|
|
result = group.createDownloadResult();
|
2010-11-28 07:52:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(error_code::IN_PROGRESS, result->result);
|
2009-01-12 12:27:34 +00:00
|
|
|
}
|
|
|
|
{
|
2010-11-28 08:00:30 +00:00
|
|
|
group.setLastErrorCode(error_code::RESOURCE_NOT_FOUND);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadResult> result = group.createDownloadResult();
|
2009-01-12 12:27:34 +00:00
|
|
|
|
2010-11-28 07:52:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(error_code::RESOURCE_NOT_FOUND, result->result);
|
2009-01-12 12:27:34 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
group.getPieceStorage()->markAllPiecesDone();
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadResult> result = group.createDownloadResult();
|
2009-01-12 12:27:34 +00:00
|
|
|
|
2010-11-28 07:52:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(error_code::FINISHED, result->result);
|
2009-01-12 12:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|