1/*
2 * Copyright (C) 2009 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
17package android.pim.vcard;
18
19import android.content.ContentProvider;
20import android.content.ContentProviderOperation;
21import android.content.ContentProviderResult;
22import android.content.ContentValues;
23import android.content.EntityIterator;
24import android.content.res.AssetFileDescriptor;
25import android.database.Cursor;
26import android.database.CursorWindow;
27import android.database.IBulkCursor;
28import android.database.IContentObserver;
29import android.net.Uri;
30import android.os.IBinder;
31import android.os.ParcelFileDescriptor;
32import android.os.RemoteException;
33import android.pim.vcard.VCardConfig;
34import android.test.AndroidTestCase;
35import android.util.Log;
36
37import java.util.ArrayList;
38
39/**
40 * Almost a dead copy of android.test.mock.MockContentProvider, but different in that this
41 * class extends ContentProvider, not implementing IContentProvider,
42 * so that MockContentResolver is able to accept this class :(
43 */
44class MockContentProvider extends ContentProvider {
45    @Override
46    public boolean onCreate() {
47        return true;
48    }
49
50    @Override
51    public int bulkInsert(Uri url, ContentValues[] initialValues) {
52        throw new UnsupportedOperationException("unimplemented mock method");
53    }
54
55    @SuppressWarnings("unused")
56    public IBulkCursor bulkQuery(Uri url, String[] projection, String selection,
57            String[] selectionArgs, String sortOrder, IContentObserver observer,
58            CursorWindow window) throws RemoteException {
59        throw new UnsupportedOperationException("unimplemented mock method");
60    }
61
62    @Override
63    @SuppressWarnings("unused")
64    public int delete(Uri url, String selection, String[] selectionArgs) {
65        throw new UnsupportedOperationException("unimplemented mock method");
66    }
67
68    @Override
69    public String getType(Uri url) {
70        throw new UnsupportedOperationException("unimplemented mock method");
71    }
72
73    @Override
74    public Uri insert(Uri url, ContentValues initialValues) {
75        throw new UnsupportedOperationException("unimplemented mock method");
76    }
77
78    @Override
79    public ParcelFileDescriptor openFile(Uri url, String mode) {
80        throw new UnsupportedOperationException("unimplemented mock method");
81    }
82
83    @Override
84    public AssetFileDescriptor openAssetFile(Uri uri, String mode) {
85        throw new UnsupportedOperationException("unimplemented mock method");
86    }
87
88    @Override
89    public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) {
90        throw new UnsupportedOperationException("unimplemented mock method");
91    }
92
93    @Override
94    public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs,
95            String sortOrder) {
96        throw new UnsupportedOperationException("unimplemented mock method");
97    }
98
99    @Override
100    public int update(Uri url, ContentValues values, String selection, String[] selectionArgs) {
101        throw new UnsupportedOperationException("unimplemented mock method");
102    }
103
104    public IBinder asBinder() {
105        throw new UnsupportedOperationException("unimplemented mock method");
106    }
107}
108
109/**
110 * BaseClass for vCard unit tests with utility classes.
111 * Please do not add each unit test here.
112 */
113/* package */ class VCardTestsBase extends AndroidTestCase {
114    public static final int V21 = VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8;
115    public static final int V30 = VCardConfig.VCARD_TYPE_V30_GENERIC_UTF8;
116
117    // Do not modify these during tests.
118    protected final ContentValues mContentValuesForQP;
119    protected final ContentValues mContentValuesForSJis;
120    protected final ContentValues mContentValuesForUtf8;
121    protected final ContentValues mContentValuesForQPAndSJis;
122    protected final ContentValues mContentValuesForQPAndUtf8;
123    protected final ContentValues mContentValuesForBase64V21;
124    protected final ContentValues mContentValuesForBase64V30;
125
126    protected VCardVerifier mVerifier;
127    private boolean mSkipVerification;
128
129    public VCardTestsBase() {
130        super();
131        mContentValuesForQP = new ContentValues();
132        mContentValuesForQP.put("ENCODING", "QUOTED-PRINTABLE");
133        mContentValuesForSJis = new ContentValues();
134        mContentValuesForSJis.put("CHARSET", "SHIFT_JIS");
135        mContentValuesForUtf8 = new ContentValues();
136        mContentValuesForUtf8.put("CHARSET", "UTF-8");
137        mContentValuesForQPAndSJis = new ContentValues();
138        mContentValuesForQPAndSJis.put("ENCODING", "QUOTED-PRINTABLE");
139        mContentValuesForQPAndSJis.put("CHARSET", "SHIFT_JIS");
140        mContentValuesForQPAndUtf8 = new ContentValues();
141        mContentValuesForQPAndUtf8.put("ENCODING", "QUOTED-PRINTABLE");
142        mContentValuesForQPAndUtf8.put("CHARSET", "UTF-8");
143        mContentValuesForBase64V21 = new ContentValues();
144        mContentValuesForBase64V21.put("ENCODING", "BASE64");
145        mContentValuesForBase64V30 = new ContentValues();
146        mContentValuesForBase64V30.put("ENCODING", "b");
147    }
148
149    @Override
150    public void testAndroidTestCaseSetupProperly() {
151        super.testAndroidTestCaseSetupProperly();
152        mSkipVerification = true;
153    }
154
155    @Override
156    public void setUp() throws Exception{
157        super.setUp();
158        mVerifier = new VCardVerifier(this);
159        mSkipVerification = false;
160    }
161
162    @Override
163    public void tearDown() throws Exception {
164        super.tearDown();
165        if (!mSkipVerification) {
166            mVerifier.verify();
167        }
168    }
169}
170