blob: 9b4c44bc96ae174919d9892b7a3cd779a06f9377 [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 Cross844cb6a2025-01-29 15:53:21 -080027 t.Parallel()
Colin Crossffbcd1d2021-11-12 12:19:42 -080028 result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
Jaewoong Jungf9b44652020-12-21 12:29:12 -080029 android_app_set {
30 name: "foo",
31 set: "prebuilts/apks/app.apks",
32 prerelease: true,
33 }`)
Colin Cross90607e92025-02-11 14:58:07 -080034 module := result.ModuleForTests(t, "foo", "android_common")
Jaewoong Jungf9b44652020-12-21 12:29:12 -080035 const packedSplitApks = "foo.zip"
36 params := module.Output(packedSplitApks)
37 if params.Rule == nil {
38 t.Errorf("expected output %s is missing", packedSplitApks)
39 }
40 if s := params.Args["allow-prereleased"]; s != "true" {
41 t.Errorf("wrong allow-prereleased value: '%s', expected 'true'", s)
42 }
43 if s := params.Args["partition"]; s != "system" {
44 t.Errorf("wrong partition value: '%s', expected 'system'", s)
45 }
Colin Crossffbcd1d2021-11-12 12:19:42 -080046
47 android.AssertPathRelativeToTopEquals(t, "incorrect output path",
48 "out/soong/.intermediates/foo/android_common/foo.apk", params.Output)
49
50 android.AssertPathsRelativeToTopEquals(t, "incorrect implicit output paths",
51 []string{
52 "out/soong/.intermediates/foo/android_common/foo.zip",
53 "out/soong/.intermediates/foo/android_common/apkcerts.txt",
54 },
55 params.ImplicitOutputs.Paths())
56
57 mkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, module.Module())[0]
Jaewoong Jungf9b44652020-12-21 12:29:12 -080058 actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"]
Colin Crossffbcd1d2021-11-12 12:19:42 -080059 expectedInstallFile := []string{
Colin Cross3b1c6842024-07-26 11:52:57 -070060 strings.Replace(params.ImplicitOutputs[0].String(), android.TestOutSoongDir, result.Config.SoongOutDir(), 1),
Colin Crossffbcd1d2021-11-12 12:19:42 -080061 }
Jaewoong Jungf9b44652020-12-21 12:29:12 -080062 if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) {
63 t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',",
64 actualInstallFile, expectedInstallFile)
65 }
66}
67
68func TestAndroidAppSet_Variants(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -080069 t.Parallel()
Jaewoong Jungf9b44652020-12-21 12:29:12 -080070 bp := `
71 android_app_set {
72 name: "foo",
73 set: "prebuilts/apks/app.apks",
74 }`
75 testCases := []struct {
76 name string
77 targets []android.Target
78 aaptPrebuiltDPI []string
79 sdkVersion int
80 expected map[string]string
81 }{
82 {
83 name: "One",
84 targets: []android.Target{
85 {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
86 },
87 aaptPrebuiltDPI: []string{"ldpi", "xxhdpi"},
88 sdkVersion: 29,
89 expected: map[string]string{
90 "abis": "X86",
91 "allow-prereleased": "false",
92 "screen-densities": "LDPI,XXHDPI",
93 "sdk-version": "29",
Pranav Gupta51645ff2023-03-20 16:19:53 -070094 "skip-sdk-check": "false",
Jaewoong Jungf9b44652020-12-21 12:29:12 -080095 "stem": "foo",
96 },
97 },
98 {
99 name: "Two",
100 targets: []android.Target{
101 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64}},
102 {Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
103 },
104 aaptPrebuiltDPI: nil,
105 sdkVersion: 30,
106 expected: map[string]string{
107 "abis": "X86_64,X86",
108 "allow-prereleased": "false",
109 "screen-densities": "all",
110 "sdk-version": "30",
Pranav Gupta51645ff2023-03-20 16:19:53 -0700111 "skip-sdk-check": "false",
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800112 "stem": "foo",
113 },
114 },
115 }
116
117 for _, test := range testCases {
Colin Cross844cb6a2025-01-29 15:53:21 -0800118 t.Run(test.name, func(t *testing.T) {
119 ctx := android.GroupFixturePreparers(
120 PrepareForTestWithJavaDefaultModules,
121 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
122 variables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
123 variables.Platform_sdk_version = &test.sdkVersion
124 }),
125 android.FixtureModifyConfig(func(config android.Config) {
126 config.Targets[android.Android] = test.targets
127 }),
128 ).RunTestWithBp(t, bp)
Paul Duffinf71e4ed2021-03-22 17:31:52 +0000129
Colin Cross90607e92025-02-11 14:58:07 -0800130 module := ctx.ModuleForTests(t, "foo", "android_common")
Colin Cross844cb6a2025-01-29 15:53:21 -0800131 const packedSplitApks = "foo.zip"
132 params := module.Output(packedSplitApks)
133 for k, v := range test.expected {
Paul Duffinf71e4ed2021-03-22 17:31:52 +0000134 android.AssertStringEquals(t, fmt.Sprintf("arg value for `%s`", k), v, params.Args[k])
Colin Cross844cb6a2025-01-29 15:53:21 -0800135 }
136 })
Jaewoong Jungf9b44652020-12-21 12:29:12 -0800137 }
138}