blob: 10bc5de926b16501d642ec33aedd9711947912a4 [file] [log] [blame]
Jaewoong Jungf9b44652020-12-21 12:29:12 -08001// Copyright 2020 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 java
16
17import (
Paul Duffinf71e4ed2021-03-22 17:31:52 +000018 "fmt"
Jaewoong Jungf9b44652020-12-21 12:29:12 -080019 "reflect"
Colin Crossffbcd1d2021-11-12 12:19:42 -080020 "strings"
Jaewoong Jungf9b44652020-12-21 12:29:12 -080021 "testing"
22
23 "android/soong/android"
24)
25
26func TestAndroidAppSet(t *testing.T) {
Colin Crossffbcd1d2021-11-12 12:19:42 -080027 result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
Jaewoong Jungf9b44652020-12-21 12:29:12 -080028 android_app_set {
29 name: "foo",
30 set: "prebuilts/apks/app.apks",
31 prerelease: true,
32 }`)
Colin Crossffbcd1d2021-11-12 12:19:42 -080033 module := result.ModuleForTests("foo", "android_common")
Jaewoong Jungf9b44652020-12-21 12:29:12 -080034 const packedSplitApks = "foo.zip"
35 params := module.Output(packedSplitApks)
36 if params.Rule == nil {
37 t.Errorf("expected output %s is missing", packedSplitApks)
38 }
39 if s := params.Args["allow-prereleased"]; s != "true" {
40 t.Errorf("wrong allow-prereleased value: '%s', expected 'true'", s)
41 }
42 if s := params.Args["partition"]; s != "system" {
43 t.Errorf("wrong partition value: '%s', expected 'system'", s)
44 }
Colin Crossffbcd1d2021-11-12 12:19:42 -080045
46 android.AssertPathRelativeToTopEquals(t, "incorrect output path",
47 "out/soong/.intermediates/foo/android_common/foo.apk", params.Output)
48
49 android.AssertPathsRelativeToTopEquals(t, "incorrect implicit output paths",
50 []string{
51 "out/soong/.intermediates/foo/android_common/foo.zip",
52 "out/soong/.intermediates/foo/android_common/apkcerts.txt",
53 },
54 params.ImplicitOutputs.Paths())
55
56 mkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, module.Module())[0]
Jaewoong Jungf9b44652020-12-21 12:29:12 -080057 actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"]
Colin Crossffbcd1d2021-11-12 12:19:42 -080058 expectedInstallFile := []string{
59 strings.Replace(params.ImplicitOutputs[0].String(), android.OutSoongDir, result.Config.SoongOutDir(), 1),
60 }
Jaewoong Jungf9b44652020-12-21 12:29:12 -080061 if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) {
62 t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',",
63 actualInstallFile, expectedInstallFile)
64 }
65}
66
67func TestAndroidAppSet_Variants(t *testing.T) {
68 bp := `
69 android_app_set {
70 name: "foo",
71 set: "prebuilts/apks/app.apks",
72 }`
73 testCases := []struct {
74 name string
75 targets []android.Target
76 aaptPrebuiltDPI []string
77 sdkVersion int
78 expected map[string]string
79 }{
80 {
81 name: "One",
82 targets: []android.Target{
83 {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
84 },
85 aaptPrebuiltDPI: []string{"ldpi", "xxhdpi"},
86 sdkVersion: 29,
87 expected: map[string]string{
88 "abis": "X86",
89 "allow-prereleased": "false",
90 "screen-densities": "LDPI,XXHDPI",
91 "sdk-version": "29",
Pranav Gupta51645ff2023-03-20 16:19:53 -070092 "skip-sdk-check": "false",
Jaewoong Jungf9b44652020-12-21 12:29:12 -080093 "stem": "foo",
94 },
95 },
96 {
97 name: "Two",
98 targets: []android.Target{
99 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64}},
100 {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
101 },
102 aaptPrebuiltDPI: nil,
103 sdkVersion: 30,
104 expected: map[string]string{
105 "abis": "X86_64,X86",
106 "allow-prereleased": "false",
107 "screen-densities": "all",
108 "sdk-version": "30",
Pranav Gupta51645ff2023-03-20 16:19:53 -0700109 "skip-sdk-check": "false",
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800110 "stem": "foo",
111 },
112 },
113 }
114
115 for _, test := range testCases {
Paul Duffinf71e4ed2021-03-22 17:31:52 +0000116 ctx := android.GroupFixturePreparers(
117 PrepareForTestWithJavaDefaultModules,
118 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
119 variables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
120 variables.Platform_sdk_version = &test.sdkVersion
121 }),
122 android.FixtureModifyConfig(func(config android.Config) {
123 config.Targets[android.Android] = test.targets
124 }),
125 ).RunTestWithBp(t, bp)
126
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800127 module := ctx.ModuleForTests("foo", "android_common")
128 const packedSplitApks = "foo.zip"
129 params := module.Output(packedSplitApks)
130 for k, v := range test.expected {
Paul Duffinf71e4ed2021-03-22 17:31:52 +0000131 t.Run(test.name, func(t *testing.T) {
132 android.AssertStringEquals(t, fmt.Sprintf("arg value for `%s`", k), v, params.Args[k])
133 })
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800134 }
135 }
136}