DownloadHandlerFactoryTest.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "DownloadHandlerFactory.h"
  2. #include <cppunit/extensions/HelperMacros.h>
  3. #include "RequestGroup.h"
  4. #include "Option.h"
  5. #include "SingleFileDownloadContext.h"
  6. #include "MemoryBufferPreDownloadHandler.h"
  7. #include "FileEntry.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. SharedHandle<Option> _option;
  22. public:
  23. void setUp()
  24. {
  25. _option.reset(new Option());
  26. }
  27. #ifdef ENABLE_METALINK
  28. void testGetMetalinkPreDownloadHandler_extension();
  29. void testGetMetalinkPreDownloadHandler_contentType();
  30. #endif // ENABLE_METALINK
  31. #ifdef ENABLE_BITTORRENT
  32. void testGetBtPreDownloadHandler_extension();
  33. void testGetBtPreDownloadHandler_contentType();
  34. #endif // ENABLE_BITTORRENT
  35. };
  36. CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
  37. #ifdef ENABLE_METALINK
  38. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
  39. {
  40. SharedHandle<SingleFileDownloadContext> dctx
  41. (new SingleFileDownloadContext(0, 0, "test.metalink"));
  42. RequestGroup rg(_option, std::deque<std::string>());
  43. rg.setDownloadContext(dctx);
  44. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  45. CPPUNIT_ASSERT(handler->canHandle(&rg));
  46. dctx->setFilename("test.metalink2");
  47. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  48. }
  49. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
  50. {
  51. SharedHandle<SingleFileDownloadContext> dctx
  52. (new SingleFileDownloadContext(0, 0, "test"));
  53. dctx->setContentType("application/metalink+xml");
  54. RequestGroup rg(_option, std::deque<std::string>());
  55. rg.setDownloadContext(dctx);
  56. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  57. CPPUNIT_ASSERT(handler->canHandle(&rg));
  58. dctx->setContentType("application/octet-stream");
  59. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  60. }
  61. #endif // ENABLE_METALINK
  62. #ifdef ENABLE_BITTORRENT
  63. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
  64. {
  65. SharedHandle<SingleFileDownloadContext> dctx
  66. (new SingleFileDownloadContext(0, 0, "test.torrent"));
  67. RequestGroup rg(_option, std::deque<std::string>());
  68. rg.setDownloadContext(dctx);
  69. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  70. CPPUNIT_ASSERT(handler->canHandle(&rg));
  71. dctx->setFilename("test.torrent2");
  72. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  73. }
  74. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
  75. {
  76. SharedHandle<SingleFileDownloadContext> dctx
  77. (new SingleFileDownloadContext(0, 0, "test"));
  78. dctx->setContentType("application/x-bittorrent");
  79. RequestGroup rg(_option, 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