ProtocolDetectorTest.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "ProtocolDetector.h"
  2. #include "Exception.h"
  3. #include "Util.h"
  4. #include <iostream>
  5. #include <cppunit/extensions/HelperMacros.h>
  6. namespace aria2 {
  7. class ProtocolDetectorTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(ProtocolDetectorTest);
  9. CPPUNIT_TEST(testIsStreamProtocol);
  10. CPPUNIT_TEST(testGuessTorrentFile);
  11. CPPUNIT_TEST(testGuessMetalinkFile);
  12. CPPUNIT_TEST_SUITE_END();
  13. public:
  14. void setUp() {}
  15. void tearDown() {}
  16. void testIsStreamProtocol();
  17. void testGuessTorrentFile();
  18. void testGuessMetalinkFile();
  19. };
  20. CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
  21. void ProtocolDetectorTest::testIsStreamProtocol()
  22. {
  23. ProtocolDetector detector;
  24. CPPUNIT_ASSERT(detector.isStreamProtocol("http://localhost/index.html"));
  25. CPPUNIT_ASSERT(detector.isStreamProtocol("ftp://localhost/index.html"));
  26. CPPUNIT_ASSERT(!detector.isStreamProtocol("/home/web/localhost/index.html"));
  27. }
  28. void ProtocolDetectorTest::testGuessTorrentFile()
  29. {
  30. ProtocolDetector detector;
  31. CPPUNIT_ASSERT(detector.guessTorrentFile("test.torrent"));
  32. CPPUNIT_ASSERT(!detector.guessTorrentFile("http://localhost/test.torrent"));
  33. CPPUNIT_ASSERT(!detector.guessTorrentFile("test.xml"));
  34. }
  35. void ProtocolDetectorTest::testGuessMetalinkFile()
  36. {
  37. ProtocolDetector detector;
  38. CPPUNIT_ASSERT(detector.guessMetalinkFile("test.xml"));
  39. CPPUNIT_ASSERT(!detector.guessMetalinkFile("http://localhost/test.xml"));
  40. CPPUNIT_ASSERT(!detector.guessMetalinkFile("test.torrent"));
  41. }
  42. } // namespace aria2