Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 1 | // Copyright 2023 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 aidl_library |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 22 | func TestAidlLibrary(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | ctx := android.GroupFixturePreparers( |
| 25 | PrepareForTestWithAidlLibrary, |
| 26 | android.MockFS{ |
| 27 | "package_bar/Android.bp": []byte(` |
| 28 | aidl_library { |
| 29 | name: "bar", |
| 30 | srcs: ["x/y/Bar.aidl"], |
| 31 | strip_import_prefix: "x", |
| 32 | } |
| 33 | `), |
| 34 | }.AddToFixture(), |
| 35 | android.MockFS{ |
| 36 | "package_foo/Android.bp": []byte(` |
| 37 | aidl_library { |
| 38 | name: "foo", |
| 39 | srcs: ["a/b/Foo.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 40 | hdrs: ["a/Header.aidl"], |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 41 | strip_import_prefix: "a", |
| 42 | deps: ["bar"], |
| 43 | } |
| 44 | `), |
| 45 | }.AddToFixture(), |
| 46 | ).RunTest(t).TestContext |
| 47 | |
| 48 | foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) |
| 49 | actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) |
| 50 | |
| 51 | android.AssertArrayString( |
| 52 | t, |
| 53 | "aidl include dirs", |
| 54 | []string{"package_foo/a", "package_bar/x"}, |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame^] | 55 | android.Paths(actualInfo.IncludeDirs.ToList()).Strings(), |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 56 | ) |
| 57 | |
| 58 | android.AssertPathsRelativeToTopEquals( |
| 59 | t, |
| 60 | "aidl srcs paths", |
| 61 | []string{"package_foo/a/b/Foo.aidl"}, |
| 62 | actualInfo.Srcs, |
| 63 | ) |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 64 | |
| 65 | android.AssertPathsRelativeToTopEquals( |
| 66 | t, |
| 67 | "aidl hdrs paths", |
| 68 | []string{"package_foo/a/Header.aidl"}, |
| 69 | actualInfo.Hdrs.ToList(), |
| 70 | ) |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { |
| 74 | t.Parallel() |
| 75 | ctx := android.GroupFixturePreparers( |
| 76 | PrepareForTestWithAidlLibrary, |
| 77 | android.MockFS{ |
| 78 | "package_bar/Android.bp": []byte(` |
| 79 | aidl_library { |
| 80 | name: "bar", |
| 81 | srcs: ["x/y/Bar.aidl"], |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 82 | hdrs: ["BarHeader.aidl"], |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 83 | } |
| 84 | `), |
| 85 | }.AddToFixture(), |
| 86 | android.MockFS{ |
| 87 | "package_foo/Android.bp": []byte(` |
| 88 | aidl_library { |
| 89 | name: "foo", |
| 90 | srcs: ["a/b/Foo.aidl"], |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 91 | deps: ["bar"], |
| 92 | } |
| 93 | `), |
| 94 | }.AddToFixture(), |
| 95 | ).RunTest(t).TestContext |
| 96 | |
| 97 | foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) |
| 98 | actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) |
| 99 | |
| 100 | android.AssertArrayString( |
| 101 | t, |
| 102 | "aidl include dirs", |
| 103 | []string{"package_foo", "package_bar"}, |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame^] | 104 | android.Paths(actualInfo.IncludeDirs.ToList()).Strings(), |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 105 | ) |
| 106 | |
| 107 | android.AssertPathsRelativeToTopEquals( |
| 108 | t, |
| 109 | "aidl srcs paths", |
| 110 | []string{"package_foo/a/b/Foo.aidl"}, |
| 111 | actualInfo.Srcs, |
| 112 | ) |
Vinh Tran | 0958195 | 2023-05-16 16:03:20 -0400 | [diff] [blame] | 113 | |
| 114 | android.AssertPathsRelativeToTopEquals( |
| 115 | t, |
| 116 | "aidl hdrs paths", |
| 117 | []string{"package_bar/BarHeader.aidl"}, |
| 118 | actualInfo.Hdrs.ToList(), |
| 119 | ) |
Vinh Tran | 0e7fd8a | 2023-04-28 11:21:25 -0400 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) { |
| 123 | t.Parallel() |
| 124 | android.GroupFixturePreparers( |
| 125 | PrepareForTestWithAidlLibrary, |
| 126 | android.MockFS{ |
| 127 | "package_bar/Android.bp": []byte(` |
| 128 | aidl_library { |
| 129 | name: "bar", |
| 130 | } |
| 131 | `), |
| 132 | }.AddToFixture(), |
| 133 | ). |
| 134 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("at least srcs or hdrs prop must be non-empty")). |
| 135 | RunTest(t) |
| 136 | } |