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"], |
| 40 | hdrs: ["Header.aidl"], |
| 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"}, |
| 55 | actualInfo.IncludeDirs.ToList().Strings(), |
| 56 | ) |
| 57 | |
| 58 | android.AssertPathsRelativeToTopEquals( |
| 59 | t, |
| 60 | "aidl srcs paths", |
| 61 | []string{"package_foo/a/b/Foo.aidl"}, |
| 62 | actualInfo.Srcs, |
| 63 | ) |
| 64 | } |
| 65 | |
| 66 | func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { |
| 67 | t.Parallel() |
| 68 | ctx := android.GroupFixturePreparers( |
| 69 | PrepareForTestWithAidlLibrary, |
| 70 | android.MockFS{ |
| 71 | "package_bar/Android.bp": []byte(` |
| 72 | aidl_library { |
| 73 | name: "bar", |
| 74 | srcs: ["x/y/Bar.aidl"], |
| 75 | } |
| 76 | `), |
| 77 | }.AddToFixture(), |
| 78 | android.MockFS{ |
| 79 | "package_foo/Android.bp": []byte(` |
| 80 | aidl_library { |
| 81 | name: "foo", |
| 82 | srcs: ["a/b/Foo.aidl"], |
| 83 | hdrs: ["Header.aidl"], |
| 84 | deps: ["bar"], |
| 85 | } |
| 86 | `), |
| 87 | }.AddToFixture(), |
| 88 | ).RunTest(t).TestContext |
| 89 | |
| 90 | foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) |
| 91 | actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) |
| 92 | |
| 93 | android.AssertArrayString( |
| 94 | t, |
| 95 | "aidl include dirs", |
| 96 | []string{"package_foo", "package_bar"}, |
| 97 | actualInfo.IncludeDirs.ToList().Strings(), |
| 98 | ) |
| 99 | |
| 100 | android.AssertPathsRelativeToTopEquals( |
| 101 | t, |
| 102 | "aidl srcs paths", |
| 103 | []string{"package_foo/a/b/Foo.aidl"}, |
| 104 | actualInfo.Srcs, |
| 105 | ) |
| 106 | } |
| 107 | |
| 108 | func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) { |
| 109 | t.Parallel() |
| 110 | android.GroupFixturePreparers( |
| 111 | PrepareForTestWithAidlLibrary, |
| 112 | android.MockFS{ |
| 113 | "package_bar/Android.bp": []byte(` |
| 114 | aidl_library { |
| 115 | name: "bar", |
| 116 | } |
| 117 | `), |
| 118 | }.AddToFixture(), |
| 119 | ). |
| 120 | ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("at least srcs or hdrs prop must be non-empty")). |
| 121 | RunTest(t) |
| 122 | } |