File: ServerStatTest.cc

package info (click to toggle)
aria2 1.37.0%2Bdebian-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,128 kB
  • sloc: cpp: 115,006; ansic: 9,140; makefile: 1,466; ruby: 475; python: 373; sh: 260; xml: 176
file content (74 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download | duplicates (6)
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
#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(testToString);
  CPPUNIT_TEST_SUITE_END();

public:
  void setUp() {}

  void tearDown() {}

  void testSetStatus();
  void testToString();
};

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::A2_ERROR, ss.getStatus());
  // See undefined status string will not change current status.
  ss.setStatus("__BADSTATUS");
  CPPUNIT_ASSERT_EQUAL(ServerStat::A2_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::testToString()
{
  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);

  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"),
      localhost_http.toString());

  ServerStat localhost_ftp("localhost", "ftp");
  localhost_ftp.setDownloadSpeed(10000);
  localhost_ftp.setLastUpdated(Time(1210000000));
  localhost_ftp.setStatus("ERROR");

  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"),
      localhost_ftp.toString());
}

} // namespace aria2