ProtocolDetectorTest.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(testGuessTorrentMagnet);
  12. CPPUNIT_TEST(testGuessMetalinkFile);
  13. CPPUNIT_TEST_SUITE_END();
  14. public:
  15. void setUp() {}
  16. void tearDown() {}
  17. void testIsStreamProtocol();
  18. void testGuessTorrentFile();
  19. void testGuessTorrentMagnet();
  20. void testGuessMetalinkFile();
  21. };
  22. CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
  23. void ProtocolDetectorTest::testIsStreamProtocol()
  24. {
  25. ProtocolDetector detector;
  26. CPPUNIT_ASSERT(detector.isStreamProtocol("http://localhost/index.html"));
  27. CPPUNIT_ASSERT(detector.isStreamProtocol("ftp://localhost/index.html"));
  28. CPPUNIT_ASSERT(!detector.isStreamProtocol("/home/web/localhost/index.html"));
  29. }
  30. void ProtocolDetectorTest::testGuessTorrentFile()
  31. {
  32. ProtocolDetector detector;
  33. CPPUNIT_ASSERT(detector.guessTorrentFile("test.torrent"));
  34. CPPUNIT_ASSERT(!detector.guessTorrentFile("http://localhost/test.torrent"));
  35. CPPUNIT_ASSERT(!detector.guessTorrentFile("test.xml"));
  36. }
  37. void ProtocolDetectorTest::testGuessTorrentMagnet()
  38. {
  39. ProtocolDetector detector;
  40. CPPUNIT_ASSERT
  41. (detector.guessTorrentMagnet
  42. ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
  43. CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?"));
  44. }
  45. void ProtocolDetectorTest::testGuessMetalinkFile()
  46. {
  47. ProtocolDetector detector;
  48. CPPUNIT_ASSERT(detector.guessMetalinkFile("test.xml"));
  49. CPPUNIT_ASSERT(!detector.guessMetalinkFile("http://localhost/test.xml"));
  50. CPPUNIT_ASSERT(!detector.guessMetalinkFile("test.torrent"));
  51. }
  52. } // namespace aria2