2007-08-28 15:48:05 +00:00
|
|
|
#include "RequestGroup.h"
|
2007-12-12 13:53:33 +00:00
|
|
|
#include "ServerHost.h"
|
|
|
|
#include "Option.h"
|
2007-08-28 15:48:05 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-08-28 15:48:05 +00:00
|
|
|
|
|
|
|
class RequestGroupTest : public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(RequestGroupTest);
|
2007-12-12 13:53:33 +00:00
|
|
|
CPPUNIT_TEST(testRegisterSearchRemove);
|
|
|
|
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
|
2007-08-28 15:48:05 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
2007-12-12 13:53:33 +00:00
|
|
|
|
|
|
|
void testRegisterSearchRemove();
|
|
|
|
void testRemoveURIWhoseHostnameIs();
|
2007-08-28 15:48:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest );
|
2007-12-12 13:53:33 +00:00
|
|
|
|
|
|
|
void RequestGroupTest::testRegisterSearchRemove()
|
|
|
|
{
|
|
|
|
Option op;
|
2008-02-08 15:53:45 +00:00
|
|
|
RequestGroup rg(&op, std::deque<std::string>());
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<ServerHost> sv1(new ServerHost(1, "localhost1"));
|
|
|
|
SharedHandle<ServerHost> sv2(new ServerHost(2, "localhost2"));
|
|
|
|
SharedHandle<ServerHost> sv3(new ServerHost(3, "localhost3"));
|
2007-12-12 13:53:33 +00:00
|
|
|
|
|
|
|
rg.registerServerHost(sv3);
|
|
|
|
rg.registerServerHost(sv1);
|
|
|
|
rg.registerServerHost(sv2);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(rg.searchServerHost(0).isNull());
|
|
|
|
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<ServerHost> sv = rg.searchServerHost(1);
|
2007-12-12 13:53:33 +00:00
|
|
|
CPPUNIT_ASSERT(!sv.isNull());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost1"), sv->getHostname());
|
2007-12-12 13:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rg.removeServerHost(1);
|
|
|
|
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<ServerHost> sv = rg.searchServerHost(1);
|
2007-12-12 13:53:33 +00:00
|
|
|
CPPUNIT_ASSERT(sv.isNull());
|
|
|
|
}
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<ServerHost> sv = rg.searchServerHost(2);
|
2007-12-12 13:53:33 +00:00
|
|
|
CPPUNIT_ASSERT(!sv.isNull());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost2"), sv->getHostname());
|
2007-12-12 13:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupTest::testRemoveURIWhoseHostnameIs()
|
|
|
|
{
|
|
|
|
const char* uris[] = { "http://localhost/aria2.zip",
|
|
|
|
"ftp://localhost/aria2.zip",
|
|
|
|
"http://mirror/aria2.zip" };
|
|
|
|
Option op;
|
2008-02-08 15:53:45 +00:00
|
|
|
RequestGroup rg(&op, std::deque<std::string>(&uris[0], &uris[3]));
|
2007-12-12 13:53:33 +00:00
|
|
|
rg.removeURIWhoseHostnameIs("localhost");
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, rg.getRemainingUris().size());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"),
|
2007-12-12 13:53:33 +00:00
|
|
|
rg.getRemainingUris()[0]);
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|