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