blob: 42fa5367e3f7b94a934b4304d4136242aeed5351 [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
22var PrepareForTestWithAidlLibrary = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
23 registerAidlLibraryBuildComponents(ctx)
24})
25
26func TestAidlLibrary(t *testing.T) {
27 t.Parallel()
28 ctx := android.GroupFixturePreparers(
29 PrepareForTestWithAidlLibrary,
30 android.MockFS{
31 "package_bar/Android.bp": []byte(`
32 aidl_library {
33 name: "bar",
34 srcs: ["x/y/Bar.aidl"],
35 strip_import_prefix: "x",
36 }
37 `),
38 }.AddToFixture(),
39 android.MockFS{
40 "package_foo/Android.bp": []byte(`
41 aidl_library {
42 name: "foo",
43 srcs: ["a/b/Foo.aidl"],
44 hdrs: ["Header.aidl"],
45 strip_import_prefix: "a",
46 deps: ["bar"],
47 }
48 `),
49 }.AddToFixture(),
50 ).RunTest(t).TestContext
51
52 foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary)
53 actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo)
54
55 android.AssertArrayString(
56 t,
57 "aidl include dirs",
58 []string{"package_foo/a", "package_bar/x"},
59 actualInfo.IncludeDirs.ToList().Strings(),
60 )
61
62 android.AssertPathsRelativeToTopEquals(
63 t,
64 "aidl srcs paths",
65 []string{"package_foo/a/b/Foo.aidl"},
66 actualInfo.Srcs,
67 )
68}
69
70func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
71 t.Parallel()
72 ctx := android.GroupFixturePreparers(
73 PrepareForTestWithAidlLibrary,
74 android.MockFS{
75 "package_bar/Android.bp": []byte(`
76 aidl_library {
77 name: "bar",
78 srcs: ["x/y/Bar.aidl"],
79 }
80 `),
81 }.AddToFixture(),
82 android.MockFS{
83 "package_foo/Android.bp": []byte(`
84 aidl_library {
85 name: "foo",
86 srcs: ["a/b/Foo.aidl"],
87 hdrs: ["Header.aidl"],
88 deps: ["bar"],
89 }
90 `),
91 }.AddToFixture(),
92 ).RunTest(t).TestContext
93
94 foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary)
95 actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo)
96
97 android.AssertArrayString(
98 t,
99 "aidl include dirs",
100 []string{"package_foo", "package_bar"},
101 actualInfo.IncludeDirs.ToList().Strings(),
102 )
103
104 android.AssertPathsRelativeToTopEquals(
105 t,
106 "aidl srcs paths",
107 []string{"package_foo/a/b/Foo.aidl"},
108 actualInfo.Srcs,
109 )
110}
111
112func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) {
113 t.Parallel()
114 android.GroupFixturePreparers(
115 PrepareForTestWithAidlLibrary,
116 android.MockFS{
117 "package_bar/Android.bp": []byte(`
118 aidl_library {
119 name: "bar",
120 }
121 `),
122 }.AddToFixture(),
123 ).
124 ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("at least srcs or hdrs prop must be non-empty")).
125 RunTest(t)
126}