mirror of https://github.com/aria2/aria2
2009-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added unit tests. * test/XmlRpcMethodTest.ccpull/1/head
parent
4259514395
commit
fbb2613379
|
@ -1,3 +1,8 @@
|
||||||
|
2009-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added unit tests.
|
||||||
|
* test/XmlRpcMethodTest.cc
|
||||||
|
|
||||||
2009-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Made exception message more verbose.
|
Made exception message more verbose.
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "XmlRpcResponse.h"
|
#include "XmlRpcResponse.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "TestUtil.h"
|
#include "TestUtil.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -25,10 +26,21 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
|
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
|
||||||
CPPUNIT_TEST(testAddUri);
|
CPPUNIT_TEST(testAddUri);
|
||||||
|
CPPUNIT_TEST(testAddUri_withoutUri);
|
||||||
|
CPPUNIT_TEST(testAddUri_notUri);
|
||||||
|
CPPUNIT_TEST(testAddUri_withBadOption);
|
||||||
CPPUNIT_TEST(testAddTorrent);
|
CPPUNIT_TEST(testAddTorrent);
|
||||||
|
CPPUNIT_TEST(testAddTorrent_withoutTorrent);
|
||||||
|
CPPUNIT_TEST(testAddTorrent_notBase64Torrent);
|
||||||
CPPUNIT_TEST(testAddMetalink);
|
CPPUNIT_TEST(testAddMetalink);
|
||||||
|
CPPUNIT_TEST(testAddMetalink_withoutMetalink);
|
||||||
|
CPPUNIT_TEST(testAddMetalink_notBase64Metalink);
|
||||||
CPPUNIT_TEST(testChangeOption);
|
CPPUNIT_TEST(testChangeOption);
|
||||||
|
CPPUNIT_TEST(testChangeOption_withBadOption);
|
||||||
|
CPPUNIT_TEST(testChangeOption_withoutGid);
|
||||||
CPPUNIT_TEST(testChangeGlobalOption);
|
CPPUNIT_TEST(testChangeGlobalOption);
|
||||||
|
CPPUNIT_TEST(testChangeGlobalOption_withBadOption);
|
||||||
|
CPPUNIT_TEST(testTellStatus_withoutGid);
|
||||||
CPPUNIT_TEST(testNoSuchMethod);
|
CPPUNIT_TEST(testNoSuchMethod);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
@ -50,10 +62,21 @@ public:
|
||||||
void tearDown() {}
|
void tearDown() {}
|
||||||
|
|
||||||
void testAddUri();
|
void testAddUri();
|
||||||
|
void testAddUri_withoutUri();
|
||||||
|
void testAddUri_notUri();
|
||||||
|
void testAddUri_withBadOption();
|
||||||
void testAddTorrent();
|
void testAddTorrent();
|
||||||
|
void testAddTorrent_withoutTorrent();
|
||||||
|
void testAddTorrent_notBase64Torrent();
|
||||||
void testAddMetalink();
|
void testAddMetalink();
|
||||||
|
void testAddMetalink_withoutMetalink();
|
||||||
|
void testAddMetalink_notBase64Metalink();
|
||||||
void testChangeOption();
|
void testChangeOption();
|
||||||
|
void testChangeOption_withBadOption();
|
||||||
|
void testChangeOption_withoutGid();
|
||||||
void testChangeGlobalOption();
|
void testChangeGlobalOption();
|
||||||
|
void testChangeGlobalOption_withBadOption();
|
||||||
|
void testTellStatus_withoutGid();
|
||||||
void testNoSuchMethod();
|
void testNoSuchMethod();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,13 +89,57 @@ void XmlRpcMethodTest::testAddUri()
|
||||||
XmlRpcRequest req("aria2.addUri", BDE::list());
|
XmlRpcRequest req("aria2.addUri", BDE::list());
|
||||||
req._params << BDE::list();
|
req._params << BDE::list();
|
||||||
req._params[0] << BDE("http://localhost/");
|
req._params[0] << BDE("http://localhost/");
|
||||||
|
{
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
||||||
|
const std::deque<SharedHandle<RequestGroup> > rgs =
|
||||||
|
_e->_requestGroupMan->getReservedGroups();
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)1, rgs.size());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/"),
|
||||||
|
rgs.front()->getRemainingUris().front());
|
||||||
|
}
|
||||||
|
// with options
|
||||||
|
BDE opt = BDE::dict();
|
||||||
|
opt[PREF_DIR] = BDE("/sink");
|
||||||
|
req._params << opt;
|
||||||
|
{
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("/sink"),
|
||||||
|
_e->_requestGroupMan->findReservedGroup(2)->
|
||||||
|
getDownloadContext()->getDir());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testAddUri_withoutUri()
|
||||||
|
{
|
||||||
|
AddUriXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addUri", BDE::list());
|
||||||
XmlRpcResponse res = m.execute(req, _e.get());
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
const std::deque<SharedHandle<RequestGroup> > rgs =
|
}
|
||||||
_e->_requestGroupMan->getReservedGroups();
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, rgs.size());
|
void XmlRpcMethodTest::testAddUri_notUri()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/"),
|
{
|
||||||
rgs.front()->getRemainingUris().front());
|
AddUriXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addUri", BDE::list());
|
||||||
|
req._params << BDE::list();
|
||||||
|
req._params[0] << BDE("not uri");
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testAddUri_withBadOption()
|
||||||
|
{
|
||||||
|
AddUriXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addUri", BDE::list());
|
||||||
|
req._params << BDE::list();
|
||||||
|
req._params[0] << BDE("http://localhost");
|
||||||
|
BDE opt = BDE::dict();
|
||||||
|
opt[PREF_FILE_ALLOCATION] = BDE("badvalue");
|
||||||
|
req._params << opt;
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlRpcMethodTest::testAddTorrent()
|
void XmlRpcMethodTest::testAddTorrent()
|
||||||
|
@ -108,6 +175,23 @@ void XmlRpcMethodTest::testAddTorrent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testAddTorrent_withoutTorrent()
|
||||||
|
{
|
||||||
|
AddTorrentXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addTorrent", BDE::list());
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testAddTorrent_notBase64Torrent()
|
||||||
|
{
|
||||||
|
AddTorrentXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addTorrent", BDE::list());
|
||||||
|
req._params << BDE("not torrent");
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
void XmlRpcMethodTest::testAddMetalink()
|
void XmlRpcMethodTest::testAddMetalink()
|
||||||
{
|
{
|
||||||
AddMetalinkXmlRpcMethod m;
|
AddMetalinkXmlRpcMethod m;
|
||||||
|
@ -141,6 +225,23 @@ void XmlRpcMethodTest::testAddMetalink()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testAddMetalink_withoutMetalink()
|
||||||
|
{
|
||||||
|
AddMetalinkXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addMetalink", BDE::list());
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testAddMetalink_notBase64Metalink()
|
||||||
|
{
|
||||||
|
AddMetalinkXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.addMetalink", BDE::list());
|
||||||
|
req._params << BDE("not metalink");
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
void XmlRpcMethodTest::testChangeOption()
|
void XmlRpcMethodTest::testChangeOption()
|
||||||
{
|
{
|
||||||
SharedHandle<RequestGroup> group
|
SharedHandle<RequestGroup> group
|
||||||
|
@ -162,6 +263,30 @@ void XmlRpcMethodTest::testChangeOption()
|
||||||
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testChangeOption_withBadOption()
|
||||||
|
{
|
||||||
|
SharedHandle<RequestGroup> group
|
||||||
|
(new RequestGroup(_option, std::deque<std::string>()));
|
||||||
|
_e->_requestGroupMan->addReservedGroup(group);
|
||||||
|
|
||||||
|
ChangeOptionXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.changeOption", BDE::list());
|
||||||
|
req._params << BDE("1");
|
||||||
|
BDE opt = BDE::dict();
|
||||||
|
opt[PREF_MAX_DOWNLOAD_LIMIT] = BDE("badvalue");
|
||||||
|
req._params << opt;
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testChangeOption_withoutGid()
|
||||||
|
{
|
||||||
|
ChangeOptionXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.changeOption", BDE::list());
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
void XmlRpcMethodTest::testChangeGlobalOption()
|
void XmlRpcMethodTest::testChangeGlobalOption()
|
||||||
{
|
{
|
||||||
ChangeGlobalOptionXmlRpcMethod m;
|
ChangeGlobalOptionXmlRpcMethod m;
|
||||||
|
@ -179,6 +304,17 @@ void XmlRpcMethodTest::testChangeGlobalOption()
|
||||||
_e->_requestGroupMan->getMaxOverallUploadSpeedLimit());
|
_e->_requestGroupMan->getMaxOverallUploadSpeedLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testChangeGlobalOption_withBadOption()
|
||||||
|
{
|
||||||
|
ChangeGlobalOptionXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.changeGlobalOption", BDE::list());
|
||||||
|
BDE opt = BDE::dict();
|
||||||
|
opt[PREF_MAX_OVERALL_DOWNLOAD_LIMIT] = BDE("badvalue");
|
||||||
|
req._params << opt;
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
void XmlRpcMethodTest::testNoSuchMethod()
|
void XmlRpcMethodTest::testNoSuchMethod()
|
||||||
{
|
{
|
||||||
NoSuchMethodXmlRpcMethod m;
|
NoSuchMethodXmlRpcMethod m;
|
||||||
|
@ -209,6 +345,14 @@ void XmlRpcMethodTest::testNoSuchMethod()
|
||||||
res.toXml());
|
res.toXml());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlRpcMethodTest::testTellStatus_withoutGid()
|
||||||
|
{
|
||||||
|
TellStatusXmlRpcMethod m;
|
||||||
|
XmlRpcRequest req("aria2.tellStatus", BDE::list());
|
||||||
|
XmlRpcResponse res = m.execute(req, _e.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xmlrpc
|
} // namespace xmlrpc
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue