summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2009-06-05 14:23:20 -0700
committerOwen Lin <owenlin@google.com>2009-06-08 12:12:49 -0700
commitedbebe1fae8d677184b47976af69e927fbc48936 (patch)
treee445106baab12f289c07622d736c8588602edce4 /tests
parent7c2eb95660f25619742bf73b51d0c75ac37fe4e9 (diff)
downloadLegacyCamera-edbebe1fae8d677184b47976af69e927fbc48936.zip
LegacyCamera-edbebe1fae8d677184b47976af69e927fbc48936.tar.gz
LegacyCamera-edbebe1fae8d677184b47976af69e927fbc48936.tar.bz2
Use a week reference to trace all the items which are in used.
By doing so, we can make sure there are only item of the given key in the system.
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/camera/gallery/LruCacheUnitTests.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/src/com/android/camera/gallery/LruCacheUnitTests.java b/tests/src/com/android/camera/gallery/LruCacheUnitTests.java
new file mode 100644
index 0000000..f699724
--- /dev/null
+++ b/tests/src/com/android/camera/gallery/LruCacheUnitTests.java
@@ -0,0 +1,37 @@
+package com.android.camera.gallery;
+
+import android.test.AndroidTestCase;
+
+public class LruCacheUnitTests extends AndroidTestCase {
+
+ public void testPut() {
+ LruCache<Integer, Integer> cache = new LruCache<Integer, Integer>(2);
+ Integer key = Integer.valueOf(1);
+ Integer value = Integer.valueOf(3);
+ cache.put(key, value);
+ assertEquals(value, cache.get(key));
+ }
+
+ public void testTracingInUsedObject() {
+ LruCache<Integer, Integer> cache = new LruCache<Integer, Integer>(2);
+ Integer key = Integer.valueOf(1);
+ Integer value = new Integer(3);
+ cache.put(key, value);
+ for (int i = 0; i < 3; ++i) {
+ cache.put(i + 10, i * i);
+ }
+ System.gc();
+ assertEquals(value, cache.get(key));
+ }
+
+ public void testLruAlgorithm() {
+ LruCache<Integer, Integer> cache = new LruCache<Integer, Integer>(2);
+ cache.put(0, new Integer(0));
+ for (int i = 0; i < 3; ++i) {
+ cache.put(i + 1, i * i);
+ cache.get(0);
+ }
+ System.gc();
+ assertEquals(Integer.valueOf(0), cache.get(0));
+ }
+}