aria2/test/IteratableChecksumValidatorTest.cc
Tatsuhiro Tsujikawa 89f997ec0d 2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Replaced MessageDigestContext with MessageDigest.  Cleaned up
	unnecessary functions in MessageDigestHelper.
	* src/BtPieceMessage.cc
	* src/Checksum.h
	* src/DHTTokenTracker.cc
	* src/DownloadCommand.cc
	* src/DownloadCommand.h
	* src/HashFuncEntry.h
	* src/IteratableChecksumValidator.cc
	* src/IteratableChecksumValidator.h
	* src/IteratableChunkChecksumValidator.cc
	* src/IteratableChunkChecksumValidator.h
	* src/LibgcryptMessageDigestImpl.cc
	* src/LibgcryptMessageDigestImpl.h
	* src/LibsslMessageDigestImpl.cc
	* src/LibsslMessageDigestImpl.h
	* src/MSEHandshake.cc
	* src/MSEHandshake.h
	* src/Makefile.am
	* src/MessageDigest.cc
	* src/MessageDigest.h
	* src/MessageDigestHelper.cc
	* src/MessageDigestHelper.h
	* src/MessageDigestImpl.h
	* src/MetalinkParserController.cc
	* src/Piece.cc
	* src/Piece.h
	* src/UTMetadataDataExtensionMessage.cc
	* src/bittorrent_helper.cc
	* src/messageDigest.cc: Removed
	* src/messageDigest.h: Removed
	* src/util.cc
	* src/version_usage.cc
	* test/BittorrentHelperTest.cc
	* test/GZipDecoderTest.cc
	* test/GZipDecodingStreamFilterTest.cc
	* test/IteratableChecksumValidatorTest.cc
	* test/IteratableChunkChecksumValidatorTest.cc
	* test/Makefile.am
	* test/MessageDigestHelperTest.cc
	* test/MessageDigestTest.cc
	* test/Metalink2RequestGroupTest.cc
	* test/MetalinkProcessorTest.cc
	* test/PieceTest.cc
	* test/TestUtil.cc
	* test/TestUtil.h
	* test/UTMetadataDataExtensionMessageTest.cc
	* test/UTMetadataPostDownloadHandlerTest.cc
2010-11-11 02:56:24 +00:00

73 lines
1.8 KiB
C++

#include "IteratableChecksumValidator.h"
#include <cppunit/extensions/HelperMacros.h>
#include "DownloadContext.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<DownloadContext> dctx
(new DownloadContext(100, 250, "chunkChecksumTestFile250.txt"));
dctx->setChecksum("898a81b8e0181280ae2ee1b81e269196d91e869a");
dctx->setChecksumHashAlgo("sha-1");
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<DownloadContext> dctx
(new DownloadContext(100, 250, "chunkChecksumTestFile250.txt"));
dctx->setChecksum(std::string(40, '0')); // set wrong checksum
dctx->setChecksumHashAlgo("sha-1");
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