From cc08ee921a974e6ec0faf3b614a3620882346d2c Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Wed, 5 Feb 2014 22:25:51 -0800 Subject: [PATCH] Add SMS test to verify emulator can receive sms from DDMS Change-Id: I168a8c75df76eb997ac5abf06a10437881bdff76 --- tools/emulator/test-apps/SmsTest/Android.mk | 32 ++++++++++ .../test-apps/SmsTest/AndroidManifest.xml | 24 +++++++ .../android/emulator/sms/test/SmsTest.java | 62 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 tools/emulator/test-apps/SmsTest/Android.mk create mode 100644 tools/emulator/test-apps/SmsTest/AndroidManifest.xml create mode 100644 tools/emulator/test-apps/SmsTest/src/com/android/emulator/sms/test/SmsTest.java diff --git a/tools/emulator/test-apps/SmsTest/Android.mk b/tools/emulator/test-apps/SmsTest/Android.mk new file mode 100644 index 000000000..9a5411ab3 --- /dev/null +++ b/tools/emulator/test-apps/SmsTest/Android.mk @@ -0,0 +1,32 @@ +# Copyright (C) 2014 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_STATIC_JAVA_LIBRARIES := android-support-test + +LOCAL_MODULE_TAGS := optional + +# Only compile source java files in this apk. +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := SmsTest + +LOCAL_SDK_VERSION := 4 + +LOCAL_PROGUARD_ENABLED := disabled + + +include $(BUILD_PACKAGE) diff --git a/tools/emulator/test-apps/SmsTest/AndroidManifest.xml b/tools/emulator/test-apps/SmsTest/AndroidManifest.xml new file mode 100644 index 000000000..2819b6e6f --- /dev/null +++ b/tools/emulator/test-apps/SmsTest/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/tools/emulator/test-apps/SmsTest/src/com/android/emulator/sms/test/SmsTest.java b/tools/emulator/test-apps/SmsTest/src/com/android/emulator/sms/test/SmsTest.java new file mode 100644 index 000000000..104e33fc0 --- /dev/null +++ b/tools/emulator/test-apps/SmsTest/src/com/android/emulator/sms/test/SmsTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2014 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 com.android.emulator.sms.test; + +import android.content.Context; +import android.content.ContentResolver; +import android.net.Uri; +import android.database.Cursor; +import android.os.Bundle; +import android.os.HandlerThread; + +import android.support.test.InjectContext; + +import static junit.framework.Assert.assertEquals; + +import org.junit.Test; +/** + * Sms Test + * + * Test that an SMS message has been received + */ +public class SmsTest { + + /** + * Prior to running this test an sms must be sent + * via DDMS + */ + public final static String NUMBER = "5551212"; + public final static String BODY = "test sms"; + + @InjectContext + public Context mContext; + + /** + * Verify that an SMS has been recieved with the correct number and body + */ + public void testRecievedSms(){ + ContentResolver r = mContext.getContentResolver(); + Uri message = Uri.parse("content://sms/"); + Cursor c = r.query(message,null,null,null,null); + c.moveToFirst(); + String number = c.getString(c.getColumnIndexOrThrow("address")); + String body = c.getString(c.getColumnIndexOrThrow("body")); + c.close(); + assertEquals(NUMBER, number); + assertEquals(BODY, body); + } + +}