use of android.test.suitebuilder.annotation.MediumTest in project platform_frameworks_base by android.
the class SettingsProviderTest method testSettingsChangeForOtherUser.
@MediumTest
public void testSettingsChangeForOtherUser() {
UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
ContentResolver r = getContext().getContentResolver();
// Make sure there's an owner
assertTrue(findUser(um, UserHandle.USER_SYSTEM));
// create a new user to use for testing
UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
assertTrue(otherUser != null);
try {
assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
final String testKey = "testSettingsChangeForOtherUser";
final String testValue1 = "value1";
final String testValue2 = "value2";
Settings.Secure.putString(r, testKey, testValue1);
Settings.Secure.putStringForUser(r, testKey, testValue2, otherUser.id);
assertEquals(testValue1, Settings.Secure.getString(r, testKey));
assertEquals(testValue2, Settings.Secure.getStringForUser(r, testKey, otherUser.id));
assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
} finally {
// Tidy up
um.removeUser(otherUser.id);
}
}
use of android.test.suitebuilder.annotation.MediumTest in project platform_frameworks_base by android.
the class SpannableTest method testGetSpans.
@MediumTest
public void testGetSpans() {
Spannable spannable = newSpannableWithText("abcdef");
Object emptySpan = new Object();
spannable.setSpan(emptySpan, 1, 1, 0);
Object unemptySpan = new Object();
spannable.setSpan(unemptySpan, 1, 2, 0);
Object[] spans;
// Empty spans are included when they merely abut the query region
// but other spans are not, unless the query region is empty, in
// in which case any abutting spans are returned.
spans = spannable.getSpans(0, 1, Object.class);
MoreAsserts.assertEquals(new Object[] { emptySpan }, spans);
spans = spannable.getSpans(0, 2, Object.class);
MoreAsserts.assertEquals(new Object[] { emptySpan, unemptySpan }, spans);
spans = spannable.getSpans(1, 2, Object.class);
MoreAsserts.assertEquals(new Object[] { emptySpan, unemptySpan }, spans);
spans = spannable.getSpans(2, 2, Object.class);
MoreAsserts.assertEquals(new Object[] { unemptySpan }, spans);
}
use of android.test.suitebuilder.annotation.MediumTest in project platform_frameworks_base by android.
the class IPrintManagerParametersTest method testRemovePrintServiceRecommendationsChangeListener.
/**
* test IPrintManager.removePrintServicesChangeListener
*/
@MediumTest
public void testRemovePrintServiceRecommendationsChangeListener() throws Exception {
final IRecommendationsChangeListener listener = createMockIPrintServiceRecommendationsChangeListener();
mIPrintManager.addPrintServiceRecommendationsChangeListener(listener, mUserId);
mIPrintManager.removePrintServiceRecommendationsChangeListener(listener, mUserId);
// Removing unknown listeners is a no-op
mIPrintManager.removePrintServiceRecommendationsChangeListener(listener, mUserId);
mIPrintManager.addPrintServiceRecommendationsChangeListener(listener, mUserId);
assertException(new Invokable() {
@Override
public void run() throws Exception {
mIPrintManager.removePrintServiceRecommendationsChangeListener(null, mUserId);
}
}, NullPointerException.class);
// Cannot test bad user Id as these tests are allowed to call across users
}
use of android.test.suitebuilder.annotation.MediumTest in project platform_frameworks_base by android.
the class MessageQueueTest method testFieldIntegrity.
@MediumTest
public void testFieldIntegrity() throws Exception {
TestHandlerThread tester = new TestFieldIntegrityHandler() {
Bundle mBundle;
public void go() {
super.go();
mLastMessage = 1;
mCount = 0;
mHandler.sendMessage(mHandler.obtainMessage(0));
}
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 0) {
msg.flags = -1;
msg.what = 1;
msg.arg1 = 456;
msg.arg2 = 789;
msg.obj = this;
msg.replyTo = null;
mBundle = new Bundle();
msg.data = mBundle;
msg.data.putString("key", "value");
Message newMsg = mHandler.obtainMessage();
newMsg.copyFrom(msg);
if (newMsg.isInUse() != false) {
failure(new RuntimeException("newMsg.isInUse is true should be false after copyFrom"));
}
if (newMsg.flags != 0) {
failure(new RuntimeException(String.format("newMsg.flags is %d should be 0 after copyFrom", newMsg.flags)));
}
if (newMsg.what != 1) {
failure(new RuntimeException(String.format("newMsg.what is %d should be %d after copyFrom", newMsg.what, 1)));
}
if (newMsg.arg1 != 456) {
failure(new RuntimeException(String.format("newMsg.arg1 is %d should be %d after copyFrom", msg.arg1, 456)));
}
if (newMsg.arg2 != 789) {
failure(new RuntimeException(String.format("newMsg.arg2 is %d should be %d after copyFrom", msg.arg2, 789)));
}
if (newMsg.obj != this) {
failure(new RuntimeException("newMsg.obj should be 'this' after copyFrom"));
}
if (newMsg.replyTo != null) {
failure(new RuntimeException("newMsg.replyTo should be null after copyFrom"));
}
if (newMsg.data == mBundle) {
failure(new RuntimeException("newMsg.data should NOT be mBundle after copyFrom"));
}
if (!newMsg.data.getString("key").equals(mBundle.getString("key"))) {
failure(new RuntimeException(String.format("newMsg.data.getString(\"key\") is %s and does not equal" + " mBundle.getString(\"key\") which is %s after copyFrom", newMsg.data.getString("key"), mBundle.getString("key"))));
}
if (newMsg.when != 0) {
failure(new RuntimeException(String.format("newMsg.when is %d should be 0 after copyFrom", newMsg.when)));
}
if (newMsg.target != mHandler) {
failure(new RuntimeException("newMsg.target is NOT mHandler after copyFrom"));
}
if (newMsg.callback != null) {
failure(new RuntimeException("newMsg.callback is NOT null after copyFrom"));
}
mHandler.sendMessage(newMsg);
} else if (msg.what == 1) {
if (msg.isInUse() != true) {
failure(new RuntimeException(String.format("msg.isInUse is false should be true after when processing %d", msg.what)));
}
if (msg.arg1 != 456) {
failure(new RuntimeException(String.format("msg.arg1 is %d should be %d when processing # %d", msg.arg1, 456, msg.what)));
}
if (msg.arg2 != 789) {
failure(new RuntimeException(String.format("msg.arg2 is %d should be %d when processing # %d", msg.arg2, 789, msg.what)));
}
if (msg.obj != this) {
failure(new RuntimeException(String.format("msg.obj should be 'this' when processing # %d", msg.what)));
}
if (msg.replyTo != null) {
failure(new RuntimeException(String.format("msg.replyTo should be null when processing # %d", msg.what)));
}
if (!msg.data.getString("key").equals(mBundle.getString("key"))) {
failure(new RuntimeException(String.format("msg.data.getString(\"key\") is %s and does not equal" + " mBundle.getString(\"key\") which is %s when processing # %d", msg.data.getString("key"), mBundle.getString("key"), msg.what)));
}
if (msg.when != 0) {
failure(new RuntimeException(String.format("msg.when is %d should be 0 when processing # %d", msg.when, msg.what)));
}
if (msg.target != null) {
failure(new RuntimeException(String.format("msg.target is NOT null when processing # %d", msg.what)));
}
if (msg.callback != null) {
failure(new RuntimeException(String.format("msg.callback is NOT null when processing # %d", msg.what)));
}
} else {
failure(new RuntimeException(String.format("Unexpected msg.what is %d" + msg.what)));
}
}
};
tester.doTest(1000);
}
use of android.test.suitebuilder.annotation.MediumTest in project platform_frameworks_base by android.
the class BroadcasterTest method test4.
@MediumTest
public void test4() throws Exception {
/*
* Two handlers request different messages, with translations, sending
* only one. The other one should never get sent.
*/
HandlerTester tester = new HandlerTester() {
Handler h1;
Handler h2;
public void go() {
Broadcaster b = new Broadcaster();
h1 = new H();
h2 = new H();
b.request(MESSAGE_A, h1, MESSAGE_C);
b.request(MESSAGE_B, h2, MESSAGE_D);
Message msg = new Message();
msg.what = MESSAGE_A;
b.broadcast(msg);
}
public void handleMessage(Message msg) {
if (msg.what == MESSAGE_C && msg.getTarget() == h1) {
success();
} else {
failure();
}
}
};
tester.doTest(1000);
}
Aggregations