ServerStatTest.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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("host=localhost, protocol=http, dl_speed=90000,"
  45. " sc_avg_speed=101, mc_avg_speed=102,"
  46. " last_updated=1000, counter=5, status=OK"),
  47. localhost_http.toString());
  48. ServerStat localhost_ftp("localhost", "ftp");
  49. localhost_ftp.setDownloadSpeed(10000);
  50. localhost_ftp.setLastUpdated(Time(1210000000));
  51. localhost_ftp.setStatus("ERROR");
  52. CPPUNIT_ASSERT_EQUAL(
  53. std::string("host=localhost, protocol=ftp, dl_speed=10000,"
  54. " sc_avg_speed=0, mc_avg_speed=0,"
  55. " last_updated=1210000000, counter=0, status=ERROR"),
  56. localhost_ftp.toString());
  57. }
  58. } // namespace aria2