Jingwen Chen | 6528999 | 2023-09-21 15:15:47 +0000 | [diff] [blame^] | 1 | // Copyright 2023 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java" |
| 20 | |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | func runAndroidTestTestCase(t *testing.T, tc Bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | RunBp2BuildTestCase(t, registerAndroidTestModuleTypes, tc) |
| 27 | } |
| 28 | |
| 29 | func registerAndroidTestModuleTypes(ctx android.RegistrationContext) { |
| 30 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 31 | ctx.RegisterModuleType("java_library", java.LibraryFactory) |
| 32 | } |
| 33 | |
| 34 | func TestMinimalAndroidTest(t *testing.T) { |
| 35 | runAndroidAppTestCase(t, Bp2buildTestCase{ |
| 36 | Description: "Android test - simple example", |
| 37 | ModuleTypeUnderTest: "android_test", |
| 38 | ModuleTypeUnderTestFactory: java.AndroidTestFactory, |
| 39 | Filesystem: map[string]string{ |
| 40 | "app.java": "", |
| 41 | "res/res.png": "", |
| 42 | "AndroidManifest.xml": "", |
| 43 | "assets/asset.png": "", |
| 44 | }, |
| 45 | Blueprint: ` |
| 46 | android_test { |
| 47 | name: "TestApp", |
| 48 | srcs: ["app.java"], |
| 49 | sdk_version: "current", |
| 50 | optimize: { |
| 51 | shrink: true, |
| 52 | optimize: true, |
| 53 | obfuscate: true, |
| 54 | }, |
| 55 | } |
| 56 | `, |
| 57 | ExpectedBazelTargets: []string{ |
| 58 | MakeBazelTarget("android_test", "TestApp", AttrNameToString{ |
| 59 | "srcs": `["app.java"]`, |
| 60 | "manifest": `"AndroidManifest.xml"`, |
| 61 | "resource_files": `["res/res.png"]`, |
| 62 | "sdk_version": `"current"`, |
| 63 | "assets": `["assets/asset.png"]`, |
| 64 | "assets_dir": `"assets"`, |
| 65 | }), |
| 66 | }}) |
| 67 | } |
| 68 | |
| 69 | func TestMinimalAndroidTestHelperApp(t *testing.T) { |
| 70 | runAndroidAppTestCase(t, Bp2buildTestCase{ |
| 71 | Description: "Android test helper app - simple example", |
| 72 | ModuleTypeUnderTest: "android_test_helper_app", |
| 73 | ModuleTypeUnderTestFactory: java.AndroidTestHelperAppFactory, |
| 74 | Filesystem: map[string]string{ |
| 75 | "app.java": "", |
| 76 | "res/res.png": "", |
| 77 | "AndroidManifest.xml": "", |
| 78 | "assets/asset.png": "", |
| 79 | }, |
| 80 | Blueprint: ` |
| 81 | android_test_helper_app { |
| 82 | name: "TestApp", |
| 83 | srcs: ["app.java"], |
| 84 | sdk_version: "current", |
| 85 | optimize: { |
| 86 | shrink: true, |
| 87 | optimize: true, |
| 88 | obfuscate: true, |
| 89 | }, |
| 90 | } |
| 91 | `, |
| 92 | ExpectedBazelTargets: []string{ |
| 93 | MakeBazelTarget("android_binary", "TestApp", AttrNameToString{ |
| 94 | "srcs": `["app.java"]`, |
| 95 | "manifest": `"AndroidManifest.xml"`, |
| 96 | "resource_files": `["res/res.png"]`, |
| 97 | "sdk_version": `"current"`, |
| 98 | "assets": `["assets/asset.png"]`, |
| 99 | "assets_dir": `"assets"`, |
| 100 | "testonly": `True`, |
| 101 | }), |
| 102 | }}) |
| 103 | } |