DownloadHandlerFactoryTest.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "DownloadHandlerFactory.h"
  2. #include "RequestGroup.h"
  3. #include "Option.h"
  4. #include "SingleFileDownloadContext.h"
  5. #include "MemoryBufferPreDownloadHandler.h"
  6. #include "FileEntry.h"
  7. #include <cppunit/extensions/HelperMacros.h>
  8. namespace aria2 {
  9. class DownloadHandlerFactoryTest:public CppUnit::TestFixture {
  10. CPPUNIT_TEST_SUITE(DownloadHandlerFactoryTest);
  11. #ifdef ENABLE_METALINK
  12. CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension);
  13. CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType);
  14. #endif // ENABLE_METALINK
  15. #ifdef ENABLE_BITTORRENT
  16. CPPUNIT_TEST(testGetBtPreDownloadHandler_extension);
  17. CPPUNIT_TEST(testGetBtPreDownloadHandler_contentType);
  18. #endif // ENABLE_BITTORRENT
  19. CPPUNIT_TEST_SUITE_END();
  20. private:
  21. public:
  22. void setUp() {}
  23. #ifdef ENABLE_METALINK
  24. void testGetMetalinkPreDownloadHandler_extension();
  25. void testGetMetalinkPreDownloadHandler_contentType();
  26. #endif // ENABLE_METALINK
  27. #ifdef ENABLE_BITTORRENT
  28. void testGetBtPreDownloadHandler_extension();
  29. void testGetBtPreDownloadHandler_contentType();
  30. #endif // ENABLE_BITTORRENT
  31. };
  32. CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
  33. #ifdef ENABLE_METALINK
  34. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
  35. {
  36. Option op;
  37. SharedHandle<SingleFileDownloadContext> dctx
  38. (new SingleFileDownloadContext(0, 0, "test.metalink"));
  39. RequestGroup rg(&op, std::deque<std::string>());
  40. rg.setDownloadContext(dctx);
  41. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  42. CPPUNIT_ASSERT(handler->canHandle(&rg));
  43. dctx->setFilename("test.metalink2");
  44. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  45. }
  46. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
  47. {
  48. Option op;
  49. SharedHandle<SingleFileDownloadContext> dctx
  50. (new SingleFileDownloadContext(0, 0, "test"));
  51. dctx->setContentType("application/metalink+xml");
  52. RequestGroup rg(&op, std::deque<std::string>());
  53. rg.setDownloadContext(dctx);
  54. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  55. CPPUNIT_ASSERT(handler->canHandle(&rg));
  56. dctx->setContentType("application/octet-stream");
  57. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  58. }
  59. #endif // ENABLE_METALINK
  60. #ifdef ENABLE_BITTORRENT
  61. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
  62. {
  63. Option op;
  64. SharedHandle<SingleFileDownloadContext> dctx
  65. (new SingleFileDownloadContext(0, 0, "test.torrent"));
  66. RequestGroup rg(&op, std::deque<std::string>());
  67. rg.setDownloadContext(dctx);
  68. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  69. CPPUNIT_ASSERT(handler->canHandle(&rg));
  70. dctx->setFilename("test.torrent2");
  71. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  72. }
  73. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
  74. {
  75. Option op;
  76. SharedHandle<SingleFileDownloadContext> dctx
  77. (new SingleFileDownloadContext(0, 0, "test"));
  78. dctx->setContentType("application/x-bittorrent");
  79. RequestGroup rg(&op, std::deque<std::string>());
  80. rg.setDownloadContext(dctx);
  81. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  82. CPPUNIT_ASSERT(handler->canHandle(&rg));
  83. dctx->setContentType("application/octet-stream");
  84. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  85. }
  86. #endif // ENABLE_BITTORRENT
  87. } // namespace aria2