2009-01-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Applied exit-status patch from Pascal Rigaux at Mandriva.  aria2
	now returns last error encountered in the HTTP/FTP downloads as
	a exit status value.  If all downloads finished successfully, 
	aria2 returns 0.  The error code is defined in
	src/DownloadResult.h.
	The error occurred in the download currently in progress is not
	reported as a last error.  If no error has encountered but there
	are in progress or waiting downloads, aria2 returns 7.
	
	* src/AbstractCommand.cc
	* src/DlAbortEx.h
	* src/DlRetryEx.h
	* src/DownloadCommand.cc
	* src/DownloadFailureException.h
	* src/DownloadResult.h
	* src/FtpNegotiationCommand.cc
	* src/HttpSkipResponseCommand.cc
	* src/Makefile.am
	* src/MultiUrlRequestInfo.cc
	* src/MultiUrlRequestInfo.h
	* src/RecoverableException.h
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/RequestGroupMan.h
	* src/URIResult.cc
	* src/URIResult.h
	* src/main.cc
	* src/option_processing.cc
	* test/RequestGroupTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2009-01-12 12:27:34 +00:00
parent 0a4f43d0ed
commit 8a9d921465
23 changed files with 386 additions and 88 deletions

View file

@ -6,6 +6,7 @@
#include "Option.h"
#include "SingleFileDownloadContext.h"
#include "FileEntry.h"
#include "PieceStorage.h"
namespace aria2 {
@ -15,6 +16,7 @@ class RequestGroupTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testRegisterSearchRemove);
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
CPPUNIT_TEST(testGetFilePath);
CPPUNIT_TEST(testCreateDownloadResult);
CPPUNIT_TEST_SUITE_END();
private:
@ -24,6 +26,7 @@ public:
void testRegisterSearchRemove();
void testRemoveURIWhoseHostnameIs();
void testGetFilePath();
void testCreateDownloadResult();
};
@ -93,4 +96,47 @@ void RequestGroupTest::testGetFilePath()
CPPUNIT_ASSERT_EQUAL(std::string("[MEMORY]myfile"), group.getFilePath());
}
void RequestGroupTest::testCreateDownloadResult()
{
SharedHandle<SingleFileDownloadContext> ctx
(new SingleFileDownloadContext(1024, 1024*1024, "myfile"));
ctx->setDir("/tmp");
Option op;
std::deque<std::string> uris;
uris.push_back("http://first/file");
uris.push_back("http://second/file");
RequestGroup group(&op, uris);
group.setDownloadContext(ctx);
group.initPieceStorage();
{
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), result->filePath);
CPPUNIT_ASSERT_EQUAL((uint64_t)1024*1024, result->totalLength);
CPPUNIT_ASSERT_EQUAL(std::string("http://first/file"), result->uri);
CPPUNIT_ASSERT_EQUAL((size_t)2, result->numUri);
CPPUNIT_ASSERT_EQUAL((uint64_t)0, result->sessionDownloadLength);
CPPUNIT_ASSERT_EQUAL((time_t)0, result->sessionTime);
// result is UNKNOWN_ERROR if download has not completed and no specific
// error has been reported
CPPUNIT_ASSERT_EQUAL(DownloadResult::UNKNOWN_ERROR, result->result);
}
{
group.addURIResult("http://first/file", DownloadResult::TIME_OUT);
group.addURIResult("http://second/file",DownloadResult::RESOURCE_NOT_FOUND);
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(DownloadResult::RESOURCE_NOT_FOUND, result->result);
}
{
group.getPieceStorage()->markAllPiecesDone();
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(DownloadResult::FINISHED, result->result);
}
}
} // namespace aria2