2008-08-09 11:29:27 +00:00
|
|
|
#include "ServerStat.h"
|
2009-01-06 13:13:42 +00:00
|
|
|
|
2008-08-09 11:29:27 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2009-01-06 13:13:42 +00:00
|
|
|
|
2008-08-09 11:29:27 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2009-01-06 13:13:42 +00:00
|
|
|
#include "Exception.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2009-01-06 13:13:42 +00:00
|
|
|
|
2008-08-09 11:29:27 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class ServerStatTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(ServerStatTest);
|
|
|
|
CPPUNIT_TEST(testSetStatus);
|
2011-08-06 15:10:53 +00:00
|
|
|
CPPUNIT_TEST(testToString);
|
2008-08-09 11:29:27 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testSetStatus();
|
2011-08-06 15:10:53 +00:00
|
|
|
void testToString();
|
2008-08-09 11:29:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ServerStatTest);
|
|
|
|
|
|
|
|
void ServerStatTest::testSetStatus()
|
|
|
|
{
|
|
|
|
ServerStat ss("localhost", "http");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
|
|
|
|
ss.setStatus("ERROR");
|
2011-08-09 15:38:48 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::A2_ERROR, ss.getStatus());
|
2008-08-09 11:29:27 +00:00
|
|
|
// See undefined status string will not change current status.
|
|
|
|
ss.setStatus("__BADSTATUS");
|
2011-08-09 15:38:48 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::A2_ERROR, ss.getStatus());
|
2008-08-09 11:29:27 +00:00
|
|
|
ss.setStatus("OK");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
|
|
|
|
// See undefined status string will not change current status.
|
|
|
|
ss.setStatus("__BADSTATUS");
|
2012-10-01 14:52:22 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
|
2008-08-09 11:29:27 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 15:10:53 +00:00
|
|
|
void ServerStatTest::testToString()
|
2008-08-09 11:29:27 +00:00
|
|
|
{
|
|
|
|
ServerStat localhost_http("localhost", "http");
|
|
|
|
localhost_http.setDownloadSpeed(90000);
|
|
|
|
localhost_http.setLastUpdated(Time(1000));
|
2009-01-06 13:13:42 +00:00
|
|
|
localhost_http.setSingleConnectionAvgSpeed(101);
|
|
|
|
localhost_http.setMultiConnectionAvgSpeed(102);
|
|
|
|
localhost_http.setCounter(5);
|
2008-08-09 11:29:27 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string
|
2009-01-06 13:13:42 +00:00
|
|
|
("host=localhost, protocol=http, dl_speed=90000,"
|
|
|
|
" sc_avg_speed=101, mc_avg_speed=102,"
|
|
|
|
" last_updated=1000, counter=5, status=OK"),
|
2011-08-06 15:10:53 +00:00
|
|
|
localhost_http.toString());
|
2008-08-09 11:29:27 +00:00
|
|
|
|
|
|
|
ServerStat localhost_ftp("localhost", "ftp");
|
|
|
|
localhost_ftp.setDownloadSpeed(10000);
|
|
|
|
localhost_ftp.setLastUpdated(Time(1210000000));
|
|
|
|
localhost_ftp.setStatus("ERROR");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
(std::string
|
2009-01-06 13:13:42 +00:00
|
|
|
("host=localhost, protocol=ftp, dl_speed=10000,"
|
|
|
|
" sc_avg_speed=0, mc_avg_speed=0,"
|
|
|
|
" last_updated=1210000000, counter=0, status=ERROR"),
|
2011-08-06 15:10:53 +00:00
|
|
|
localhost_ftp.toString());
|
2008-08-09 11:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|