2008-08-26 12:39:07 +00:00
|
|
|
#include "DirectDiskAdaptor.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-08-26 12:39:07 +00:00
|
|
|
#include "FileEntry.h"
|
|
|
|
#include "DefaultDiskWriter.h"
|
|
|
|
#include "Exception.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-08-26 12:39:07 +00:00
|
|
|
#include "TestUtil.h"
|
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class DirectDiskAdaptorTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DirectDiskAdaptorTest);
|
|
|
|
CPPUNIT_TEST(testCutTrailingGarbage);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testCutTrailingGarbage();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DirectDiskAdaptorTest);
|
|
|
|
|
|
|
|
void DirectDiskAdaptorTest::testCutTrailingGarbage()
|
|
|
|
{
|
2010-12-02 13:38:36 +00:00
|
|
|
std::string dir = A2_TEST_OUT_DIR;
|
2008-08-26 12:39:07 +00:00
|
|
|
SharedHandle<FileEntry> entry
|
2009-03-09 15:10:26 +00:00
|
|
|
(new FileEntry(dir+"/aria2_DirectDiskAdaptorTest_testCutTrailingGarbage",
|
2010-01-05 16:01:46 +00:00
|
|
|
256, 0));
|
2009-03-09 15:10:26 +00:00
|
|
|
createFile(entry->getPath(), entry->getLength()+100);
|
2008-08-26 12:39:07 +00:00
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
std::vector<SharedHandle<FileEntry> > fileEntries;
|
2008-08-26 12:39:07 +00:00
|
|
|
fileEntries.push_back(entry);
|
|
|
|
|
|
|
|
DirectDiskAdaptor adaptor;
|
2009-05-04 07:50:38 +00:00
|
|
|
adaptor.setDiskWriter
|
|
|
|
(SharedHandle<DiskWriter>(new DefaultDiskWriter(entry->getPath())));
|
2008-08-26 12:39:07 +00:00
|
|
|
adaptor.setTotalLength(entry->getLength());
|
2009-06-28 10:37:15 +00:00
|
|
|
adaptor.setFileEntries(fileEntries.begin(), fileEntries.end());
|
2008-08-26 12:39:07 +00:00
|
|
|
adaptor.openFile();
|
|
|
|
|
|
|
|
adaptor.cutTrailingGarbage();
|
|
|
|
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)entry->getLength(),
|
2010-01-05 16:01:46 +00:00
|
|
|
File(entry->getPath()).size());
|
2008-08-26 12:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|