2007-06-03 14:24:37 +00:00
|
|
|
#include "RequestGroupMan.h"
|
2009-01-06 13:13:42 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2012-12-22 14:37:44 +00:00
|
|
|
#include "TestUtil.h"
|
2007-07-09 13:30:45 +00:00
|
|
|
#include "prefs.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "RequestGroup.h"
|
2007-10-30 12:48:01 +00:00
|
|
|
#include "Option.h"
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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
2007-11-27 12:27:10 +00:00
|
|
|
#include "DownloadResult.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2008-08-04 17:06:47 +00:00
|
|
|
#include "ServerStatMan.h"
|
2008-08-23 15:42:06 +00:00
|
|
|
#include "ServerStat.h"
|
|
|
|
#include "File.h"
|
2009-12-21 15:17:34 +00:00
|
|
|
#include "array_fun.h"
|
2010-06-18 14:47:09 +00:00
|
|
|
#include "RecoverableException.h"
|
2011-10-25 12:44:04 +00:00
|
|
|
#include "util.h"
|
2012-12-22 14:37:44 +00:00
|
|
|
#include "DownloadEngine.h"
|
|
|
|
#include "SelectEventPoll.h"
|
2012-12-22 10:29:27 +00:00
|
|
|
#include "UriListParser.h"
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-06-03 14:24:37 +00:00
|
|
|
|
|
|
|
class RequestGroupManTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(RequestGroupManTest);
|
|
|
|
CPPUNIT_TEST(testIsSameFileBeingDownloaded);
|
2007-07-09 13:30:45 +00:00
|
|
|
CPPUNIT_TEST(testGetInitialCommands);
|
2008-08-23 15:42:06 +00:00
|
|
|
CPPUNIT_TEST(testLoadServerStat);
|
|
|
|
CPPUNIT_TEST(testSaveServerStat);
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_TEST(testChangeReservedGroupPosition);
|
2012-12-22 14:37:44 +00:00
|
|
|
CPPUNIT_TEST(testFillRequestGroupFromReserver);
|
2012-12-22 10:29:27 +00:00
|
|
|
CPPUNIT_TEST(testFillRequestGroupFromReserver_uriParser);
|
|
|
|
CPPUNIT_TEST(testInsertReservedGroup);
|
2013-02-25 12:42:54 +00:00
|
|
|
CPPUNIT_TEST(testAddDownloadResult);
|
2007-06-03 14:24:37 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadEngine> e_;
|
|
|
|
std::shared_ptr<Option> option_;
|
|
|
|
std::shared_ptr<RequestGroupMan> rgman_;
|
2007-06-03 14:24:37 +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());
|
2012-12-22 14:37:44 +00:00
|
|
|
option_->put(PREF_PIECE_LENGTH, "1048576");
|
|
|
|
// To enable paused RequestGroup
|
|
|
|
option_->put(PREF_ENABLE_RPC, A2_V_TRUE);
|
|
|
|
File(option_->get(PREF_DIR)).mkdirs();
|
|
|
|
e_.reset
|
2013-06-21 16:10:38 +00:00
|
|
|
(new DownloadEngine(std::shared_ptr<EventPoll>(new SelectEventPoll())));
|
2012-12-22 14:37:44 +00:00
|
|
|
e_->setOption(option_.get());
|
2013-06-21 16:10:38 +00:00
|
|
|
rgman_ = std::shared_ptr<RequestGroupMan>
|
|
|
|
(new RequestGroupMan(std::vector<std::shared_ptr<RequestGroup> >(),
|
2012-12-22 14:37:44 +00:00
|
|
|
3, option_.get()));
|
|
|
|
e_->setRequestGroupMan(rgman_);
|
2009-05-08 16:41:21 +00:00
|
|
|
}
|
|
|
|
|
2007-06-03 14:24:37 +00:00
|
|
|
void testIsSameFileBeingDownloaded();
|
2007-07-09 13:30:45 +00:00
|
|
|
void testGetInitialCommands();
|
2008-08-23 15:42:06 +00:00
|
|
|
void testLoadServerStat();
|
|
|
|
void testSaveServerStat();
|
2009-12-21 15:17:34 +00:00
|
|
|
void testChangeReservedGroupPosition();
|
2012-12-22 14:37:44 +00:00
|
|
|
void testFillRequestGroupFromReserver();
|
2012-12-22 10:29:27 +00:00
|
|
|
void testFillRequestGroupFromReserver_uriParser();
|
|
|
|
void testInsertReservedGroup();
|
2013-02-25 12:42:54 +00:00
|
|
|
void testAddDownloadResult();
|
2007-06-03 14:24:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupManTest );
|
|
|
|
|
|
|
|
void RequestGroupManTest::testIsSameFileBeingDownloaded()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup> rg1(new RequestGroup(GroupId::create(),
|
2012-12-16 07:00:18 +00:00
|
|
|
util::copy(option_)));
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup> rg2(new RequestGroup(GroupId::create(),
|
2012-12-16 07:00:18 +00:00
|
|
|
util::copy(option_)));
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx1
|
2009-06-28 10:37:15 +00:00
|
|
|
(new DownloadContext(0, 0, "aria2.tar.bz2"));
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx2
|
2009-06-28 10:37:15 +00:00
|
|
|
(new DownloadContext(0, 0, "aria2.tar.bz2"));
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
rg1->setDownloadContext(dctx1);
|
|
|
|
rg2->setDownloadContext(dctx2);
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
RequestGroupMan gm(std::vector<std::shared_ptr<RequestGroup> >(), 1,
|
2010-06-21 13:51:56 +00:00
|
|
|
option_.get());
|
2007-06-03 14:24:37 +00:00
|
|
|
|
2009-10-31 09:53:23 +00:00
|
|
|
gm.addRequestGroup(rg1);
|
|
|
|
gm.addRequestGroup(rg2);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2007-06-03 14:24:37 +00:00
|
|
|
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
dctx2->getFirstFileEntry()->setPath("aria2.tar.gz");
|
2007-06-03 14:24:37 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!gm.isSameFileBeingDownloaded(rg1.get()));
|
|
|
|
|
|
|
|
}
|
2007-07-09 13:30:45 +00:00
|
|
|
|
|
|
|
void RequestGroupManTest::testGetInitialCommands()
|
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
// TODO implement later
|
2007-07-09 13:30:45 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-08-23 15:42:06 +00:00
|
|
|
void RequestGroupManTest::testSaveServerStat()
|
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
RequestGroupMan rm
|
2013-06-21 16:10:38 +00:00
|
|
|
(std::vector<std::shared_ptr<RequestGroup> >(),0,option_.get());
|
|
|
|
std::shared_ptr<ServerStat> ss_localhost(new ServerStat("localhost", "http"));
|
2008-08-23 15:42:06 +00:00
|
|
|
rm.addServerStat(ss_localhost);
|
2010-12-02 13:38:36 +00:00
|
|
|
File f(A2_TEST_OUT_DIR"/aria2_RequestGroupManTest_testSaveServerStat");
|
2008-08-23 15:42:06 +00:00
|
|
|
if(f.exists()) {
|
|
|
|
f.remove();
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(rm.saveServerStat(f.getPath()));
|
|
|
|
CPPUNIT_ASSERT(f.isFile());
|
|
|
|
|
|
|
|
f.remove();
|
|
|
|
CPPUNIT_ASSERT(f.mkdirs());
|
|
|
|
CPPUNIT_ASSERT(!rm.saveServerStat(f.getPath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupManTest::testLoadServerStat()
|
|
|
|
{
|
2010-12-02 13:38:36 +00:00
|
|
|
File f(A2_TEST_OUT_DIR"/aria2_RequestGroupManTest_testLoadServerStat");
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ofstream o(f.getPath().c_str(), std::ios::binary);
|
2008-08-23 15:42:06 +00:00
|
|
|
o << "host=localhost, protocol=http, dl_speed=0, last_updated=1219505257,"
|
|
|
|
<< "status=OK";
|
|
|
|
o.close();
|
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
RequestGroupMan rm
|
2013-06-21 16:10:38 +00:00
|
|
|
(std::vector<std::shared_ptr<RequestGroup> >(),0,option_.get());
|
2009-01-06 13:13:42 +00:00
|
|
|
std::cerr << "testLoadServerStat" << std::endl;
|
2008-08-23 15:42:06 +00:00
|
|
|
CPPUNIT_ASSERT(rm.loadServerStat(f.getPath()));
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<ServerStat> ss_localhost = rm.findServerStat("localhost",
|
2010-01-05 16:01:46 +00:00
|
|
|
"http");
|
2010-11-12 12:48:48 +00:00
|
|
|
CPPUNIT_ASSERT(ss_localhost);
|
2008-08-23 15:42:06 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), ss_localhost->getHostname());
|
|
|
|
}
|
|
|
|
|
2009-12-21 15:17:34 +00:00
|
|
|
void RequestGroupManTest::testChangeReservedGroupPosition()
|
|
|
|
{
|
2013-06-24 12:46:42 +00:00
|
|
|
std::vector<std::shared_ptr<RequestGroup>> gs {
|
|
|
|
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_)),
|
|
|
|
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_)),
|
|
|
|
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_)),
|
|
|
|
std::make_shared<RequestGroup>(GroupId::create(), util::copy(option_))
|
2009-12-21 15:17:34 +00:00
|
|
|
};
|
2013-06-24 12:46:42 +00:00
|
|
|
RequestGroupMan rm(gs, 0, option_.get());
|
2009-12-21 15:17:34 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)0, rm.changeReservedGroupPosition(gs[0]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
0, OFFSET_MODE_SET));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)1, rm.changeReservedGroupPosition(gs[0]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
1, OFFSET_MODE_SET));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)3, rm.changeReservedGroupPosition(gs[0]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
10,OFFSET_MODE_SET));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)0, rm.changeReservedGroupPosition(gs[0]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
-10, OFFSET_MODE_SET));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
0, OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)2, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
1, OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
-1,OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)0, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
-10, OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
1, OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)3, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
10, OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
-2,OFFSET_MODE_CUR));
|
2009-12-21 15:17:34 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)3, rm.changeReservedGroupPosition(gs[3]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
0, OFFSET_MODE_END));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)2, rm.changeReservedGroupPosition(gs[3]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
-1,OFFSET_MODE_END));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)0, rm.changeReservedGroupPosition(gs[3]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
-10, OFFSET_MODE_END));
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
2012-12-16 07:00:18 +00:00
|
|
|
((size_t)3, rm.changeReservedGroupPosition(gs[3]->getGID(),
|
2013-05-14 15:50:55 +00:00
|
|
|
10, OFFSET_MODE_END));
|
2009-12-21 15:17:34 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, rm.getReservedGroups().size());
|
|
|
|
|
|
|
|
try {
|
2012-12-16 07:00:18 +00:00
|
|
|
rm.changeReservedGroupPosition(GroupId::create()->getNumericId(),
|
2013-05-14 15:50:55 +00:00
|
|
|
0, OFFSET_MODE_CUR);
|
2009-12-21 15:17:34 +00:00
|
|
|
CPPUNIT_FAIL("exception must be thrown.");
|
|
|
|
} catch(RecoverableException& e) {
|
|
|
|
// success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-22 14:37:44 +00:00
|
|
|
void RequestGroupManTest::testFillRequestGroupFromReserver()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup> rgs[] = {
|
2012-12-22 14:37:44 +00:00
|
|
|
createRequestGroup(0, 0, "foo1", "http://host/foo1", util::copy(option_)),
|
|
|
|
createRequestGroup(0, 0, "foo2", "http://host/foo2", util::copy(option_)),
|
|
|
|
createRequestGroup(0, 0, "foo3", "http://host/foo3", util::copy(option_)),
|
|
|
|
// Intentionally same path/URI for first RequestGroup and set
|
|
|
|
// length explicitly to do duplicate filename check.
|
|
|
|
createRequestGroup(0, 10, "foo1", "http://host/foo1", util::copy(option_)),
|
|
|
|
createRequestGroup(0, 0, "foo4", "http://host/foo4", util::copy(option_)),
|
|
|
|
createRequestGroup(0, 0, "foo5", "http://host/foo5", util::copy(option_))
|
|
|
|
};
|
|
|
|
rgs[1]->setPauseRequested(true);
|
2013-06-24 12:46:42 +00:00
|
|
|
for(const auto& i : rgs) {
|
|
|
|
rgman_->addReservedGroup(i);
|
2012-12-22 14:37:44 +00:00
|
|
|
}
|
|
|
|
rgman_->fillRequestGroupFromReserver(e_.get());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, rgman_->getReservedGroups().size());
|
|
|
|
}
|
|
|
|
|
2012-12-22 10:29:27 +00:00
|
|
|
void RequestGroupManTest::testFillRequestGroupFromReserver_uriParser()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup> rgs[] = {
|
2012-12-22 10:29:27 +00:00
|
|
|
createRequestGroup(0, 0, "mem1", "http://mem1", util::copy(option_)),
|
|
|
|
createRequestGroup(0, 0, "mem2", "http://mem2", util::copy(option_)),
|
|
|
|
};
|
|
|
|
rgs[0]->setPauseRequested(true);
|
2013-06-24 12:46:42 +00:00
|
|
|
for(const auto& i : rgs) {
|
|
|
|
rgman_->addReservedGroup(i);
|
2012-12-22 10:29:27 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<UriListParser> flp
|
2012-12-22 10:29:27 +00:00
|
|
|
(new UriListParser(A2_TEST_DIR"/filelist2.txt"));
|
|
|
|
rgman_->setUriListParser(flp);
|
|
|
|
|
|
|
|
rgman_->fillRequestGroupFromReserver(e_.get());
|
|
|
|
|
2013-03-01 14:13:24 +00:00
|
|
|
RequestGroupList::const_iterator itr;
|
2012-12-22 10:29:27 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, rgman_->getReservedGroups().size());
|
|
|
|
itr = rgman_->getReservedGroups().begin();
|
2013-03-01 14:13:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(rgs[0]->getGID(), (*itr)->getGID());
|
2012-12-22 10:29:27 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, rgman_->getRequestGroups().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupManTest::testInsertReservedGroup()
|
|
|
|
{
|
2013-06-24 12:46:42 +00:00
|
|
|
std::vector<std::shared_ptr<RequestGroup>> rgs1 {
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
|
2012-12-22 10:29:27 +00:00
|
|
|
util::copy(option_))),
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
|
2012-12-22 10:29:27 +00:00
|
|
|
util::copy(option_)))
|
|
|
|
};
|
2013-06-24 12:46:42 +00:00
|
|
|
std::vector<std::shared_ptr<RequestGroup>> rgs2 {
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
|
2012-12-22 10:29:27 +00:00
|
|
|
util::copy(option_))),
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<RequestGroup>(new RequestGroup(GroupId::create(),
|
2012-12-22 10:29:27 +00:00
|
|
|
util::copy(option_)))
|
|
|
|
};
|
2013-06-24 12:46:42 +00:00
|
|
|
rgman_->insertReservedGroup(0, rgs1);
|
2012-12-22 10:29:27 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, rgman_->getReservedGroups().size());
|
2013-03-01 14:13:24 +00:00
|
|
|
RequestGroupList::const_iterator itr;
|
2012-12-22 10:29:27 +00:00
|
|
|
itr = rgman_->getReservedGroups().begin();
|
2013-03-01 14:13:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(rgs1[0]->getGID(), (*itr++)->getGID());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rgs1[1]->getGID(), (*itr++)->getGID());
|
2012-12-22 10:29:27 +00:00
|
|
|
|
2013-06-24 12:46:42 +00:00
|
|
|
rgman_->insertReservedGroup(1, rgs2);
|
2012-12-22 10:29:27 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, rgman_->getReservedGroups().size());
|
|
|
|
itr = rgman_->getReservedGroups().begin();
|
|
|
|
++itr;
|
2013-03-01 14:13:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(rgs2[0]->getGID(), (*itr++)->getGID());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(rgs2[1]->getGID(), (*itr++)->getGID());
|
2012-12-22 10:29:27 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 12:42:54 +00:00
|
|
|
void RequestGroupManTest::testAddDownloadResult()
|
|
|
|
{
|
|
|
|
std::string uri = "http://example.org";
|
|
|
|
rgman_->setMaxDownloadResult(3);
|
|
|
|
rgman_->addDownloadResult(createDownloadResult(error_code::TIME_OUT, uri));
|
|
|
|
rgman_->addDownloadResult(createDownloadResult(error_code::FINISHED, uri));
|
|
|
|
rgman_->addDownloadResult(createDownloadResult(error_code::FINISHED, uri));
|
|
|
|
rgman_->addDownloadResult(createDownloadResult(error_code::FINISHED, uri));
|
|
|
|
rgman_->addDownloadResult(createDownloadResult(error_code::FINISHED, uri));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(error_code::TIME_OUT,
|
|
|
|
rgman_->getDownloadStat().getLastErrorResult());
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|