ServerStatTest.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(testOperatorOstream);
  12. CPPUNIT_TEST_SUITE_END();
  13. public:
  14. void setUp() {}
  15. void tearDown() {}
  16. void testSetStatus();
  17. void testOperatorOstream();
  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::ERROR, ss.getStatus());
  26. // See undefined status string will not change current status.
  27. ss.setStatus("__BADSTATUS");
  28. CPPUNIT_ASSERT_EQUAL(ServerStat::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::testOperatorOstream()
  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. std::stringstream ss;
  44. ss << localhost_http;
  45. CPPUNIT_ASSERT_EQUAL
  46. (std::string
  47. ("host=localhost, protocol=http, dl_speed=90000,"
  48. " sc_avg_speed=101, mc_avg_speed=102,"
  49. " last_updated=1000, counter=5, status=OK"),
  50. ss.str());
  51. ss.str("");
  52. ServerStat localhost_ftp("localhost", "ftp");
  53. localhost_ftp.setDownloadSpeed(10000);
  54. localhost_ftp.setLastUpdated(Time(1210000000));
  55. localhost_ftp.setStatus("ERROR");
  56. ss << localhost_ftp;
  57. CPPUNIT_ASSERT_EQUAL
  58. (std::string
  59. ("host=localhost, protocol=ftp, dl_speed=10000,"
  60. " sc_avg_speed=0, mc_avg_speed=0,"
  61. " last_updated=1210000000, counter=0, status=ERROR"),
  62. ss.str());
  63. }
  64. } // namespace aria2