Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "reflect" |
| 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) { |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 25 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 35 | dpInfo := &android.IdeInfo{} |
| 36 | |
| 37 | module.IDEInfo(dpInfo) |
| 38 | |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 39 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) { |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 47 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 57 | dpInfo := &android.IdeInfo{} |
| 58 | |
| 59 | module.IDEInfo(dpInfo) |
| 60 | |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 61 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | func 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 | |
| 81 | func 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 | |
| 94 | func TestCollectJavaLibraryPropertiesAddJarjarRules(t *testing.T) { |
| 95 | expected := "Jarjar_rules.txt" |
| 96 | module := LibraryFactory().(*Library) |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 97 | module.expandJarjarRules = android.PathForTesting(expected) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 98 | 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 Das | 6e8bd1c | 2024-08-09 00:07:03 +0000 | [diff] [blame] | 106 | |
| 107 | func 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 | } |