mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 14:07:37 +03:00
Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
73 lines
2 KiB
C++
73 lines
2 KiB
C++
#include "BtPostDownloadHandler.h"
|
|
#include "BtContext.h"
|
|
#include "RequestGroup.h"
|
|
#include "Option.h"
|
|
#include "SingleFileDownloadContext.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
class BtPostDownloadHandlerTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(BtPostDownloadHandlerTest);
|
|
CPPUNIT_TEST(testCanHandle_extension);
|
|
CPPUNIT_TEST(testCanHandle_contentType);
|
|
CPPUNIT_TEST(testGetNextRequestGroups);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {}
|
|
|
|
void testCanHandle_extension();
|
|
void testCanHandle_contentType();
|
|
void testGetNextRequestGroups();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest );
|
|
|
|
void BtPostDownloadHandlerTest::testCanHandle_extension()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
BtPostDownloadHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle(&rg));
|
|
|
|
dctx->setFilename("test.torrent2");
|
|
CPPUNIT_ASSERT(!handler.canHandle(&rg));
|
|
}
|
|
|
|
void BtPostDownloadHandlerTest::testCanHandle_contentType()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test");
|
|
dctx->setContentType("application/x-bittorrent");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
BtPostDownloadHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle(&rg));
|
|
|
|
dctx->setContentType("application/octet-stream");
|
|
CPPUNIT_ASSERT(!handler.canHandle(&rg));
|
|
}
|
|
|
|
void BtPostDownloadHandlerTest::testGetNextRequestGroups()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
rg.initPieceStorage();
|
|
|
|
BtPostDownloadHandler handler;
|
|
RequestGroups groups = handler.getNextRequestGroups(&rg);
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
|
|
BtContextHandle btctx = groups.front()->getDownloadContext();
|
|
CPPUNIT_ASSERT(!btctx.isNull());
|
|
CPPUNIT_ASSERT_EQUAL(string("aria2-test"), btctx->getName());
|
|
}
|