Merge "Phase 2 of test cleanup: moving test files from AndroidTests closer to their sources."

This commit is contained in:
Neal Nguyen
2010-01-29 16:38:53 -08:00
committed by Android (Google) Code Review
181 changed files with 1731 additions and 1417 deletions

View File

@@ -5,10 +5,14 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
# Include all test java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES := \
$(call all-java-files-under, src) \
src/android/os/IAidlTest.aidl
LOCAL_JAVA_LIBRARIES := android.test.runner
LOCAL_PACKAGE_NAME := FrameworksCoreTests
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)

View File

@@ -16,6 +16,46 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.frameworks.coretests">
<permission android:name="com.android.frameworks.coretests.permission.TEST_GRANTED"
android:protectionLevel="normal"
android:label="@string/permlab_testGranted"
android:description="@string/permdesc_testGranted">
<meta-data android:name="com.android.frameworks.coretests.string" android:value="foo" />
<meta-data android:name="com.android.frameworks.coretests.boolean" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.integer" android:value="100" />
<meta-data android:name="com.android.frameworks.coretests.color" android:value="#ff000000" />
<meta-data android:name="com.android.frameworks.coretests.float" android:value="100.1" />
<meta-data android:name="com.android.frameworks.coretests.reference" android:resource="@xml/metadata" />
</permission>
<permission android:name="com.android.frameworks.coretests.permission.TEST_DENIED"
android:protectionLevel="normal"
android:label="@string/permlab_testDenied"
android:description="@string/permdesc_testDenied" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
<uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.TEST_GRANTED" />
<uses-permission android:name="com.google.android.googleapps.permission.ACCESS_GOOGLE_PASSWORD" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.ALL_SERVICES" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
@@ -28,12 +68,8 @@
<!-- location test permissions -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.HARDWARE_TEST" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESSIBILITY_EVENT_VIEW_TYPES" />
<uses-permission android:name="android.permission.ACCESSIBILITY_EVENT_TRANSITION_TYPES" />
<uses-permission android:name="android.permission.ACCESSIBILITY_EVENT_NOTIFICATION_TYPES" />
@@ -975,6 +1011,187 @@
</intent-filter>
</activity>
<!-- Activity-level metadata -->
<meta-data android:name="com.android.frameworks.coretests.isApp" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.string" android:value="foo" />
<meta-data android:name="com.android.frameworks.coretests.boolean" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.integer" android:value="100" />
<meta-data android:name="com.android.frameworks.coretests.color" android:value="#ff000000" />
<meta-data android:name="com.android.frameworks.coretests.float" android:value="100.1" />
<meta-data android:name="com.android.frameworks.coretests.reference"
android:resource="@xml/metadata_app" />
<activity android:name="AndroidPerformanceTests" android:label="Android Performance Tests">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.UNIT_TEST" />
</intent-filter>
</activity>
<!-- Application components used for activity tests -->
<activity android:name="android.app.activity.TestedActivity"
android:process=":remoteActivity">
</activity>
<activity android:name="android.app.activity.LocalActivity" android:multiprocess="true">
<meta-data android:name="com.android.frameworks.coretests.string" android:value="foo" />
<meta-data android:name="com.android.frameworks.coretests.boolean" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.integer" android:value="100" />
<meta-data android:name="com.android.frameworks.coretests.color" android:value="#ff000000" />
<meta-data android:name="com.android.frameworks.coretests.float" android:value="100.1" />
<meta-data android:name="com.android.frameworks.coretests.reference" android:resource="@xml/metadata" />
</activity>
<activity android:name="android.app.activity.TestedScreen"
android:process=":remoteScreen">
</activity>
<activity android:name="android.app.activity.LocalScreen" android:multiprocess="true">
</activity>
<activity android:name="android.app.activity.ClearTop" android:multiprocess="true"
android:launchMode="singleTop">
</activity>
<activity android:name="android.app.activity.LocalDialog" android:multiprocess="true"
android:theme="@android:style/Theme.Dialog">
</activity>
<activity android:name="android.app.activity.SubActivityScreen">
</activity>
<activity android:name="android.app.activity.RemoteSubActivityScreen"
android:process=":remoteActivity">
</activity>
<activity android:name="android.app.activity.LaunchpadActivity" android:multiprocess="true">
</activity>
<activity android:name="android.app.activity.LaunchpadTabActivity" android:multiprocess="true">
</activity>
<receiver android:name="android.app.activity.AbortReceiver">
<intent-filter android:priority="1">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_ABORT" />
</intent-filter>
</receiver>
<receiver android:name="android.app.activity.LocalReceiver">
<intent-filter android:priority="-1">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_ABORT" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_ALL" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_REPEAT" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_LOCAL" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_FAIL_REGISTER" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_FAIL_BIND" />
</intent-filter>
<meta-data android:name="com.android.frameworks.coretests.string" android:value="foo" />
<meta-data android:name="com.android.frameworks.coretests.boolean" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.integer" android:value="100" />
<meta-data android:name="com.android.frameworks.coretests.color" android:value="#ff000000" />
<meta-data android:name="com.android.frameworks.coretests.float" android:value="100.1" />
<meta-data android:name="com.android.frameworks.coretests.reference" android:resource="@xml/metadata" />
</receiver>
<receiver android:name="android.app.activity.ResultReceiver">
<intent-filter>
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_RESULT" />
</intent-filter>
</receiver>
<receiver android:name="android.app.activity.LocalGrantedReceiver"
android:permission="com.android.frameworks.coretests.permission.TEST_GRANTED">
<intent-filter android:priority="-1">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_LOCAL_GRANTED" />
</intent-filter>
</receiver>
<receiver android:name="android.app.activity.LocalDeniedReceiver"
android:permission="com.android.frameworks.coretests.permission.TEST_DENIED">
<intent-filter android:priority="-1">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_LOCAL_DENIED" />
</intent-filter>
</receiver>
<receiver android:name="android.app.activity.RemoteReceiver"
android:process=":remoteReceiver">
<intent-filter android:priority="2">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_ABORT" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_ALL" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_REPEAT" />
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_REMOTE" />
</intent-filter>
</receiver>
<receiver android:name="android.app.activity.RemoteGrantedReceiver"
android:permission="com.android.frameworks.coretests.permission.TEST_GRANTED">
<intent-filter android:priority="2">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_REMOTE_GRANTED" />
</intent-filter>
</receiver>
<receiver android:name="android.app.activity.RemoteDeniedReceiver"
android:permission="com.android.frameworks.coretests.permission.TEST_DENIED">
<intent-filter android:priority="2">
<action android:name="com.android.frameworks.coretests.activity.BROADCAST_REMOTE_DENIED" />
</intent-filter>
</receiver>
<service android:name="android.app.activity.LocalService">
<intent-filter>
<action android:name="com.android.frameworks.coretests.activity.SERVICE_LOCAL" />
</intent-filter>
<meta-data android:name="com.android.frameworks.coretests.string" android:value="foo" />
<meta-data android:name="com.android.frameworks.coretests.boolean" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.integer" android:value="100" />
<meta-data android:name="com.android.frameworks.coretests.color" android:value="#ff000000" />
<meta-data android:name="com.android.frameworks.coretests.float" android:value="100.1" />
<meta-data android:name="com.android.frameworks.coretests.reference" android:resource="@xml/metadata" />
</service>
<service android:name="android.app.activity.LocalDeniedService"
android:permission="com.android.frameworks.coretests.permission.TEST_DENIED">
<intent-filter>
<action android:name="com.android.frameworks.coretests.activity.SERVICE_LOCAL_DENIED" />
</intent-filter>
</service>
<service android:name="android.app.activity.LocalGrantedService"
android:permission="com.android.frameworks.coretests.permission.TEST_GRANTED">
<intent-filter>
<action android:name="com.android.frameworks.coretests.activity.SERVICE_LOCAL_GRANTED" />
</intent-filter>
</service>
<provider android:name="android.app.activity.LocalProvider"
android:authorities="com.android.frameworks.coretests.LocalProvider">
<meta-data android:name="com.android.frameworks.coretests.string" android:value="foo" />
<meta-data android:name="com.android.frameworks.coretests.boolean" android:value="true" />
<meta-data android:name="com.android.frameworks.coretests.integer" android:value="100" />
<meta-data android:name="com.android.frameworks.coretests.color" android:value="#ff000000" />
<meta-data android:name="com.android.frameworks.coretests.float" android:value="100.1" />
<meta-data android:name="com.android.frameworks.coretests.reference" android:resource="@xml/metadata" />
</provider>
<!-- Application components used for content tests -->
<provider android:name="android.content.MemoryFileProvider"
android:authorities="android.content.MemoryFileProvider"
android:process=":MemoryFileProvider">
</provider>
<!-- Application components used for os tests -->
<service android:name="android.os.MessengerService"
android:process=":messengerService">
</service>
<!-- Application components used for search manager tests -->
<activity android:name="android.app.activity.SearchableActivity"
android:label="Searchable Activity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<provider android:name="android.app.SuggestionProvider"
android:authorities="android.app.SuggestionProvider">
</provider>
<!-- Used to test IPC. -->
<service android:name="com.android.frameworks.coretests.binder.BinderTestService"
android:process="binder.BinderTestService" />
<service android:name="com.android.frameworks.coretests.binder.BinderPerformanceService"
android:process="binder.BinderPerformanceService" />
<service android:name="com.android.frameworks.coretests.binder.BinderVsMessagingService"
android:process="binder.BinderVsMessagingService" />
</application>
<instrumentation

View File

@@ -17,4 +17,4 @@
** limitations under the License.
*/
-->
<view xmlns:android="http://schemas.android.com/apk/res/android" class="com.android.unit_tests.InflateTest$ViewOne" android:id="@+id/viewOne" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view xmlns:android="http://schemas.android.com/apk/res/android" class="android.view.InflateTest$ViewOne" android:id="@+id/viewOne" android:layout_width="match_parent" android:layout_height="match_parent"/>

View File

@@ -18,6 +18,6 @@
*/
-->
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="com.android.unit_tests.InflateTest$ViewOne"
class="android.view.InflateTest$ViewOne"
android:id="@+id/viewOne" android:tag="MyTag"
android:layout_width="match_parent" android:layout_height="match_parent"/>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2006, 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.
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
<view class="android.view.InflateTest$ViewOne" android:id="@+id/view1" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view class="android.view.InflateTest$ViewOne" android:id="@+id/view2" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view class="android.view.InflateTest$ViewOne" android:id="@+id/view3" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view class="android.view.InflateTest$ViewOne" android:id="@+id/view4" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view class="android.view.InflateTest$ViewOne" android:id="@+id/view5" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view class="android.view.InflateTest$ViewOne" android:id="@+id/view6" android:layout_width="match_parent" android:layout_height="match_parent"/>
</LinearLayout>

View File

@@ -18,6 +18,6 @@
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
<view class="com.android.unit_tests.InflateTest$ViewOne" android:id="@+id/viewOne" android:layout_width="match_parent" android:layout_height="match_parent"/>
<view class="android.view.InflateTest$ViewOne" android:id="@+id/viewOne" android:layout_width="match_parent" android:layout_height="match_parent"/>
</LinearLayout>

View File

@@ -100,4 +100,21 @@
<string name="include_button">I was included!</string>
<string name="view">View</string>
<string name="layout_five_text_text">S</string>
<string name="layout_four_text_text">S</string>
<string name="layout_six_text_text">S</string>
<string name="menu_test">test</string>
<string name="metadata_text">text</string>
<string name="permlab_testGranted">Test Granted</string>
<string name="permdesc_testGranted">Used for running unit tests, for
testing operations where we have the permission.</string>
<string name="permlab_testDenied">Test Denied</string>
<string name="permdesc_testDenied">Used for running unit tests, for
testing operations where we do not have the permission.</string>
<string name="searchable_label">SearchManager Test</string>
<string name="searchable_hint">A search hint</string>
</resources>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.accounts;
package android.accounts;
import android.test.AndroidTestCase;
import android.test.RenamingDelegatingContext;
@@ -175,4 +175,4 @@ public class AccountManagerServiceTest extends AndroidTestCase {
assertNull(ams.readAuthTokenFromDatabase(a12, "att2"));
}
}
}

View File

@@ -14,9 +14,9 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.app;
import com.android.unit_tests.activity.LocalActivity;
import android.app.activity.LocalActivity;
import android.app.Activity;
import android.app.ISearchManager;
@@ -39,8 +39,8 @@ import android.test.suitebuilder.annotation.MediumTest;
public class SearchManagerTest extends ActivityInstrumentationTestCase2<LocalActivity> {
private ComponentName SEARCHABLE_ACTIVITY =
new ComponentName("com.android.unit_tests",
"com.android.unit_tests.SearchableActivity");
new ComponentName("com.android.frameworks.coretests",
"android.app.activity.SearchableActivity");
/*
* Bug list of test ideas.
@@ -76,7 +76,7 @@ public class SearchManagerTest extends ActivityInstrumentationTestCase2<LocalAct
Context mContext;
public SearchManagerTest() {
super("com.android.unit_tests", LocalActivity.class);
super("com.android.frameworks.coretests", LocalActivity.class);
}
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.app;
import android.app.SearchManager;
import android.app.SearchableInfo;
@@ -108,8 +108,8 @@ public class SearchablesTest extends AndroidTestCase {
// confirm that we return null for non-searchy activities
ComponentName nonActivity = new ComponentName(
"com.android.unit_tests",
"com.android.unit_tests.NO_SEARCH_ACTIVITY");
"com.android.frameworks.coretests",
"com.android.frameworks.coretests.activity.NO_SEARCH_ACTIVITY");
SearchableInfo si = searchables.getSearchableInfo(nonActivity);
assertNull(si);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.app;
import android.app.SearchManager;
import android.content.ContentProvider;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.Context;
import android.content.Intent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.ActivityManager;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import junit.framework.TestSuite;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.content.Context;
@@ -25,9 +25,9 @@ import android.test.PerformanceTestCase;
public class ActivityTestsBase extends AndroidTestCase
implements PerformanceTestCase, LaunchpadActivity.CallingTest {
public static final String PERMISSION_GRANTED =
"com.android.unit_tests.permission.TEST_GRANTED";
"com.android.frameworks.coretests.permission.TEST_GRANTED";
public static final String PERMISSION_DENIED =
"com.android.unit_tests.permission.TEST_DENIED";
"com.android.frameworks.coretests.permission.TEST_DENIED";
protected Intent mIntent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.app.ActivityManagerNative;
@@ -36,35 +36,35 @@ public class BroadcastTest extends ActivityTestsBase {
public static final int BROADCAST_TIMEOUT = 5 * 1000;
public static final String BROADCAST_REGISTERED =
"com.android.unit_tests.activity.BROADCAST_REGISTERED";
"com.android.frameworks.coretests.activity.BROADCAST_REGISTERED";
public static final String BROADCAST_LOCAL =
"com.android.unit_tests.activity.BROADCAST_LOCAL";
"com.android.frameworks.coretests.activity.BROADCAST_LOCAL";
public static final String BROADCAST_LOCAL_GRANTED =
"com.android.unit_tests.activity.BROADCAST_LOCAL_GRANTED";
"com.android.frameworks.coretests.activity.BROADCAST_LOCAL_GRANTED";
public static final String BROADCAST_LOCAL_DENIED =
"com.android.unit_tests.activity.BROADCAST_LOCAL_DENIED";
"com.android.frameworks.coretests.activity.BROADCAST_LOCAL_DENIED";
public static final String BROADCAST_REMOTE =
"com.android.unit_tests.activity.BROADCAST_REMOTE";
"com.android.frameworks.coretests.activity.BROADCAST_REMOTE";
public static final String BROADCAST_REMOTE_GRANTED =
"com.android.unit_tests.activity.BROADCAST_REMOTE_GRANTED";
"com.android.frameworks.coretests.activity.BROADCAST_REMOTE_GRANTED";
public static final String BROADCAST_REMOTE_DENIED =
"com.android.unit_tests.activity.BROADCAST_REMOTE_DENIED";
"com.android.frameworks.coretests.activity.BROADCAST_REMOTE_DENIED";
public static final String BROADCAST_ALL =
"com.android.unit_tests.activity.BROADCAST_ALL";
"com.android.frameworks.coretests.activity.BROADCAST_ALL";
public static final String BROADCAST_MULTI =
"com.android.unit_tests.activity.BROADCAST_MULTI";
"com.android.frameworks.coretests.activity.BROADCAST_MULTI";
public static final String BROADCAST_ABORT =
"com.android.unit_tests.activity.BROADCAST_ABORT";
"com.android.frameworks.coretests.activity.BROADCAST_ABORT";
public static final String BROADCAST_STICKY1 =
"com.android.unit_tests.activity.BROADCAST_STICKY1";
"com.android.frameworks.coretests.activity.BROADCAST_STICKY1";
public static final String BROADCAST_STICKY2 =
"com.android.unit_tests.activity.BROADCAST_STICKY2";
"com.android.frameworks.coretests.activity.BROADCAST_STICKY2";
public static final String BROADCAST_FAIL_REGISTER =
"com.android.unit_tests.activity.BROADCAST_FAIL_REGISTER";
"com.android.frameworks.coretests.activity.BROADCAST_FAIL_REGISTER";
public static final String BROADCAST_FAIL_BIND =
"com.android.unit_tests.activity.BROADCAST_FAIL_BIND";
"com.android.frameworks.coretests.activity.BROADCAST_FAIL_BIND";
public static final String RECEIVER_REG = "receiver-reg";
public static final String RECEIVER_LOCAL = "receiver-local";
@@ -276,7 +276,7 @@ public class BroadcastTest extends ActivityTestsBase {
map.putString("foo", "you");
map.putString("remove", "me");
getContext().sendOrderedBroadcast(
new Intent("com.android.unit_tests.activity.BROADCAST_RESULT"),
new Intent("com.android.frameworks.coretests.activity.BROADCAST_RESULT"),
null, broadcastReceiver, null, 1, "foo", map);
while (!broadcastReceiver.mHaveResult) {
try {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.content.Intent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.app.PendingIntent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.ComponentName;
import android.test.suitebuilder.annotation.LargeTest;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.content.BroadcastReceiver;
@@ -71,49 +71,49 @@ public class LaunchpadActivity extends Activity {
}
// Also used as the Binder interface descriptor string in these tests
public static final String LAUNCH = "com.android.unit_tests.activity.LAUNCH";
public static final String LAUNCH = "com.android.frameworks.coretests.activity.LAUNCH";
public static final String FORWARD_RESULT =
"com.android.unit_tests.activity.FORWARD_RESULT";
"com.android.frameworks.coretests.activity.FORWARD_RESULT";
public static final String RETURNED_RESULT =
"com.android.unit_tests.activity.RETURNED_RESULT";
"com.android.frameworks.coretests.activity.RETURNED_RESULT";
public static final String BAD_PARCELABLE =
"com.android.unit_tests.activity.BAD_PARCELABLE";
"comcom.android.frameworks.coretests.activity.BAD_PARCELABLE";
public static final int LAUNCHED_RESULT = 1;
public static final int FORWARDED_RESULT = 2;
public static final String LIFECYCLE_BASIC =
"com.android.unit_tests.activity.LIFECYCLE_BASIC";
"com.android.frameworks.coretests.activity.LIFECYCLE_BASIC";
public static final String LIFECYCLE_SCREEN =
"com.android.unit_tests.activity.LIFECYCLE_SCREEN";
"com.android.frameworks.coretests.activity.LIFECYCLE_SCREEN";
public static final String LIFECYCLE_DIALOG =
"com.android.unit_tests.activity.LIFECYCLE_DIALOG";
"com.android.frameworks.coretests.activity.LIFECYCLE_DIALOG";
public static final String LIFECYCLE_FINISH_CREATE =
"com.android.unit_tests.activity.LIFECYCLE_FINISH_CREATE";
"com.android.frameworks.coretests.activity.LIFECYCLE_FINISH_CREATE";
public static final String LIFECYCLE_FINISH_START =
"com.android.unit_tests.activity.LIFECYCLE_FINISH_START";
"com.android.frameworks.coretests.activity.LIFECYCLE_FINISH_START";
public static final String BROADCAST_REGISTERED =
"com.android.unit_tests.activity.BROADCAST_REGISTERED";
"com.android.frameworks.coretests.activity.BROADCAST_REGISTERED";
public static final String BROADCAST_LOCAL =
"com.android.unit_tests.activity.BROADCAST_LOCAL";
"com.android.frameworks.coretests.activity.BROADCAST_LOCAL";
public static final String BROADCAST_REMOTE =
"com.android.unit_tests.activity.BROADCAST_REMOTE";
"com.android.frameworks.coretests.activity.BROADCAST_REMOTE";
public static final String BROADCAST_ALL =
"com.android.unit_tests.activity.BROADCAST_ALL";
"com.android.frameworks.coretests.activity.BROADCAST_ALL";
public static final String BROADCAST_REPEAT =
"com.android.unit_tests.activity.BROADCAST_REPEAT";
"com.android.frameworks.coretests.activity.BROADCAST_REPEAT";
public static final String BROADCAST_MULTI =
"com.android.unit_tests.activity.BROADCAST_MULTI";
"com.android.frameworks.coretests.activity.BROADCAST_MULTI";
public static final String BROADCAST_ABORT =
"com.android.unit_tests.activity.BROADCAST_ABORT";
"com.android.frameworks.coretests.activity.BROADCAST_ABORT";
public static final String BROADCAST_STICKY1 =
"com.android.unit_tests.activity.BROADCAST_STICKY1";
"com.android.frameworks.coretests.activity.BROADCAST_STICKY1";
public static final String BROADCAST_STICKY2 =
"com.android.unit_tests.activity.BROADCAST_STICKY2";
"com.android.frameworks.coretests.activity.BROADCAST_STICKY2";
public static final String RECEIVER_REG = "receiver-reg";
public static final String RECEIVER_LOCAL = "receiver-local";

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.TabActivity;
import android.content.ComponentName;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.ComponentName;
import android.content.Intent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.BroadcastReceiver;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
public class LocalDeniedService extends LocalService
{

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.BroadcastReceiver;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
public class LocalGrantedService extends LocalService
{

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.UriMatcher;
import android.content.*;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Service;
import android.content.Intent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.ComponentName;
import android.content.pm.ActivityInfo;
@@ -29,7 +29,7 @@ import android.os.Bundle;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.unit_tests.R;
import com.android.frameworks.coretests.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -47,18 +47,18 @@ public class MetaDataTest extends AndroidTestCase {
Bundle md = ci.metaData;
assertNotNull("No meta data found", md);
assertEquals("foo", md.getString("com.android.unit_tests.string"));
assertTrue(md.getBoolean("com.android.unit_tests.boolean"));
assertEquals(100, md.getInt("com.android.unit_tests.integer"));
assertEquals(0xff000000, md.getInt("com.android.unit_tests.color"));
assertEquals("foo", md.getString("com.android.frameworks.coretests.string"));
assertTrue(md.getBoolean("com.android.frameworks.coretests.boolean"));
assertEquals(100, md.getInt("com.android.frameworks.coretests.integer"));
assertEquals(0xff000000, md.getInt("com.android.frameworks.coretests.color"));
assertEquals((double) 1001,
Math.floor(md.getFloat("com.android.unit_tests.float") * 10 + .5));
Math.floor(md.getFloat("com.android.frameworks.coretests.float") * 10 + .5));
assertEquals(R.xml.metadata, md.getInt("com.android.unit_tests.reference"));
assertEquals(R.xml.metadata, md.getInt("com.android.frameworks.coretests.reference"));
XmlResourceParser xml = ci.loadXmlMetaData(mContext.getPackageManager(),
"com.android.unit_tests.reference");
"com.android.frameworks.coretests.reference");
assertNotNull(xml);
int type;
@@ -138,12 +138,12 @@ public class MetaDataTest extends AndroidTestCase {
public void testProviderWithData() throws Exception {
ComponentName cn = new ComponentName(mContext, LocalProvider.class);
ProviderInfo pi = mContext.getPackageManager().resolveContentProvider(
"com.android.unit_tests.LocalProvider",
"com.android.frameworks.coretests.LocalProvider",
PackageManager.GET_META_DATA);
checkMetaData(cn, pi);
pi = mContext.getPackageManager().resolveContentProvider(
"com.android.unit_tests.LocalProvider", 0);
"com.android.frameworks.coretests.LocalProvider", 0);
assertNull("Meta data returned when not requested", pi.metaData);
}
@@ -151,7 +151,7 @@ public class MetaDataTest extends AndroidTestCase {
@SmallTest
public void testPermissionWithData() throws Exception {
ComponentName cn = new ComponentName("foo",
"com.android.unit_tests.permission.TEST_GRANTED");
"com.android.frameworks.coretests.permission.TEST_GRANTED");
PermissionInfo pi = mContext.getPackageManager().getPermissionInfo(
cn.getClassName(), PackageManager.GET_META_DATA);
checkMetaData(cn, pi);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.BroadcastReceiver;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.BroadcastReceiver;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.Context;
import android.content.Intent;

View File

@@ -15,7 +15,7 @@
** limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.Intent;
import android.os.Bundle;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.Context;
import android.content.Intent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.app.activity;
import android.app.Activity;
import android.os.Bundle;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.content.ComponentName;
import android.content.Context;
@@ -38,11 +38,11 @@ import android.util.Log;
public class ServiceTest extends ActivityTestsBase {
public static final String SERVICE_LOCAL =
"com.android.unit_tests.activity.SERVICE_LOCAL";
"com.android.frameworks.coretests.activity.SERVICE_LOCAL";
public static final String SERVICE_LOCAL_GRANTED =
"com.android.unit_tests.activity.SERVICE_LOCAL_GRANTED";
"com.android.frameworks.coretests.activity.SERVICE_LOCAL_GRANTED";
public static final String SERVICE_LOCAL_DENIED =
"com.android.unit_tests.activity.SERVICE_LOCAL_DENIED";
"com.android.frameworks.coretests.activity.SERVICE_LOCAL_DENIED";
public static final String REPORT_OBJ_NAME = "report";

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.AlarmManager;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.app.PendingIntent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.test.suitebuilder.annotation.Suppress;
import android.content.ComponentName;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.os.Handler;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.activity;
package android.app.activity;
import android.app.Activity;
import android.content.Intent;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.content;
package android.content;
import android.content.res.AssetManager;
import android.test.AndroidTestCase;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.content;
import android.content.ContentQueryMap;
import android.content.ContentResolver;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.content;
package android.content;
import junit.framework.TestSuite;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.content;
package android.content;
import android.content.ContentProvider;
import android.content.ContentValues;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.content;
package android.content;
import android.content.ContentResolver;
import android.net.Uri;
@@ -34,7 +34,7 @@ public class MemoryFileProviderTest extends AndroidTestCase {
@MediumTest
public void testRead() throws Exception {
ContentResolver resolver = getContext().getContentResolver();
Uri uri = Uri.parse("content://com.android.unit_tests.content.MemoryFileProvider/data/1/blob");
Uri uri = Uri.parse("content://android.content.MemoryFileProvider/data/1/blob");
byte[] buf = new byte[MemoryFileProvider.TEST_BLOB.length];
InputStream in = resolver.openInputStream(uri);
assertNotNull(in);
@@ -52,7 +52,7 @@ public class MemoryFileProviderTest extends AndroidTestCase {
// open enough file descriptors that we will crash something if we leak FDs
// or address space
for (int i = 0; i < 1025; i++) {
Uri uri = Uri.parse("content://com.android.unit_tests.content.MemoryFileProvider/huge");
Uri uri = Uri.parse("content://android.content.MemoryFileProvider/huge");
InputStream in = resolver.openInputStream(uri);
assertNotNull("Failed to open stream number " + i, in);
assertEquals(1000000, in.skip(1000000));
@@ -68,7 +68,7 @@ public class MemoryFileProviderTest extends AndroidTestCase {
@MediumTest
public void testFile() throws Exception {
ContentResolver resolver = getContext().getContentResolver();
Uri uri = Uri.parse("content://com.android.unit_tests.content.MemoryFileProvider/file");
Uri uri = Uri.parse("content://android.content.MemoryFileProvider/file");
byte[] buf = new byte[MemoryFileProvider.TEST_BLOB.length];
InputStream in = resolver.openInputStream(uri);
assertNotNull(in);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.database;
import android.database.AbstractCursor;
import android.test.suitebuilder.annotation.SmallTest;

View File

@@ -0,0 +1,630 @@
/*
* Copyright (C) 2007 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 android.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.database.DataSetObserver;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;
import android.database.sqlite.SQLiteStatement;
import android.os.Looper;
import android.test.AndroidTestCase;
import android.test.PerformanceTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
import java.io.File;
import java.util.Arrays;
import java.util.Random;
import junit.framework.TestCase;
public class DatabaseCursorTest extends AndroidTestCase implements PerformanceTestCase {
private static final String sString1 = "this is a test";
private static final String sString2 = "and yet another test";
private static final String sString3 = "this string is a little longer, but still a test";
private static final int CURRENT_DATABASE_VERSION = 42;
private SQLiteDatabase mDatabase;
private File mDatabaseFile;
@Override
protected void setUp() throws Exception {
super.setUp();
File dbDir = getContext().getDir("tests", Context.MODE_PRIVATE);
mDatabaseFile = new File(dbDir, "database_test.db");
if (mDatabaseFile.exists()) {
mDatabaseFile.delete();
}
mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
assertNotNull(mDatabase);
mDatabase.setVersion(CURRENT_DATABASE_VERSION);
}
@Override
protected void tearDown() throws Exception {
mDatabase.close();
mDatabaseFile.delete();
super.tearDown();
}
public boolean isPerformanceOnly() {
return false;
}
// These test can only be run once.
public int startPerformance(Intermediates intermediates) {
return 1;
}
private void populateDefaultTable() {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");
mDatabase.execSQL("INSERT INTO test (data) VALUES ('" + sString1 + "');");
mDatabase.execSQL("INSERT INTO test (data) VALUES ('" + sString2 + "');");
mDatabase.execSQL("INSERT INTO test (data) VALUES ('" + sString3 + "');");
}
@MediumTest
public void testCursorUpdate() {
mDatabase.execSQL(
"CREATE TABLE test (_id INTEGER PRIMARY KEY, d INTEGER, s INTEGER);");
for(int i = 0; i < 20; i++) {
mDatabase.execSQL("INSERT INTO test (d, s) VALUES (" + i +
"," + i%2 + ");");
}
Cursor c = mDatabase.query("test", null, "s = 0", null, null, null, null);
int dCol = c.getColumnIndexOrThrow("d");
int sCol = c.getColumnIndexOrThrow("s");
int count = 0;
while (c.moveToNext()) {
assertTrue(c.updateInt(dCol, 3));
count++;
}
assertEquals(10, count);
assertTrue(c.commitUpdates());
assertTrue(c.requery());
count = 0;
while (c.moveToNext()) {
assertEquals(3, c.getInt(dCol));
count++;
}
assertEquals(10, count);
assertTrue(c.moveToFirst());
assertTrue(c.deleteRow());
assertEquals(9, c.getCount());
c.close();
}
@MediumTest
public void testBlob() throws Exception {
// create table
mDatabase.execSQL(
"CREATE TABLE test (_id INTEGER PRIMARY KEY, s TEXT, d REAL, l INTEGER, b BLOB);");
// insert blob
Object[] args = new Object[4];
byte[] blob = new byte[1000];
byte value = 99;
Arrays.fill(blob, value);
args[3] = blob;
String s = new String("text");
args[0] = s;
Double d = 99.9;
args[1] = d;
Long l = (long)1000;
args[2] = l;
String sql = "INSERT INTO test (s, d, l, b) VALUES (?,?,?,?)";
mDatabase.execSQL(sql, args);
// use cursor to access blob
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
c.moveToNext();
ContentValues cv = new ContentValues();
DatabaseUtils.cursorRowToContentValues(c, cv);
int bCol = c.getColumnIndexOrThrow("b");
int sCol = c.getColumnIndexOrThrow("s");
int dCol = c.getColumnIndexOrThrow("d");
int lCol = c.getColumnIndexOrThrow("l");
byte[] cBlob = c.getBlob(bCol);
assertTrue(Arrays.equals(blob, cBlob));
assertEquals(s, c.getString(sCol));
assertEquals((double)d, c.getDouble(dCol));
assertEquals((long)l, c.getLong(lCol));
// new byte[]
byte[] newblob = new byte[1000];
value = 98;
Arrays.fill(blob, value);
c.updateBlob(bCol, newblob);
cBlob = c.getBlob(bCol);
assertTrue(Arrays.equals(newblob, cBlob));
// commit
assertTrue(c.commitUpdates());
assertTrue(c.requery());
c.moveToNext();
cBlob = c.getBlob(bCol);
assertTrue(Arrays.equals(newblob, cBlob));
c.close();
}
@MediumTest
public void testRealColumns() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data REAL);");
ContentValues values = new ContentValues();
values.put("data", 42.11);
long id = mDatabase.insert("test", "data", values);
assertTrue(id > 0);
Cursor c = mDatabase.rawQuery("SELECT data FROM test", null);
assertNotNull(c);
assertTrue(c.moveToFirst());
assertEquals(42.11, c.getDouble(0));
c.close();
}
@MediumTest
public void testCursor1() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int dataColumn = c.getColumnIndexOrThrow("data");
// The cursor should ignore text before the last period when looking for a column. (This
// is a temporary hack in all implementations of getColumnIndex.)
int dataColumn2 = c.getColumnIndexOrThrow("junk.data");
assertEquals(dataColumn, dataColumn2);
assertSame(3, c.getCount());
assertTrue(c.isBeforeFirst());
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.moveToNext();
assertEquals(1, c.getInt(0));
String s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString2, s);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString3, s);
c.moveToPosition(-1);
c.moveToNext();
s = c.getString(dataColumn);
assertEquals(sString1, s);
c.moveToPosition(2);
s = c.getString(dataColumn);
assertEquals(sString3, s);
int i;
for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
c.getInt(0);
}
assertEquals(3, i);
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.close();
}
@MediumTest
public void testCursor2() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.query("test", null, "_id > 1000", null, null, null, null);
assertEquals(0, c.getCount());
assertTrue(c.isBeforeFirst());
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
int i;
for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
c.getInt(0);
}
assertEquals(0, i);
try {
c.getInt(0);
fail("CursorIndexOutOfBoundsException expected");
} catch (CursorIndexOutOfBoundsException ex) {
// expected
}
c.close();
}
@MediumTest
public void testLargeField() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");
StringBuilder sql = new StringBuilder(2100);
sql.append("INSERT INTO test (data) VALUES ('");
Random random = new Random(System.currentTimeMillis());
StringBuilder randomString = new StringBuilder(1979);
for (int i = 0; i < 1979; i++) {
randomString.append((random.nextInt() & 0xf) % 10);
}
sql.append(randomString);
sql.append("');");
mDatabase.execSQL(sql.toString());
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
assertNotNull(c);
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(0, c.getPosition());
String largeString = c.getString(c.getColumnIndexOrThrow("data"));
assertNotNull(largeString);
assertEquals(randomString.toString(), largeString);
c.close();
}
class TestObserver extends DataSetObserver {
int total;
SQLiteCursor c;
boolean quit = false;
public TestObserver(int total_, SQLiteCursor cursor) {
c = cursor;
total = total_;
}
@Override
public void onChanged() {
int count = c.getCount();
if (total == count) {
int i = 0;
while (c.moveToNext()) {
assertEquals(i, c.getInt(1));
i++;
}
assertEquals(count, i);
quit = true;
Looper.myLooper().quit();
}
}
@Override
public void onInvalidated() {
}
}
//@Large
@Suppress
public void testLoadingThreadDelayRegisterData() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
final int count = 505;
String sql = "INSERT INTO test (data) VALUES (?);";
SQLiteStatement s = mDatabase.compileStatement(sql);
for (int i = 0; i < count; i++) {
s.bindLong(1, i);
s.execute();
}
int maxRead = 500;
int initialRead = 5;
SQLiteCursor c = (SQLiteCursor)mDatabase.rawQuery("select * from test;",
null, initialRead, maxRead);
TestObserver observer = new TestObserver(count, c);
c.getCount();
c.registerDataSetObserver(observer);
if (!observer.quit) {
Looper.loop();
}
c.close();
}
@LargeTest
public void testLoadingThread() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
final int count = 50000;
String sql = "INSERT INTO test (data) VALUES (?);";
SQLiteStatement s = mDatabase.compileStatement(sql);
for (int i = 0; i < count; i++) {
s.bindLong(1, i);
s.execute();
}
int maxRead = 1000;
int initialRead = 5;
SQLiteCursor c = (SQLiteCursor)mDatabase.rawQuery("select * from test;",
null, initialRead, maxRead);
TestObserver observer = new TestObserver(count, c);
c.registerDataSetObserver(observer);
c.getCount();
Looper.loop();
c.close();
}
@LargeTest
public void testLoadingThreadClose() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
final int count = 1000;
String sql = "INSERT INTO test (data) VALUES (?);";
SQLiteStatement s = mDatabase.compileStatement(sql);
for (int i = 0; i < count; i++) {
s.bindLong(1, i);
s.execute();
}
int maxRead = 11;
int initialRead = 5;
SQLiteCursor c = (SQLiteCursor)mDatabase.rawQuery("select * from test;",
null, initialRead, maxRead);
TestObserver observer = new TestObserver(count, c);
c.registerDataSetObserver(observer);
c.getCount();
c.close();
}
@LargeTest
public void testLoadingThreadDeactivate() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
final int count = 1000;
String sql = "INSERT INTO test (data) VALUES (?);";
SQLiteStatement s = mDatabase.compileStatement(sql);
for (int i = 0; i < count; i++) {
s.bindLong(1, i);
s.execute();
}
int maxRead = 11;
int initialRead = 5;
SQLiteCursor c = (SQLiteCursor)mDatabase.rawQuery("select * from test;",
null, initialRead, maxRead);
TestObserver observer = new TestObserver(count, c);
c.registerDataSetObserver(observer);
c.getCount();
c.deactivate();
c.close();
}
@LargeTest
public void testManyRowsLong() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
final int count = 36799;
for (int i = 0; i < count; i++) {
mDatabase.execSQL("INSERT INTO test (data) VALUES (" + i + ");");
}
Cursor c = mDatabase.query("test", new String[]{"data"}, null, null, null, null, null);
assertNotNull(c);
int i = 0;
while (c.moveToNext()) {
assertEquals(i, c.getInt(0));
i++;
}
assertEquals(count, i);
assertEquals(count, c.getCount());
Log.d("testManyRows", "count " + Integer.toString(i));
c.close();
}
@LargeTest
public void testManyRowsTxt() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");
StringBuilder sql = new StringBuilder(2100);
sql.append("INSERT INTO test (data) VALUES ('");
Random random = new Random(System.currentTimeMillis());
StringBuilder randomString = new StringBuilder(1979);
for (int i = 0; i < 1979; i++) {
randomString.append((random.nextInt() & 0xf) % 10);
}
sql.append(randomString);
sql.append("');");
// if cursor window size changed, adjust this value too
final int count = 600; // more than two fillWindow needed
for (int i = 0; i < count; i++) {
mDatabase.execSQL(sql.toString());
}
Cursor c = mDatabase.query("test", new String[]{"data"}, null, null, null, null, null);
assertNotNull(c);
int i = 0;
while (c.moveToNext()) {
assertEquals(randomString.toString(), c.getString(0));
i++;
}
assertEquals(count, i);
assertEquals(count, c.getCount());
c.close();
}
@LargeTest
public void testManyRowsTxtLong() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, txt TEXT, data INT);");
Random random = new Random(System.currentTimeMillis());
StringBuilder randomString = new StringBuilder(1979);
for (int i = 0; i < 1979; i++) {
randomString.append((random.nextInt() & 0xf) % 10);
}
// if cursor window size changed, adjust this value too
final int count = 600;
for (int i = 0; i < count; i++) {
StringBuilder sql = new StringBuilder(2100);
sql.append("INSERT INTO test (txt, data) VALUES ('");
sql.append(randomString);
sql.append("','");
sql.append(i);
sql.append("');");
mDatabase.execSQL(sql.toString());
}
Cursor c = mDatabase.query("test", new String[]{"txt", "data"}, null, null, null, null, null);
assertNotNull(c);
int i = 0;
while (c.moveToNext()) {
assertEquals(randomString.toString(), c.getString(0));
assertEquals(i, c.getInt(1));
i++;
}
assertEquals(count, i);
assertEquals(count, c.getCount());
c.close();
}
@MediumTest
public void testRequery() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.rawQuery("SELECT * FROM test", null);
assertNotNull(c);
assertEquals(3, c.getCount());
c.deactivate();
c.requery();
assertEquals(3, c.getCount());
c.close();
}
@MediumTest
public void testRequeryWithSelection() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.rawQuery("SELECT data FROM test WHERE data = '" + sString1 + "'",
null);
assertNotNull(c);
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(sString1, c.getString(0));
c.deactivate();
c.requery();
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(sString1, c.getString(0));
c.close();
}
@MediumTest
public void testRequeryWithSelectionArgs() throws Exception {
populateDefaultTable();
Cursor c = mDatabase.rawQuery("SELECT data FROM test WHERE data = ?",
new String[]{sString1});
assertNotNull(c);
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(sString1, c.getString(0));
c.deactivate();
c.requery();
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(sString1, c.getString(0));
c.close();
}
@MediumTest
public void testRequeryWithAlteredSelectionArgs() throws Exception {
/**
* Test the ability of a subclass of SQLiteCursor to change its query arguments.
*/
populateDefaultTable();
SQLiteDatabase.CursorFactory factory = new SQLiteDatabase.CursorFactory() {
public Cursor newCursor(
SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable,
SQLiteQuery query) {
return new SQLiteCursor(db, masterQuery, editTable, query) {
@Override
public boolean requery() {
setSelectionArguments(new String[]{"2"});
return super.requery();
}
};
}
};
Cursor c = mDatabase.rawQueryWithFactory(
factory, "SELECT data FROM test WHERE _id <= ?", new String[]{"1"},
null);
assertNotNull(c);
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(sString1, c.getString(0));
// Our hacked requery() changes the query arguments in the cursor.
c.requery();
assertEquals(2, c.getCount());
assertTrue(c.moveToFirst());
assertEquals(sString1, c.getString(0));
assertTrue(c.moveToNext());
assertEquals(sString2, c.getString(0));
// Test that setting query args on a deactivated cursor also works.
c.deactivate();
c.requery();
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.database;
import android.content.ContentValues;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.database;
import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;
@@ -126,4 +126,4 @@ public class DatabaseLocaleTest extends TestCase {
if (cursor != null) cursor.close();
}
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.database;
import android.app.Activity;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.database;
import junit.framework.Assert;

View File

@@ -0,0 +1,324 @@
/*
* Copyright (C) 2007 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 android.database;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDoneException;
import android.database.sqlite.SQLiteStatement;
import android.test.AndroidTestCase;
import android.test.PerformanceTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.TestCase;
import java.io.File;
public class DatabaseStatementTest extends AndroidTestCase implements PerformanceTestCase {
private static final String sString1 = "this is a test";
private static final String sString2 = "and yet another test";
private static final String sString3 = "this string is a little longer, but still a test";
private static final int CURRENT_DATABASE_VERSION = 42;
private SQLiteDatabase mDatabase;
private File mDatabaseFile;
@Override
protected void setUp() throws Exception {
super.setUp();
File dbDir = getContext().getDir("tests", Context.MODE_PRIVATE);
mDatabaseFile = new File(dbDir, "database_test.db");
if (mDatabaseFile.exists()) {
mDatabaseFile.delete();
}
mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
assertNotNull(mDatabase);
mDatabase.setVersion(CURRENT_DATABASE_VERSION);
}
@Override
protected void tearDown() throws Exception {
mDatabase.close();
mDatabaseFile.delete();
super.tearDown();
}
public boolean isPerformanceOnly() {
return false;
}
// These test can only be run once.
public int startPerformance(Intermediates intermediates) {
return 1;
}
private void populateDefaultTable() {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");
mDatabase.execSQL("INSERT INTO test (data) VALUES ('" + sString1 + "');");
mDatabase.execSQL("INSERT INTO test (data) VALUES ('" + sString2 + "');");
mDatabase.execSQL("INSERT INTO test (data) VALUES ('" + sString3 + "');");
}
@MediumTest
public void testExecuteStatement() throws Exception {
populateDefaultTable();
SQLiteStatement statement = mDatabase.compileStatement("DELETE FROM test");
statement.execute();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
assertEquals(0, c.getCount());
c.deactivate();
statement.close();
}
@MediumTest
public void testSimpleQuery() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL, str TEXT NOT NULL);");
mDatabase.execSQL("INSERT INTO test VALUES (1234, 'hello');");
SQLiteStatement statement1 =
mDatabase.compileStatement("SELECT num FROM test WHERE str = ?");
SQLiteStatement statement2 =
mDatabase.compileStatement("SELECT str FROM test WHERE num = ?");
try {
statement1.bindString(1, "hello");
long value = statement1.simpleQueryForLong();
assertEquals(1234, value);
statement1.bindString(1, "world");
statement1.simpleQueryForLong();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
try {
statement2.bindLong(1, 1234);
String value = statement1.simpleQueryForString();
assertEquals("hello", value);
statement2.bindLong(1, 5678);
statement1.simpleQueryForString();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
statement1.close();
statement2.close();
}
@MediumTest
public void testStatementLongBinding() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER);");
SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
for (int i = 0; i < 10; i++) {
statement.bindLong(1, i);
statement.execute();
}
statement.close();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int numCol = c.getColumnIndexOrThrow("num");
c.moveToFirst();
for (long i = 0; i < 10; i++) {
long num = c.getLong(numCol);
assertEquals(i, num);
c.moveToNext();
}
c.close();
}
@MediumTest
public void testStatementStringBinding() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num TEXT);");
SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
for (long i = 0; i < 10; i++) {
statement.bindString(1, Long.toHexString(i));
statement.execute();
}
statement.close();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int numCol = c.getColumnIndexOrThrow("num");
c.moveToFirst();
for (long i = 0; i < 10; i++) {
String num = c.getString(numCol);
assertEquals(Long.toHexString(i), num);
c.moveToNext();
}
c.close();
}
@MediumTest
public void testStatementClearBindings() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER);");
SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
for (long i = 0; i < 10; i++) {
statement.bindLong(1, i);
statement.clearBindings();
statement.execute();
}
statement.close();
Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
int numCol = c.getColumnIndexOrThrow("num");
assertTrue(c.moveToFirst());
for (long i = 0; i < 10; i++) {
assertTrue(c.isNull(numCol));
c.moveToNext();
}
c.close();
}
@MediumTest
public void testSimpleStringBinding() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num TEXT, value TEXT);");
String statement = "INSERT INTO test (num, value) VALUES (?,?)";
String[] args = new String[2];
for (int i = 0; i < 2; i++) {
args[i] = Integer.toHexString(i);
}
mDatabase.execSQL(statement, args);
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int numCol = c.getColumnIndexOrThrow("num");
int valCol = c.getColumnIndexOrThrow("value");
c.moveToFirst();
String num = c.getString(numCol);
assertEquals(Integer.toHexString(0), num);
String val = c.getString(valCol);
assertEquals(Integer.toHexString(1), val);
c.close();
}
@MediumTest
public void testStatementMultipleBindings() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER, str TEXT);");
SQLiteStatement statement =
mDatabase.compileStatement("INSERT INTO test (num, str) VALUES (?, ?)");
for (long i = 0; i < 10; i++) {
statement.bindLong(1, i);
statement.bindString(2, Long.toHexString(i));
statement.execute();
}
statement.close();
Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
int numCol = c.getColumnIndexOrThrow("num");
int strCol = c.getColumnIndexOrThrow("str");
assertTrue(c.moveToFirst());
for (long i = 0; i < 10; i++) {
long num = c.getLong(numCol);
String str = c.getString(strCol);
assertEquals(i, num);
assertEquals(Long.toHexString(i), str);
c.moveToNext();
}
c.close();
}
private static class StatementTestThread extends Thread {
private SQLiteDatabase mDatabase;
private SQLiteStatement mStatement;
public StatementTestThread(SQLiteDatabase db, SQLiteStatement statement) {
super();
mDatabase = db;
mStatement = statement;
}
@Override
public void run() {
mDatabase.beginTransaction();
for (long i = 0; i < 10; i++) {
mStatement.bindLong(1, i);
mStatement.bindString(2, Long.toHexString(i));
mStatement.execute();
}
mDatabase.setTransactionSuccessful();
mDatabase.endTransaction();
Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
int numCol = c.getColumnIndexOrThrow("num");
int strCol = c.getColumnIndexOrThrow("str");
assertTrue(c.moveToFirst());
for (long i = 0; i < 10; i++) {
long num = c.getLong(numCol);
String str = c.getString(strCol);
assertEquals(i, num);
assertEquals(Long.toHexString(i), str);
c.moveToNext();
}
c.close();
}
}
@MediumTest
public void testStatementMultiThreaded() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER, str TEXT);");
SQLiteStatement statement =
mDatabase.compileStatement("INSERT INTO test (num, str) VALUES (?, ?)");
StatementTestThread thread = new StatementTestThread(mDatabase, statement);
thread.start();
try {
thread.join();
} finally {
statement.close();
}
}
@MediumTest
public void testStatementConstraint() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL);");
SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
// Try to insert NULL, which violates the constraint
try {
statement.clearBindings();
statement.execute();
fail("expected exception not thrown");
} catch (SQLiteConstraintException e) {
// expected
}
// Make sure the statement can still be used
statement.bindLong(1, 1);
statement.execute();
statement.close();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
int numCol = c.getColumnIndexOrThrow("num");
c.moveToFirst();
long num = c.getLong(numCol);
assertEquals(1, num);
c.close();
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.database;
import android.content.Context;
import android.database.sqlite.*;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.net;
import android.net.Credentials;
import android.net.LocalServerSocket;
@@ -35,11 +35,11 @@ public class LocalSocketTest extends TestCase {
LocalSocket ls;
LocalSocket ls1;
ss = new LocalServerSocket("com.android.unit_tests.LocalSocketTest");
ss = new LocalServerSocket("android.net.LocalSocketTest");
ls = new LocalSocket();
ls.connect(new LocalSocketAddress("com.android.unit_tests.LocalSocketTest"));
ls.connect(new LocalSocketAddress("android.net.LocalSocketTest"));
ls1 = ss.accept();

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.net;
import android.net.SSLCertificateSocketFactory;
import android.test.suitebuilder.annotation.Suppress;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.net;
import android.content.UriMatcher;
import android.net.Uri;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.net;
import android.net.Uri;
import android.content.ContentUris;
@@ -52,15 +52,20 @@ public class UriTest extends TestCase {
private void parcelAndUnparcel(Uri u) {
Parcel p = Parcel.obtain();
Uri.writeToParcel(p, u);
p.setDataPosition(0);
assertEquals(u, Uri.CREATOR.createFromParcel(p));
try {
Uri.writeToParcel(p, u);
p.setDataPosition(0);
assertEquals(u, Uri.CREATOR.createFromParcel(p));
p.setDataPosition(0);
u = u.buildUpon().build();
Uri.writeToParcel(p, u);
p.setDataPosition(0);
assertEquals(u, Uri.CREATOR.createFromParcel(p));
p.setDataPosition(0);
u = u.buildUpon().build();
Uri.writeToParcel(p, u);
p.setDataPosition(0);
assertEquals(u, Uri.CREATOR.createFromParcel(p));
}
finally {
p.recycle();
}
}
@SmallTest

View File

@@ -15,6 +15,6 @@
** limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
parcelable AidlTest.TestParcelable;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.os.IInterface;
import android.os.Parcel;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.os.Broadcaster;
import android.os.Handler;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests;
package android.os;
import android.os.Build;
import android.test.suitebuilder.annotation.SmallTest;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.content.Context;
import android.os.FileUtils;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.os.Handler;
import android.os.Looper;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import junit.framework.TestCase;
import android.os.Handler;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import junit.framework.TestCase;

View File

@@ -15,9 +15,9 @@
** limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import com.android.unit_tests.os.AidlTest;
import android.os.AidlTest;
interface IAidlTest {
int intMethod(int a);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.os.Handler;
import android.os.Looper;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.os.MemoryFile;
import android.test.AndroidTestCase;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.unit_tests.os;
package android.os;
import android.os.Handler;
import android.os.Message;

Some files were not shown because too many files have changed in this diff Show More