aria2/test/IteratableChecksumValidatorTest.cc
Tatsuhiro Tsujikawa 660c480cca 2009-01-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use LongestSequencePieceSelector for HTTP/FTP/BitTorrent
	integrated downloads. This PieceSelector subclass finds the
	longest continuous sequence in the available missing pieces and
	selects the last index of such sequence. This makes HTTP/FTP
	connections less interrupted by the pieces obtained by
	BitTorrent peers.
	* src/DefaultPieceStorage.cc
	* src/DefaultPieceStorage.h
	* src/LongestSequencePieceSelector.cc
	* src/LongestSequencePieceSelector.h
	* src/Makefile.am
	* src/PieceSelector.h
	* src/RarestPieceSelector.h
	* src/RequestGroup.cc
	* test/BtDependencyTest.cc
	* test/DefaultPieceStorageTest.cc
	* test/IteratableChecksumValidatorTest.cc
	* test/LongestSequencePieceSelectorTest.cc
	* test/Makefile.am
	* test/SegmentManTest.cc
2009-01-31 14:34:29 +00:00

73 lines
1.9 KiB
C++

#include "IteratableChecksumValidator.h"
#include <cppunit/extensions/HelperMacros.h>
#include "SingleFileDownloadContext.h"
#include "DefaultPieceStorage.h"
#include "Option.h"
#include "DiskAdaptor.h"
#include "FileEntry.h"
#include "PieceSelector.h"
namespace aria2 {
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;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(100, 250, "chunkChecksumTestFile250.txt"));
dctx->setChecksum("898a81b8e0181280ae2ee1b81e269196d91e869a");
dctx->setChecksumHashAlgo("sha1");
SharedHandle<DefaultPieceStorage> 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;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(100, 250, "chunkChecksumTestFile250.txt"));
dctx->setChecksum(std::string(40, '0')); // set wrong checksum
dctx->setChecksumHashAlgo("sha1");
SharedHandle<DefaultPieceStorage> 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());
}
} // namespace aria2