blob: 16604563596281625d7165c1a76b3d048ff22978 [file] [log] [blame]
Vinh Tran0e7fd8a2023-04-28 11:21:25 -04001// 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 (
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040018 "testing"
Yu Liu663e4502024-08-12 18:23:59 +000019
20 "android/soong/android"
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040021)
22
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040023func 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 Tran09581952023-05-16 16:03:20 -040041 hdrs: ["a/Header.aidl"],
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040042 strip_import_prefix: "a",
43 deps: ["bar"],
44 }
45 `),
46 }.AddToFixture(),
47 ).RunTest(t).TestContext
48
49 foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary)
Yu Liu663e4502024-08-12 18:23:59 +000050 actualInfo, _ := android.OtherModuleProvider(ctx, foo, AidlLibraryProvider)
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040051
52 android.AssertArrayString(
53 t,
54 "aidl include dirs",
55 []string{"package_foo/a", "package_bar/x"},
Colin Crossc85750b2022-04-21 12:50:51 -070056 android.Paths(actualInfo.IncludeDirs.ToList()).Strings(),
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040057 )
58
59 android.AssertPathsRelativeToTopEquals(
60 t,
61 "aidl srcs paths",
62 []string{"package_foo/a/b/Foo.aidl"},
63 actualInfo.Srcs,
64 )
Vinh Tran09581952023-05-16 16:03:20 -040065
66 android.AssertPathsRelativeToTopEquals(
67 t,
68 "aidl hdrs paths",
69 []string{"package_foo/a/Header.aidl"},
70 actualInfo.Hdrs.ToList(),
71 )
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040072}
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"],
Vinh Tran09581952023-05-16 16:03:20 -040083 hdrs: ["BarHeader.aidl"],
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040084 }
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 Tran0e7fd8a2023-04-28 11:21:25 -040092 deps: ["bar"],
93 }
94 `),
95 }.AddToFixture(),
96 ).RunTest(t).TestContext
97
98 foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary)
Yu Liu663e4502024-08-12 18:23:59 +000099 actualInfo, _ := android.OtherModuleProvider(ctx, foo, AidlLibraryProvider)
Vinh Tran0e7fd8a2023-04-28 11:21:25 -0400100
101 android.AssertArrayString(
102 t,
103 "aidl include dirs",
104 []string{"package_foo", "package_bar"},
Colin Crossc85750b2022-04-21 12:50:51 -0700105 android.Paths(actualInfo.IncludeDirs.ToList()).Strings(),
Vinh Tran0e7fd8a2023-04-28 11:21:25 -0400106 )
107
108 android.AssertPathsRelativeToTopEquals(
109 t,
110 "aidl srcs paths",
111 []string{"package_foo/a/b/Foo.aidl"},
112 actualInfo.Srcs,
113 )
Vinh Tran09581952023-05-16 16:03:20 -0400114
115 android.AssertPathsRelativeToTopEquals(
116 t,
117 "aidl hdrs paths",
118 []string{"package_bar/BarHeader.aidl"},
119 actualInfo.Hdrs.ToList(),
120 )
Vinh Tran0e7fd8a2023-04-28 11:21:25 -0400121}
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}