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 15package aidl_library 16 17import ( 18 "testing" 19 20 "android/soong/android" 21) 22 23func 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"], 41 hdrs: ["a/Header.aidl"], 42 strip_import_prefix: "a", 43 deps: ["bar"], 44 } 45 `), 46 }.AddToFixture(), 47 ).RunTest(t).TestContext 48 49 foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) 50 actualInfo, _ := android.OtherModuleProvider(ctx, foo, AidlLibraryProvider) 51 52 android.AssertArrayString( 53 t, 54 "aidl include dirs", 55 []string{"package_foo/a", "package_bar/x"}, 56 android.Paths(actualInfo.IncludeDirs.ToList()).Strings(), 57 ) 58 59 android.AssertPathsRelativeToTopEquals( 60 t, 61 "aidl srcs paths", 62 []string{"package_foo/a/b/Foo.aidl"}, 63 actualInfo.Srcs, 64 ) 65 66 android.AssertPathsRelativeToTopEquals( 67 t, 68 "aidl hdrs paths", 69 []string{"package_foo/a/Header.aidl"}, 70 actualInfo.Hdrs.ToList(), 71 ) 72} 73 74func 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"], 83 hdrs: ["BarHeader.aidl"], 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"], 92 deps: ["bar"], 93 } 94 `), 95 }.AddToFixture(), 96 ).RunTest(t).TestContext 97 98 foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) 99 actualInfo, _ := android.OtherModuleProvider(ctx, foo, AidlLibraryProvider) 100 101 android.AssertArrayString( 102 t, 103 "aidl include dirs", 104 []string{"package_foo", "package_bar"}, 105 android.Paths(actualInfo.IncludeDirs.ToList()).Strings(), 106 ) 107 108 android.AssertPathsRelativeToTopEquals( 109 t, 110 "aidl srcs paths", 111 []string{"package_foo/a/b/Foo.aidl"}, 112 actualInfo.Srcs, 113 ) 114 115 android.AssertPathsRelativeToTopEquals( 116 t, 117 "aidl hdrs paths", 118 []string{"package_bar/BarHeader.aidl"}, 119 actualInfo.Hdrs.ToList(), 120 ) 121} 122 123func 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} 138