summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/gallery/ImageListUber.java7
-rw-r--r--tests/src/com/android/camera/gallery/ImageListUberUnitTests.java84
-rw-r--r--tests/src/com/android/camera/gallery/MockImage.java100
-rw-r--r--tests/src/com/android/camera/gallery/MockImageList.java54
4 files changed, 244 insertions, 1 deletions
diff --git a/src/com/android/camera/gallery/ImageListUber.java b/src/com/android/camera/gallery/ImageListUber.java
index d5e96c5..4962094 100644
--- a/src/com/android/camera/gallery/ImageListUber.java
+++ b/src/com/android/camera/gallery/ImageListUber.java
@@ -20,6 +20,7 @@ import com.android.camera.ImageManager;
import com.android.camera.Util;
import android.net.Uri;
+import android.util.Log;
import java.io.IOException;
import java.util.Arrays;
@@ -257,8 +258,10 @@ public class ImageListUber implements IImageList {
private static class DescendingComparator implements Comparator<MergeSlot> {
public int compare(MergeSlot m1, MergeSlot m2) {
+ Log.v(TAG, String.format(
+ "compare %s : %s", m1.mDateTaken, m2.mDateTaken ));
if (m1.mDateTaken != m2.mDateTaken) {
- return m1.mDateTaken < m2.mDateTaken ? -1 : 1;
+ return m1.mDateTaken < m2.mDateTaken ? 1 : -1;
}
return m1.mListIndex - m2.mListIndex;
}
@@ -267,6 +270,8 @@ public class ImageListUber implements IImageList {
private static class AscendingComparator implements Comparator<MergeSlot> {
public int compare(MergeSlot m1, MergeSlot m2) {
+ Log.v(TAG, String.format(
+ "compare %s : %s", m1.mDateTaken, m2.mDateTaken ));
if (m1.mDateTaken != m2.mDateTaken) {
return m1.mDateTaken < m2.mDateTaken ? -1 : 1;
}
diff --git a/tests/src/com/android/camera/gallery/ImageListUberUnitTests.java b/tests/src/com/android/camera/gallery/ImageListUberUnitTests.java
new file mode 100644
index 0000000..a123d05
--- /dev/null
+++ b/tests/src/com/android/camera/gallery/ImageListUberUnitTests.java
@@ -0,0 +1,84 @@
+package com.android.camera.gallery;
+
+import com.android.camera.ImageManager;
+
+import android.test.AndroidTestCase;
+
+public class ImageListUberUnitTests extends AndroidTestCase {
+
+ public void testTheOrderOfGetImageAt() {
+ MockImageList listA = new MockImageList();
+ MockImageList listB = new MockImageList();
+ listA.addImage(new MockImage(2, 2));
+ listA.addImage(new MockImage(0, 0));
+ listB.addImage(new MockImage(1, 1));
+ ImageListUber uber = new ImageListUber(
+ new IImageList[] {listA, listB}, ImageManager.SORT_DESCENDING);
+
+ assertEquals(2, uber.getImageAt(0).fullSizeImageId());
+ assertEquals(1, uber.getImageAt(1).fullSizeImageId());
+ assertEquals(0, uber.getImageAt(2).fullSizeImageId());
+
+ uber = new ImageListUber(
+ new IImageList[] {listA, listB}, ImageManager.SORT_DESCENDING);
+ assertEquals(2, uber.getImageAt(0).fullSizeImageId());
+ assertEquals(1, uber.getImageAt(1).fullSizeImageId());
+ assertEquals(0, uber.getImageAt(2).fullSizeImageId());
+ }
+
+ public void testTheOrderOfGetImageAtCaseTwo() {
+ MockImageList listA = new MockImageList();
+ MockImageList listB = new MockImageList();
+ listA.addImage(new MockImage(2, 2));
+ listA.addImage(new MockImage(1, 1));
+ listB.addImage(new MockImage(0, 0));
+ ImageListUber uber = new ImageListUber(
+ new IImageList[] {listB, listA}, ImageManager.SORT_DESCENDING);
+
+ assertEquals(2, uber.getImageAt(0).fullSizeImageId());
+ assertEquals(1, uber.getImageAt(1).fullSizeImageId());
+ assertEquals(0, uber.getImageAt(2).fullSizeImageId());
+
+ uber = new ImageListUber(
+ new IImageList[] {listA, listB}, ImageManager.SORT_DESCENDING);
+
+ assertEquals(2, uber.getImageAt(0).fullSizeImageId());
+ assertEquals(1, uber.getImageAt(1).fullSizeImageId());
+ assertEquals(0, uber.getImageAt(2).fullSizeImageId());
+
+ }
+
+ public void testRemoveImage() {
+ MockImageList listA = new MockImageList();
+ MockImageList listB = new MockImageList();
+ MockImage target = new MockImage(1, 1);
+ listA.addImage(new MockImage(2, 2));
+ listA.addImage(new MockImage(0, 0));
+ listB.addImage(target);
+ ImageListUber uber = new ImageListUber(
+ new IImageList[] {listB, listA}, ImageManager.SORT_DESCENDING);
+ uber.removeImage(target);
+ assertEquals(2, uber.getImageAt(0).fullSizeImageId());
+ assertEquals(0, uber.getImageAt(1).fullSizeImageId());
+
+ assertEquals(0, uber.getImageIndex(uber.getImageAt(0)));
+ assertEquals(1, uber.getImageIndex(uber.getImageAt(1)));
+ }
+
+ public void testRemoveImageAt() {
+ MockImageList listA = new MockImageList();
+ MockImageList listB = new MockImageList();
+ MockImage target = new MockImage(1, 1);
+ listA.addImage(new MockImage(2, 2));
+ listA.addImage(new MockImage(0, 0));
+ listB.addImage(target);
+ ImageListUber uber = new ImageListUber(
+ new IImageList[] {listB, listA}, ImageManager.SORT_DESCENDING);
+ uber.removeImageAt(1);
+ assertEquals(2, uber.getImageAt(0).fullSizeImageId());
+ assertEquals(0, uber.getImageAt(1).fullSizeImageId());
+
+ assertEquals(0, uber.getImageIndex(uber.getImageAt(0)));
+ assertEquals(1, uber.getImageIndex(uber.getImageAt(1)));
+ }
+}
diff --git a/tests/src/com/android/camera/gallery/MockImage.java b/tests/src/com/android/camera/gallery/MockImage.java
new file mode 100644
index 0000000..fe4579b
--- /dev/null
+++ b/tests/src/com/android/camera/gallery/MockImage.java
@@ -0,0 +1,100 @@
+package com.android.camera.gallery;
+
+import android.graphics.Bitmap;
+import android.net.Uri;
+
+import java.io.InputStream;
+
+public class MockImage implements IImage {
+ private final long mId;
+ private final long mTakenDate;
+ private IImageList mContainer;
+
+ public MockImage(long id, long takenDate) {
+ mId = id;
+ mTakenDate = takenDate;
+ }
+
+ protected void setContainer(IImageList container) {
+ this.mContainer = container;
+ }
+
+ public Bitmap fullSizeBitmap(int targetWidthOrHeight) {
+ return null;
+ }
+
+ public Cancelable<Bitmap> fullSizeBitmapCancelable(int targetWidthOrHeight) {
+ return null;
+ }
+
+ public InputStream fullSizeImageData() {
+ return null;
+ }
+
+ public long fullSizeImageId() {
+ return mId;
+ }
+
+ public Uri fullSizeImageUri() {
+ return null;
+ }
+
+ public IImageList getContainer() {
+ return mContainer;
+ }
+
+ public String getDataPath() {
+ return null;
+ }
+
+ public long getDateTaken() {
+ return mTakenDate;
+ }
+
+ public String getDisplayName() {
+ return null;
+ }
+
+ public int getHeight() {
+ return 0;
+ }
+
+ public String getMimeType() {
+ return null;
+ }
+
+ public String getTitle() {
+ return null;
+ }
+
+ public int getWidth() {
+ return 0;
+ }
+
+ public boolean isDrm() {
+ return false;
+ }
+
+ public boolean isReadonly() {
+ return false;
+ }
+
+ public Bitmap miniThumbBitmap() {
+ return null;
+ }
+
+ public boolean rotateImageBy(int degrees) {
+ return false;
+ }
+
+ public void setTitle(String name) {
+ }
+
+ public Bitmap thumbBitmap() {
+ return null;
+ }
+
+ public Uri thumbUri() {
+ return null;
+ }
+}
diff --git a/tests/src/com/android/camera/gallery/MockImageList.java b/tests/src/com/android/camera/gallery/MockImageList.java
new file mode 100644
index 0000000..fe67c34
--- /dev/null
+++ b/tests/src/com/android/camera/gallery/MockImageList.java
@@ -0,0 +1,54 @@
+package com.android.camera.gallery;
+
+import android.net.Uri;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class MockImageList implements IImageList {
+
+ private final ArrayList<IImage> mList = new ArrayList<IImage>();
+
+ public void checkThumbnail(int index) {
+ }
+
+ public void deactivate() {
+ }
+
+ public HashMap<String, String> getBucketIds() {
+ return null;
+ }
+
+ public int getCount() {
+ return mList.size();
+ }
+
+ public IImage getImageAt(int i) {
+ return mList.get(i);
+ }
+
+ public IImage getImageForUri(Uri uri) {
+ return null;
+ }
+
+ public int getImageIndex(IImage image) {
+ return mList.indexOf(image);
+ }
+
+ public boolean isEmpty() {
+ return mList.isEmpty();
+ }
+
+ public boolean removeImage(IImage image) {
+ return mList.remove(image);
+ }
+
+ public boolean removeImageAt(int i) {
+ return mList.remove(i) != null;
+ }
+
+ public void addImage(MockImage image) {
+ mList.add(image);
+ image.setContainer(this);
+ }
+}