SingleFileDownloadContextTest.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "SingleFileDownloadContext.h"
  2. #include "FileEntry.h"
  3. #include <cppunit/extensions/HelperMacros.h>
  4. namespace aria2 {
  5. class SingleFileDownloadContextTest:public CppUnit::TestFixture {
  6. CPPUNIT_TEST_SUITE(SingleFileDownloadContextTest);
  7. CPPUNIT_TEST(testGetPieceHash);
  8. CPPUNIT_TEST(testGetNumPieces);
  9. CPPUNIT_TEST(testGetActualBasePath);
  10. CPPUNIT_TEST_SUITE_END();
  11. public:
  12. SingleFileDownloadContextTest() {}
  13. void setUp() {}
  14. void testGetPieceHash();
  15. void testGetNumPieces();
  16. void testGetActualBasePath();
  17. };
  18. CPPUNIT_TEST_SUITE_REGISTRATION( SingleFileDownloadContextTest );
  19. void SingleFileDownloadContextTest::testGetPieceHash()
  20. {
  21. SingleFileDownloadContext ctx(0, 0, "");
  22. std::deque<std::string> pieceHashes;
  23. pieceHashes.push_back("0000");
  24. pieceHashes.push_back("0001");
  25. pieceHashes.push_back("0002");
  26. ctx.setPieceHashes(pieceHashes);
  27. CPPUNIT_ASSERT_EQUAL(std::string("0000"), ctx.getPieceHash(0));
  28. CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getPieceHash(3));
  29. }
  30. void SingleFileDownloadContextTest::testGetNumPieces()
  31. {
  32. SingleFileDownloadContext ctx(345, 9889, "");
  33. CPPUNIT_ASSERT_EQUAL((size_t)29, ctx.getNumPieces());
  34. }
  35. void SingleFileDownloadContextTest::testGetActualBasePath()
  36. {
  37. SingleFileDownloadContext ctx(0, 0, "");
  38. CPPUNIT_ASSERT_EQUAL(std::string("./index.html"), ctx.getActualBasePath());
  39. ctx.setFilename("aria2.tar.bz2");
  40. CPPUNIT_ASSERT_EQUAL(std::string("./aria2.tar.bz2"), ctx.getActualBasePath());
  41. ctx.setUFilename("aria.tar.bz2");
  42. CPPUNIT_ASSERT_EQUAL(std::string("./aria.tar.bz2"), ctx.getActualBasePath());
  43. ctx.setDir("/tmp");
  44. CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria.tar.bz2"), ctx.getActualBasePath());
  45. }
  46. } // namespace aria2