SingleFileDownloadContextTest.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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(""), ctx.getPieceHash(-1));
  28. CPPUNIT_ASSERT_EQUAL(std::string("0000"), ctx.getPieceHash(0));
  29. CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getPieceHash(3));
  30. }
  31. void SingleFileDownloadContextTest::testGetNumPieces()
  32. {
  33. SingleFileDownloadContext ctx(345, 9889, "");
  34. CPPUNIT_ASSERT_EQUAL((size_t)29, ctx.getNumPieces());
  35. }
  36. void SingleFileDownloadContextTest::testGetActualBasePath()
  37. {
  38. SingleFileDownloadContext ctx(0, 0, "");
  39. CPPUNIT_ASSERT_EQUAL(std::string("./index.html"), ctx.getActualBasePath());
  40. ctx.setFilename("aria2.tar.bz2");
  41. CPPUNIT_ASSERT_EQUAL(std::string("./aria2.tar.bz2"), ctx.getActualBasePath());
  42. ctx.setUFilename("aria.tar.bz2");
  43. CPPUNIT_ASSERT_EQUAL(std::string("./aria.tar.bz2"), ctx.getActualBasePath());
  44. ctx.setDir("/tmp");
  45. CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria.tar.bz2"), ctx.getActualBasePath());
  46. }
  47. } // namespace aria2