Add tests for SystemProperties.java

Change-Id: I878192090848d2c811444a135ec9d8ae6c578ec3
This commit is contained in:
satok
2011-03-02 23:15:26 -08:00
parent d72fcf68f6
commit edd767d777
4 changed files with 126 additions and 0 deletions

View File

@@ -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)

View File

@@ -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>

View File

@@ -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

View File

@@ -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);
}
}