blob: 47bfac16c63a60a6f614bd8bd7f6576411c5dab3 [file] [log] [blame]
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001// Copyright 2018 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 "reflect"
19 "testing"
20
21 "android/soong/android"
22)
23
24func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) {
Spandan Das8aac9932024-07-18 23:14:13 +000025 ctx, _ := testJava(t,
26 `
27 java_library {name: "Foo"}
28 java_library {name: "Bar"}
29 java_library {
30 name: "javalib",
31 libs: ["Foo", "Bar"],
32 }
33 `)
34 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070035 dpInfo := &android.IdeInfo{}
36
37 module.IDEInfo(dpInfo)
38
Spandan Das8aac9932024-07-18 23:14:13 +000039 for _, expected := range []string{"Foo", "Bar"} {
40 if !android.InList(expected, dpInfo.Deps) {
41 t.Errorf("Library.IDEInfo() Deps = %v, %v not found", dpInfo.Deps, expected)
42 }
Brandon Lee5d45c6f2018-08-15 15:35:38 -070043 }
44}
45
46func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
Spandan Das8aac9932024-07-18 23:14:13 +000047 ctx, _ := testJava(t,
48 `
49 java_library {name: "Foo"}
50 java_library {name: "Bar"}
51 java_library {
52 name: "javalib",
53 static_libs: ["Foo", "Bar"],
54 }
55 `)
56 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070057 dpInfo := &android.IdeInfo{}
58
59 module.IDEInfo(dpInfo)
60
Spandan Das8aac9932024-07-18 23:14:13 +000061 for _, expected := range []string{"Foo", "Bar"} {
62 if !android.InList(expected, dpInfo.Deps) {
63 t.Errorf("Library.IDEInfo() Deps = %v, %v not found", dpInfo.Deps, expected)
64 }
Brandon Lee5d45c6f2018-08-15 15:35:38 -070065 }
66}
67
68func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) {
69 expected := []string{"Foo", "Bar"}
70 module := LibraryFactory().(*Library)
71 module.expandIDEInfoCompiledSrcs = append(module.expandIDEInfoCompiledSrcs, expected...)
72 dpInfo := &android.IdeInfo{}
73
74 module.IDEInfo(dpInfo)
75
76 if !reflect.DeepEqual(dpInfo.Srcs, expected) {
77 t.Errorf("Library.IDEInfo() Srcs = %v, want %v", dpInfo.Srcs, expected)
78 }
79}
80
81func TestCollectJavaLibraryPropertiesAddAidlIncludeDirs(t *testing.T) {
82 expected := []string{"Foo", "Bar"}
83 module := LibraryFactory().(*Library)
84 module.deviceProperties.Aidl.Include_dirs = append(module.deviceProperties.Aidl.Include_dirs, expected...)
85 dpInfo := &android.IdeInfo{}
86
87 module.IDEInfo(dpInfo)
88
89 if !reflect.DeepEqual(dpInfo.Aidl_include_dirs, expected) {
90 t.Errorf("Library.IDEInfo() Aidl_include_dirs = %v, want %v", dpInfo.Aidl_include_dirs, expected)
91 }
92}
93
94func TestCollectJavaLibraryPropertiesAddJarjarRules(t *testing.T) {
95 expected := "Jarjar_rules.txt"
96 module := LibraryFactory().(*Library)
Steven Morelandc4efd9c2019-01-18 11:51:25 -080097 module.expandJarjarRules = android.PathForTesting(expected)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070098 dpInfo := &android.IdeInfo{}
99
100 module.IDEInfo(dpInfo)
101
102 if dpInfo.Jarjar_rules[0] != expected {
103 t.Errorf("Library.IDEInfo() Jarjar_rules = %v, want %v", dpInfo.Jarjar_rules[0], expected)
104 }
105}
Spandan Das6e8bd1c2024-08-09 00:07:03 +0000106
107func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) {
108 ctx := android.GroupFixturePreparers(
109 prepareForJavaTest,
110 FixtureWithPrebuiltApis(map[string][]string{
111 "29": {},
112 })).RunTestWithBp(t,
113 `
114 java_library {
115 name: "javalib",
116 srcs: ["foo.java"],
117 sdk_version: "29",
118 }
119 `)
120 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
121 dpInfo := &android.IdeInfo{}
122
123 module.IDEInfo(dpInfo)
124 android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android")
125}