blob: 233e9d5c5022819b9bebee535e94a2838cc2cce6 [file] [log] [blame]
Jooyung Han12df5fb2019-07-11 16:18:47 +09001// Copyright 2019 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 (
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070018 "reflect"
Jooyung Han12df5fb2019-07-11 16:18:47 +090019 "testing"
Jaewoong Jungf9a04432019-07-17 11:15:09 -070020
21 "android/soong/android"
Jooyung Han12df5fb2019-07-11 16:18:47 +090022)
23
Jooyung Han12df5fb2019-07-11 16:18:47 +090024func TestRequired(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070025 ctx, config := testJava(t, `
Jooyung Han12df5fb2019-07-11 16:18:47 +090026 java_library {
27 name: "foo",
28 srcs: ["a.java"],
29 required: ["libfoo"],
30 }
Jaewoong Jungf9a04432019-07-17 11:15:09 -070031 `)
Jooyung Han12df5fb2019-07-11 16:18:47 +090032
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070033 mod := ctx.ModuleForTests("foo", "android_common").Module()
Jiyong Park0b0e1b92019-12-03 13:24:29 +090034 entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070035
36 expected := []string{"libfoo"}
37 actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"]
38 if !reflect.DeepEqual(expected, actual) {
39 t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
40 }
Jooyung Han12df5fb2019-07-11 16:18:47 +090041}
42
43func TestHostdex(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070044 ctx, config := testJava(t, `
Jooyung Han12df5fb2019-07-11 16:18:47 +090045 java_library {
46 name: "foo",
47 srcs: ["a.java"],
48 hostdex: true,
49 }
Jaewoong Jungf9a04432019-07-17 11:15:09 -070050 `)
Jooyung Han12df5fb2019-07-11 16:18:47 +090051
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070052 mod := ctx.ModuleForTests("foo", "android_common").Module()
Jiyong Park55bd98b2019-12-11 17:27:07 +090053 entriesList := android.AndroidMkEntriesForTest(t, config, "", mod)
54 if len(entriesList) != 2 {
55 t.Errorf("two entries are expected, but got %d", len(entriesList))
56 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070057
Jiyong Park55bd98b2019-12-11 17:27:07 +090058 mainEntries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070059 expected := []string{"foo"}
Jiyong Park55bd98b2019-12-11 17:27:07 +090060 actual := mainEntries.EntryMap["LOCAL_MODULE"]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070061 if !reflect.DeepEqual(expected, actual) {
62 t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual)
63 }
64
Jiyong Park55bd98b2019-12-11 17:27:07 +090065 subEntries := &entriesList[1]
66 expected = []string{"foo-hostdex"}
67 actual = subEntries.EntryMap["LOCAL_MODULE"]
68 if !reflect.DeepEqual(expected, actual) {
69 t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070070 }
Jooyung Han12df5fb2019-07-11 16:18:47 +090071}
72
73func TestHostdexRequired(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070074 ctx, config := testJava(t, `
Jooyung Han12df5fb2019-07-11 16:18:47 +090075 java_library {
76 name: "foo",
77 srcs: ["a.java"],
78 hostdex: true,
79 required: ["libfoo"],
80 }
Jaewoong Jungf9a04432019-07-17 11:15:09 -070081 `)
Jooyung Han12df5fb2019-07-11 16:18:47 +090082
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070083 mod := ctx.ModuleForTests("foo", "android_common").Module()
Jiyong Park55bd98b2019-12-11 17:27:07 +090084 entriesList := android.AndroidMkEntriesForTest(t, config, "", mod)
85 if len(entriesList) != 2 {
86 t.Errorf("two entries are expected, but got %d", len(entriesList))
87 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070088
Jiyong Park55bd98b2019-12-11 17:27:07 +090089 mainEntries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070090 expected := []string{"libfoo"}
Jiyong Park55bd98b2019-12-11 17:27:07 +090091 actual := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070092 if !reflect.DeepEqual(expected, actual) {
93 t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
94 }
95
Jiyong Park55bd98b2019-12-11 17:27:07 +090096 subEntries := &entriesList[1]
97 expected = []string{"libfoo"}
98 actual = subEntries.EntryMap["LOCAL_REQUIRED_MODULES"]
99 if !reflect.DeepEqual(expected, actual) {
100 t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700101 }
Jooyung Han12df5fb2019-07-11 16:18:47 +0900102}
103
104func TestHostdexSpecificRequired(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -0700105 ctx, config := testJava(t, `
Jooyung Han12df5fb2019-07-11 16:18:47 +0900106 java_library {
107 name: "foo",
108 srcs: ["a.java"],
109 hostdex: true,
110 target: {
111 hostdex: {
112 required: ["libfoo"],
113 },
114 },
115 }
Jaewoong Jungf9a04432019-07-17 11:15:09 -0700116 `)
Jooyung Han12df5fb2019-07-11 16:18:47 +0900117
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700118 mod := ctx.ModuleForTests("foo", "android_common").Module()
Jiyong Park55bd98b2019-12-11 17:27:07 +0900119 entriesList := android.AndroidMkEntriesForTest(t, config, "", mod)
120 if len(entriesList) != 2 {
121 t.Errorf("two entries are expected, but got %d", len(entriesList))
122 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700123
Jiyong Park55bd98b2019-12-11 17:27:07 +0900124 mainEntries := &entriesList[0]
125 if r, ok := mainEntries.EntryMap["LOCAL_REQUIRED_MODULES"]; ok {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700126 t.Errorf("Unexpected required modules: %q", r)
127 }
128
Jiyong Park55bd98b2019-12-11 17:27:07 +0900129 subEntries := &entriesList[1]
130 expected := []string{"libfoo"}
131 actual := subEntries.EntryMap["LOCAL_REQUIRED_MODULES"]
132 if !reflect.DeepEqual(expected, actual) {
133 t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700134 }
Jooyung Han12df5fb2019-07-11 16:18:47 +0900135}
Anton Hansson78156ef2020-03-27 19:39:48 +0000136
Yo Chiang07d75072020-06-05 17:43:19 +0800137func TestJavaSdkLibrary_RequireXmlPermissionFile(t *testing.T) {
138 ctx, config := testJava(t, `
139 java_sdk_library {
140 name: "foo-shared_library",
141 srcs: ["a.java"],
142 }
143 java_sdk_library {
144 name: "foo-no_shared_library",
145 srcs: ["a.java"],
146 shared_library: false,
147 }
148 `)
149
150 // Verify the existence of internal modules
151 ctx.ModuleForTests("foo-shared_library.xml", "android_common")
152
153 testCases := []struct {
154 moduleName string
155 expected []string
156 }{
157 {"foo-shared_library", []string{"foo-shared_library.xml"}},
158 {"foo-no_shared_library", nil},
159 }
160 for _, tc := range testCases {
161 mod := ctx.ModuleForTests(tc.moduleName, "android_common").Module()
162 entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
163 actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"]
164 if !reflect.DeepEqual(tc.expected, actual) {
165 t.Errorf("Unexpected required modules - expected: %q, actual: %q", tc.expected, actual)
166 }
167 }
168}