blob: 020562904aee419d5c6cc26c4b3d88f6bcd3a2db [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 (
18 "android/soong/android"
19 "testing"
20)
21
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040022func 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 Tran09581952023-05-16 16:03:20 -040040 hdrs: ["a/Header.aidl"],
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040041 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 Crossc85750b2022-04-21 12:50:51 -070055 android.Paths(actualInfo.IncludeDirs.ToList()).Strings(),
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040056 )
57
58 android.AssertPathsRelativeToTopEquals(
59 t,
60 "aidl srcs paths",
61 []string{"package_foo/a/b/Foo.aidl"},
62 actualInfo.Srcs,
63 )
Vinh Tran09581952023-05-16 16:03:20 -040064
65 android.AssertPathsRelativeToTopEquals(
66 t,
67 "aidl hdrs paths",
68 []string{"package_foo/a/Header.aidl"},
69 actualInfo.Hdrs.ToList(),
70 )
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040071}
72
73func 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 Tran09581952023-05-16 16:03:20 -040082 hdrs: ["BarHeader.aidl"],
Vinh Tran0e7fd8a2023-04-28 11:21:25 -040083 }
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 Tran0e7fd8a2023-04-28 11:21:25 -040091 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 Crossc85750b2022-04-21 12:50:51 -0700104 android.Paths(actualInfo.IncludeDirs.ToList()).Strings(),
Vinh Tran0e7fd8a2023-04-28 11:21:25 -0400105 )
106
107 android.AssertPathsRelativeToTopEquals(
108 t,
109 "aidl srcs paths",
110 []string{"package_foo/a/b/Foo.aidl"},
111 actualInfo.Srcs,
112 )
Vinh Tran09581952023-05-16 16:03:20 -0400113
114 android.AssertPathsRelativeToTopEquals(
115 t,
116 "aidl hdrs paths",
117 []string{"package_bar/BarHeader.aidl"},
118 actualInfo.Hdrs.ToList(),
119 )
Vinh Tran0e7fd8a2023-04-28 11:21:25 -0400120}
121
122func 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}