mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 05:57:36 +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
90 lines
2.8 KiB
C++
90 lines
2.8 KiB
C++
#include "DownloadHandlerFactory.h"
|
|
#include "RequestGroup.h"
|
|
#include "Option.h"
|
|
#include "SingleFileDownloadContext.h"
|
|
#include "MemoryBufferPreDownloadHandler.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
class DownloadHandlerFactoryTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(DownloadHandlerFactoryTest);
|
|
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension);
|
|
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType);
|
|
CPPUNIT_TEST(testGetBtPreDownloadHandler_extension);
|
|
CPPUNIT_TEST(testGetBtPreDownloadHandler_contentType);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {}
|
|
|
|
void testGetMetalinkPreDownloadHandler_extension();
|
|
void testGetMetalinkPreDownloadHandler_contentType();
|
|
void testGetBtPreDownloadHandler_extension();
|
|
void testGetBtPreDownloadHandler_contentType();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
|
|
|
|
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.metalink");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
PreDownloadHandlerHandle handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
|
|
|
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
|
|
|
dctx->setFilename("test.metalink2");
|
|
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
|
}
|
|
|
|
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test");
|
|
dctx->setContentType("application/metalink+xml");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
PreDownloadHandlerHandle handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
|
|
|
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
|
|
|
dctx->setContentType("application/octet-stream");
|
|
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
|
}
|
|
|
|
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
PreDownloadHandlerHandle handler = DownloadHandlerFactory::getBtPreDownloadHandler();
|
|
|
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
|
|
|
dctx->setFilename("test.torrent2");
|
|
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
|
}
|
|
|
|
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
|
|
{
|
|
Option op;
|
|
SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test");
|
|
dctx->setContentType("application/x-bittorrent");
|
|
RequestGroup rg(&op, Strings());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
PreDownloadHandlerHandle handler = DownloadHandlerFactory::getBtPreDownloadHandler();
|
|
|
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
|
|
|
dctx->setContentType("application/octet-stream");
|
|
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
|
}
|