mirror of
https://github.com/aria2/aria2.git
synced 2025-01-09 03:21:33 +00:00
b1edad42ff
Fixed the bug that prevents aria2 from downloading 0-length files via HTTP/FTP. * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/DownloadContext.h * src/FtpNegotiationCommand.cc * src/HttpResponseCommand.cc * src/HttpResponseCommand.h * src/RequestGroup.cc * src/SingleFileDownloadContext.cc * src/SingleFileDownloadContext.h * test/BtPostDownloadHandlerTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/MockBtContext.h
83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include "MetalinkPostDownloadHandler.h"
|
|
#include "RequestGroup.h"
|
|
#include "Option.h"
|
|
#include "SingleFileDownloadContext.h"
|
|
#include "FileEntry.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class MetalinkPostDownloadHandlerTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(MetalinkPostDownloadHandlerTest);
|
|
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( MetalinkPostDownloadHandlerTest );
|
|
|
|
void MetalinkPostDownloadHandlerTest::testCanHandle_extension()
|
|
{
|
|
Option op;
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(new SingleFileDownloadContext(0, 0, "test.metalink"));
|
|
RequestGroup rg(&op, std::deque<std::string>());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
MetalinkPostDownloadHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle(&rg));
|
|
|
|
dctx->setFilename("test.metalink2");
|
|
CPPUNIT_ASSERT(!handler.canHandle(&rg));
|
|
}
|
|
|
|
void MetalinkPostDownloadHandlerTest::testCanHandle_contentType()
|
|
{
|
|
Option op;
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(new SingleFileDownloadContext(0, 0, "test"));
|
|
dctx->setContentType("application/metalink+xml");
|
|
RequestGroup rg(&op, std::deque<std::string>());
|
|
rg.setDownloadContext(dctx);
|
|
|
|
MetalinkPostDownloadHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle(&rg));
|
|
|
|
dctx->setContentType("application/octet-stream");
|
|
CPPUNIT_ASSERT(!handler.canHandle(&rg));
|
|
}
|
|
|
|
void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups()
|
|
{
|
|
Option op;
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
(new SingleFileDownloadContext(1024, 0, "test.xml"));
|
|
RequestGroup rg(&op, std::deque<std::string>());
|
|
rg.setDownloadContext(dctx);
|
|
rg.initPieceStorage();
|
|
|
|
MetalinkPostDownloadHandler handler;
|
|
RequestGroups groups;
|
|
handler.getNextRequestGroups(groups, &rg);
|
|
#ifdef ENABLE_BITTORRENT
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6/* 5 + 1 torrent file download */, groups.size());
|
|
#else
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, groups.size());
|
|
#endif // ENABLE_BITTORRENT
|
|
}
|
|
|
|
} // namespace aria2
|