Loading tests/src/com/android/contacts/activities/CallLogActivityTests.java +22 −43 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.contacts.calllog.CallLogAdapter; import com.android.contacts.calllog.CallLogFragment; import com.android.contacts.calllog.CallLogListItemViews; import com.android.contacts.calllog.CallLogQuery; import com.android.contacts.calllog.CallLogQueryTestUtils; import com.android.contacts.calllog.ContactInfo; import com.android.contacts.calllog.IntentProvider; import com.android.internal.telephony.CallerInfo; Loading Loading @@ -477,30 +478,19 @@ public class CallLogActivityTests * @param type Either Call.OUTGOING_TYPE or Call.INCOMING_TYPE or Call.MISSED_TYPE. */ private void insert(String number, long date, int duration, int type) { MatrixCursor.RowBuilder row = mCursor.newRow(); row.add(mIndex); mIndex ++; row.add(number); if (NOW == date) { row.add(new Date().getTime()); } else { row.add(date); } if (duration < 0) { duration = mRnd.nextInt(10 * 60); // 0 - 10 minutes random. } row.add(duration); // duration Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mIndex; values[CallLogQuery.NUMBER] = number; values[CallLogQuery.DATE] = date == NOW ? new Date().getTime() : date; values[CallLogQuery.DURATION] = duration < 0 ? mRnd.nextInt(10 * 60) : duration; if (mVoicemail != null && mVoicemail.equals(number)) { assertEquals(Calls.OUTGOING_TYPE, type); } row.add(type); // type row.add(TEST_COUNTRY_ISO); // country ISO row.add(null); // voicemail_uri row.add(null); // geocoded_location row.add(null); // cached_name row.add(0); // cached_number_type row.add(null); // cached_number_label row.add(CallLogQuery.SECTION_OLD_ITEM); // section values[CallLogQuery.CALL_TYPE] = type; values[CallLogQuery.COUNTRY_ISO] = TEST_COUNTRY_ISO; values[CallLogQuery.SECTION] = CallLogQuery.SECTION_OLD_ITEM; mCursor.addRow(values); ++mIndex; } /** Loading @@ -511,30 +501,19 @@ public class CallLogActivityTests * @param duration In seconds of the call. Use RAND_DURATION to pick a random one. */ private void insertVoicemail(String number, long date, int duration) { MatrixCursor.RowBuilder row = mCursor.newRow(); Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mIndex; values[CallLogQuery.NUMBER] = number; values[CallLogQuery.DATE] = date == NOW ? new Date().getTime() : date; values[CallLogQuery.DURATION] = duration < 0 ? mRnd.nextInt(10 * 60) : duration; values[CallLogQuery.CALL_TYPE] = Calls.VOICEMAIL_TYPE; values[CallLogQuery.COUNTRY_ISO] = TEST_COUNTRY_ISO; // Must have the same index as the row. Uri voicemailUri = values[CallLogQuery.VOICEMAIL_URI] = ContentUris.withAppendedId(VoicemailContract.Voicemails.CONTENT_URI, mIndex); row.add(mIndex); mIndex ++; row.add(number); if (NOW == date) { row.add(new Date().getTime()); } else { row.add(date); } if (duration < 0) { duration = mRnd.nextInt(10 * 60); // 0 - 10 minutes random. } row.add(duration); // duration row.add(Calls.VOICEMAIL_TYPE); // type row.add(TEST_COUNTRY_ISO); // country ISO row.add(voicemailUri); // voicemail_uri row.add(null); // geocoded_location row.add(null); // cached_name row.add(0); // cached_number_type row.add(null); // cached_number_label row.add(CallLogQuery.SECTION_OLD_ITEM); // section values[CallLogQuery.SECTION] = CallLogQuery.SECTION_OLD_ITEM; mCursor.addRow(values); ++mIndex; } /** Loading tests/src/com/android/contacts/calllog/CallLogGroupBuilderTest.java +10 −6 Original line number Diff line number Diff line Loading @@ -221,9 +221,12 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { throw new IllegalArgumentException("not an item section: " + section); } mCursor.moveToNext(); mCursor.addRow(new Object[]{ mCursor.getPosition(), number, 0L, 0L, type, "", "", "", null, 0, null, section }); Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mCursor.getPosition(); values[CallLogQuery.NUMBER] = number; values[CallLogQuery.CALL_TYPE] = type; values[CallLogQuery.SECTION] = section; mCursor.addRow(values); } /** Adds the old section header to the call log. */ Loading @@ -243,9 +246,10 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { throw new IllegalArgumentException("not a header section: " + section); } mCursor.moveToNext(); mCursor.addRow(new Object[]{ mCursor.getPosition(), "", 0L, 0L, 0, "", "", "", null, 0, null, section }); Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mCursor.getPosition(); values[CallLogQuery.SECTION] = section; mCursor.addRow(values); } /** Asserts that the group matches the given values. */ Loading tests/src/com/android/contacts/calllog/CallLogQueryTestUtils.java 0 → 100644 +37 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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.contacts.calllog; import static junit.framework.Assert.assertEquals; import junit.framework.Assert; /** * Helper class to create test values for {@link CallLogQuery}. */ public class CallLogQueryTestUtils { public static Object[] createTestValues() { Object[] values = new Object[]{ -1L, "", 0L, 0L, 0, "", "", "", null, 0, null }; assertEquals(CallLogQuery._PROJECTION.length, values.length); return values; } public static Object[] createTestExtendedValues() { Object[] values = new Object[]{ -1L, "", 0L, 0L, 0, "", "", "", null, 0, null, 0 }; Assert.assertEquals(CallLogQuery.EXTENDED_PROJECTION.length, values.length); return values; } } Loading
tests/src/com/android/contacts/activities/CallLogActivityTests.java +22 −43 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.contacts.calllog.CallLogAdapter; import com.android.contacts.calllog.CallLogFragment; import com.android.contacts.calllog.CallLogListItemViews; import com.android.contacts.calllog.CallLogQuery; import com.android.contacts.calllog.CallLogQueryTestUtils; import com.android.contacts.calllog.ContactInfo; import com.android.contacts.calllog.IntentProvider; import com.android.internal.telephony.CallerInfo; Loading Loading @@ -477,30 +478,19 @@ public class CallLogActivityTests * @param type Either Call.OUTGOING_TYPE or Call.INCOMING_TYPE or Call.MISSED_TYPE. */ private void insert(String number, long date, int duration, int type) { MatrixCursor.RowBuilder row = mCursor.newRow(); row.add(mIndex); mIndex ++; row.add(number); if (NOW == date) { row.add(new Date().getTime()); } else { row.add(date); } if (duration < 0) { duration = mRnd.nextInt(10 * 60); // 0 - 10 minutes random. } row.add(duration); // duration Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mIndex; values[CallLogQuery.NUMBER] = number; values[CallLogQuery.DATE] = date == NOW ? new Date().getTime() : date; values[CallLogQuery.DURATION] = duration < 0 ? mRnd.nextInt(10 * 60) : duration; if (mVoicemail != null && mVoicemail.equals(number)) { assertEquals(Calls.OUTGOING_TYPE, type); } row.add(type); // type row.add(TEST_COUNTRY_ISO); // country ISO row.add(null); // voicemail_uri row.add(null); // geocoded_location row.add(null); // cached_name row.add(0); // cached_number_type row.add(null); // cached_number_label row.add(CallLogQuery.SECTION_OLD_ITEM); // section values[CallLogQuery.CALL_TYPE] = type; values[CallLogQuery.COUNTRY_ISO] = TEST_COUNTRY_ISO; values[CallLogQuery.SECTION] = CallLogQuery.SECTION_OLD_ITEM; mCursor.addRow(values); ++mIndex; } /** Loading @@ -511,30 +501,19 @@ public class CallLogActivityTests * @param duration In seconds of the call. Use RAND_DURATION to pick a random one. */ private void insertVoicemail(String number, long date, int duration) { MatrixCursor.RowBuilder row = mCursor.newRow(); Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mIndex; values[CallLogQuery.NUMBER] = number; values[CallLogQuery.DATE] = date == NOW ? new Date().getTime() : date; values[CallLogQuery.DURATION] = duration < 0 ? mRnd.nextInt(10 * 60) : duration; values[CallLogQuery.CALL_TYPE] = Calls.VOICEMAIL_TYPE; values[CallLogQuery.COUNTRY_ISO] = TEST_COUNTRY_ISO; // Must have the same index as the row. Uri voicemailUri = values[CallLogQuery.VOICEMAIL_URI] = ContentUris.withAppendedId(VoicemailContract.Voicemails.CONTENT_URI, mIndex); row.add(mIndex); mIndex ++; row.add(number); if (NOW == date) { row.add(new Date().getTime()); } else { row.add(date); } if (duration < 0) { duration = mRnd.nextInt(10 * 60); // 0 - 10 minutes random. } row.add(duration); // duration row.add(Calls.VOICEMAIL_TYPE); // type row.add(TEST_COUNTRY_ISO); // country ISO row.add(voicemailUri); // voicemail_uri row.add(null); // geocoded_location row.add(null); // cached_name row.add(0); // cached_number_type row.add(null); // cached_number_label row.add(CallLogQuery.SECTION_OLD_ITEM); // section values[CallLogQuery.SECTION] = CallLogQuery.SECTION_OLD_ITEM; mCursor.addRow(values); ++mIndex; } /** Loading
tests/src/com/android/contacts/calllog/CallLogGroupBuilderTest.java +10 −6 Original line number Diff line number Diff line Loading @@ -221,9 +221,12 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { throw new IllegalArgumentException("not an item section: " + section); } mCursor.moveToNext(); mCursor.addRow(new Object[]{ mCursor.getPosition(), number, 0L, 0L, type, "", "", "", null, 0, null, section }); Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mCursor.getPosition(); values[CallLogQuery.NUMBER] = number; values[CallLogQuery.CALL_TYPE] = type; values[CallLogQuery.SECTION] = section; mCursor.addRow(values); } /** Adds the old section header to the call log. */ Loading @@ -243,9 +246,10 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { throw new IllegalArgumentException("not a header section: " + section); } mCursor.moveToNext(); mCursor.addRow(new Object[]{ mCursor.getPosition(), "", 0L, 0L, 0, "", "", "", null, 0, null, section }); Object[] values = CallLogQueryTestUtils.createTestExtendedValues(); values[CallLogQuery.ID] = mCursor.getPosition(); values[CallLogQuery.SECTION] = section; mCursor.addRow(values); } /** Asserts that the group matches the given values. */ Loading
tests/src/com/android/contacts/calllog/CallLogQueryTestUtils.java 0 → 100644 +37 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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.contacts.calllog; import static junit.framework.Assert.assertEquals; import junit.framework.Assert; /** * Helper class to create test values for {@link CallLogQuery}. */ public class CallLogQueryTestUtils { public static Object[] createTestValues() { Object[] values = new Object[]{ -1L, "", 0L, 0L, 0, "", "", "", null, 0, null }; assertEquals(CallLogQuery._PROJECTION.length, values.length); return values; } public static Object[] createTestExtendedValues() { Object[] values = new Object[]{ -1L, "", 0L, 0L, 0, "", "", "", null, 0, null, 0 }; Assert.assertEquals(CallLogQuery.EXTENDED_PROJECTION.length, values.length); return values; } }