summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/gallery3d/data/RealDataTest.java
blob: 526cfe3573583f2c6237fbb7a3535777e0a8da20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * 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);
    }
}