blob: 967357630f0cdcf36765246a82518d60a92c18d3 [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 Park0b0e1b92019-12-03 13:24:29 +090053 entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070054
55 expected := []string{"foo"}
56 actual := entries.EntryMap["LOCAL_MODULE"]
57 if !reflect.DeepEqual(expected, actual) {
58 t.Errorf("Unexpected module name - expected: %q, actual: %q", expected, actual)
59 }
60
61 footerLines := entries.FooterLinesForTests()
62 if !android.InList("LOCAL_MODULE := foo-hostdex", footerLines) {
63 t.Errorf("foo-hostdex is not found in the footers: %q", footerLines)
64 }
Jooyung Han12df5fb2019-07-11 16:18:47 +090065}
66
67func TestHostdexRequired(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070068 ctx, config := testJava(t, `
Jooyung Han12df5fb2019-07-11 16:18:47 +090069 java_library {
70 name: "foo",
71 srcs: ["a.java"],
72 hostdex: true,
73 required: ["libfoo"],
74 }
Jaewoong Jungf9a04432019-07-17 11:15:09 -070075 `)
Jooyung Han12df5fb2019-07-11 16:18:47 +090076
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070077 mod := ctx.ModuleForTests("foo", "android_common").Module()
Jiyong Park0b0e1b92019-12-03 13:24:29 +090078 entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -070079
80 expected := []string{"libfoo"}
81 actual := entries.EntryMap["LOCAL_REQUIRED_MODULES"]
82 if !reflect.DeepEqual(expected, actual) {
83 t.Errorf("Unexpected required modules - expected: %q, actual: %q", expected, actual)
84 }
85
86 footerLines := entries.FooterLinesForTests()
87 if !android.InList("LOCAL_REQUIRED_MODULES := libfoo", footerLines) {
88 t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines)
89 }
Jooyung Han12df5fb2019-07-11 16:18:47 +090090}
91
92func TestHostdexSpecificRequired(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070093 ctx, config := testJava(t, `
Jooyung Han12df5fb2019-07-11 16:18:47 +090094 java_library {
95 name: "foo",
96 srcs: ["a.java"],
97 hostdex: true,
98 target: {
99 hostdex: {
100 required: ["libfoo"],
101 },
102 },
103 }
Jaewoong Jungf9a04432019-07-17 11:15:09 -0700104 `)
Jooyung Han12df5fb2019-07-11 16:18:47 +0900105
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700106 mod := ctx.ModuleForTests("foo", "android_common").Module()
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900107 entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700108
109 if r, ok := entries.EntryMap["LOCAL_REQUIRED_MODULES"]; ok {
110 t.Errorf("Unexpected required modules: %q", r)
111 }
112
113 footerLines := entries.FooterLinesForTests()
114 if !android.InList("LOCAL_REQUIRED_MODULES += libfoo", footerLines) {
115 t.Errorf("Wrong or missing required line for foo-hostdex in the footers: %q", footerLines)
116 }
Jooyung Han12df5fb2019-07-11 16:18:47 +0900117}