BtPostDownloadHandlerTest.cc 2.0 KB

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