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