Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.gallery3d.data;
     18 
     19 import com.android.gallery3d.app.GalleryApp;
     20 import com.android.gallery3d.picasasource.PicasaSource;
     21 
     22 import android.os.Looper;
     23 import android.test.AndroidTestCase;
     24 import android.test.suitebuilder.annotation.LargeTest;
     25 import android.util.Log;
     26 
     27 import java.util.ArrayList;
     28 import java.util.HashSet;
     29 
     30 // This test reads real data directly and dump information out in the log.
     31 public class RealDataTest extends AndroidTestCase {
     32     private static final String TAG = "RealDataTest";
     33 
     34     private HashSet<Path> mUsedId = new HashSet<Path>();
     35     private GalleryApp mApplication;
     36     private DataManager mDataManager;
     37 
     38     @LargeTest
     39     public void testRealData() {
     40         mUsedId.clear();
     41         mApplication = new GalleryAppMock(
     42                 mContext,
     43                 mContext.getContentResolver(),
     44                 Looper.myLooper());
     45         mDataManager = mApplication.getDataManager();
     46         mDataManager.addSource(new LocalSource(mApplication));
     47         mDataManager.addSource(new PicasaSource(mApplication));
     48         new TestLocalImage().run();
     49         new TestLocalVideo().run();
     50         new TestPicasa().run();
     51     }
     52 
     53     class TestLocalImage {
     54         public void run() {
     55             MediaSet set = mDataManager.getMediaSet("/local/image");
     56             set.reload();
     57             Log.v(TAG, "LocalAlbumSet (Image)");
     58             dumpMediaSet(set, "");
     59         }
     60     }
     61 
     62     class TestLocalVideo {
     63         public void run() {
     64             MediaSet set = mDataManager.getMediaSet("/local/video");
     65             set.reload();
     66             Log.v(TAG, "LocalAlbumSet (Video)");
     67             dumpMediaSet(set, "");
     68         }
     69     }
     70 
     71     class TestPicasa implements Runnable {
     72         public void run() {
     73             MediaSet set = mDataManager.getMediaSet("/picasa");
     74             set.reload();
     75             Log.v(TAG, "PicasaAlbumSet");
     76             dumpMediaSet(set, "");
     77         }
     78     }
     79 
     80     void dumpMediaSet(MediaSet set, String prefix) {
     81         Log.v(TAG, "getName() = " + set.getName());
     82         Log.v(TAG, "getPath() = " + set.getPath());
     83         Log.v(TAG, "getMediaItemCount() = " + set.getMediaItemCount());
     84         Log.v(TAG, "getSubMediaSetCount() = " + set.getSubMediaSetCount());
     85         Log.v(TAG, "getTotalMediaItemCount() = " + set.getTotalMediaItemCount());
     86         assertNewId(set.getPath());
     87         for (int i = 0, n = set.getSubMediaSetCount(); i < n; i++) {
     88             MediaSet sub = set.getSubMediaSet(i);
     89             Log.v(TAG, prefix + "got set " + i);
     90             dumpMediaSet(sub, prefix + "  ");
     91         }
     92         for (int i = 0, n = set.getMediaItemCount(); i < n; i += 10) {
     93             ArrayList<MediaItem> list = set.getMediaItem(i, 10);
     94             Log.v(TAG, prefix + "got item " + i + " (+" + list.size() + ")");
     95             for (MediaItem item : list) {
     96                 dumpMediaItem(item, prefix + "..");
     97             }
     98         }
     99     }
    100 
    101     void dumpMediaItem(MediaItem item, String prefix) {
    102         assertNewId(item.getPath());
    103         Log.v(TAG, prefix + "getPath() = " + item.getPath());
    104     }
    105 
    106     void assertNewId(Path key) {
    107         assertFalse(key + " has already appeared.", mUsedId.contains(key));
    108         mUsedId.add(key);
    109     }
    110 }
    111