New package with unit tests for the phone app.
Added a new tests subdir with all the tests to be consistent
with other apps.
The top makefile will build the tests.
Added a unitest class for the cnap handling.
Currently has only one trivial test.
diff --git a/tests/Android.mk b/tests/Android.mk
new file mode 100755
index 0000000..b10572f
--- /dev/null
+++ b/tests/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2009 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_PACKAGE_NAME := PhoneAppTests
+LOCAL_CERTIFICATE := platform
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_INSTRUMENTATION_FOR := Phone
+
+include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
new file mode 100644
index 0000000..30578f9
--- /dev/null
+++ b/tests/AndroidManifest.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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"
+ package="com.android.phone.tests">
+
+ <application android:label="PhoneAppTests">
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!--
+ The prefered way is to use 'runtest':
+ runtest phone-unit
+
+ runtest is a wrapper around 'adb shell'. The low level shell command is:
+ adb shell am instrument -w com.android.phone.tests/android.test.InstrumentationTestRunner
+
+ To run a single test case:
+ adb shell am instrument -w com.android.phone.tests/android.test.InstrumentationTestRunner
+ -e com.android.phone.unit.FooUnitTest
+ -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.phone"
+ android:label="Phone application tests." />
+</manifest>
+
diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml
new file mode 100644
index 0000000..86dd125
--- /dev/null
+++ b/tests/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">PhoneAppTests</string>
+</resources>
diff --git a/tests/src/com/android/phone/unit/CnapTest.java b/tests/src/com/android/phone/unit/CnapTest.java
new file mode 100644
index 0000000..27bd284
--- /dev/null
+++ b/tests/src/com/android/phone/unit/CnapTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+// Need to be in this package to access package methods.
+package com.android.phone;
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Log;
+import com.android.internal.telephony.CallerInfo;
+import com.android.phone.PhoneUtils;
+import static com.android.internal.telephony.Connection.PRESENTATION_ALLOWED;
+import static com.android.internal.telephony.Connection.PRESENTATION_PAYPHONE;
+import static com.android.internal.telephony.Connection.PRESENTATION_RESTRICTED;
+import static com.android.internal.telephony.Connection.PRESENTATION_UNKNOWN;
+
+// Test suite for the Caller Name Presentation (CNAP) handling.
+// See AndroidManifest.xml how to run these tests.
+public class CnapTest extends AndroidTestCase {
+ private static final String TAG = "CnapTest";
+ private Context mContext;
+ private CallerInfo mCallerInfo;
+ // TODO: This string should be loaded from the phone package and
+ // not hardcoded.
+ private String mUnknown = "Unknown";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContext = getContext();
+ mCallerInfo = new CallerInfo();
+ }
+
+ // Checks the cnap 'ABSENT NUMBER' is mapped to the unknown presentation.
+ @SmallTest
+ public void testAbsentNumberIsMappedToUnknown() throws Exception {
+ String num = modifyForSpecialCnapCases("ABSENT NUMBER", PRESENTATION_ALLOWED);
+ assertIsUnknown(num);
+ }
+
+ // HELPERS
+
+ /**
+ * Checks the number and CallerInfo structure indicate the number
+ * is unknown.
+ */
+ private void assertIsUnknown(String number) {
+ assertEquals(mUnknown, number);
+ assertEquals(PRESENTATION_UNKNOWN, mCallerInfo.numberPresentation);
+ // TODO: cnapName and name presentation should be set to
+ // unknown. At least I cannot see why it shouldn't be the case
+ // assertEquals(mUnknown, mCallerInfo.cnapName);
+ // assertEquals(PRESENTATION_UNKNOWN, mCallerInfo.namePresentation);
+ }
+
+ /**
+ * Shorthand for PhoneUtils.modifyForSpecialCnapCases(mContext, mCallerInfo, ...)
+ */
+ private String modifyForSpecialCnapCases(String number, int presentation) {
+ return PhoneUtils.modifyForSpecialCnapCases(
+ mContext, mCallerInfo, number, presentation);
+ }
+}