2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Throw an exception if position is less than 0.
	* src/XmlRpcMethodImpl.cc
	* test/XmlRpcMethodTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-06-14 11:29:46 +00:00
parent daf0c5ee73
commit a28f19befb
3 changed files with 26 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Throw an exception if position is less than 0.
* src/XmlRpcMethodImpl.cc
* test/XmlRpcMethodTest.cc
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use writeFilePath() in ConsoleStatCalc.cc Use writeFilePath() in ConsoleStatCalc.cc

View File

@ -102,8 +102,12 @@ static void getPosParam(const BDE& params, size_t posParamIndex,
bool& posGiven, size_t& pos) bool& posGiven, size_t& pos)
{ {
if(params.size() > posParamIndex && params[posParamIndex].isInteger()) { if(params.size() > posParamIndex && params[posParamIndex].isInteger()) {
if(params[posParamIndex].i() >= 0) {
pos = params[posParamIndex].i(); pos = params[posParamIndex].i();
posGiven = true; posGiven = true;
} else {
throw DL_ABORT_EX("Position must be greater than or equal to 0.");
}
} else { } else {
posGiven = false; posGiven = false;
} }

View File

@ -30,6 +30,7 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testAddUri_notUri); CPPUNIT_TEST(testAddUri_notUri);
CPPUNIT_TEST(testAddUri_withBadOption); CPPUNIT_TEST(testAddUri_withBadOption);
CPPUNIT_TEST(testAddUri_withPosition); CPPUNIT_TEST(testAddUri_withPosition);
CPPUNIT_TEST(testAddUri_withBadPosition);
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
CPPUNIT_TEST(testAddTorrent); CPPUNIT_TEST(testAddTorrent);
CPPUNIT_TEST(testAddTorrent_withoutTorrent); CPPUNIT_TEST(testAddTorrent_withoutTorrent);
@ -73,6 +74,7 @@ public:
void testAddUri_notUri(); void testAddUri_notUri();
void testAddUri_withBadOption(); void testAddUri_withBadOption();
void testAddUri_withPosition(); void testAddUri_withPosition();
void testAddUri_withBadPosition();
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
void testAddTorrent(); void testAddTorrent();
void testAddTorrent_withoutTorrent(); void testAddTorrent_withoutTorrent();
@ -178,6 +180,18 @@ void XmlRpcMethodTest::testAddUri_withPosition()
CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri); CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri);
} }
void XmlRpcMethodTest::testAddUri_withBadPosition()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req("aria2.addUri", BDE::list());
req._params << BDE::list();
req._params[0] << BDE("http://localhost/");
req._params << BDE::dict();
req._params << BDE((int64_t)-1);
XmlRpcResponse res = m.execute(req, _e.get());
CPPUNIT_ASSERT_EQUAL(1, res._code);
}
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
void XmlRpcMethodTest::testAddTorrent() void XmlRpcMethodTest::testAddTorrent()
{ {