• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 android.appsecurity.cts;
18 
19 import com.android.cts.migration.MigrationHelper;
20 import com.android.tradefed.build.IBuildInfo;
21 import com.android.tradefed.device.DeviceNotAvailableException;
22 import com.android.tradefed.testtype.DeviceTestCase;
23 import com.android.tradefed.testtype.IAbi;
24 import com.android.tradefed.testtype.IAbiReceiver;
25 import com.android.tradefed.testtype.IBuildReceiver;
26 
27 /**
28  * Base class for {@link android.provider.DocumentsContract} and related test cases.
29  */
30 abstract  class DocumentsTestCase extends DeviceTestCase implements IAbiReceiver, IBuildReceiver {
31     protected static final String CLIENT_PKG = "com.android.cts.documentclient";
32     protected static final String CLIENT_APK = "CtsDocumentClient.apk";
33 
34     protected IAbi mAbi;
35     protected IBuildInfo mCtsBuild;
36 
37     @Override
setAbi(IAbi abi)38     public void setAbi(IAbi abi) {
39         mAbi = abi;
40     }
41 
42     @Override
setBuild(IBuildInfo buildInfo)43     public void setBuild(IBuildInfo buildInfo) {
44         mCtsBuild = buildInfo;
45     }
46 
47     @Override
setUp()48     protected void setUp() throws Exception {
49         super.setUp();
50 
51         assertNotNull(mAbi);
52         assertNotNull(mCtsBuild);
53 
54         reinstallClientPackage();
55     }
56 
57     @Override
tearDown()58     protected void tearDown() throws Exception {
59         super.tearDown();
60 
61         getDevice().uninstallPackage(CLIENT_PKG);
62     }
63 
runDeviceTests(String packageName, String testClassName, String testMethodName)64     public void runDeviceTests(String packageName, String testClassName, String testMethodName)
65             throws DeviceNotAvailableException {
66         Utils.runDeviceTests(getDevice(), packageName, testClassName, testMethodName);
67     }
68 
reinstallClientPackage()69     protected void reinstallClientPackage() throws Exception {
70         getDevice().uninstallPackage(CLIENT_PKG);
71 
72         assertNull(getDevice().installPackage(
73                 MigrationHelper.getTestFile(mCtsBuild, CLIENT_APK), false));
74     }
75 }
76