Add SMS test to verify emulator can receive sms from DDMS

Change-Id: I168a8c75df76eb997ac5abf06a10437881bdff76
This commit is contained in:
Steve Moyer
2014-02-05 22:25:51 -08:00
parent 819f19e62f
commit cc08ee921a
3 changed files with 118 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.emulator.sms.test">
<uses-permission android:name="android.permission.READ_SMS" />
<uses-sdk android:minSdkVersion="4" />
<instrumentation android:targetPackage="com.android.emulator.sms.test"
android:name="android.support.test.runner.AndroidJUnitRunner" />
<application android:label="Sms Test">
</application>
</manifest>

View File

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