BtPostDownloadHandlerTest.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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
  27. (new SingleFileDownloadContext(0, 0, "test.torrent"));
  28. RequestGroup rg(&op, std::deque<std::string>());
  29. rg.setDownloadContext(dctx);
  30. BtPostDownloadHandler handler;
  31. CPPUNIT_ASSERT(handler.canHandle(&rg));
  32. dctx->setFilename("test.torrent2");
  33. CPPUNIT_ASSERT(!handler.canHandle(&rg));
  34. }
  35. void BtPostDownloadHandlerTest::testCanHandle_contentType()
  36. {
  37. Option op;
  38. SharedHandle<SingleFileDownloadContext> dctx
  39. (new SingleFileDownloadContext(0, 0, "test"));
  40. dctx->setContentType("application/x-bittorrent");
  41. RequestGroup rg(&op, std::deque<std::string>());
  42. rg.setDownloadContext(dctx);
  43. BtPostDownloadHandler handler;
  44. CPPUNIT_ASSERT(handler.canHandle(&rg));
  45. dctx->setContentType("application/octet-stream");
  46. CPPUNIT_ASSERT(!handler.canHandle(&rg));
  47. }
  48. void BtPostDownloadHandlerTest::testGetNextRequestGroups()
  49. {
  50. Option op;
  51. SharedHandle<SingleFileDownloadContext> dctx
  52. (new SingleFileDownloadContext(0, 0, "test.torrent"));
  53. RequestGroup rg(&op, std::deque<std::string>());
  54. rg.setDownloadContext(dctx);
  55. rg.initPieceStorage();
  56. BtPostDownloadHandler handler;
  57. std::deque<SharedHandle<RequestGroup> > groups;
  58. handler.getNextRequestGroups(groups, &rg);
  59. CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
  60. SharedHandle<BtContext> btctx
  61. (dynamic_pointer_cast<BtContext>(groups.front()->getDownloadContext()));
  62. CPPUNIT_ASSERT(!btctx.isNull());
  63. CPPUNIT_ASSERT_EQUAL(std::string("aria2-test"), btctx->getName());
  64. }
  65. } // namespace aria2