BtPostDownloadHandlerTest.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "BtPostDownloadHandler.h"
  2. #include "BtContext.h"
  3. #include "RequestGroup.h"
  4. #include "Option.h"
  5. #include "SingleFileDownloadContext.h"
  6. #include "FileEntry.h"
  7. #include <cppunit/extensions/HelperMacros.h>
  8. namespace aria2 {
  9. class BtPostDownloadHandlerTest:public CppUnit::TestFixture {
  10. CPPUNIT_TEST_SUITE(BtPostDownloadHandlerTest);
  11. CPPUNIT_TEST(testCanHandle_extension);
  12. CPPUNIT_TEST(testCanHandle_contentType);
  13. CPPUNIT_TEST(testGetNextRequestGroups);
  14. CPPUNIT_TEST_SUITE_END();
  15. private:
  16. public:
  17. void setUp() {}
  18. void testCanHandle_extension();
  19. void testCanHandle_contentType();
  20. void testGetNextRequestGroups();
  21. };
  22. CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest );
  23. void BtPostDownloadHandlerTest::testCanHandle_extension()
  24. {
  25. Option op;
  26. SharedHandle<SingleFileDownloadContext> dctx = new SingleFileDownloadContext(0, 0, "test.torrent");
  27. RequestGroup rg(&op, std::deque<std::string>());
  28. rg.setDownloadContext(dctx);
  29. BtPostDownloadHandler handler;
  30. CPPUNIT_ASSERT(handler.canHandle(&rg));
  31. dctx->setFilename("test.torrent2");
  32. CPPUNIT_ASSERT(!handler.canHandle(&rg));
  33. }
  34. void BtPostDownloadHandlerTest::testCanHandle_contentType()
  35. {
  36. Option op;
  37. SharedHandle<SingleFileDownloadContext> dctx = new SingleFileDownloadContext(0, 0, "test");
  38. dctx->setContentType("application/x-bittorrent");
  39. RequestGroup rg(&op, std::deque<std::string>());
  40. rg.setDownloadContext(dctx);
  41. BtPostDownloadHandler handler;
  42. CPPUNIT_ASSERT(handler.canHandle(&rg));
  43. dctx->setContentType("application/octet-stream");
  44. CPPUNIT_ASSERT(!handler.canHandle(&rg));
  45. }
  46. void BtPostDownloadHandlerTest::testGetNextRequestGroups()
  47. {
  48. Option op;
  49. SharedHandle<SingleFileDownloadContext> dctx = new SingleFileDownloadContext(0, 0, "test.torrent");
  50. RequestGroup rg(&op, std::deque<std::string>());
  51. rg.setDownloadContext(dctx);
  52. rg.initPieceStorage();
  53. BtPostDownloadHandler handler;
  54. std::deque<SharedHandle<RequestGroup> > groups = handler.getNextRequestGroups(&rg);
  55. CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
  56. SharedHandle<BtContext> btctx = groups.front()->getDownloadContext();
  57. CPPUNIT_ASSERT(!btctx.isNull());
  58. CPPUNIT_ASSERT_EQUAL(std::string("aria2-test"), btctx->getName());
  59. }
  60. } // namespace aria2