DownloadHandlerFactoryTest.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "DownloadHandlerFactory.h"
  2. #include "RequestGroup.h"
  3. #include "Option.h"
  4. #include "SingleFileDownloadContext.h"
  5. #include "MemoryBufferPreDownloadHandler.h"
  6. #include <cppunit/extensions/HelperMacros.h>
  7. class DownloadHandlerFactoryTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(DownloadHandlerFactoryTest);
  9. CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension);
  10. CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType);
  11. CPPUNIT_TEST(testGetBtPreDownloadHandler_extension);
  12. CPPUNIT_TEST(testGetBtPreDownloadHandler_contentType);
  13. CPPUNIT_TEST_SUITE_END();
  14. private:
  15. public:
  16. void setUp() {}
  17. void testGetMetalinkPreDownloadHandler_extension();
  18. void testGetMetalinkPreDownloadHandler_contentType();
  19. void testGetBtPreDownloadHandler_extension();
  20. void testGetBtPreDownloadHandler_contentType();
  21. };
  22. CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
  23. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
  24. {
  25. Option op;
  26. SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.metalink");
  27. RequestGroup rg(&op, Strings());
  28. rg.setDownloadContext(dctx);
  29. PreDownloadHandlerHandle handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  30. CPPUNIT_ASSERT(handler->canHandle(&rg));
  31. dctx->setFilename("test.metalink2");
  32. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  33. }
  34. void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
  35. {
  36. Option op;
  37. SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test");
  38. dctx->setContentType("application/metalink+xml");
  39. RequestGroup rg(&op, Strings());
  40. rg.setDownloadContext(dctx);
  41. PreDownloadHandlerHandle handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
  42. CPPUNIT_ASSERT(handler->canHandle(&rg));
  43. dctx->setContentType("application/octet-stream");
  44. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  45. }
  46. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
  47. {
  48. Option op;
  49. SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test.torrent");
  50. RequestGroup rg(&op, Strings());
  51. rg.setDownloadContext(dctx);
  52. PreDownloadHandlerHandle handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  53. CPPUNIT_ASSERT(handler->canHandle(&rg));
  54. dctx->setFilename("test.torrent2");
  55. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  56. }
  57. void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
  58. {
  59. Option op;
  60. SingleFileDownloadContextHandle dctx = new SingleFileDownloadContext(0, 0, "test");
  61. dctx->setContentType("application/x-bittorrent");
  62. RequestGroup rg(&op, Strings());
  63. rg.setDownloadContext(dctx);
  64. PreDownloadHandlerHandle handler = DownloadHandlerFactory::getBtPreDownloadHandler();
  65. CPPUNIT_ASSERT(handler->canHandle(&rg));
  66. dctx->setContentType("application/octet-stream");
  67. CPPUNIT_ASSERT(!handler->canHandle(&rg));
  68. }