ServerStatManTest.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "ServerStatMan.h"
  2. #include "ServerStat.h"
  3. #include "Exception.h"
  4. #include "Util.h"
  5. #include <iostream>
  6. #include <cppunit/extensions/HelperMacros.h>
  7. namespace aria2 {
  8. class ServerStatManTest:public CppUnit::TestFixture {
  9. CPPUNIT_TEST_SUITE(ServerStatManTest);
  10. CPPUNIT_TEST(testAddAndFind);
  11. CPPUNIT_TEST_SUITE_END();
  12. public:
  13. void setUp() {}
  14. void tearDown() {}
  15. void testAddAndFind();
  16. };
  17. CPPUNIT_TEST_SUITE_REGISTRATION(ServerStatManTest);
  18. void ServerStatManTest::testAddAndFind()
  19. {
  20. SharedHandle<ServerStat> localhost_http(new ServerStat("localhost", "http"));
  21. SharedHandle<ServerStat> localhost_ftp(new ServerStat("localhost", "ftp"));
  22. SharedHandle<ServerStat> mirror(new ServerStat("mirror", "http"));
  23. ServerStatMan ssm;
  24. CPPUNIT_ASSERT(ssm.add(localhost_http));
  25. CPPUNIT_ASSERT(!ssm.add(localhost_http));
  26. CPPUNIT_ASSERT(ssm.add(localhost_ftp));
  27. CPPUNIT_ASSERT(ssm.add(mirror));
  28. {
  29. SharedHandle<ServerStat> r = ssm.find("localhost", "http");
  30. CPPUNIT_ASSERT(!r.isNull());
  31. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), r->getHostname());
  32. CPPUNIT_ASSERT_EQUAL(std::string("http"), r->getProtocol());
  33. }
  34. {
  35. SharedHandle<ServerStat> r = ssm.find("mirror", "ftp");
  36. CPPUNIT_ASSERT(r.isNull());
  37. }
  38. }
  39. } // namespace aria2