mirror of
https://github.com/aria2/aria2.git
synced 2025-02-26 08:22:11 +00:00
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)
80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
#include "Metalink2RequestGroup.h"
|
|
#include "SingleFileDownloadContext.h"
|
|
#include "prefs.h"
|
|
#include "Option.h"
|
|
#include "RequestGroup.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
class Metalink2RequestGroupTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(Metalink2RequestGroupTest);
|
|
CPPUNIT_TEST(testGenerate);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
SharedHandle<Option> _option;
|
|
|
|
public:
|
|
void setUp()
|
|
{
|
|
_option = new Option();
|
|
_option->put(PREF_SPLIT, "1");
|
|
}
|
|
|
|
void testGenerate();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest );
|
|
|
|
void Metalink2RequestGroupTest::testGenerate()
|
|
{
|
|
RequestGroups groups = Metalink2RequestGroup(_option.get()).generate("test.xml");
|
|
// first file
|
|
{
|
|
RequestGroupHandle rg = groups[0];
|
|
Strings uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
|
|
CPPUNIT_ASSERT_EQUAL(string("ftp://ftphost/aria2-0.5.2.tar.bz2"), uris[0]);
|
|
CPPUNIT_ASSERT_EQUAL(string("http://httphost/aria2-0.5.2.tar.bz2"), uris[1]);
|
|
SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)0, dctx->getTotalLength());
|
|
CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getChecksumHashAlgo());
|
|
CPPUNIT_ASSERT_EQUAL(string("a96cf3f0266b91d87d5124cf94326422800b627d"),
|
|
dctx->getChecksum());
|
|
}
|
|
// second file
|
|
{
|
|
RequestGroupHandle rg = groups[1];
|
|
Strings uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
|
|
SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("sha1"), dctx->getPieceHashAlgo());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)262144, dctx->getPieceLength());
|
|
CPPUNIT_ASSERT_EQUAL(string(""), dctx->getChecksumHashAlgo());
|
|
CPPUNIT_ASSERT_EQUAL(string(""), dctx->getChecksum());
|
|
}
|
|
|
|
// fifth file <- downloading .torrent file
|
|
{
|
|
RequestGroupHandle rg = groups[4];
|
|
Strings uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
|
|
CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated.torrent"),
|
|
uris[0]);
|
|
SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
}
|
|
// sixth file <- depends on thrid file
|
|
{
|
|
RequestGroupHandle rg = groups[5];
|
|
Strings uris = rg->getUris();
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
|
|
CPPUNIT_ASSERT_EQUAL(string("http://host/torrent-http.integrated"), uris[0]);
|
|
SingleFileDownloadContextHandle dctx = rg->getDownloadContext();
|
|
CPPUNIT_ASSERT(!dctx.isNull());
|
|
}
|
|
}
|