summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2009-08-19 07:35:57 -0700
committerDaniel Burrows <dburrows@debian.org>2009-08-19 07:35:57 -0700
commit572ef12324eb6fec53876091e5db52f5e8036987 (patch)
tree37cca4fa0d0ac3f64d2ac068cb8aa0cb98893b74 /tests
parent67385f63883d9480b0c766414488a7ff47c33084 (diff)
downloadaptitude-572ef12324eb6fec53876091e5db52f5e8036987.tar.gz
Add test cases to verify what happens when values are evicted from the cache.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_file_cache.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/test_file_cache.cc b/tests/test_file_cache.cc
index 5f32f0c8..b9afccc4 100644
--- a/tests/test_file_cache.cc
+++ b/tests/test_file_cache.cc
@@ -1,3 +1,5 @@
+#include <boost/function.hpp>
+#include <boost/lambda/bind.hpp>
#include <boost/test/unit_test.hpp>
#include <generic/util/file_cache.h>
@@ -255,3 +257,82 @@ BOOST_AUTO_TEST_CASE(fileCacheStoreDiskAndMemory)
fileCacheTestInfo testInfo;
setupFileCacheTest(td, cache, testInfo);
}
+
+
+void runDropLeastRecentlyUsedTest(const temp::dir &td,
+ const boost::function<boost::shared_ptr<file_cache> ()> &cache_k)
+{
+ // Check that we can control which of the three entries is dropped
+ // when we add a fourth entry.
+
+
+ // Drop key3.
+ {
+ boost::shared_ptr<file_cache> cache(cache_k());
+
+ fileCacheTestInfo testInfo;
+ setupFileCacheTest(td, cache, testInfo);
+
+ CHECK_CACHED_VALUE(cache, testInfo.key1, testInfo.infileData1);
+ CHECK_CACHED_VALUE(cache, testInfo.key2, testInfo.infileData2);
+ CHECK_CACHED_VALUE(cache, testInfo.key3, testInfo.infileData3);
+
+ cache->putItem("key4", testInfo.infilename1.get_name());
+
+
+ CHECK_CACHED_VALUE(cache, testInfo.key1, testInfo.infileData1);
+ CHECK_CACHED_VALUE(cache, testInfo.key2, testInfo.infileData2);
+ CHECK_CACHED_VALUE(cache, "key4", testInfo.infileData1);
+ BOOST_CHECK(!cache->getItem(testInfo.key3).valid());
+ }
+
+
+ // Drop key2.
+ {
+ boost::shared_ptr<file_cache> cache(cache_k());
+
+ fileCacheTestInfo testInfo;
+ setupFileCacheTest(td, cache, testInfo);
+
+ CHECK_CACHED_VALUE(cache, testInfo.key1, testInfo.infileData1);
+ CHECK_CACHED_VALUE(cache, testInfo.key3, testInfo.infileData3);
+ CHECK_CACHED_VALUE(cache, testInfo.key2, testInfo.infileData2);
+
+ cache->putItem("key4", testInfo.infilename1.get_name());
+
+
+ CHECK_CACHED_VALUE(cache, testInfo.key1, testInfo.infileData1);
+ CHECK_CACHED_VALUE(cache, testInfo.key3, testInfo.infileData3);
+ CHECK_CACHED_VALUE(cache, "key4", testInfo.infileData1);
+ BOOST_CHECK(!cache->getItem(testInfo.key2).valid());
+ }
+
+
+ // Drop key1.
+ {
+ boost::shared_ptr<file_cache> cache(cache_k());
+
+ fileCacheTestInfo testInfo;
+ setupFileCacheTest(td, cache, testInfo);
+
+ CHECK_CACHED_VALUE(cache, testInfo.key3, testInfo.infileData3);
+ CHECK_CACHED_VALUE(cache, testInfo.key2, testInfo.infileData2);
+ CHECK_CACHED_VALUE(cache, testInfo.key1, testInfo.infileData1);
+
+ cache->putItem("key4", testInfo.infilename1.get_name());
+
+
+ CHECK_CACHED_VALUE(cache, testInfo.key2, testInfo.infileData2);
+ CHECK_CACHED_VALUE(cache, testInfo.key3, testInfo.infileData3);
+ CHECK_CACHED_VALUE(cache, "key4", testInfo.infileData1);
+ BOOST_CHECK(!cache->getItem(testInfo.key1).valid());
+ }
+}
+
+BOOST_AUTO_TEST_CASE(fileCacheDropLeastRecentlyUsedDisk)
+{
+ temp::dir td("testFileCache");
+ temp::name tn(td, "testFileCache");
+
+ runDropLeastRecentlyUsedTest(td, boost::lambda::bind(&file_cache::create, tn.get_name(), 0, 1000));
+}