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
18package android.os;
19
20import android.os.Process;
21import android.os.UserHandle;
22import android.test.suitebuilder.annotation.MediumTest;
23import android.test.suitebuilder.annotation.SmallTest;
24
25import junit.framework.TestCase;
26
27
28public 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(UserHandle.getUid(1, Process.SYSTEM_UID), Process.getUidForName("u1_system"));
36        assertEquals(UserHandle.getUid(2, Process.FIRST_ISOLATED_UID),
37                Process.getUidForName("u2_i0"));
38        assertEquals(UserHandle.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}
55