2007-10-11 16:58:24 +00:00
|
|
|
#include "SingleFileAllocationIterator.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2015-06-21 09:04:30 +00:00
|
|
|
#include "File.h"
|
|
|
|
#include "DefaultDiskWriter.h"
|
|
|
|
#include "a2functional.h"
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
class SingleFileAllocationIteratorTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SingleFileAllocationIteratorTest);
|
|
|
|
CPPUNIT_TEST(testAllocate);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void testAllocate();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SingleFileAllocationIteratorTest );
|
|
|
|
|
|
|
|
void SingleFileAllocationIteratorTest::testAllocate()
|
|
|
|
{
|
2010-12-02 13:38:36 +00:00
|
|
|
std::string dir = A2_TEST_OUT_DIR;
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string fname = "aria2_SingleFileAllocationIteratorTest_testAllocate";
|
|
|
|
std::string fn = dir+"/"+fname;
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ofstream of(fn.c_str(), std::ios::binary);
|
2007-10-11 16:58:24 +00:00
|
|
|
of << "0123456789";
|
|
|
|
of.close();
|
|
|
|
|
|
|
|
File x(fn);
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)10, x.size());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2009-05-04 07:50:38 +00:00
|
|
|
DefaultDiskWriter writer(fn);
|
2012-07-23 12:36:24 +00:00
|
|
|
int64_t offset = 10;
|
2015-06-21 09:04:30 +00:00
|
|
|
int64_t totalLength = 32_k + 8_k;
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// we have to open file first.
|
2009-05-04 07:50:38 +00:00
|
|
|
writer.openExistingFile();
|
2007-11-28 14:22:28 +00:00
|
|
|
SingleFileAllocationIterator itr(&writer, offset, totalLength);
|
|
|
|
itr.init();
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2007-11-28 14:22:28 +00:00
|
|
|
while(!itr.finished()) {
|
|
|
|
itr.allocateChunk();
|
|
|
|
}
|
2007-10-11 16:58:24 +00:00
|
|
|
File f(fn);
|
2015-06-21 09:04:30 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)40_k, f.size());
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|