mirror of
https://github.com/aria2/aria2.git
synced 2025-01-24 10:41:18 +00:00
2952abf064
Added following 2 keys, followedBy and belongsTo, to the response of tellStatus. followedBy: List of GIDs which are generated by the consequence of this download. For example, when aria2 downloaded Metalink file, it generates downloads described in it(see *--follow-metalink* option). This value is useful to track these auto generated downloads. If there is no such downloads, this key will not be included in the response. belongsTo: GID of a parent download. Some downloads are a part of another download. For example, if a file in Metalink has BitTorrent resource, the download of .torrent is a part of that file. If this download has no parent, this key will not be included in the response. * src/BtPostDownloadHandler.cc * src/DownloadResult.h * src/Metalink2RequestGroup.cc * src/MetalinkPostDownloadHandler.cc * src/RequestGroup.cc * src/RequestGroup.h * src/UTMetadataPostDownloadHandler.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.h
85 lines
2.3 KiB
C++
85 lines
2.3 KiB
C++
#include "BtPostDownloadHandler.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "DownloadContext.h"
|
|
#include "RequestGroup.h"
|
|
#include "Option.h"
|
|
#include "FileEntry.h"
|
|
#include "bittorrent_helper.h"
|
|
|
|
namespace aria2 {
|
|
|
|
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:
|
|
SharedHandle<Option> _option;
|
|
public:
|
|
void setUp()
|
|
{
|
|
_option.reset(new Option());
|
|
}
|
|
|
|
void testCanHandle_extension();
|
|
void testCanHandle_contentType();
|
|
void testGetNextRequestGroups();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest );
|
|
|
|
void BtPostDownloadHandlerTest::testCanHandle_extension()
|
|
{
|
|
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.torrent"));
|
|
RequestGroup rg(_option);
|
|
rg.setDownloadContext(dctx);
|
|
|
|
BtPostDownloadHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle(&rg));
|
|
|
|
dctx->getFirstFileEntry()->setPath("test.torrent2");
|
|
CPPUNIT_ASSERT(!handler.canHandle(&rg));
|
|
}
|
|
|
|
void BtPostDownloadHandlerTest::testCanHandle_contentType()
|
|
{
|
|
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
|
|
dctx->getFirstFileEntry()->setContentType("application/x-bittorrent");
|
|
RequestGroup rg(_option);
|
|
rg.setDownloadContext(dctx);
|
|
|
|
BtPostDownloadHandler handler;
|
|
|
|
CPPUNIT_ASSERT(handler.canHandle(&rg));
|
|
|
|
dctx->getFirstFileEntry()->setContentType("application/octet-stream");
|
|
CPPUNIT_ASSERT(!handler.canHandle(&rg));
|
|
}
|
|
|
|
void BtPostDownloadHandlerTest::testGetNextRequestGroups()
|
|
{
|
|
SharedHandle<DownloadContext> dctx
|
|
(new DownloadContext(1024, 0, "test.torrent"));
|
|
RequestGroup rg(_option);
|
|
rg.setDownloadContext(dctx);
|
|
rg.initPieceStorage();
|
|
|
|
BtPostDownloadHandler handler;
|
|
std::deque<SharedHandle<RequestGroup> > groups;
|
|
handler.getNextRequestGroups(groups, &rg);
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
|
|
CPPUNIT_ASSERT_EQUAL
|
|
(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
|
bittorrent::getInfoHashString(groups.front()->getDownloadContext()));
|
|
CPPUNIT_ASSERT(std::find(rg.followedBy().begin(), rg.followedBy().end(),
|
|
groups.front()->getGID()) != rg.followedBy().end());
|
|
}
|
|
|
|
} // namespace aria2
|