Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 1 | // Copyright 2021 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 runAndroidAppTestCase(t *testing.T, tc bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | runBp2BuildTestCase(t, registerAndroidAppModuleTypes, tc) |
| 27 | } |
| 28 | |
| 29 | func registerAndroidAppModuleTypes(ctx android.RegistrationContext) { |
| 30 | } |
| 31 | |
| 32 | func TestMinimalAndroidApp(t *testing.T) { |
| 33 | runAndroidAppTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 34 | description: "Android app - simple example", |
| 35 | moduleTypeUnderTest: "android_app", |
| 36 | moduleTypeUnderTestFactory: java.AndroidAppFactory, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 37 | filesystem: map[string]string{ |
| 38 | "app.java": "", |
| 39 | "res/res.png": "", |
| 40 | "AndroidManifest.xml": "", |
| 41 | }, |
| 42 | blueprint: ` |
| 43 | android_app { |
| 44 | name: "TestApp", |
| 45 | srcs: ["app.java"], |
| 46 | sdk_version: "current", |
| 47 | } |
| 48 | `, |
| 49 | expectedBazelTargets: []string{ |
| 50 | makeBazelTarget("android_binary", "TestApp", attrNameToString{ |
| 51 | "srcs": `["app.java"]`, |
| 52 | "manifest": `"AndroidManifest.xml"`, |
| 53 | "resource_files": `["res/res.png"]`, |
| 54 | }), |
| 55 | }}) |
| 56 | } |
| 57 | |
| 58 | func TestAndroidAppAllSupportedFields(t *testing.T) { |
| 59 | runAndroidAppTestCase(t, bp2buildTestCase{ |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 60 | description: "Android app - all supported fields", |
| 61 | moduleTypeUnderTest: "android_app", |
| 62 | moduleTypeUnderTestFactory: java.AndroidAppFactory, |
Romain Jobredeaux | 1282c42 | 2021-10-29 10:52:59 -0400 | [diff] [blame] | 63 | filesystem: map[string]string{ |
| 64 | "app.java": "", |
| 65 | "resa/res.png": "", |
| 66 | "resb/res.png": "", |
| 67 | "manifest/AndroidManifest.xml": "", |
| 68 | }, |
| 69 | blueprint: ` |
| 70 | android_app { |
| 71 | name: "TestApp", |
| 72 | srcs: ["app.java"], |
| 73 | sdk_version: "current", |
| 74 | package_name: "com.google", |
| 75 | resource_dirs: ["resa", "resb"], |
| 76 | manifest: "manifest/AndroidManifest.xml", |
| 77 | } |
| 78 | `, |
| 79 | expectedBazelTargets: []string{ |
| 80 | makeBazelTarget("android_binary", "TestApp", attrNameToString{ |
| 81 | "srcs": `["app.java"]`, |
| 82 | "manifest": `"manifest/AndroidManifest.xml"`, |
| 83 | "resource_files": `[ |
| 84 | "resa/res.png", |
| 85 | "resb/res.png", |
| 86 | ]`, |
| 87 | "custom_package": `"com.google"`, |
| 88 | }), |
| 89 | }}) |
| 90 | } |