mirror of
https://github.com/aria2/aria2.git
synced 2025-01-24 10:41:18 +00:00
0a4f43d0ed
Applied AdaptiveURISelector patch from Aurelien Lefebvre. This patch adds AdaptiveURISelector, which selects one of the bests mirrors for first and reserved connections. For supplementary ones, it returns mirrors which has not been tested yet, and if each of them already tested, returns mirrors which has to be tested again. Otherwise, it doesn't return anymore mirrors. * src/AdaptiveURISelector.cc * src/AdaptiveURISelector.h * src/FtpNegotiationCommand.cc * src/HttpResponseCommand.cc * src/Makefile.am * src/Makefile.in * src/OptionHandlerFactory.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/ServerStat.cc * src/ServerStat.h * src/ServerStatMan.cc * src/SpeedCalc.cc * src/URISelector.h * src/prefs.cc * src/prefs.h * test/RequestGroupManTest.cc * test/ServerStatManTest.cc * test/ServerStatTest.cc
86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#include "ServerStat.h"
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "Exception.h"
|
|
#include "Util.h"
|
|
|
|
namespace aria2 {
|
|
|
|
class ServerStatTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(ServerStatTest);
|
|
CPPUNIT_TEST(testSetStatus);
|
|
CPPUNIT_TEST(testOperatorOstream);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testSetStatus();
|
|
void testOperatorOstream();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ServerStatTest);
|
|
|
|
void ServerStatTest::testSetStatus()
|
|
{
|
|
ServerStat ss("localhost", "http");
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
|
|
ss.setStatus("ERROR");
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::ERROR, ss.getStatus());
|
|
// See undefined status string will not change current status.
|
|
ss.setStatus("__BADSTATUS");
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::ERROR, ss.getStatus());
|
|
ss.setStatus("OK");
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
|
|
// See undefined status string will not change current status.
|
|
ss.setStatus("__BADSTATUS");
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
|
|
}
|
|
|
|
void ServerStatTest::testOperatorOstream()
|
|
{
|
|
ServerStat localhost_http("localhost", "http");
|
|
localhost_http.setDownloadSpeed(90000);
|
|
localhost_http.setLastUpdated(Time(1000));
|
|
localhost_http.setSingleConnectionAvgSpeed(101);
|
|
localhost_http.setMultiConnectionAvgSpeed(102);
|
|
localhost_http.setCounter(5);
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << localhost_http;
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
(std::string
|
|
("host=localhost, protocol=http, dl_speed=90000,"
|
|
" sc_avg_speed=101, mc_avg_speed=102,"
|
|
" last_updated=1000, counter=5, status=OK"),
|
|
ss.str());
|
|
|
|
ss.str("");
|
|
|
|
ServerStat localhost_ftp("localhost", "ftp");
|
|
localhost_ftp.setDownloadSpeed(10000);
|
|
localhost_ftp.setLastUpdated(Time(1210000000));
|
|
localhost_ftp.setStatus("ERROR");
|
|
|
|
ss << localhost_ftp;
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
(std::string
|
|
("host=localhost, protocol=ftp, dl_speed=10000,"
|
|
" sc_avg_speed=0, mc_avg_speed=0,"
|
|
" last_updated=1210000000, counter=0, status=ERROR"),
|
|
ss.str());
|
|
|
|
}
|
|
|
|
} // namespace aria2
|