summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/gallery3d/data
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/gallery3d/data')
-rw-r--r--tests/src/com/android/gallery3d/data/GalleryAppMock.java50
-rw-r--r--tests/src/com/android/gallery3d/data/GalleryAppStub.java47
-rw-r--r--tests/src/com/android/gallery3d/data/LocalDataTest.java461
-rw-r--r--tests/src/com/android/gallery3d/data/MediaSetTest.java63
-rw-r--r--tests/src/com/android/gallery3d/data/MockItem.java53
-rw-r--r--tests/src/com/android/gallery3d/data/MockSet.java88
-rw-r--r--tests/src/com/android/gallery3d/data/MockSource.java48
-rw-r--r--tests/src/com/android/gallery3d/data/PathTest.java82
-rw-r--r--tests/src/com/android/gallery3d/data/RealDataTest.java110
9 files changed, 0 insertions, 1002 deletions
diff --git a/tests/src/com/android/gallery3d/data/GalleryAppMock.java b/tests/src/com/android/gallery3d/data/GalleryAppMock.java
deleted file mode 100644
index bbc569238..000000000
--- a/tests/src/com/android/gallery3d/data/GalleryAppMock.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.os.Looper;
-
-import com.android.gallery3d.ui.GLRoot;
-import com.android.gallery3d.ui.GLRootStub;
-
-class GalleryAppMock extends GalleryAppStub {
- GLRoot mGLRoot = new GLRootStub();
- DataManager mDataManager = new DataManager(this);
- ContentResolver mResolver;
- Context mContext;
- Looper mMainLooper;
-
- GalleryAppMock(Context context,
- ContentResolver resolver, Looper mainLooper) {
- mContext = context;
- mResolver = resolver;
- mMainLooper = mainLooper;
- }
-
- @Override
- public GLRoot getGLRoot() { return mGLRoot; }
- @Override
- public DataManager getDataManager() { return mDataManager; }
- @Override
- public Context getAndroidContext() { return mContext; }
- @Override
- public ContentResolver getContentResolver() { return mResolver; }
- @Override
- public Looper getMainLooper() { return mMainLooper; }
-}
diff --git a/tests/src/com/android/gallery3d/data/GalleryAppStub.java b/tests/src/com/android/gallery3d/data/GalleryAppStub.java
deleted file mode 100644
index 5aff2a2b2..000000000
--- a/tests/src/com/android/gallery3d/data/GalleryAppStub.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import com.android.gallery3d.app.GalleryApp;
-import com.android.gallery3d.app.StateManager;
-import com.android.gallery3d.app.StitchingProgressManager;
-import com.android.gallery3d.ui.GLRoot;
-import com.android.gallery3d.util.ThreadPool;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.res.Resources;
-import android.os.Looper;
-
-class GalleryAppStub implements GalleryApp {
- public ImageCacheService getImageCacheService() { return null; }
- public StateManager getStateManager() { return null; }
- public DataManager getDataManager() { return null; }
- public DownloadUtils getDownloadService() { return null; }
- public DecodeUtils getDecodeService() { return null; }
-
- public GLRoot getGLRoot() { return null; }
-
- public Context getAndroidContext() { return null; }
-
- public Looper getMainLooper() { return null; }
- public Resources getResources() { return null; }
- public ContentResolver getContentResolver() { return null; }
- public ThreadPool getThreadPool() { return null; }
- public DownloadCache getDownloadCache() { return null; }
- public StitchingProgressManager getStitchingProgressManager() { return null; }
-}
diff --git a/tests/src/com/android/gallery3d/data/LocalDataTest.java b/tests/src/com/android/gallery3d/data/LocalDataTest.java
deleted file mode 100644
index 8f6a46b8e..000000000
--- a/tests/src/com/android/gallery3d/data/LocalDataTest.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import android.content.ContentProvider;
-import android.content.ContentResolver;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteQueryBuilder;
-import android.net.Uri;
-import android.os.Looper;
-import android.test.AndroidTestCase;
-import android.test.mock.MockContentProvider;
-import android.test.mock.MockContentResolver;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.util.Log;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class LocalDataTest extends AndroidTestCase {
- @SuppressWarnings("unused")
- private static final String TAG = "LocalDataTest";
- private static final long DEFAULT_TIMEOUT = 1000; // one second
-
- @MediumTest
- public void testLocalAlbum() throws Exception {
- new TestZeroImage().run();
- new TestOneImage().run();
- new TestMoreImages().run();
- new TestZeroVideo().run();
- new TestOneVideo().run();
- new TestMoreVideos().run();
- new TestDeleteOneImage().run();
- new TestDeleteOneAlbum().run();
- }
-
- abstract class TestLocalAlbumBase {
- private boolean mIsImage;
- protected GalleryAppStub mApp;
- protected LocalAlbumSet mAlbumSet;
-
- TestLocalAlbumBase(boolean isImage) {
- mIsImage = isImage;
- }
-
- public void run() throws Exception {
- SQLiteDatabase db = SQLiteDatabase.create(null);
- prepareData(db);
- mApp = newGalleryContext(db, Looper.getMainLooper());
- Path.clearAll();
- Path path = Path.fromString(
- mIsImage ? "/local/image" : "/local/video");
- mAlbumSet = new LocalAlbumSet(path, mApp);
- mAlbumSet.reload();
- verifyResult();
- }
-
- abstract void prepareData(SQLiteDatabase db);
- abstract void verifyResult() throws Exception;
- }
-
- abstract class TestLocalImageAlbum extends TestLocalAlbumBase {
- TestLocalImageAlbum() {
- super(true);
- }
- }
-
- abstract class TestLocalVideoAlbum extends TestLocalAlbumBase {
- TestLocalVideoAlbum() {
- super(false);
- }
- }
-
- class TestZeroImage extends TestLocalImageAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- createImageTable(db);
- }
-
- @Override
- public void verifyResult() {
- assertEquals(0, mAlbumSet.getMediaItemCount());
- assertEquals(0, mAlbumSet.getSubMediaSetCount());
- assertEquals(0, mAlbumSet.getTotalMediaItemCount());
- }
- }
-
- class TestOneImage extends TestLocalImageAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- createImageTable(db);
- insertImageData(db);
- }
-
- @Override
- public void verifyResult() {
- assertEquals(0, mAlbumSet.getMediaItemCount());
- assertEquals(1, mAlbumSet.getSubMediaSetCount());
- assertEquals(1, mAlbumSet.getTotalMediaItemCount());
- MediaSet sub = mAlbumSet.getSubMediaSet(0);
- assertEquals(1, sub.getMediaItemCount());
- assertEquals(0, sub.getSubMediaSetCount());
- LocalMediaItem item = (LocalMediaItem) sub.getMediaItem(0, 1).get(0);
- assertEquals(1, item.id);
- assertEquals("IMG_0072", item.caption);
- assertEquals("image/jpeg", item.mimeType);
- assertEquals(12.0, item.latitude);
- assertEquals(34.0, item.longitude);
- assertEquals(0xD000, item.dateTakenInMs);
- assertEquals(1280395646L, item.dateAddedInSec);
- assertEquals(1275934796L, item.dateModifiedInSec);
- assertEquals("/mnt/sdcard/DCIM/100CANON/IMG_0072.JPG", item.filePath);
- }
- }
-
- class TestMoreImages extends TestLocalImageAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- // Albums are sorted by names, and items are sorted by
- // dateTimeTaken (descending)
- createImageTable(db);
- // bucket 0xB000
- insertImageData(db, 1000, 0xB000, "second"); // id 1
- insertImageData(db, 2000, 0xB000, "second"); // id 2
- // bucket 0xB001
- insertImageData(db, 3000, 0xB001, "first"); // id 3
- }
-
- @Override
- public void verifyResult() {
- assertEquals(0, mAlbumSet.getMediaItemCount());
- assertEquals(2, mAlbumSet.getSubMediaSetCount());
- assertEquals(3, mAlbumSet.getTotalMediaItemCount());
-
- MediaSet first = mAlbumSet.getSubMediaSet(0);
- assertEquals(1, first.getMediaItemCount());
- LocalMediaItem item = (LocalMediaItem) first.getMediaItem(0, 1).get(0);
- assertEquals(3, item.id);
- assertEquals(3000L, item.dateTakenInMs);
-
- MediaSet second = mAlbumSet.getSubMediaSet(1);
- assertEquals(2, second.getMediaItemCount());
- item = (LocalMediaItem) second.getMediaItem(0, 1).get(0);
- assertEquals(2, item.id);
- assertEquals(2000L, item.dateTakenInMs);
- item = (LocalMediaItem) second.getMediaItem(1, 1).get(0);
- assertEquals(1, item.id);
- assertEquals(1000L, item.dateTakenInMs);
- }
- }
-
- class OnContentDirtyLatch implements ContentListener {
- private CountDownLatch mLatch = new CountDownLatch(1);
-
- public void onContentDirty() {
- mLatch.countDown();
- }
-
- public boolean isOnContentDirtyBeCalled(long timeout)
- throws InterruptedException {
- return mLatch.await(timeout, TimeUnit.MILLISECONDS);
- }
- }
-
- class TestDeleteOneAlbum extends TestLocalImageAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- // Albums are sorted by names, and items are sorted by
- // dateTimeTaken (descending)
- createImageTable(db);
- // bucket 0xB000
- insertImageData(db, 1000, 0xB000, "second"); // id 1
- insertImageData(db, 2000, 0xB000, "second"); // id 2
- // bucket 0xB001
- insertImageData(db, 3000, 0xB001, "first"); // id 3
- }
-
- @Override
- public void verifyResult() throws Exception {
- MediaSet sub = mAlbumSet.getSubMediaSet(1); // "second"
- assertEquals(2, mAlbumSet.getSubMediaSetCount());
- OnContentDirtyLatch latch = new OnContentDirtyLatch();
- sub.addContentListener(latch);
- assertTrue((sub.getSupportedOperations() & MediaSet.SUPPORT_DELETE) != 0);
- sub.delete();
- mAlbumSet.fakeChange();
- latch.isOnContentDirtyBeCalled(DEFAULT_TIMEOUT);
- mAlbumSet.reload();
- assertEquals(1, mAlbumSet.getSubMediaSetCount());
- }
- }
-
- class TestDeleteOneImage extends TestLocalImageAlbum {
-
- @Override
- public void prepareData(SQLiteDatabase db) {
- createImageTable(db);
- insertImageData(db);
- }
-
- @Override
- public void verifyResult() {
- MediaSet sub = mAlbumSet.getSubMediaSet(0);
- LocalMediaItem item = (LocalMediaItem) sub.getMediaItem(0, 1).get(0);
- assertEquals(1, sub.getMediaItemCount());
- assertTrue((sub.getSupportedOperations() & MediaSet.SUPPORT_DELETE) != 0);
- sub.delete();
- sub.reload();
- assertEquals(0, sub.getMediaItemCount());
- }
- }
-
- static void createImageTable(SQLiteDatabase db) {
- // This is copied from MediaProvider
- db.execSQL("CREATE TABLE IF NOT EXISTS images (" +
- "_id INTEGER PRIMARY KEY," +
- "_data TEXT," +
- "_size INTEGER," +
- "_display_name TEXT," +
- "mime_type TEXT," +
- "title TEXT," +
- "date_added INTEGER," +
- "date_modified INTEGER," +
- "description TEXT," +
- "picasa_id TEXT," +
- "isprivate INTEGER," +
- "latitude DOUBLE," +
- "longitude DOUBLE," +
- "datetaken INTEGER," +
- "orientation INTEGER," +
- "mini_thumb_magic INTEGER," +
- "bucket_id TEXT," +
- "bucket_display_name TEXT" +
- ");");
- }
-
- static void insertImageData(SQLiteDatabase db) {
- insertImageData(db, 0xD000, 0xB000, "name");
- }
-
- static void insertImageData(SQLiteDatabase db, long dateTaken,
- int bucketId, String bucketName) {
- db.execSQL("INSERT INTO images (title, mime_type, latitude, longitude, "
- + "datetaken, date_added, date_modified, bucket_id, "
- + "bucket_display_name, _data, orientation) "
- + "VALUES ('IMG_0072', 'image/jpeg', 12, 34, "
- + dateTaken + ", 1280395646, 1275934796, '" + bucketId + "', "
- + "'" + bucketName + "', "
- + "'/mnt/sdcard/DCIM/100CANON/IMG_0072.JPG', 0)");
- }
-
- class TestZeroVideo extends TestLocalVideoAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- createVideoTable(db);
- }
-
- @Override
- public void verifyResult() {
- assertEquals(0, mAlbumSet.getMediaItemCount());
- assertEquals(0, mAlbumSet.getSubMediaSetCount());
- assertEquals(0, mAlbumSet.getTotalMediaItemCount());
- }
- }
-
- class TestOneVideo extends TestLocalVideoAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- createVideoTable(db);
- insertVideoData(db);
- }
-
- @Override
- public void verifyResult() {
- assertEquals(0, mAlbumSet.getMediaItemCount());
- assertEquals(1, mAlbumSet.getSubMediaSetCount());
- assertEquals(1, mAlbumSet.getTotalMediaItemCount());
- MediaSet sub = mAlbumSet.getSubMediaSet(0);
- assertEquals(1, sub.getMediaItemCount());
- assertEquals(0, sub.getSubMediaSetCount());
- LocalMediaItem item = (LocalMediaItem) sub.getMediaItem(0, 1).get(0);
- assertEquals(1, item.id);
- assertEquals("VID_20100811_051413", item.caption);
- assertEquals("video/mp4", item.mimeType);
- assertEquals(11.0, item.latitude);
- assertEquals(22.0, item.longitude);
- assertEquals(0xD000, item.dateTakenInMs);
- assertEquals(1281503663L, item.dateAddedInSec);
- assertEquals(1281503662L, item.dateModifiedInSec);
- assertEquals("/mnt/sdcard/DCIM/Camera/VID_20100811_051413.3gp",
- item.filePath);
- }
- }
-
- class TestMoreVideos extends TestLocalVideoAlbum {
- @Override
- public void prepareData(SQLiteDatabase db) {
- // Albums are sorted by names, and items are sorted by
- // dateTimeTaken (descending)
- createVideoTable(db);
- // bucket 0xB002
- insertVideoData(db, 1000, 0xB000, "second"); // id 1
- insertVideoData(db, 2000, 0xB000, "second"); // id 2
- // bucket 0xB001
- insertVideoData(db, 3000, 0xB001, "first"); // id 3
- }
-
- @Override
- public void verifyResult() {
- assertEquals(0, mAlbumSet.getMediaItemCount());
- assertEquals(2, mAlbumSet.getSubMediaSetCount());
- assertEquals(3, mAlbumSet.getTotalMediaItemCount());
-
- MediaSet first = mAlbumSet.getSubMediaSet(0);
- assertEquals(1, first.getMediaItemCount());
- LocalMediaItem item = (LocalMediaItem) first.getMediaItem(0, 1).get(0);
- assertEquals(3, item.id);
- assertEquals(3000L, item.dateTakenInMs);
-
- MediaSet second = mAlbumSet.getSubMediaSet(1);
- assertEquals(2, second.getMediaItemCount());
- item = (LocalMediaItem) second.getMediaItem(0, 1).get(0);
- assertEquals(2, item.id);
- assertEquals(2000L, item.dateTakenInMs);
- item = (LocalMediaItem) second.getMediaItem(1, 1).get(0);
- assertEquals(1, item.id);
- assertEquals(1000L, item.dateTakenInMs);
- }
- }
-
- static void createVideoTable(SQLiteDatabase db) {
- db.execSQL("CREATE TABLE IF NOT EXISTS video (" +
- "_id INTEGER PRIMARY KEY," +
- "_data TEXT NOT NULL," +
- "_display_name TEXT," +
- "_size INTEGER," +
- "mime_type TEXT," +
- "date_added INTEGER," +
- "date_modified INTEGER," +
- "title TEXT," +
- "duration INTEGER," +
- "artist TEXT," +
- "album TEXT," +
- "resolution TEXT," +
- "description TEXT," +
- "isprivate INTEGER," + // for YouTube videos
- "tags TEXT," + // for YouTube videos
- "category TEXT," + // for YouTube videos
- "language TEXT," + // for YouTube videos
- "mini_thumb_data TEXT," +
- "latitude DOUBLE," +
- "longitude DOUBLE," +
- "datetaken INTEGER," +
- "mini_thumb_magic INTEGER" +
- ");");
- db.execSQL("ALTER TABLE video ADD COLUMN bucket_id TEXT;");
- db.execSQL("ALTER TABLE video ADD COLUMN bucket_display_name TEXT");
- }
-
- static void insertVideoData(SQLiteDatabase db) {
- insertVideoData(db, 0xD000, 0xB000, "name");
- }
-
- static void insertVideoData(SQLiteDatabase db, long dateTaken,
- int bucketId, String bucketName) {
- db.execSQL("INSERT INTO video (title, mime_type, latitude, longitude, "
- + "datetaken, date_added, date_modified, bucket_id, "
- + "bucket_display_name, _data, duration) "
- + "VALUES ('VID_20100811_051413', 'video/mp4', 11, 22, "
- + dateTaken + ", 1281503663, 1281503662, '" + bucketId + "', "
- + "'" + bucketName + "', "
- + "'/mnt/sdcard/DCIM/Camera/VID_20100811_051413.3gp', 2964)");
- }
-
- static GalleryAppStub newGalleryContext(SQLiteDatabase db, Looper mainLooper) {
- MockContentResolver cr = new MockContentResolver();
- ContentProvider cp = new DbContentProvider(db, cr);
- cr.addProvider("media", cp);
- return new GalleryAppMock(null, cr, mainLooper);
- }
-}
-
-class DbContentProvider extends MockContentProvider {
- private static final String TAG = "DbContentProvider";
- private SQLiteDatabase mDatabase;
- private ContentResolver mContentResolver;
-
- DbContentProvider(SQLiteDatabase db, ContentResolver cr) {
- mDatabase = db;
- mContentResolver = cr;
- }
-
- @Override
- public Cursor query(Uri uri, String[] projection,
- String selection, String[] selectionArgs, String sortOrder) {
- // This is a simplified version extracted from MediaProvider.
-
- String tableName = getTableName(uri);
- if (tableName == null) return null;
-
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- qb.setTables(tableName);
-
- String groupBy = null;
- String limit = uri.getQueryParameter("limit");
-
- if (uri.getQueryParameter("distinct") != null) {
- qb.setDistinct(true);
- }
-
- Log.v(TAG, "query = " + qb.buildQuery(projection, selection,
- selectionArgs, groupBy, null, sortOrder, limit));
-
- if (selectionArgs != null) {
- for (String s : selectionArgs) {
- Log.v(TAG, " selectionArgs = " + s);
- }
- }
-
- Cursor c = qb.query(mDatabase, projection, selection,
- selectionArgs, groupBy, null, sortOrder, limit);
-
- return c;
- }
-
- @Override
- public int delete(Uri uri, String whereClause, String[] whereArgs) {
- Log.v(TAG, "delete " + uri + "," + whereClause + "," + whereArgs[0]);
- String tableName = getTableName(uri);
- if (tableName == null) return 0;
- int count = mDatabase.delete(tableName, whereClause, whereArgs);
- mContentResolver.notifyChange(uri, null);
- return count;
- }
-
- private String getTableName(Uri uri) {
- String uriString = uri.toString();
- if (uriString.startsWith("content://media/external/images/media")) {
- return "images";
- } else if (uriString.startsWith("content://media/external/video/media")) {
- return "video";
- } else {
- return null;
- }
- }
-}
diff --git a/tests/src/com/android/gallery3d/data/MediaSetTest.java b/tests/src/com/android/gallery3d/data/MediaSetTest.java
deleted file mode 100644
index 33dfe96de..000000000
--- a/tests/src/com/android/gallery3d/data/MediaSetTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import com.android.gallery3d.app.GalleryApp;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-public class MediaSetTest extends AndroidTestCase {
- @SuppressWarnings("unused")
- private static final String TAG = "MediaSetTest";
-
- @SmallTest
- public void testComboAlbumSet() {
- GalleryApp app = new GalleryAppMock(null, null, null);
- Path.clearAll();
- DataManager dataManager = app.getDataManager();
-
- dataManager.addSource(new ComboSource(app));
- dataManager.addSource(new MockSource(app));
-
- MockSet set00 = new MockSet(Path.fromString("/mock/00"), dataManager, 0, 2000);
- MockSet set01 = new MockSet(Path.fromString("/mock/01"), dataManager, 1, 3000);
- MockSet set10 = new MockSet(Path.fromString("/mock/10"), dataManager, 2, 4000);
- MockSet set11 = new MockSet(Path.fromString("/mock/11"), dataManager, 3, 5000);
- MockSet set12 = new MockSet(Path.fromString("/mock/12"), dataManager, 4, 6000);
-
- MockSet set0 = new MockSet(Path.fromString("/mock/0"), dataManager, 7, 7000);
- set0.addMediaSet(set00);
- set0.addMediaSet(set01);
-
- MockSet set1 = new MockSet(Path.fromString("/mock/1"), dataManager, 8, 8000);
- set1.addMediaSet(set10);
- set1.addMediaSet(set11);
- set1.addMediaSet(set12);
-
- MediaSet combo = dataManager.getMediaSet("/combo/{/mock/0,/mock/1}");
- assertEquals(5, combo.getSubMediaSetCount());
- assertEquals(0, combo.getMediaItemCount());
- assertEquals("/mock/00", combo.getSubMediaSet(0).getPath().toString());
- assertEquals("/mock/01", combo.getSubMediaSet(1).getPath().toString());
- assertEquals("/mock/10", combo.getSubMediaSet(2).getPath().toString());
- assertEquals("/mock/11", combo.getSubMediaSet(3).getPath().toString());
- assertEquals("/mock/12", combo.getSubMediaSet(4).getPath().toString());
-
- assertEquals(10, combo.getTotalMediaItemCount());
- }
-}
diff --git a/tests/src/com/android/gallery3d/data/MockItem.java b/tests/src/com/android/gallery3d/data/MockItem.java
deleted file mode 100644
index 2901979de..000000000
--- a/tests/src/com/android/gallery3d/data/MockItem.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import com.android.gallery3d.util.ThreadPool.Job;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapRegionDecoder;
-
-public class MockItem extends MediaItem {
- public MockItem(Path path) {
- super(path, nextVersionNumber());
- }
-
- @Override
- public Job<Bitmap> requestImage(int type) {
- return null;
- }
-
- @Override
- public Job<BitmapRegionDecoder> requestLargeImage() {
- return null;
- }
-
- @Override
- public String getMimeType() {
- return null;
- }
-
- @Override
- public int getWidth() {
- return 0;
- }
-
- @Override
- public int getHeight() {
- return 0;
- }
-}
diff --git a/tests/src/com/android/gallery3d/data/MockSet.java b/tests/src/com/android/gallery3d/data/MockSet.java
deleted file mode 100644
index fa83c796f..000000000
--- a/tests/src/com/android/gallery3d/data/MockSet.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import java.util.ArrayList;
-
-public class MockSet extends MediaSet {
- ArrayList<MediaItem> mItems = new ArrayList<MediaItem>();
- ArrayList<MediaSet> mSets = new ArrayList<MediaSet>();
- Path mItemPath;
-
- public MockSet(Path path, DataManager dataManager) {
- super(path, nextVersionNumber());
- mItemPath = Path.fromString("/mock/item");
- }
-
- public MockSet(Path path, DataManager dataManager,
- int items, int item_id_start) {
- this(path, dataManager);
- for (int i = 0; i < items; i++) {
- Path childPath = mItemPath.getChild(item_id_start + i);
- mItems.add(new MockItem(childPath));
- }
- }
-
- public void addMediaSet(MediaSet sub) {
- mSets.add(sub);
- }
-
- @Override
- public int getMediaItemCount() {
- return mItems.size();
- }
-
- @Override
- public ArrayList<MediaItem> getMediaItem(int start, int count) {
- ArrayList<MediaItem> result = new ArrayList<MediaItem>();
- int end = Math.min(start + count, mItems.size());
-
- for (int i = start; i < end; i++) {
- result.add(mItems.get(i));
- }
- return result;
- }
-
- @Override
- public int getSubMediaSetCount() {
- return mSets.size();
- }
-
- @Override
- public MediaSet getSubMediaSet(int index) {
- return mSets.get(index);
- }
-
- @Override
- public int getTotalMediaItemCount() {
- int result = mItems.size();
- for (MediaSet s : mSets) {
- result += s.getTotalMediaItemCount();
- }
- return result;
- }
-
- @Override
- public String getName() {
- return "Set " + mPath;
- }
-
- @Override
- public long reload() {
- return 0;
- }
-}
diff --git a/tests/src/com/android/gallery3d/data/MockSource.java b/tests/src/com/android/gallery3d/data/MockSource.java
deleted file mode 100644
index 27ed4d0de..000000000
--- a/tests/src/com/android/gallery3d/data/MockSource.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import com.android.gallery3d.app.GalleryApp;
-
-class MockSource extends MediaSource {
- GalleryApp mApplication;
- PathMatcher mMatcher;
-
- private static final int MOCK_SET = 0;
- private static final int MOCK_ITEM = 1;
-
- public MockSource(GalleryApp context) {
- super("mock");
- mApplication = context;
- mMatcher = new PathMatcher();
- mMatcher.add("/mock/*", MOCK_SET);
- mMatcher.add("/mock/item/*", MOCK_ITEM);
- }
-
- @Override
- public MediaObject createMediaObject(Path path) {
- MediaObject obj;
- switch (mMatcher.match(path)) {
- case MOCK_SET:
- return new MockSet(path, mApplication.getDataManager());
- case MOCK_ITEM:
- return new MockItem(path);
- default:
- throw new RuntimeException("bad path: " + path);
- }
- }
-}
diff --git a/tests/src/com/android/gallery3d/data/PathTest.java b/tests/src/com/android/gallery3d/data/PathTest.java
deleted file mode 100644
index b43d10963..000000000
--- a/tests/src/com/android/gallery3d/data/PathTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-public class PathTest extends AndroidTestCase {
- @SuppressWarnings("unused")
- private static final String TAG = "PathTest";
-
- @SmallTest
- public void testToString() {
- Path p = Path.fromString("/hello/world");
- assertEquals("/hello/world", p.toString());
-
- p = Path.fromString("/a");
- assertEquals("/a", p.toString());
-
- p = Path.fromString("");
- assertEquals("", p.toString());
- }
-
- @SmallTest
- public void testSplit() {
- Path p = Path.fromString("/hello/world");
- String[] s = p.split();
- assertEquals(2, s.length);
- assertEquals("hello", s[0]);
- assertEquals("world", s[1]);
-
- p = Path.fromString("");
- assertEquals(0, p.split().length);
- }
-
- @SmallTest
- public void testPrefix() {
- Path p = Path.fromString("/hello/world");
- assertEquals("hello", p.getPrefix());
-
- p = Path.fromString("");
- assertEquals("", p.getPrefix());
- }
-
- @SmallTest
- public void testGetChild() {
- Path p = Path.fromString("/hello");
- Path q = Path.fromString("/hello/world");
- assertSame(q, p.getChild("world"));
- Path r = q.getChild(17);
- assertEquals("/hello/world/17", r.toString());
- }
-
- @SmallTest
- public void testSplitSequence() {
- String[] s = Path.splitSequence("{a,bb,ccc}");
- assertEquals(3, s.length);
- assertEquals("a", s[0]);
- assertEquals("bb", s[1]);
- assertEquals("ccc", s[2]);
-
- s = Path.splitSequence("{a,{bb,ccc},d}");
- assertEquals(3, s.length);
- assertEquals("a", s[0]);
- assertEquals("{bb,ccc}", s[1]);
- assertEquals("d", s[2]);
- }
-}
diff --git a/tests/src/com/android/gallery3d/data/RealDataTest.java b/tests/src/com/android/gallery3d/data/RealDataTest.java
deleted file mode 100644
index 526cfe357..000000000
--- a/tests/src/com/android/gallery3d/data/RealDataTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.data;
-
-import com.android.gallery3d.app.GalleryApp;
-import com.android.gallery3d.picasasource.PicasaSource;
-
-import android.os.Looper;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-
-// This test reads real data directly and dump information out in the log.
-public class RealDataTest extends AndroidTestCase {
- private static final String TAG = "RealDataTest";
-
- private HashSet<Path> mUsedId = new HashSet<Path>();
- private GalleryApp mApplication;
- private DataManager mDataManager;
-
- @LargeTest
- public void testRealData() {
- mUsedId.clear();
- mApplication = new GalleryAppMock(
- mContext,
- mContext.getContentResolver(),
- Looper.myLooper());
- mDataManager = mApplication.getDataManager();
- mDataManager.addSource(new LocalSource(mApplication));
- mDataManager.addSource(new PicasaSource(mApplication));
- new TestLocalImage().run();
- new TestLocalVideo().run();
- new TestPicasa().run();
- }
-
- class TestLocalImage {
- public void run() {
- MediaSet set = mDataManager.getMediaSet("/local/image");
- set.reload();
- Log.v(TAG, "LocalAlbumSet (Image)");
- dumpMediaSet(set, "");
- }
- }
-
- class TestLocalVideo {
- public void run() {
- MediaSet set = mDataManager.getMediaSet("/local/video");
- set.reload();
- Log.v(TAG, "LocalAlbumSet (Video)");
- dumpMediaSet(set, "");
- }
- }
-
- class TestPicasa implements Runnable {
- public void run() {
- MediaSet set = mDataManager.getMediaSet("/picasa");
- set.reload();
- Log.v(TAG, "PicasaAlbumSet");
- dumpMediaSet(set, "");
- }
- }
-
- void dumpMediaSet(MediaSet set, String prefix) {
- Log.v(TAG, "getName() = " + set.getName());
- Log.v(TAG, "getPath() = " + set.getPath());
- Log.v(TAG, "getMediaItemCount() = " + set.getMediaItemCount());
- Log.v(TAG, "getSubMediaSetCount() = " + set.getSubMediaSetCount());
- Log.v(TAG, "getTotalMediaItemCount() = " + set.getTotalMediaItemCount());
- assertNewId(set.getPath());
- for (int i = 0, n = set.getSubMediaSetCount(); i < n; i++) {
- MediaSet sub = set.getSubMediaSet(i);
- Log.v(TAG, prefix + "got set " + i);
- dumpMediaSet(sub, prefix + " ");
- }
- for (int i = 0, n = set.getMediaItemCount(); i < n; i += 10) {
- ArrayList<MediaItem> list = set.getMediaItem(i, 10);
- Log.v(TAG, prefix + "got item " + i + " (+" + list.size() + ")");
- for (MediaItem item : list) {
- dumpMediaItem(item, prefix + "..");
- }
- }
- }
-
- void dumpMediaItem(MediaItem item, String prefix) {
- assertNewId(item.getPath());
- Log.v(TAG, prefix + "getPath() = " + item.getPath());
- }
-
- void assertNewId(Path key) {
- assertFalse(key + " has already appeared.", mUsedId.contains(key));
- mUsedId.add(key);
- }
-}