Skip to content

Commit b26295b

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Tests for mapping android name to uid" into jb-mr1-dev
2 parents 38cc2a5 + dc09102 commit b26295b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
package android.os;
19+
20+
import android.os.Process;
21+
import android.os.UserId;
22+
import android.test.suitebuilder.annotation.MediumTest;
23+
import android.test.suitebuilder.annotation.SmallTest;
24+
25+
import junit.framework.TestCase;
26+
27+
28+
public class ProcessTest extends TestCase {
29+
30+
@MediumTest
31+
public void testProcessGetUidFromName() throws Exception {
32+
assertEquals(android.os.Process.SYSTEM_UID, Process.getUidForName("system"));
33+
assertEquals(Process.BLUETOOTH_UID, Process.getUidForName("bluetooth"));
34+
assertEquals(Process.FIRST_APPLICATION_UID, Process.getUidForName("u0_a0"));
35+
assertEquals(UserId.getUid(1, Process.SYSTEM_UID), Process.getUidForName("u1_system"));
36+
assertEquals(UserId.getUid(2, Process.FIRST_ISOLATED_UID),
37+
Process.getUidForName("u2_i0"));
38+
assertEquals(UserId.getUid(3, Process.FIRST_APPLICATION_UID + 100),
39+
Process.getUidForName("u3_a100"));
40+
}
41+
42+
@MediumTest
43+
public void testProcessGetUidFromNameFailure() throws Exception {
44+
// Failure cases
45+
assertEquals(-1, Process.getUidForName("u2a_foo"));
46+
assertEquals(-1, Process.getUidForName("u1_abcdef"));
47+
assertEquals(-1, Process.getUidForName("u23"));
48+
assertEquals(-1, Process.getUidForName("u2_i34a"));
49+
assertEquals(-1, Process.getUidForName("akjhwiuefhiuhsf"));
50+
assertEquals(-1, Process.getUidForName("u5_radio5"));
51+
assertEquals(-1, Process.getUidForName("u2jhsajhfkjhsafkhskafhkashfkjashfkjhaskjfdhakj3"));
52+
}
53+
54+
}

0 commit comments

Comments
 (0)