1 /*
2  * Copyright (C) 2010 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 package com.android.tradefed.targetprep;
18 
19 import static org.junit.Assert.assertTrue;
20 
21 import com.android.tradefed.build.DeviceBuildInfo;
22 import com.android.tradefed.build.IDeviceBuildInfo;
23 import com.android.tradefed.device.ITestDevice;
24 import com.android.tradefed.invoker.IInvocationContext;
25 import com.android.tradefed.invoker.InvocationContext;
26 import com.android.tradefed.invoker.TestInformation;
27 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
28 import com.android.tradefed.testtype.IDeviceTest;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 
34 /** Functional tests for {@link DeviceSetup}. */
35 @RunWith(DeviceJUnit4ClassRunner.class)
36 public class DeviceSetupFuncTest implements IDeviceTest {
37 
38     private DeviceSetup mDeviceSetup;
39     private ITestDevice mDevice;
40     private IDeviceBuildInfo mMockBuildInfo;
41     private TestInformation mStubInformation;
42 
43     @Override
setDevice(ITestDevice device)44     public void setDevice(ITestDevice device) {
45         mDevice = device;
46     }
47 
48     @Override
getDevice()49     public ITestDevice getDevice() {
50         return mDevice;
51     }
52 
53     @Before
setUp()54     public void setUp() throws Exception {
55         mMockBuildInfo = new DeviceBuildInfo("0", "");
56         mDeviceSetup = new DeviceSetup();
57         IInvocationContext context = new InvocationContext();
58         context.addAllocatedDevice("device", mDevice);
59         context.addDeviceBuildInfo("device", mMockBuildInfo);
60         mStubInformation = TestInformation.newBuilder().setInvocationContext(context).build();
61     }
62 
63     /**
64      * Simple normal case test for {@link DeviceSetup#setUp(TestInformation)}.
65      *
66      * <p>Do setup and verify a few expected properties
67      */
68     @Test
testSetup()69     public void testSetup() throws Exception {
70         // Reset expected property
71         getDevice().executeShellCommand("setprop ro.audio.silent 0");
72         mDeviceSetup.setUp(mStubInformation);
73         assertTrue(getDevice().executeShellCommand("getprop ro.audio.silent").contains("1"));
74         assertTrue(getDevice().executeShellCommand("getprop ro.monkey").contains("1"));
75         assertTrue(getDevice().executeShellCommand("getprop ro.test_harness").contains("1"));
76         // Verify root
77         assertTrue(getDevice().executeShellCommand("id").contains("root"));
78     }
79 }
80