2009-05-08 07:58:50 +00:00
|
|
|
#include "XmlRpcMethod.h"
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include "DownloadEngine.h"
|
|
|
|
#include "SelectEventPoll.h"
|
|
|
|
#include "Option.h"
|
|
|
|
#include "RequestGroupMan.h"
|
|
|
|
#include "ServerStatMan.h"
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "XmlRpcMethodImpl.h"
|
|
|
|
#include "BDE.h"
|
|
|
|
#include "OptionParser.h"
|
|
|
|
#include "OptionHandler.h"
|
|
|
|
#include "XmlRpcRequest.h"
|
2009-05-14 12:59:52 +00:00
|
|
|
#include "XmlRpcResponse.h"
|
2009-05-08 07:58:50 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
namespace xmlrpc {
|
|
|
|
|
|
|
|
class XmlRpcMethodTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
|
2009-05-10 14:51:20 +00:00
|
|
|
CPPUNIT_TEST(testAddUri);
|
2009-05-09 04:55:53 +00:00
|
|
|
CPPUNIT_TEST(testNoSuchMethod);
|
2009-05-08 07:58:50 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
SharedHandle<DownloadEngine> _e;
|
|
|
|
SharedHandle<Option> _option;
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
_option.reset(new Option());
|
|
|
|
_e.reset(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
|
|
|
_e->option = _option.get();
|
|
|
|
_e->_requestGroupMan.reset
|
|
|
|
(new RequestGroupMan(std::deque<SharedHandle<RequestGroup> >(),
|
|
|
|
1, _option.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
2009-05-10 14:51:20 +00:00
|
|
|
void testAddUri();
|
2009-05-09 04:55:53 +00:00
|
|
|
void testNoSuchMethod();
|
2009-05-08 07:58:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcMethodTest);
|
|
|
|
|
2009-05-10 14:51:20 +00:00
|
|
|
void XmlRpcMethodTest::testAddUri()
|
2009-05-08 07:58:50 +00:00
|
|
|
{
|
2009-05-10 14:51:20 +00:00
|
|
|
AddUriXmlRpcMethod m;
|
|
|
|
XmlRpcRequest req("aria2.addUri", BDE::list());
|
2009-05-08 07:58:50 +00:00
|
|
|
req._params << BDE::list();
|
|
|
|
req._params[0] << BDE("http://localhost/");
|
2009-05-14 12:59:52 +00:00
|
|
|
XmlRpcResponse res = m.execute(req, _e.get());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, res._code);
|
2009-05-08 07:58:50 +00:00
|
|
|
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());
|
2009-05-09 04:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XmlRpcMethodTest::testNoSuchMethod()
|
|
|
|
{
|
|
|
|
NoSuchMethodXmlRpcMethod m;
|
|
|
|
XmlRpcRequest req("make.hamburger", BDE::none);
|
2009-05-14 12:59:52 +00:00
|
|
|
XmlRpcResponse res = m.execute(req, 0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("No such method: make.hamburger"),
|
|
|
|
res._param["faultString"].s());
|
2009-05-09 04:55:53 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string("<?xml version=\"1.0\"?>"
|
|
|
|
"<methodResponse>"
|
|
|
|
"<fault>"
|
|
|
|
"<value>"
|
|
|
|
"<struct>"
|
|
|
|
"<member>"
|
|
|
|
"<name>faultCode</name><value><int>1</int></value>"
|
|
|
|
"</member>"
|
|
|
|
"<member>"
|
|
|
|
"<name>faultString</name>"
|
|
|
|
"<value>"
|
|
|
|
"<string>No such method: make.hamburger</string>"
|
|
|
|
"</value>"
|
|
|
|
"</member>"
|
|
|
|
"</struct>"
|
|
|
|
"</value>"
|
|
|
|
"</fault>"
|
|
|
|
"</methodResponse>"),
|
2009-05-14 12:59:52 +00:00
|
|
|
res.toXml());
|
2009-05-08 07:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xmlrpc
|
|
|
|
|
|
|
|
} // namespace aria2
|