aboutsummaryrefslogtreecommitdiffstats
path: root/java/app_test.go
blob: 0b1491e7b3668dfe49fb0c4df59ee6783eb465ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package java

import (
	"android/soong/android"
	"reflect"
	"testing"
)

var (
	resourceFiles = []string{
		"res/layout/layout.xml",
		"res/values/strings.xml",
		"res/values-en-rUS/strings.xml",
	}

	compiledResourceFiles = []string{
		"aapt2/res/layout_layout.xml.flat",
		"aapt2/res/values_strings.arsc.flat",
		"aapt2/res/values-en-rUS_strings.arsc.flat",
	}
)

func testApp(t *testing.T, bp string) *android.TestContext {
	bp += `
		android_app {
			name: "framework-res",
			no_framework_libs: true,
		}
	`

	appFs := map[string][]byte{
		"AndroidManifest.xml":                   nil,
		"build/target/product/security/testkey": nil,
	}

	for _, file := range resourceFiles {
		appFs[file] = nil
	}

	return testJavaWithEnvFs(t, bp, nil, appFs)
}

func TestApp(t *testing.T) {
	ctx := testApp(t, `
		android_app {
			name: "foo",
			srcs: ["a.java"],
		}
	`)

	foo := ctx.ModuleForTests("foo", "android_common")

	expectedLinkImplicits := []string{"AndroidManifest.xml"}

	frameworkRes := ctx.ModuleForTests("framework-res", "android_common")
	expectedLinkImplicits = append(expectedLinkImplicits,
		frameworkRes.Output("package-res.apk").Output.String())

	// Test the mapping from input files to compiled output file names
	compile := foo.Output(compiledResourceFiles[0])
	if !reflect.DeepEqual(resourceFiles, compile.Inputs.Strings()) {
		t.Errorf("expected aapt2 compile inputs expected:\n  %#v\n got:\n  %#v",
			resourceFiles, compile.Inputs.Strings())
	}
	expectedLinkImplicits = append(expectedLinkImplicits, compile.Outputs.Strings()...)

	list := foo.Output("aapt2/res.list")
	expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String())

	// Check that the link rule uses
	res := ctx.ModuleForTests("foo", "android_common").Output("package-res.apk")
	if !reflect.DeepEqual(expectedLinkImplicits, res.Implicits.Strings()) {
		t.Errorf("expected aapt2 link implicits expected:\n  %#v\n got:\n  %#v",
			expectedLinkImplicits, res.Implicits.Strings())
	}
}