diff options
author | satok <satok@google.com> | 2011-03-03 13:54:38 -0800 |
---|---|---|
committer | satok <satok@google.com> | 2011-03-03 13:54:38 -0800 |
commit | c91437d38ae14a20046de47831eb0f9bfd329af7 (patch) | |
tree | 2a4cab2322172de2f2503c5255c9882013439fb9 /core/tests/systemproperties | |
parent | 6c8d76527c938eb49182a6fd0677ccbc1618e7a8 (diff) | |
download | frameworks_base-c91437d38ae14a20046de47831eb0f9bfd329af7.zip frameworks_base-c91437d38ae14a20046de47831eb0f9bfd329af7.tar.gz frameworks_base-c91437d38ae14a20046de47831eb0f9bfd329af7.tar.bz2 |
do not merge: Cherry pick change I878192090 from master.
A test for system properties
Change-Id: Id28da70b8e333ca83129c2b7b7aed2ddf9adf51c
Diffstat (limited to 'core/tests/systemproperties')
4 files changed, 126 insertions, 0 deletions
diff --git a/core/tests/systemproperties/Android.mk b/core/tests/systemproperties/Android.mk new file mode 100644 index 0000000..05216e0 --- /dev/null +++ b/core/tests/systemproperties/Android.mk @@ -0,0 +1,18 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# We only want this apk build for tests. +LOCAL_MODULE_TAGS := tests + +# Include all test java files. +LOCAL_SRC_FILES := \ + $(call all-java-files-under, src) + +LOCAL_DX_FLAGS := --core-library +LOCAL_STATIC_JAVA_LIBRARIES := core-tests-supportlib android-common frameworks-core-util-lib +LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_PACKAGE_NAME := FrameworksCoreSystemPropertiesTests + +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) diff --git a/core/tests/systemproperties/AndroidManifest.xml b/core/tests/systemproperties/AndroidManifest.xml new file mode 100644 index 0000000..ad0abf4 --- /dev/null +++ b/core/tests/systemproperties/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + android:installLocation="internalOnly" + package="com.android.frameworks.coretests.systemproperties" + android:sharedUserId="android.uid.system"> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.frameworks.coretests" + android:label="Frameworks Core Tests" /> + +</manifest> diff --git a/core/tests/systemproperties/run_core_systemproperties_test.sh b/core/tests/systemproperties/run_core_systemproperties_test.sh new file mode 100755 index 0000000..48880f3 --- /dev/null +++ b/core/tests/systemproperties/run_core_systemproperties_test.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +while [[ $# -gt 0 ]]; do + case "$1" in + --rebuild ) echo Rebuild && rebuild=true;; + * ) com_opts+=($1);; + esac + shift +done + +if [[ -z $ANDROID_PRODUCT_OUT && $rebuilld == true ]]; then + echo You must lunch before running this test. + exit 0 +fi + +if [[ $rebuild == true ]]; then + make -j4 FrameworksCoreSystemPropertiesTests + TESTAPP=${ANDROID_PRODUCT_OUT}/data/app/FrameworksCoreSystemPropertiesTests.apk +fi + +adb shell am instrument -w -e class android.os.SystemPropertiesTest com.android.frameworks.coretests.systemproperties/android.test.InstrumentationTestRunner diff --git a/core/tests/systemproperties/src/android/os/SystemPropertiesTest.java b/core/tests/systemproperties/src/android/os/SystemPropertiesTest.java new file mode 100644 index 0000000..243ac38 --- /dev/null +++ b/core/tests/systemproperties/src/android/os/SystemPropertiesTest.java @@ -0,0 +1,57 @@ +/* + * 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 android.os; + +import junit.framework.TestCase; + +import android.os.SystemProperties; +import android.test.suitebuilder.annotation.SmallTest; + +public class SystemPropertiesTest extends TestCase { + private static final String KEY = "sys.testkey"; + @SmallTest + public void testLongSequencialProperties() throws Exception { + for (int i = 0; i < 100; ++i) { + SystemProperties.set(KEY, Long.toString(i)); + long ret = SystemProperties.getLong(KEY, -1); + assertEquals(i, ret); + } + } + + @SmallTest + public void testProperties() throws Exception { + String value; + + SystemProperties.set(KEY, ""); + value = SystemProperties.get(KEY, "default"); + assertEquals("default", value); + + SystemProperties.set(KEY, "SA"); + value = SystemProperties.get(KEY, "default"); + assertEquals("SA", value); + + value = SystemProperties.get(KEY); + assertEquals("SA", value); + + SystemProperties.set(KEY, ""); + value = SystemProperties.get(KEY, "default"); + assertEquals("default", value); + + value = SystemProperties.get(KEY); + assertEquals("", value); + } +} |