aria2/test/XmlRpcMethodTest.cc

99 lines
2.4 KiB
C++
Raw Normal View History

#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"
#include "XmlRpcResponse.h"
namespace aria2 {
namespace xmlrpc {
class XmlRpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
CPPUNIT_TEST(testAddUri);
CPPUNIT_TEST(testNoSuchMethod);
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() {}
void testAddUri();
void testNoSuchMethod();
};
CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcMethodTest);
void XmlRpcMethodTest::testAddUri()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req("aria2.addUri", BDE::list());
req._params << BDE::list();
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());
}
void XmlRpcMethodTest::testNoSuchMethod()
{
NoSuchMethodXmlRpcMethod m;
XmlRpcRequest req("make.hamburger", BDE::none);
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());
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>"),
res.toXml());
}
} // namespace xmlrpc
} // namespace aria2