blob: 0522da45e659fbe2681cf3807baf77b0d5898347 [file] [log] [blame]
Vinh Tran3d169902023-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 bp2build
16
17import (
18 "testing"
19
20 "android/soong/aidl_library"
21 "android/soong/android"
22)
23
24func runAidlLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
25 t.Helper()
26 (&tc).ModuleTypeUnderTest = "aidl_library"
27 (&tc).ModuleTypeUnderTestFactory = aidl_library.AidlLibraryFactory
28 RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
29}
30
31func TestAidlLibrary(t *testing.T) {
32 testcases := []struct {
33 name string
34 bp string
35 expectedBazelAttrs AttrNameToString
36 }{
37 {
38 name: "aidl_library with strip_import_prefix",
39 bp: `
40 aidl_library {
41 name: "foo",
42 srcs: ["aidl/foo.aidl"],
43 hdrs: ["aidl/header.aidl"],
44 strip_import_prefix: "aidl",
45 }`,
46 expectedBazelAttrs: AttrNameToString{
47 "srcs": `["aidl/foo.aidl"]`,
48 "hdrs": `["aidl/header.aidl"]`,
49 "strip_import_prefix": `"aidl"`,
50 "tags": `["apex_available=//apex_available:anyapex"]`,
51 },
52 },
53 {
54 name: "aidl_library without strip_import_prefix",
55 bp: `
56 aidl_library {
57 name: "foo",
58 srcs: ["aidl/foo.aidl"],
59 hdrs: ["aidl/header.aidl"],
60 }`,
61 expectedBazelAttrs: AttrNameToString{
62 "srcs": `["aidl/foo.aidl"]`,
63 "hdrs": `["aidl/header.aidl"]`,
64 "tags": `["apex_available=//apex_available:anyapex"]`,
65 },
66 },
67 }
68
69 for _, test := range testcases {
70 t.Run(test.name, func(t *testing.T) {
71 expectedBazelTargets := []string{
72 MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
73 }
74 runAidlLibraryTestCase(t, Bp2buildTestCase{
75 Description: test.name,
76 Blueprint: test.bp,
77 ExpectedBazelTargets: expectedBazelTargets,
78 })
79 })
80 }
81}
82
83func TestAidlLibraryWithDeps(t *testing.T) {
84 bp := `
85 aidl_library {
86 name: "bar",
87 srcs: ["Bar.aidl"],
88 hdrs: ["aidl/BarHeader.aidl"],
89 }
90 aidl_library {
91 name: "foo",
92 srcs: ["aidl/Foo.aidl"],
93 hdrs: ["aidl/FooHeader.aidl"],
94 strip_import_prefix: "aidl",
95 deps: ["bar"],
96 }`
97
98 t.Run("aidl_library with deps", func(t *testing.T) {
99 expectedBazelTargets := []string{
100 MakeBazelTargetNoRestrictions("aidl_library", "bar", AttrNameToString{
101 "srcs": `["Bar.aidl"]`,
102 "hdrs": `["aidl/BarHeader.aidl"]`,
103 "tags": `["apex_available=//apex_available:anyapex"]`,
104 }),
105 MakeBazelTargetNoRestrictions("aidl_library", "foo", AttrNameToString{
106 "srcs": `["aidl/Foo.aidl"]`,
107 "hdrs": `["aidl/FooHeader.aidl"]`,
108 "strip_import_prefix": `"aidl"`,
109 "deps": `[":bar"]`,
110 "tags": `["apex_available=//apex_available:anyapex"]`,
111 }),
112 }
113 runAidlLibraryTestCase(t, Bp2buildTestCase{
114 Description: "aidl_library with deps",
115 Blueprint: bp,
116 ExpectedBazelTargets: expectedBazelTargets,
117 })
118 })
119}