Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Paul Duffin | f71e4ed | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 18 | "fmt" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 19 | "reflect" |
Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 20 | "strings" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 21 | "testing" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | ) |
| 25 | |
| 26 | func TestAndroidAppSet(t *testing.T) { |
Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 27 | result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, ` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 28 | android_app_set { |
| 29 | name: "foo", |
| 30 | set: "prebuilts/apks/app.apks", |
| 31 | prerelease: true, |
| 32 | }`) |
Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 33 | module := result.ModuleForTests("foo", "android_common") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 34 | 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 Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 45 | |
| 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 Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 57 | actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"] |
Colin Cross | ffbcd1d | 2021-11-12 12:19:42 -0800 | [diff] [blame] | 58 | expectedInstallFile := []string{ |
| 59 | strings.Replace(params.ImplicitOutputs[0].String(), android.OutSoongDir, result.Config.SoongOutDir(), 1), |
| 60 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 61 | if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) { |
| 62 | t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',", |
| 63 | actualInstallFile, expectedInstallFile) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func 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 Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 92 | "skip-sdk-check": "false", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 93 | "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 Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 109 | "skip-sdk-check": "false", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 110 | "stem": "foo", |
| 111 | }, |
| 112 | }, |
| 113 | } |
| 114 | |
| 115 | for _, test := range testCases { |
Paul Duffin | f71e4ed | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 116 | 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 Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 127 | module := ctx.ModuleForTests("foo", "android_common") |
| 128 | const packedSplitApks = "foo.zip" |
| 129 | params := module.Output(packedSplitApks) |
| 130 | for k, v := range test.expected { |
Paul Duffin | f71e4ed | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 131 | 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 Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | } |