diff --git a/core/tests/systemproperties/Android.mk b/core/tests/systemproperties/Android.mk new file mode 100644 index 0000000000000..05216e0d432e6 --- /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 0000000000000..ad0abf475c9b0 --- /dev/null +++ b/core/tests/systemproperties/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + 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 0000000000000..48880f3652fe7 --- /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 0000000000000..243ac38eac2eb --- /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); + } +}