mirror of
https://github.com/aria2/aria2.git
synced 2025-01-08 19:11:47 +00:00
ccdd5b31a3
* src/FileAllocationCommand.cc: Derived from RealtimeCommand. * src/CheckIntegrityCommand.cc: Derived from RealtimeCommand. * src/MetalinkEntry.h (checksum): Changed to ChecksumHandle * src/MetalinkRequestInfo.cc (checksum): Changed to ChecksumHandle * src/File.cc (mkdirs): OPEN_MODE -> DIR_OPEN_MODE * src/common.h (DIR_OPEN_MODE): New definition * src/RequestGroup.cc (prepareForNextAction): Added an argument. * src/message.h (MSG_GOOD_CHECKSUM): New definition (MSG_BAD_CHECKSUM): New definition * src/HttpResponseCommand.cc (handleDefaultEncoding): Continue download sequence in new non-segmented download. * src/FileAllocationEntry.h (_nextDownloadCommand): New variable. * src/DownloadCommand.cc (prepareForNextSegment): Create ChecksumCommand if checksum is available. * src/RealtimeCommand.h, src/RealtimeCommand.cc: New class. * src/IteratableChecksumValidator.h, src/IteratableChecksumValidator.cc: New class. * src/ChecksumCommand.h, src/ChecksumCommand.cc: New class.
119 lines
3.4 KiB
C++
119 lines
3.4 KiB
C++
#include "IteratableChecksumValidator.h"
|
|
#include "DefaultDiskWriter.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
using namespace std;
|
|
|
|
class IteratableChecksumValidatorTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(IteratableChecksumValidatorTest);
|
|
CPPUNIT_TEST(testValidate);
|
|
CPPUNIT_TEST(testValidate2);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {
|
|
}
|
|
|
|
void testValidate();
|
|
void testValidate2();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( IteratableChecksumValidatorTest );
|
|
|
|
void IteratableChecksumValidatorTest::testValidate() {
|
|
BitfieldMan bitfieldMan(100, 250);
|
|
bitfieldMan.setAllBit();
|
|
|
|
ChecksumHandle checksum = new Checksum("898a81b8e0181280ae2ee1b81e269196d91e869a", DIGEST_ALGO_SHA1);
|
|
|
|
DefaultDiskWriterHandle diskWriter = new DefaultDiskWriter();
|
|
diskWriter->openExistingFile("chunkChecksumTestFile250.txt");
|
|
|
|
IteratableChecksumValidator validator;
|
|
validator.setDiskWriter(diskWriter);
|
|
validator.setBitfield(&bitfieldMan);
|
|
validator.setChecksum(checksum);
|
|
|
|
validator.init();
|
|
while(!validator.finished()) {
|
|
validator.validateChunk();
|
|
}
|
|
CPPUNIT_ASSERT(bitfieldMan.isAllBitSet());
|
|
}
|
|
|
|
void IteratableChecksumValidatorTest::testValidate2() {
|
|
BitfieldMan bitfieldMan(100, 250);
|
|
bitfieldMan.setAllBit();
|
|
|
|
ChecksumHandle checksum = new Checksum("ffffffffffffffffffffffffffffffffffffffff", DIGEST_ALGO_SHA1);
|
|
|
|
DefaultDiskWriterHandle diskWriter = new DefaultDiskWriter();
|
|
diskWriter->openExistingFile("chunkChecksumTestFile250.txt");
|
|
|
|
IteratableChecksumValidator validator;
|
|
validator.setDiskWriter(diskWriter);
|
|
validator.setBitfield(&bitfieldMan);
|
|
validator.setChecksum(checksum);
|
|
|
|
validator.init();
|
|
while(!validator.finished()) {
|
|
validator.validateChunk();
|
|
}
|
|
CPPUNIT_ASSERT(!bitfieldMan.isAllBitSet());
|
|
}
|
|
/*
|
|
void IteratableChecksumValidatorTest::testValidate3() {
|
|
BitfieldMan bitfieldMan(50, 250);
|
|
bitfieldMan.setAllBit();
|
|
Strings checksums;
|
|
checksums.push_back("898a81b8e0181280ae2ee1b81e269196d91e869a");
|
|
|
|
DefaultDiskWriterHandle diskWriter = new DefaultDiskWriter();
|
|
diskWriter->openExistingFile("chunkChecksumTestFile250.txt");
|
|
|
|
IteratableChecksumValidator validator;
|
|
validator.setDiskWriter(diskWriter);
|
|
|
|
validator.validate(&bitfieldMan, checksums, 250);
|
|
|
|
CPPUNIT_ASSERT(bitfieldMan.isAllBitSet());
|
|
|
|
checksums[0] = "ffffffffffffffffffffffffffffffffffffffff";
|
|
|
|
validator.validate(&bitfieldMan, checksums, 250);
|
|
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(0));
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(1));
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(2));
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(3));
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(4));
|
|
}
|
|
|
|
void IteratableChecksumValidatorTest::testValidate4() {
|
|
BitfieldMan bitfieldMan(70, 250);
|
|
bitfieldMan.setAllBit();
|
|
Strings checksums(&csArray[0], &csArray[3]);
|
|
|
|
DefaultDiskWriterHandle diskWriter = new DefaultDiskWriter();
|
|
diskWriter->openExistingFile("chunkChecksumTestFile250.txt");
|
|
|
|
IteratableChecksumValidator validator;
|
|
validator.setDiskWriter(diskWriter);
|
|
|
|
validator.validate(&bitfieldMan, checksums, 100);
|
|
|
|
CPPUNIT_ASSERT(bitfieldMan.isAllBitSet());
|
|
|
|
checksums[1] = "ffffffffffffffffffffffffffffffffffffffff";
|
|
validator.validate(&bitfieldMan, checksums, 100);
|
|
|
|
CPPUNIT_ASSERT(bitfieldMan.isBitSet(0));
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(1));
|
|
CPPUNIT_ASSERT(!bitfieldMan.isBitSet(2));
|
|
CPPUNIT_ASSERT(bitfieldMan.isBitSet(3));
|
|
}
|
|
*/
|