Soroosh Mariooryad | 56ce766 | 2017-02-06 15:23:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | package com.android.settingslib; |
| 17 | |
| 18 | import org.junit.runners.model.InitializationError; |
| 19 | import org.robolectric.RobolectricTestRunner; |
| 20 | import org.robolectric.annotation.Config; |
| 21 | import org.robolectric.manifest.AndroidManifest; |
| 22 | import org.robolectric.res.Fs; |
Fan Zhang | 60b850d | 2017-07-18 15:59:06 -0700 | [diff] [blame] | 23 | import org.robolectric.res.ResourcePath; |
| 24 | |
| 25 | import java.util.List; |
Soroosh Mariooryad | 56ce766 | 2017-02-06 15:23:00 -0800 | [diff] [blame] | 26 | |
Tony Mantler | 4ca9ebd | 2017-07-31 10:54:20 -0700 | [diff] [blame] | 27 | public class SettingsLibRobolectricTestRunner extends RobolectricTestRunner { |
Soroosh Mariooryad | 56ce766 | 2017-02-06 15:23:00 -0800 | [diff] [blame] | 28 | |
Tony Mantler | 4ca9ebd | 2017-07-31 10:54:20 -0700 | [diff] [blame] | 29 | public SettingsLibRobolectricTestRunner(Class<?> testClass) throws InitializationError { |
Soroosh Mariooryad | 56ce766 | 2017-02-06 15:23:00 -0800 | [diff] [blame] | 30 | super(testClass); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | protected AndroidManifest getAppManifest(Config config) { |
| 35 | // Using the manifest file's relative path, we can figure out the application directory. |
| 36 | final String appRoot = "frameworks/base/packages/SettingsLib"; |
| 37 | final String manifestPath = appRoot + "/AndroidManifest.xml"; |
| 38 | final String resDir = appRoot + "/tests/robotests/res"; |
| 39 | final String assetsDir = appRoot + config.assetDir(); |
| 40 | |
| 41 | final AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(manifestPath), |
Fan Zhang | 60b850d | 2017-07-18 15:59:06 -0700 | [diff] [blame] | 42 | Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { |
| 43 | @Override |
| 44 | public List<ResourcePath> getIncludedResourcePaths() { |
| 45 | List<ResourcePath> paths = super.getIncludedResourcePaths(); |
Tony Mantler | 4ca9ebd | 2017-07-31 10:54:20 -0700 | [diff] [blame] | 46 | SettingsLibRobolectricTestRunner.getIncludedResourcePaths(getPackageName(), paths); |
Fan Zhang | 60b850d | 2017-07-18 15:59:06 -0700 | [diff] [blame] | 47 | return paths; |
| 48 | } |
| 49 | }; |
Soroosh Mariooryad | 56ce766 | 2017-02-06 15:23:00 -0800 | [diff] [blame] | 50 | manifest.setPackageName("com.android.settingslib"); |
| 51 | return manifest; |
| 52 | } |
| 53 | |
Fan Zhang | 60b850d | 2017-07-18 15:59:06 -0700 | [diff] [blame] | 54 | static void getIncludedResourcePaths(String packageName, List<ResourcePath> paths) { |
| 55 | paths.add(new ResourcePath( |
| 56 | packageName, |
| 57 | Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"), |
| 58 | null)); |
| 59 | paths.add(new ResourcePath( |
| 60 | packageName, |
| 61 | Fs.fileFromPath("./frameworks/base/core/res/res"), |
| 62 | null)); |
| 63 | paths.add(new ResourcePath( |
| 64 | packageName, |
| 65 | Fs.fileFromPath("./frameworks/support/v7/appcompat/res"), |
| 66 | null)); |
| 67 | } |
| 68 | |
Soroosh Mariooryad | 56ce766 | 2017-02-06 15:23:00 -0800 | [diff] [blame] | 69 | } |