2009-12-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added changePosition XML-RPC method. It takes 3 parameters: gid,
	pos and how.  This method changes the position of download denoted
	by gid.  If how is POS_SET, it moves the download to a position
	relative to the beginning of the queue.  If how is POS_CUR, it
	moves the download to a position relative to the current
	position. If how is POS_END, it moves the download to a position
	relative to the end of the queue. If the destination position is
	less than 0 or beyond the end of the queue, it moves the download
	to the beginning or the end of the queue respectively.  Returns
	the destination position.
	* src/RequestGroupMan.cc
	* src/RequestGroupMan.h
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* test/RequestGroupManTest.cc
	* test/XmlRpcMethodTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2009-12-21 15:17:34 +00:00
parent d78b2721a5
commit dd98c64161
8 changed files with 210 additions and 0 deletions

View file

@ -13,6 +13,7 @@
#include "ServerStatMan.h"
#include "ServerStat.h"
#include "File.h"
#include "array_fun.h"
namespace aria2 {
@ -23,12 +24,14 @@ class RequestGroupManTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testGetInitialCommands);
CPPUNIT_TEST(testLoadServerStat);
CPPUNIT_TEST(testSaveServerStat);
CPPUNIT_TEST(testChangeReservedGroupPosition);
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<Option> _option;
public:
void setUp()
{
RequestGroup::resetGIDCounter();
_option.reset(new Option());
}
@ -36,6 +39,7 @@ public:
void testGetInitialCommands();
void testLoadServerStat();
void testSaveServerStat();
void testChangeReservedGroupPosition();
};
@ -107,4 +111,58 @@ void RequestGroupManTest::testLoadServerStat()
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), ss_localhost->getHostname());
}
void RequestGroupManTest::testChangeReservedGroupPosition()
{
SharedHandle<RequestGroup> gs[] = {
SharedHandle<RequestGroup>(new RequestGroup(_option)),
SharedHandle<RequestGroup>(new RequestGroup(_option)),
SharedHandle<RequestGroup>(new RequestGroup(_option)),
SharedHandle<RequestGroup>(new RequestGroup(_option))
};
std::deque<SharedHandle<RequestGroup> > groups(&gs[0], &gs[arrayLength(gs)]);
RequestGroupMan rm(groups, 0, _option.get());
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(1, 0, RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(1, 1, RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(1, 10,RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(1,-10,RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, 0, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)2, rm.changeReservedGroupPosition(2, 1, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, -1,RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(2,-10,RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, 1, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(2, 10,RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, -2,RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(4, 0, RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL
((size_t)2, rm.changeReservedGroupPosition(4, -1,RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(4,-10,RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(4, 10,RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL((size_t)4, rm.getReservedGroups().size());
try {
rm.changeReservedGroupPosition(5, 0, RequestGroupMan::POS_CUR);
CPPUNIT_FAIL("exception must be thrown.");
} catch(RecoverableException& e) {
// success
}
}
} // namespace aria2