SingleFileAllocationIteratorTest.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "SingleFileAllocationIterator.h"
  2. #include "File.h"
  3. #include "DefaultDiskWriter.h"
  4. #include <fstream>
  5. #include <cppunit/extensions/HelperMacros.h>
  6. namespace aria2 {
  7. class SingleFileAllocationIteratorTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(SingleFileAllocationIteratorTest);
  9. CPPUNIT_TEST(testAllocate);
  10. CPPUNIT_TEST_SUITE_END();
  11. private:
  12. public:
  13. void setUp() {}
  14. void testAllocate();
  15. };
  16. CPPUNIT_TEST_SUITE_REGISTRATION( SingleFileAllocationIteratorTest );
  17. void SingleFileAllocationIteratorTest::testAllocate()
  18. {
  19. std::string dir = A2_TEST_OUT_DIR;
  20. std::string fname = "aria2_SingleFileAllocationIteratorTest_testAllocate";
  21. std::string fn = dir+"/"+fname;
  22. std::ofstream of(fn.c_str(), std::ios::binary);
  23. of << "0123456789";
  24. of.close();
  25. File x(fn);
  26. CPPUNIT_ASSERT_EQUAL((int64_t)10, x.size());
  27. DefaultDiskWriter writer(fn);
  28. off_t offset = 10;
  29. off_t totalLength = 16*1024*2+8*1024;
  30. // we have to open file first.
  31. writer.openExistingFile();
  32. SingleFileAllocationIterator itr(&writer, offset, totalLength);
  33. itr.init();
  34. while(!itr.finished()) {
  35. itr.allocateChunk();
  36. }
  37. File f(fn);
  38. CPPUNIT_ASSERT_EQUAL((int64_t)40960, f.size());
  39. }
  40. } // namespace aria2