| 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 ( | 
|  | 18 | "reflect" | 
|  | 19 | "testing" | 
|  | 20 |  | 
|  | 21 | "android/soong/android" | 
|  | 22 | ) | 
|  | 23 |  | 
|  | 24 | func TestAndroidAppSet(t *testing.T) { | 
|  | 25 | ctx, config := testJava(t, ` | 
|  | 26 | android_app_set { | 
|  | 27 | name: "foo", | 
|  | 28 | set: "prebuilts/apks/app.apks", | 
|  | 29 | prerelease: true, | 
|  | 30 | }`) | 
|  | 31 | module := ctx.ModuleForTests("foo", "android_common") | 
|  | 32 | const packedSplitApks = "foo.zip" | 
|  | 33 | params := module.Output(packedSplitApks) | 
|  | 34 | if params.Rule == nil { | 
|  | 35 | t.Errorf("expected output %s is missing", packedSplitApks) | 
|  | 36 | } | 
|  | 37 | if s := params.Args["allow-prereleased"]; s != "true" { | 
|  | 38 | t.Errorf("wrong allow-prereleased value: '%s', expected 'true'", s) | 
|  | 39 | } | 
|  | 40 | if s := params.Args["partition"]; s != "system" { | 
|  | 41 | t.Errorf("wrong partition value: '%s', expected 'system'", s) | 
|  | 42 | } | 
|  | 43 | mkEntries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0] | 
|  | 44 | actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"] | 
|  | 45 | expectedInstallFile := []string{"foo.apk"} | 
|  | 46 | if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) { | 
|  | 47 | t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',", | 
|  | 48 | actualInstallFile, expectedInstallFile) | 
|  | 49 | } | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | func TestAndroidAppSet_Variants(t *testing.T) { | 
|  | 53 | bp := ` | 
|  | 54 | android_app_set { | 
|  | 55 | name: "foo", | 
|  | 56 | set: "prebuilts/apks/app.apks", | 
|  | 57 | }` | 
|  | 58 | testCases := []struct { | 
|  | 59 | name            string | 
|  | 60 | targets         []android.Target | 
|  | 61 | aaptPrebuiltDPI []string | 
|  | 62 | sdkVersion      int | 
|  | 63 | expected        map[string]string | 
|  | 64 | }{ | 
|  | 65 | { | 
|  | 66 | name: "One", | 
|  | 67 | targets: []android.Target{ | 
|  | 68 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86}}, | 
|  | 69 | }, | 
|  | 70 | aaptPrebuiltDPI: []string{"ldpi", "xxhdpi"}, | 
|  | 71 | sdkVersion:      29, | 
|  | 72 | expected: map[string]string{ | 
|  | 73 | "abis":              "X86", | 
|  | 74 | "allow-prereleased": "false", | 
|  | 75 | "screen-densities":  "LDPI,XXHDPI", | 
|  | 76 | "sdk-version":       "29", | 
|  | 77 | "stem":              "foo", | 
|  | 78 | }, | 
|  | 79 | }, | 
|  | 80 | { | 
|  | 81 | name: "Two", | 
|  | 82 | targets: []android.Target{ | 
|  | 83 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64}}, | 
|  | 84 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86}}, | 
|  | 85 | }, | 
|  | 86 | aaptPrebuiltDPI: nil, | 
|  | 87 | sdkVersion:      30, | 
|  | 88 | expected: map[string]string{ | 
|  | 89 | "abis":              "X86_64,X86", | 
|  | 90 | "allow-prereleased": "false", | 
|  | 91 | "screen-densities":  "all", | 
|  | 92 | "sdk-version":       "30", | 
|  | 93 | "stem":              "foo", | 
|  | 94 | }, | 
|  | 95 | }, | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | for _, test := range testCases { | 
|  | 99 | config := testAppConfig(nil, bp, nil) | 
|  | 100 | config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI | 
|  | 101 | config.TestProductVariables.Platform_sdk_version = &test.sdkVersion | 
|  | 102 | config.Targets[android.Android] = test.targets | 
|  | 103 | ctx := testContext(config) | 
|  | 104 | run(t, ctx, config) | 
|  | 105 | module := ctx.ModuleForTests("foo", "android_common") | 
|  | 106 | const packedSplitApks = "foo.zip" | 
|  | 107 | params := module.Output(packedSplitApks) | 
|  | 108 | for k, v := range test.expected { | 
|  | 109 | if actual := params.Args[k]; actual != v { | 
|  | 110 | t.Errorf("%s: bad build arg value for '%s': '%s', expected '%s'", | 
|  | 111 | test.name, k, actual, v) | 
|  | 112 | } | 
|  | 113 | } | 
|  | 114 | } | 
|  | 115 | } |