aria2/test/IteratableChecksumValidatorTest.cc
Tatsuhiro Tsujikawa 7c41d11be3 2007-11-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented checksum validation feature(1 checksum for each 
file)
	The validation takes place after the download.
	* src/PieceHashCheckIntegrityEntry.{h, cc}: New class.
	* src/IteratableChecksumValidator.{h, cc}: Rewritten.
	* src/CheckIntegrityCommand.cc: Changed log message.
	* src/Metalink2RequestGroup.cc: Set checksum to
	SingleFileDownloadContext.
	* src/StreamCheckIntegrityEntry.{h, cc}: Now derived from
	PieceHashCheckIntegrity class.
	* src/BtCheckIntegrityEntry.{h, cc}: Now derived from
	PieceHashCheckIntegrity class.
	* src/ChecksumCheckIntegrityEntry.{h, cc}: New class.
	* src/IteratableValidator.h: New class.
	* src/message.h
	* src/CheckIntegrityEntry.{h, cc}
	* src/IteratableChunkChecksumValidator.{h, cc}
	* src/SingleFileDownloadContext.h
	* src/DownloadCommand.cc
	
	--allow-overwrite=true is no longer needed to check file 
integrity
	before download in BitTorrent download.
	* src/RequestGroup.cc (getInitialCommand)

	Removed RequestGroup from queue when 
RequestGroup::getInitialCommand()
	throws exception.
	* src/RequestGroupMan.cc (getInitialCommands)
2007-11-12 11:28:16 +00:00

66 lines
1.8 KiB
C++

#include "IteratableChecksumValidator.h"
#include "SingleFileDownloadContext.h"
#include "DefaultPieceStorage.h"
#include "Option.h"
#include "DiskAdaptor.h"
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class IteratableChecksumValidatorTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(IteratableChecksumValidatorTest);
CPPUNIT_TEST(testValidate);
CPPUNIT_TEST(testValidate_fail);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testValidate();
void testValidate_fail();
};
CPPUNIT_TEST_SUITE_REGISTRATION( IteratableChecksumValidatorTest );
void IteratableChecksumValidatorTest::testValidate() {
Option option;
SingleFileDownloadContextHandle dctx =
new SingleFileDownloadContext(100, 250, "chunkChecksumTestFile250.txt");
dctx->setChecksum("898a81b8e0181280ae2ee1b81e269196d91e869a");
dctx->setChecksumHashAlgo("sha1");
DefaultPieceStorageHandle ps = new DefaultPieceStorage(dctx, &option);
ps->initStorage();
ps->getDiskAdaptor()->openFile();
IteratableChecksumValidator validator(dctx, ps);
validator.init();
while(!validator.finished()) {
validator.validateChunk();
}
CPPUNIT_ASSERT(ps->downloadFinished());
}
void IteratableChecksumValidatorTest::testValidate_fail() {
Option option;
SingleFileDownloadContextHandle dctx =
new SingleFileDownloadContext(100, 250, "chunkChecksumTestFile250.txt");
dctx->setChecksum(string(40, '0')); // set wrong checksum
dctx->setChecksumHashAlgo("sha1");
DefaultPieceStorageHandle ps = new DefaultPieceStorage(dctx, &option);
ps->initStorage();
ps->getDiskAdaptor()->openFile();
IteratableChecksumValidator validator(dctx, ps);
validator.init();
while(!validator.finished()) {
validator.validateChunk();
}
CPPUNIT_ASSERT(!ps->downloadFinished());
}