FallocFileAllocationIteratorTest.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "FallocFileAllocationIterator.h"
  2. #include <fstream>
  3. #include <cppunit/extensions/HelperMacros.h>
  4. #include "File.h"
  5. #include "DefaultDiskWriter.h"
  6. namespace aria2 {
  7. class FallocFileAllocationIteratorTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(FallocFileAllocationIteratorTest);
  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( FallocFileAllocationIteratorTest );
  17. void FallocFileAllocationIteratorTest::testAllocate()
  18. {
  19. std::string dir = "/tmp";
  20. std::string fname = "aria2_FallocFileAllocationIteratorTest_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 f(fn);
  26. CPPUNIT_ASSERT_EQUAL((uint64_t)10, f.size());
  27. DefaultDiskWriter writer(fn);
  28. int64_t offset = 10;
  29. int64_t totalLength = 40960;
  30. // we have to open file first.
  31. writer.openExistingFile();
  32. FallocFileAllocationIterator itr(&writer, offset, totalLength);
  33. itr.allocateChunk();
  34. CPPUNIT_ASSERT(itr.finished());
  35. CPPUNIT_ASSERT_EQUAL((uint64_t)40960, f.size());
  36. }
  37. } // namespace aria2