diff options
author | Jaewoong Jung <jungjw@google.com> | 2019-04-26 14:31:50 -0700 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-12-11 19:03:32 +0200 |
commit | edd7f298986d42f6ed22defe42ea790a3ba5c5c1 (patch) | |
tree | f20a6fad6d9426d06b92935e75c0035d4a588fcd /java/app_test.go | |
parent | 61732d653e590a6159ae8d7650a59c68c3426c28 (diff) | |
download | android_build_soong-edd7f298986d42f6ed22defe42ea790a3ba5c5c1.tar.gz android_build_soong-edd7f298986d42f6ed22defe42ea790a3ba5c5c1.tar.bz2 android_build_soong-edd7f298986d42f6ed22defe42ea790a3ba5c5c1.zip |
Implement DPI variants in android_app_import.
Bug: 128610294
Test: app_test.go
Change-Id: Ie3e558bfdb40de6b0b9df95d3b373d08a4084d7b
Diffstat (limited to 'java/app_test.go')
-rw-r--r-- | java/app_test.go | 85 |
1 files changed, 82 insertions, 3 deletions
diff --git a/java/app_test.go b/java/app_test.go index 66f993dc..723cde3e 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -15,17 +15,18 @@ package java import ( - "android/soong/android" - "android/soong/cc" - "fmt" "path/filepath" "reflect" + "regexp" "sort" "strings" "testing" "github.com/google/blueprint/proptools" + + "android/soong/android" + "android/soong/cc" ) var ( @@ -1235,3 +1236,81 @@ func TestAndroidAppImport_Presigned(t *testing.T) { t.Errorf("can't find aligning rule") } } + +func TestAndroidAppImport_DpiVariants(t *testing.T) { + bp := ` + android_app_import { + name: "foo", + apk: "prebuilts/apk/app.apk", + dpi_variants: { + xhdpi: { + apk: "prebuilts/apk/app_xhdpi.apk", + }, + xxhdpi: { + apk: "prebuilts/apk/app_xxhdpi.apk", + }, + }, + certificate: "PRESIGNED", + dex_preopt: { + enabled: true, + }, + } + ` + testCases := []struct { + name string + aaptPreferredConfig *string + aaptPrebuiltDPI []string + expected string + }{ + { + name: "no preferred", + aaptPreferredConfig: nil, + aaptPrebuiltDPI: []string{}, + expected: "prebuilts/apk/app.apk", + }, + { + name: "AAPTPreferredConfig matches", + aaptPreferredConfig: proptools.StringPtr("xhdpi"), + aaptPrebuiltDPI: []string{"xxhdpi", "lhdpi"}, + expected: "prebuilts/apk/app_xhdpi.apk", + }, + { + name: "AAPTPrebuiltDPI matches", + aaptPreferredConfig: proptools.StringPtr("mdpi"), + aaptPrebuiltDPI: []string{"xxhdpi", "xhdpi"}, + expected: "prebuilts/apk/app_xxhdpi.apk", + }, + { + name: "non-first AAPTPrebuiltDPI matches", + aaptPreferredConfig: proptools.StringPtr("mdpi"), + aaptPrebuiltDPI: []string{"ldpi", "xhdpi"}, + expected: "prebuilts/apk/app_xhdpi.apk", + }, + { + name: "no matches", + aaptPreferredConfig: proptools.StringPtr("mdpi"), + aaptPrebuiltDPI: []string{"ldpi", "xxxhdpi"}, + expected: "prebuilts/apk/app.apk", + }, + } + + jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") + for _, test := range testCases { + config := testConfig(nil) + config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig + config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI + ctx := testAppContext(config, bp, nil) + + run(t, ctx, config) + + variant := ctx.ModuleForTests("foo", "android_common") + jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command + matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) + if len(matches) != 2 { + t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) + } + if test.expected != matches[1] { + t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) + } + } +} |