1/*
2 * Copyright (C) 2006 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.provider;
18
19import android.content.ContentResolver;
20import android.content.ContentValues;
21import android.database.Cursor;
22import android.net.Uri;
23import android.provider.Telephony.Sms;
24import android.test.AndroidTestCase;
25import android.test.suitebuilder.annotation.LargeTest;
26import android.test.suitebuilder.annotation.Suppress;
27
28import java.util.GregorianCalendar;
29
30@Suppress  // Failing.
31public class SmsProviderTest extends AndroidTestCase {
32
33    @LargeTest
34    public void testProvider() throws Exception {
35        // This test does the following
36        //  1. Insert 10 messages from the same number at different times.
37        //
38        //  . Delete the messages and make sure that they were deleted.
39
40        long now = System.currentTimeMillis();
41
42        Uri[] urls = new Uri[10];
43        String[] dates = new String[]{
44                Long.toString(new GregorianCalendar(1970, 1, 1, 0, 0, 0).getTimeInMillis()),
45                Long.toString(new GregorianCalendar(1971, 2, 13, 16, 35, 3).getTimeInMillis()),
46                Long.toString(new GregorianCalendar(1978, 10, 22, 0, 1, 0).getTimeInMillis()),
47                Long.toString(new GregorianCalendar(1980, 1, 11, 10, 22, 30).getTimeInMillis()),
48                Long.toString(now - (5 * 24 * 60 * 60 * 1000)),
49                Long.toString(now - (2 * 24 * 60 * 60 * 1000)),
50                Long.toString(now - (5 * 60 * 60 * 1000)),
51                Long.toString(now - (30 * 60 * 1000)),
52                Long.toString(now - (5 * 60 * 1000)),
53                Long.toString(now)
54        };
55
56        ContentValues map = new ContentValues();
57        map.put("address", "+15045551337");
58        map.put("read", 0);
59
60        ContentResolver contentResolver = mContext.getContentResolver();
61
62        for (int i = 0; i < urls.length; i++) {
63            map.put("body", "Test " + i + " !");
64            map.put("date", dates[i]);
65            urls[i] = contentResolver.insert(Sms.Inbox.CONTENT_URI, map);
66            assertNotNull(urls[i]);
67        }
68
69        Cursor c = contentResolver.query(Sms.Inbox.CONTENT_URI, null, null, null, "date");
70
71        //DatabaseUtils.dumpCursor(c);
72
73        for (Uri url : urls) {
74            int count = contentResolver.delete(url, null, null);
75            assertEquals(1, count);
76        }
77    }
78}
79