ServerStatTest.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "ServerStat.h"
  2. #include <iostream>
  3. #include <sstream>
  4. #include <cppunit/extensions/HelperMacros.h>
  5. #include "Exception.h"
  6. #include "util.h"
  7. namespace aria2 {
  8. class ServerStatTest:public CppUnit::TestFixture {
  9. CPPUNIT_TEST_SUITE(ServerStatTest);
  10. CPPUNIT_TEST(testSetStatus);
  11. CPPUNIT_TEST(testToString);
  12. CPPUNIT_TEST_SUITE_END();
  13. public:
  14. void setUp() {}
  15. void tearDown() {}
  16. void testSetStatus();
  17. void testToString();
  18. };
  19. CPPUNIT_TEST_SUITE_REGISTRATION(ServerStatTest);
  20. void ServerStatTest::testSetStatus()
  21. {
  22. ServerStat ss("localhost", "http");
  23. CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
  24. ss.setStatus("ERROR");
  25. CPPUNIT_ASSERT_EQUAL(ServerStat::A2_ERROR, ss.getStatus());
  26. // See undefined status string will not change current status.
  27. ss.setStatus("__BADSTATUS");
  28. CPPUNIT_ASSERT_EQUAL(ServerStat::A2_ERROR, ss.getStatus());
  29. ss.setStatus("OK");
  30. CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
  31. // See undefined status string will not change current status.
  32. ss.setStatus("__BADSTATUS");
  33. CPPUNIT_ASSERT_EQUAL(ServerStat::OK, ss.getStatus());
  34. }
  35. void ServerStatTest::testToString()
  36. {
  37. ServerStat localhost_http("localhost", "http");
  38. localhost_http.setDownloadSpeed(90000);
  39. localhost_http.setLastUpdated(Time(1000));
  40. localhost_http.setSingleConnectionAvgSpeed(101);
  41. localhost_http.setMultiConnectionAvgSpeed(102);
  42. localhost_http.setCounter(5);
  43. CPPUNIT_ASSERT_EQUAL
  44. (std::string
  45. ("host=localhost, protocol=http, dl_speed=90000,"
  46. " sc_avg_speed=101, mc_avg_speed=102,"
  47. " last_updated=1000, counter=5, status=OK"),
  48. localhost_http.toString());
  49. ServerStat localhost_ftp("localhost", "ftp");
  50. localhost_ftp.setDownloadSpeed(10000);
  51. localhost_ftp.setLastUpdated(Time(1210000000));
  52. localhost_ftp.setStatus("ERROR");
  53. CPPUNIT_ASSERT_EQUAL
  54. (std::string
  55. ("host=localhost, protocol=ftp, dl_speed=10000,"
  56. " sc_avg_speed=0, mc_avg_speed=0,"
  57. " last_updated=1210000000, counter=0, status=ERROR"),
  58. localhost_ftp.toString());
  59. }
  60. } // namespace aria2