ProtocolDetectorTest.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "ProtocolDetector.h"
  2. #include <cppunit/extensions/HelperMacros.h>
  3. #include "Exception.h"
  4. #include "util.h"
  5. namespace aria2 {
  6. class ProtocolDetectorTest : public CppUnit::TestFixture {
  7. CPPUNIT_TEST_SUITE(ProtocolDetectorTest);
  8. CPPUNIT_TEST(testIsStreamProtocol);
  9. CPPUNIT_TEST(testGuessTorrentFile);
  10. CPPUNIT_TEST(testGuessTorrentMagnet);
  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 testGuessTorrentMagnet();
  19. void testGuessMetalinkFile();
  20. };
  21. CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
  22. void ProtocolDetectorTest::testIsStreamProtocol()
  23. {
  24. ProtocolDetector detector;
  25. CPPUNIT_ASSERT(detector.isStreamProtocol("http://localhost/index.html"));
  26. CPPUNIT_ASSERT(detector.isStreamProtocol("ftp://localhost/index.html"));
  27. CPPUNIT_ASSERT(!detector.isStreamProtocol("/home/web/localhost/index.html"));
  28. }
  29. void ProtocolDetectorTest::testGuessTorrentFile()
  30. {
  31. ProtocolDetector detector;
  32. CPPUNIT_ASSERT(detector.guessTorrentFile(A2_TEST_DIR "/test.torrent"));
  33. CPPUNIT_ASSERT(!detector.guessTorrentFile("http://localhost/test.torrent"));
  34. CPPUNIT_ASSERT(!detector.guessTorrentFile(A2_TEST_DIR "/test.xml"));
  35. }
  36. void ProtocolDetectorTest::testGuessTorrentMagnet()
  37. {
  38. ProtocolDetector detector;
  39. #ifdef ENABLE_BITTORRENT
  40. CPPUNIT_ASSERT(detector.guessTorrentMagnet(
  41. "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
  42. CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?"));
  43. #else // !ENABLE_BITTORRENT
  44. CPPUNIT_ASSERT(!detector.guessTorrentMagnet(
  45. "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"));
  46. #endif // !ENABLE_BITTORRENT
  47. }
  48. void ProtocolDetectorTest::testGuessMetalinkFile()
  49. {
  50. ProtocolDetector detector;
  51. CPPUNIT_ASSERT(detector.guessMetalinkFile(A2_TEST_DIR "/test.xml"));
  52. CPPUNIT_ASSERT(!detector.guessMetalinkFile("http://localhost/test.xml"));
  53. CPPUNIT_ASSERT(!detector.guessMetalinkFile(A2_TEST_DIR "/test.torrent"));
  54. }
  55. } // namespace aria2