2008-11-13 13:40:40 +00:00
|
|
|
#include "download_helper.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "DownloadContext.h"
|
|
|
|
#include "Option.h"
|
|
|
|
#include "array_fun.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "Exception.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2010-08-24 14:21:12 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
# include "bittorrent_helper.h"
|
|
|
|
#endif // ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class DownloadHelperTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DownloadHelperTest);
|
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForUri);
|
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForUri_parameterized);
|
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForUriList);
|
2008-11-13 15:08:52 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForUri_BitTorrent);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForBitTorrent);
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
|
|
|
|
#ifdef ENABLE_METALINK
|
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForUri_Metalink);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_TEST(testCreateRequestGroupForMetalink);
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_METALINK
|
|
|
|
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
2009-05-08 16:41:21 +00:00
|
|
|
private:
|
2010-06-21 13:51:56 +00:00
|
|
|
SharedHandle<Option> option_;
|
2008-11-13 13:40:40 +00:00
|
|
|
public:
|
2009-05-08 16:41:21 +00:00
|
|
|
void setUp()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
option_.reset(new Option());
|
2009-05-08 16:41:21 +00:00
|
|
|
}
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testCreateRequestGroupForUri();
|
|
|
|
void testCreateRequestGroupForUri_parameterized();
|
|
|
|
void testCreateRequestGroupForUriList();
|
2008-11-13 15:08:52 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
void testCreateRequestGroupForUri_BitTorrent();
|
2008-11-13 13:40:40 +00:00
|
|
|
void testCreateRequestGroupForBitTorrent();
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
|
|
|
|
#ifdef ENABLE_METALINK
|
|
|
|
void testCreateRequestGroupForUri_Metalink();
|
2008-11-13 13:40:40 +00:00
|
|
|
void testCreateRequestGroupForMetalink();
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_METALINK
|
2008-11-13 13:40:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DownloadHelperTest);
|
|
|
|
|
|
|
|
void DownloadHelperTest::testCreateRequestGroupForUri()
|
|
|
|
{
|
|
|
|
std::string array[] = {
|
|
|
|
"http://alpha/file",
|
|
|
|
"http://bravo/file",
|
|
|
|
"http://charlie/file"
|
|
|
|
};
|
2010-03-25 13:51:10 +00:00
|
|
|
std::vector<std::string> uris(vbegin(array), vend(array));
|
2010-07-14 11:39:05 +00:00
|
|
|
option_->put(PREF_SPLIT, "7");
|
|
|
|
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "2");
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-07-14 11:39:05 +00:00
|
|
|
std::vector<std::string> xuris;
|
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, xuris.size());
|
|
|
|
for(size_t i = 0; i < 6; ++i) {
|
|
|
|
CPPUNIT_ASSERT_EQUAL(array[i%3], xuris[i]);
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
2010-07-14 11:39:05 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)7, group->getNumConcurrentCommand());
|
2008-11-13 13:40:40 +00:00
|
|
|
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"), ctx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "5");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-07-14 11:39:05 +00:00
|
|
|
std::vector<std::string> xuris;
|
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, xuris.size());
|
|
|
|
for(size_t i = 0; i < 5; ++i) {
|
|
|
|
CPPUNIT_ASSERT_EQUAL(array[i%3], xuris[i]);
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "2");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-07-14 11:39:05 +00:00
|
|
|
std::vector<std::string> xuris;
|
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, xuris.size());
|
|
|
|
for(size_t i = 0; i < 3; ++i) {
|
|
|
|
CPPUNIT_ASSERT_EQUAL(array[i%3], xuris[i]);
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-11 12:48:03 +00:00
|
|
|
option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE);
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
|
|
|
|
// for alpha server
|
|
|
|
SharedHandle<RequestGroup> alphaGroup = result[0];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> alphaURIs;
|
2009-06-29 08:42:58 +00:00
|
|
|
alphaGroup->getDownloadContext()->getFirstFileEntry()->getUris(alphaURIs);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, alphaURIs.size());
|
|
|
|
for(size_t i = 0; i < 2; ++i) {
|
2010-07-14 11:39:05 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(array[0], alphaURIs[i]);
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)2,
|
2010-01-05 16:01:46 +00:00
|
|
|
alphaGroup->getNumConcurrentCommand());
|
2008-11-13 13:40:40 +00:00
|
|
|
SharedHandle<DownloadContext> alphaCtx = alphaGroup->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), alphaCtx->getDir());
|
2009-03-09 15:10:26 +00:00
|
|
|
// See filename is not assigned yet
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), alphaCtx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
|
|
|
|
{
|
|
|
|
std::string array[] = {
|
|
|
|
"http://{alpha, bravo}/file",
|
|
|
|
"http://charlie/file"
|
|
|
|
};
|
2010-03-25 13:51:10 +00:00
|
|
|
std::vector<std::string> uris(vbegin(array), vend(array));
|
2010-07-14 11:39:05 +00:00
|
|
|
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "1");
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "3");
|
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2010-09-11 12:48:03 +00:00
|
|
|
option_->put(PREF_PARAMETERIZED_URI, A2_V_TRUE);
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2009-06-29 08:42:58 +00:00
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), uris[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), uris[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://charlie/file"), uris[2]);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)3, group->getNumConcurrentCommand());
|
|
|
|
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
|
2009-06-28 10:37:15 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"), ctx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
|
|
|
|
{
|
|
|
|
std::string array[] = {
|
|
|
|
"http://alpha/file",
|
|
|
|
"test.torrent",
|
|
|
|
"http://bravo/file",
|
|
|
|
"http://charlie/file"
|
|
|
|
};
|
2010-03-25 13:51:10 +00:00
|
|
|
std::vector<std::string> uris(vbegin(array), vend(array));
|
2010-07-14 11:39:05 +00:00
|
|
|
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "1");
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "3");
|
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, result.size());
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-07-14 11:39:05 +00:00
|
|
|
std::vector<std::string> xuris;
|
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, xuris.size());
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-07-14 11:39:05 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(array[0], xuris[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(array[2], xuris[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(array[3], xuris[2]);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)3, group->getNumConcurrentCommand());
|
|
|
|
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
|
2010-01-05 16:01:46 +00:00
|
|
|
ctx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
SharedHandle<RequestGroup> torrentGroup = result[1];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> auxURIs;
|
2009-06-29 08:42:58 +00:00
|
|
|
torrentGroup->getDownloadContext()->getFirstFileEntry()->getUris(auxURIs);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT(auxURIs.empty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)3,
|
2010-01-05 16:01:46 +00:00
|
|
|
torrentGroup->getNumConcurrentCommand());
|
2008-11-13 13:40:40 +00:00
|
|
|
SharedHandle<DownloadContext> btctx = torrentGroup->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), btctx->getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-test"),
|
2010-01-05 16:01:46 +00:00
|
|
|
btctx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
2008-11-13 13:40:40 +00:00
|
|
|
void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
|
|
|
|
{
|
|
|
|
std::string array[] = {
|
|
|
|
"http://alpha/file",
|
|
|
|
"http://bravo/file",
|
|
|
|
"http://charlie/file",
|
|
|
|
"test.xml"
|
|
|
|
};
|
2010-03-25 13:51:10 +00:00
|
|
|
std::vector<std::string> uris(vbegin(array), vend(array));
|
2010-07-14 11:39:05 +00:00
|
|
|
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "1");
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "3");
|
|
|
|
option_->put(PREF_METALINK_SERVERS, "2");
|
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUri(result, option_, uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
// group1: http://alpha/file, ...
|
|
|
|
// group2-7: 6 file entry in Metalink and 1 torrent file download
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)7, result.size());
|
2008-11-13 15:08:52 +00:00
|
|
|
#else // !ENABLE_BITTORRENT
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, result.size());
|
|
|
|
#endif // !ENABLE_BITTORRENT
|
|
|
|
|
2008-11-13 13:40:40 +00:00
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-07-14 11:39:05 +00:00
|
|
|
std::vector<std::string> xuris;
|
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(xuris);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, xuris.size());
|
2008-11-13 13:40:40 +00:00
|
|
|
for(size_t i = 0; i < 3; ++i) {
|
2010-07-14 11:39:05 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(array[i], xuris[i]);
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)3, group->getNumConcurrentCommand());
|
|
|
|
SharedHandle<DownloadContext> ctx = group->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), ctx->getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
|
2010-01-05 16:01:46 +00:00
|
|
|
ctx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
SharedHandle<RequestGroup> aria2052Group = result[1];
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)1, // because of maxconnections attribute
|
2010-01-05 16:01:46 +00:00
|
|
|
aria2052Group->getNumConcurrentCommand());
|
2008-11-13 13:40:40 +00:00
|
|
|
SharedHandle<DownloadContext> aria2052Ctx =
|
|
|
|
aria2052Group->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), aria2052Ctx->getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-0.5.2.tar.bz2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
aria2052Ctx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
SharedHandle<RequestGroup> aria2051Group = result[2];
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)2,
|
2010-01-05 16:01:46 +00:00
|
|
|
aria2051Group->getNumConcurrentCommand());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_METALINK
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
void DownloadHelperTest::testCreateRequestGroupForUriList()
|
|
|
|
{
|
2010-07-14 11:39:05 +00:00
|
|
|
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "3");
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "3");
|
|
|
|
option_->put(PREF_INPUT_FILE, "input_uris.txt");
|
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForUriList(result, option_);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, result.size());
|
|
|
|
|
|
|
|
SharedHandle<RequestGroup> fileGroup = result[0];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> fileURIs;
|
2009-06-29 08:42:58 +00:00
|
|
|
fileGroup->getDownloadContext()->getFirstFileEntry()->getUris(fileURIs);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), fileURIs[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), fileURIs[1]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://charlie/file"), fileURIs[2]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)3, fileGroup->getNumConcurrentCommand());
|
|
|
|
SharedHandle<DownloadContext> fileCtx = fileGroup->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/mydownloads"), fileCtx->getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/mydownloads/myfile.out"),
|
2010-01-05 16:01:46 +00:00
|
|
|
fileCtx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
SharedHandle<RequestGroup> fileISOGroup = result[1];
|
|
|
|
SharedHandle<DownloadContext> fileISOCtx = fileISOGroup->getDownloadContext();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), fileISOCtx->getDir());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
|
2010-01-05 16:01:46 +00:00
|
|
|
fileISOCtx->getBasePath());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
|
|
|
{
|
|
|
|
std::string array[] = {
|
|
|
|
"http://alpha/file",
|
|
|
|
"http://bravo/file",
|
|
|
|
"http://charlie/file"
|
|
|
|
};
|
|
|
|
|
2010-03-25 13:51:10 +00:00
|
|
|
std::vector<std::string> auxURIs(vbegin(array), vend(array));
|
2010-07-14 11:39:05 +00:00
|
|
|
option_->put(PREF_MAX_CONNECTION_PER_SERVER, "2");
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "5");
|
|
|
|
option_->put(PREF_TORRENT_FILE, "test.torrent");
|
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2010-08-24 14:21:12 +00:00
|
|
|
option_->put(PREF_BT_EXCLUDE_TRACKER, "http://tracker1");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForBitTorrent(result, option_, auxURIs);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2009-06-29 08:42:58 +00:00
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
|
2010-07-14 11:39:05 +00:00
|
|
|
// See -s option is ignored. See processRootDictionary() in
|
|
|
|
// bittorrent_helper.cc
|
2009-06-29 08:42:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
|
2010-03-25 14:22:43 +00:00
|
|
|
for(size_t i = 0; i < A2_ARRAY_LEN(array); ++i) {
|
2009-06-29 08:42:58 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(array[i]+"/aria2-test/aria2/src/aria2c", uris[i]);
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)5, group->getNumConcurrentCommand());
|
2010-08-24 14:21:12 +00:00
|
|
|
SharedHandle<TorrentAttribute> attrs =
|
|
|
|
bittorrent::getTorrentAttrs(group->getDownloadContext());
|
|
|
|
// http://tracker1 was deleted.
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, attrs->announceList.size());
|
2008-11-13 13:40:40 +00:00
|
|
|
}
|
2008-11-23 12:13:53 +00:00
|
|
|
{
|
|
|
|
// no URIs are given
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
|
|
|
std::vector<std::string> emptyURIs;
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForBitTorrent(result, option_, emptyURIs);
|
2008-11-23 12:13:53 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2009-06-29 08:42:58 +00:00
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
|
2008-11-23 12:13:53 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, uris.size());
|
|
|
|
}
|
2010-09-11 12:48:03 +00:00
|
|
|
option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE);
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForBitTorrent(result, option_, auxURIs);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
// See --force-requencial is ignored
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
|
|
|
}
|
|
|
|
}
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
2008-11-13 13:40:40 +00:00
|
|
|
void DownloadHelperTest::testCreateRequestGroupForMetalink()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
option_->put(PREF_SPLIT, "3");
|
|
|
|
option_->put(PREF_METALINK_FILE, "test.xml");
|
|
|
|
option_->put(PREF_METALINK_SERVERS, "5");
|
|
|
|
option_->put(PREF_DIR, "/tmp");
|
|
|
|
option_->put(PREF_OUT, "file.out");
|
2008-11-13 13:40:40 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
createRequestGroupForMetalink(result, option_);
|
2008-11-13 13:40:40 +00:00
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)6, result.size());
|
2008-11-13 15:08:52 +00:00
|
|
|
#else // !ENABLE_BITTORRENT
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
|
|
|
|
#endif // !ENABLE_BITTORRENT
|
2008-11-13 13:40:40 +00:00
|
|
|
SharedHandle<RequestGroup> group = result[0];
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2009-06-29 08:42:58 +00:00
|
|
|
group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
|
2008-11-13 13:40:40 +00:00
|
|
|
std::sort(uris.begin(), uris.end());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftphost/aria2-0.5.2.tar.bz2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
uris[0]);
|
2008-11-13 13:40:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://httphost/aria2-0.5.2.tar.bz2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
uris[1]);
|
2008-11-13 13:40:40 +00:00
|
|
|
// See numConcurrentCommand is 1 because of maxconnections attribute.
|
|
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)1, group->getNumConcurrentCommand());
|
|
|
|
}
|
|
|
|
}
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_METALINK
|
2008-11-13 13:40:40 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|