aria2/test/RequestGroupTest.cc
Tatsuhiro Tsujikawa cece2bc896 2009-06-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed ServerHost. Same functionality is implemented using
	FileEntry's in-flight Request objects.
	* src/AbstractCommand.cc
	* src/BtDependency.cc
	* src/CreateRequestCommand.cc
	* src/FileEntry.cc
	* src/FileEntry.h
	* src/FtpNegotiationCommand.cc
	* src/HttpResponseCommand.cc
	* src/Makefile.am
	* src/Metalink2RequestGroup.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/ServerHost.cc: Removed
	* src/ServerHost.h: Removed
	* test/BtDependencyTest.cc
	* test/FileEntryTest.cc
	* test/RequestGroupTest.cc
2009-06-29 16:43:41 +00:00

92 lines
2.6 KiB
C++

#include "RequestGroup.h"
#include <cppunit/extensions/HelperMacros.h>
#include "Option.h"
#include "DownloadContext.h"
#include "FileEntry.h"
#include "PieceStorage.h"
#include "DownloadResult.h"
namespace aria2 {
class RequestGroupTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RequestGroupTest);
CPPUNIT_TEST(testGetFirstFilePath);
CPPUNIT_TEST(testCreateDownloadResult);
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<Option> _option;
public:
void setUp()
{
_option.reset(new Option());
}
void testGetFirstFilePath();
void testCreateDownloadResult();
};
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest );
void RequestGroupTest::testGetFirstFilePath()
{
SharedHandle<DownloadContext> ctx
(new DownloadContext(1024, 1024, "/tmp/myfile"));
RequestGroup group(_option);
group.setDownloadContext(ctx);
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), group.getFirstFilePath());
group.markInMemoryDownload();
CPPUNIT_ASSERT_EQUAL(std::string("[MEMORY]myfile"), group.getFirstFilePath());
}
void RequestGroupTest::testCreateDownloadResult()
{
SharedHandle<DownloadContext> ctx
(new DownloadContext(1024, 1024*1024, "/tmp/myfile"));
RequestGroup group(_option);
group.setDownloadContext(ctx);
group.initPieceStorage();
{
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"),
result->fileEntries[0]->getPath());
CPPUNIT_ASSERT_EQUAL((off_t)1024*1024,
result->fileEntries.back()->getLastOffset());
CPPUNIT_ASSERT_EQUAL((uint64_t)0, result->sessionDownloadLength);
CPPUNIT_ASSERT_EQUAL((int64_t)0, result->sessionTime);
// result is UNKNOWN_ERROR if download has not completed and no specific
// error has been reported
CPPUNIT_ASSERT_EQUAL(downloadresultcode::UNKNOWN_ERROR, result->result);
// if haltReason is set to RequestGroup::USER_REQUEST, download
// result becomes IN_PROGRESS
group.setHaltRequested(true, RequestGroup::USER_REQUEST);
result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(downloadresultcode::IN_PROGRESS, result->result);
}
{
group.setLastUriResult
("http://second/file",downloadresultcode::RESOURCE_NOT_FOUND);
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(downloadresultcode::RESOURCE_NOT_FOUND, result->result);
}
{
group.getPieceStorage()->markAllPiecesDone();
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(downloadresultcode::FINISHED, result->result);
}
}
} // namespace aria2