summaryrefslogtreecommitdiff
path: root/test/WrDiskCacheEntryTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-11-27 22:04:59 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-03 01:39:10 +0900
commitf314719618d181036ceebcf45338ab76559daf55 (patch)
treef85677a7afad929a7cf320ff93ec4265cda0dc6a /test/WrDiskCacheEntryTest.cc
parent8ac433a8e9ab8bddd96c62db4bbeac3adce2b3ba (diff)
Added --disk-cache option
This option enables disk cache. If SIZE is 0, the disk cache is disabled. This feature caches the downloaded data in memory, which grows to at most SIZE bytes. The cache storage is created for aria2 instance and shared by all downloads. The one advantage of the disk cache is reduce the disk seek time because the data is written in larger unit and it is reordered by the offset of the file. If the underlying file is heavily fragmented it is not the case.
Diffstat (limited to 'test/WrDiskCacheEntryTest.cc')
-rw-r--r--test/WrDiskCacheEntryTest.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/WrDiskCacheEntryTest.cc b/test/WrDiskCacheEntryTest.cc
new file mode 100644
index 00000000..ad1c894b
--- /dev/null
+++ b/test/WrDiskCacheEntryTest.cc
@@ -0,0 +1,55 @@
+#include "WrDiskCacheEntry.h"
+
+#include <cstring>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "TestUtil.h"
+#include "DirectDiskAdaptor.h"
+#include "ByteArrayDiskWriter.h"
+
+namespace aria2 {
+
+class WrDiskCacheEntryTest:public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE(WrDiskCacheEntryTest);
+ CPPUNIT_TEST(testWriteToDisk);
+ CPPUNIT_TEST(testClear);
+ CPPUNIT_TEST_SUITE_END();
+
+ SharedHandle<DirectDiskAdaptor> adaptor_;
+ SharedHandle<ByteArrayDiskWriter> writer_;
+public:
+ void setUp()
+ {
+ adaptor_.reset(new DirectDiskAdaptor());
+ writer_.reset(new ByteArrayDiskWriter());
+ adaptor_->setDiskWriter(writer_);
+ }
+
+ void testWriteToDisk();
+ void testClear();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( WrDiskCacheEntryTest );
+
+void WrDiskCacheEntryTest::testWriteToDisk()
+{
+ WrDiskCacheEntry e(adaptor_);
+ e.cacheData(createDataCell(0, "??01234567", 2));
+ e.cacheData(createDataCell(8, "890"));
+ e.writeToDisk();
+ CPPUNIT_ASSERT_EQUAL((size_t)0, e.getSize());
+ CPPUNIT_ASSERT_EQUAL(std::string("01234567890"), writer_->getString());
+}
+
+void WrDiskCacheEntryTest::testClear()
+{
+ WrDiskCacheEntry e(adaptor_);
+ e.cacheData(createDataCell(0, "foo"));
+ e.clear();
+ CPPUNIT_ASSERT_EQUAL((size_t)0, e.getSize());
+ CPPUNIT_ASSERT_EQUAL(std::string(), writer_->getString());
+}
+
+} // namespace aria2