summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/emulator/test-apps/SmsTest/src/com/android/emulator/sms/test/SmsTest.java32
1 files changed, 26 insertions, 6 deletions
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
index 4df5c5125..13bcf7fca 100644
--- 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
@@ -21,9 +21,9 @@ import android.net.Uri;
import android.database.Cursor;
import android.os.Bundle;
import android.os.HandlerThread;
-
import android.support.test.InjectContext;
+import org.junit.Assert;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
@@ -40,7 +40,8 @@ public class SmsTest {
*/
public final static String NUMBER = "5551212";
public final static String BODY = "test sms";
-
+ private final static int SMS_POLL_TIME_MS = 10 * 1000;
+ private final static int SIXY_SECONDS_OF_LOOPS = 6;
@InjectContext
public Context mContext;
@@ -48,16 +49,35 @@ public class SmsTest {
* Verify that an SMS has been received with the correct number and body
*/
@Test
- public void testReceivedSms(){
- ContentResolver r = mContext.getContentResolver();
- Uri message = Uri.parse("content://sms/");
- Cursor c = r.query(message,null,null,null,null);
+ public void testReceivedSms() throws java.lang.InterruptedException {
+ Cursor c = getSmsCursor();
c.moveToFirst();
String number = c.getString(c.getColumnIndexOrThrow("address"));
String body = c.getString(c.getColumnIndexOrThrow("body"));
c.close();
+
assertEquals(NUMBER, number);
assertEquals(BODY, body);
}
+ private Cursor getSmsCursor() throws java.lang.InterruptedException {
+ ContentResolver r = mContext.getContentResolver();
+ Uri message = Uri.parse("content://sms/");
+ Cursor c;
+
+ for(int i = 0; i < SIXY_SECONDS_OF_LOOPS; i++) {
+ c = r.query(message,null,null,null,null);
+
+ if(c.getCount() != 0) {
+ return c;
+ }
+
+ c.close();
+ Thread.sleep(SMS_POLL_TIME_MS);
+ }
+ Assert.fail("Did not find any SMS messages. Giving up");
+ // necessary for compilation
+ return null;
+ }
+
}