|
@@ -15,6 +15,7 @@
|
|
|
#include "XmlRpcRequest.h"
|
|
|
#include "XmlRpcResponse.h"
|
|
|
#include "prefs.h"
|
|
|
+#include "TestUtil.h"
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
@@ -24,6 +25,8 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
|
|
|
CPPUNIT_TEST(testAddUri);
|
|
|
+ CPPUNIT_TEST(testAddTorrent);
|
|
|
+ CPPUNIT_TEST(testAddMetalink);
|
|
|
CPPUNIT_TEST(testChangeOption);
|
|
|
CPPUNIT_TEST(testChangeGlobalOption);
|
|
|
CPPUNIT_TEST(testNoSuchMethod);
|
|
@@ -36,6 +39,7 @@ public:
|
|
|
{
|
|
|
RequestGroup::resetGIDCounter();
|
|
|
_option.reset(new Option());
|
|
|
+ _option->put(PREF_DIR, "/tmp");
|
|
|
_e.reset(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
|
|
_e->option = _option.get();
|
|
|
_e->_requestGroupMan.reset
|
|
@@ -46,6 +50,8 @@ public:
|
|
|
void tearDown() {}
|
|
|
|
|
|
void testAddUri();
|
|
|
+ void testAddTorrent();
|
|
|
+ void testAddMetalink();
|
|
|
void testChangeOption();
|
|
|
void testChangeGlobalOption();
|
|
|
void testNoSuchMethod();
|
|
@@ -69,6 +75,72 @@ void XmlRpcMethodTest::testAddUri()
|
|
|
rgs.front()->getRemainingUris().front());
|
|
|
}
|
|
|
|
|
|
+void XmlRpcMethodTest::testAddTorrent()
|
|
|
+{
|
|
|
+ AddTorrentXmlRpcMethod m;
|
|
|
+ XmlRpcRequest req("aria2.addTorrent", BDE::list());
|
|
|
+ req._params << BDE(readFile("single.torrent"));
|
|
|
+ BDE uris = BDE::list();
|
|
|
+ uris << BDE("http://localhost/aria2-0.8.2.tar.bz2");
|
|
|
+ req._params << uris;
|
|
|
+ {
|
|
|
+ XmlRpcResponse res = m.execute(req, _e.get());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(0, res._code);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), res._param.s());
|
|
|
+
|
|
|
+ SharedHandle<RequestGroup> group = _e->_requestGroupMan->findReservedGroup(1);
|
|
|
+ CPPUNIT_ASSERT(!group.isNull());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-0.8.2.tar.bz2"),
|
|
|
+ group->getFilePath());
|
|
|
+ CPPUNIT_ASSERT_EQUAL((size_t)1, group->getRemainingUris().size());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2-0.8.2.tar.bz2"),
|
|
|
+ group->getRemainingUris()[0]);
|
|
|
+ }
|
|
|
+ // 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/aria2-0.8.2.tar.bz2"),
|
|
|
+ _e->_requestGroupMan->findReservedGroup(2)->getFilePath());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void XmlRpcMethodTest::testAddMetalink()
|
|
|
+{
|
|
|
+ AddMetalinkXmlRpcMethod m;
|
|
|
+ XmlRpcRequest req("aria2.addMetalink", BDE::list());
|
|
|
+ req._params << BDE(readFile("2files.metalink"));
|
|
|
+ {
|
|
|
+ XmlRpcResponse res = m.execute(req, _e.get());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(0, res._code);
|
|
|
+ CPPUNIT_ASSERT_EQUAL((size_t)2, res._param.size());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), res._param[0].s());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("2"), res._param[1].s());
|
|
|
+
|
|
|
+ SharedHandle<RequestGroup> tar = _e->_requestGroupMan->findReservedGroup(1);
|
|
|
+ CPPUNIT_ASSERT(!tar.isNull());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-5.0.0.tar.bz2"),
|
|
|
+ tar->getFilePath());
|
|
|
+ SharedHandle<RequestGroup> deb = _e->_requestGroupMan->findReservedGroup(2);
|
|
|
+ CPPUNIT_ASSERT(!deb.isNull());
|
|
|
+ CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-5.0.0.deb"),
|
|
|
+ deb->getFilePath());
|
|
|
+ }
|
|
|
+ // 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/aria2-5.0.0.tar.bz2"),
|
|
|
+ _e->_requestGroupMan->findReservedGroup(3)->getFilePath());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void XmlRpcMethodTest::testChangeOption()
|
|
|
{
|
|
|
SharedHandle<RequestGroup> group
|