blob: 0b1491e7b3668dfe49fb0c4df59ee6783eb465ff [file] [log] [blame]
Colin Cross3bc7ffa2017-11-22 16:19:37 -08001// Copyright 2017 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 (
18 "android/soong/android"
19 "reflect"
20 "testing"
21)
22
23var (
24 resourceFiles = []string{
25 "res/layout/layout.xml",
26 "res/values/strings.xml",
27 "res/values-en-rUS/strings.xml",
28 }
29
30 compiledResourceFiles = []string{
31 "aapt2/res/layout_layout.xml.flat",
32 "aapt2/res/values_strings.arsc.flat",
33 "aapt2/res/values-en-rUS_strings.arsc.flat",
34 }
35)
36
37func testApp(t *testing.T, bp string) *android.TestContext {
38 bp += `
39 android_app {
40 name: "framework-res",
41 no_framework_libs: true,
42 }
43 `
44
45 appFs := map[string][]byte{
46 "AndroidManifest.xml": nil,
47 "build/target/product/security/testkey": nil,
48 }
49
50 for _, file := range resourceFiles {
51 appFs[file] = nil
52 }
53
54 return testJavaWithEnvFs(t, bp, nil, appFs)
55}
56
57func TestApp(t *testing.T) {
58 ctx := testApp(t, `
59 android_app {
60 name: "foo",
61 srcs: ["a.java"],
62 }
63 `)
64
65 foo := ctx.ModuleForTests("foo", "android_common")
66
67 expectedLinkImplicits := []string{"AndroidManifest.xml"}
68
69 frameworkRes := ctx.ModuleForTests("framework-res", "android_common")
70 expectedLinkImplicits = append(expectedLinkImplicits,
71 frameworkRes.Output("package-res.apk").Output.String())
72
73 // Test the mapping from input files to compiled output file names
74 compile := foo.Output(compiledResourceFiles[0])
75 if !reflect.DeepEqual(resourceFiles, compile.Inputs.Strings()) {
76 t.Errorf("expected aapt2 compile inputs expected:\n %#v\n got:\n %#v",
77 resourceFiles, compile.Inputs.Strings())
78 }
79 expectedLinkImplicits = append(expectedLinkImplicits, compile.Outputs.Strings()...)
80
81 list := foo.Output("aapt2/res.list")
82 expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String())
83
84 // Check that the link rule uses
85 res := ctx.ModuleForTests("foo", "android_common").Output("package-res.apk")
86 if !reflect.DeepEqual(expectedLinkImplicits, res.Implicits.Strings()) {
87 t.Errorf("expected aapt2 link implicits expected:\n %#v\n got:\n %#v",
88 expectedLinkImplicits, res.Implicits.Strings())
89 }
90}