1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#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
|