DownloadHandlerFactoryTest.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. CPPUNIT_TEST(testGetBtPreDownloadHandler_extension);
  16. CPPUNIT_TEST(testGetBtPreDownloadHandler_contentType);
  17. CPPUNIT_TEST_SUITE_END();
  18. private:
  19. public:
  20. void setUp() {}
  21. #ifdef ENABLE_METALINK
  22. void testGetMetalinkPreDownloadHandler_extension();
  23. void testGetMetalinkPreDownloadHandler_contentType();
  24. #endif // ENABLE_METALINK
  25. void testGetBtPreDownloadHandler_extension();
  26. void testGetBtPreDownloadHandler_contentType();
  27. };
  28. CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
  29. #ifdef ENABLE_METALINK
  30. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
  31. {
  32. Option op;
  33. SharedHandle<SingleFileDownloadContext> dctx
  34. (new SingleFileDownloadContext(0, 0, "test.metalink"));
  35. RequestGroup rg(&op, std::deque<std::string>());
  36. rg.setDownloadContext(dctx);
  37. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  38. CPPUNIT_ASSERT(handler->canHandle(&rg));
  39. dctx->setFilename("test.metalink2");
  40. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  41. }
  42. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
  43. {
  44. Option op;
  45. SharedHandle<SingleFileDownloadContext> dctx
  46. (new SingleFileDownloadContext(0, 0, "test"));
  47. dctx->setContentType("application/metalink+xml");
  48. RequestGroup rg(&op, std::deque<std::string>());
  49. rg.setDownloadContext(dctx);
  50. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  51. CPPUNIT_ASSERT(handler->canHandle(&rg));
  52. dctx->setContentType("application/octet-stream");
  53. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  54. }
  55. #endif // ENABLE_METALINK
  56. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
  57. {
  58. Option op;
  59. SharedHandle<SingleFileDownloadContext> dctx
  60. (new SingleFileDownloadContext(0, 0, "test.torrent"));
  61. RequestGroup rg(&op, std::deque<std::string>());
  62. rg.setDownloadContext(dctx);
  63. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  64. CPPUNIT_ASSERT(handler->canHandle(&rg));
  65. dctx->setFilename("test.torrent2");
  66. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  67. }
  68. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
  69. {
  70. Option op;
  71. SharedHandle<SingleFileDownloadContext> dctx
  72. (new SingleFileDownloadContext(0, 0, "test"));
  73. dctx->setContentType("application/x-bittorrent");
  74. RequestGroup rg(&op, std::deque<std::string>());
  75. rg.setDownloadContext(dctx);
  76. SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  77. CPPUNIT_ASSERT(handler->canHandle(&rg));
  78. dctx->setContentType("application/octet-stream");
  79. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  80. }
  81. } // namespace aria2