mirror of https://github.com/aria2/aria2
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented ServerStatMan::save(...) function and its test case. * src/ServerStat.cc * src/ServerStat.h * src/ServerStatMan.cc * src/ServerStatMan.h * test/ServerStatManTest.ccpull/1/head
parent
70b457da01
commit
26690f692b
|
@ -1,3 +1,12 @@
|
|||
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Implemented ServerStatMan::save(...) function and its test case.
|
||||
* src/ServerStat.cc
|
||||
* src/ServerStat.h
|
||||
* src/ServerStatMan.cc
|
||||
* src/ServerStatMan.h
|
||||
* test/ServerStatManTest.cc
|
||||
|
||||
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Now aria2 uses name attribute in Metalink as local filename in
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string ServerStat::STATUS_STRING[] = {
|
||||
"OK",
|
||||
"ERROR"
|
||||
};
|
||||
|
||||
ServerStat::ServerStat(const std::string& hostname, const std::string& protocol)
|
||||
:
|
||||
_hostname(hostname),
|
||||
|
@ -56,16 +61,26 @@ const std::string& ServerStat::getProtocol() const
|
|||
return _protocol;
|
||||
}
|
||||
|
||||
Time ServerStat::getLastUpdated() const
|
||||
const Time& ServerStat::getLastUpdated() const
|
||||
{
|
||||
return _lastUpdated;
|
||||
}
|
||||
|
||||
void ServerStat::setLastUpdated(const Time& time)
|
||||
{
|
||||
_lastUpdated = time;
|
||||
}
|
||||
|
||||
unsigned int ServerStat::getDownloadSpeed() const
|
||||
{
|
||||
return _downloadSpeed;
|
||||
}
|
||||
|
||||
void ServerStat::setDownloadSpeed(unsigned int downloadSpeed)
|
||||
{
|
||||
_downloadSpeed = downloadSpeed;
|
||||
}
|
||||
|
||||
void ServerStat::updateDownloadSpeed(unsigned int downloadSpeed)
|
||||
{
|
||||
_downloadSpeed = downloadSpeed;
|
||||
|
@ -126,7 +141,8 @@ std::ostream& operator<<(std::ostream& o, const ServerStat& serverStat)
|
|||
o << "host=" << serverStat.getHostname() << ", "
|
||||
<< "protocol=" << serverStat.getProtocol() << ", "
|
||||
<< "dl_speed=" << serverStat.getDownloadSpeed() << ", "
|
||||
<< "status=" << serverStat.getStatus() << "\n";
|
||||
<< "last_updated=" << serverStat.getLastUpdated().getTime() << ", "
|
||||
<< "status=" << ServerStat::STATUS_STRING[serverStat.getStatus()];
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,10 +48,12 @@ namespace aria2 {
|
|||
class ServerStat {
|
||||
public:
|
||||
enum STATUS {
|
||||
OK,
|
||||
OK = 0,
|
||||
ERROR
|
||||
};
|
||||
|
||||
static const std::string STATUS_STRING[];
|
||||
|
||||
ServerStat(const std::string& hostname, const std::string& protocol);
|
||||
|
||||
~ServerStat();
|
||||
|
@ -60,7 +62,7 @@ public:
|
|||
|
||||
const std::string& getProtocol() const;
|
||||
|
||||
Time getLastUpdated() const;
|
||||
const Time& getLastUpdated() const;
|
||||
|
||||
void setLastUpdated(const Time& time);
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "ServerStat.h"
|
||||
#include <algorithm>
|
||||
#include <ostream>
|
||||
#include <iterator>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -70,14 +71,10 @@ bool ServerStatMan::add(const SharedHandle<ServerStat>& serverStat)
|
|||
}
|
||||
}
|
||||
|
||||
//bool save(const std::string& filepath) const;
|
||||
|
||||
void ServerStatMan::print(std::ostream& o) const
|
||||
void ServerStatMan::save(std::ostream& out) const
|
||||
{
|
||||
for(std::deque<SharedHandle<ServerStat> >::const_iterator i =
|
||||
_serverStats.begin(); i != _serverStats.end(); ++i) {
|
||||
o << *i;
|
||||
}
|
||||
std::copy(_serverStats.begin(), _serverStats.end(),
|
||||
std::ostream_iterator<SharedHandle<ServerStat> >(out, "\n"));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -58,8 +58,6 @@ public:
|
|||
void load(std::istream& in);
|
||||
|
||||
void save(std::ostream& out) const;
|
||||
|
||||
void print(std::ostream& o) const;
|
||||
private:
|
||||
std::deque<SharedHandle<ServerStat> > _serverStats;
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Exception.h"
|
||||
#include "Util.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
@ -11,6 +12,7 @@ class ServerStatManTest:public CppUnit::TestFixture {
|
|||
|
||||
CPPUNIT_TEST_SUITE(ServerStatManTest);
|
||||
CPPUNIT_TEST(testAddAndFind);
|
||||
CPPUNIT_TEST(testSave);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
@ -18,6 +20,8 @@ public:
|
|||
void tearDown() {}
|
||||
|
||||
void testAddAndFind();
|
||||
|
||||
void testSave();
|
||||
};
|
||||
|
||||
|
||||
|
@ -47,4 +51,33 @@ void ServerStatManTest::testAddAndFind()
|
|||
}
|
||||
}
|
||||
|
||||
void ServerStatManTest::testSave()
|
||||
{
|
||||
SharedHandle<ServerStat> localhost_http(new ServerStat("localhost", "http"));
|
||||
localhost_http->setDownloadSpeed(25000);
|
||||
localhost_http->setLastUpdated(Time(1210000000));
|
||||
SharedHandle<ServerStat> localhost_ftp(new ServerStat("localhost", "ftp"));
|
||||
localhost_ftp->setDownloadSpeed(30000);
|
||||
localhost_ftp->setLastUpdated(Time(1210000001));
|
||||
SharedHandle<ServerStat> mirror(new ServerStat("mirror", "http"));
|
||||
mirror->setDownloadSpeed(0);
|
||||
mirror->setError();
|
||||
mirror->setLastUpdated(Time(1210000002));
|
||||
|
||||
ServerStatMan ssm;
|
||||
CPPUNIT_ASSERT(ssm.add(localhost_http));
|
||||
CPPUNIT_ASSERT(ssm.add(localhost_ftp));
|
||||
CPPUNIT_ASSERT(ssm.add(mirror));
|
||||
|
||||
std::stringstream ss;
|
||||
ssm.save(ss);
|
||||
std::string out = ss.str();
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string
|
||||
("host=localhost, protocol=ftp, dl_speed=30000, last_updated=1210000001, status=OK\n"
|
||||
"host=localhost, protocol=http, dl_speed=25000, last_updated=1210000000, status=OK\n"
|
||||
"host=mirror, protocol=http, dl_speed=0, last_updated=1210000002, status=ERROR\n"),
|
||||
out);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue