blob: 6606ddca69173157e2f320b992257612701e3840 [file] [log] [blame]
Alix5918d642022-06-27 20:57:44 +00001// Copyright 2022 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 xml
16
17import (
18 "android/soong/android"
19 "android/soong/bp2build"
20
21 "testing"
22)
23
24func runXmlPrebuiltEtcTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) {
25 t.Helper()
26 (&tc).ModuleTypeUnderTest = "prebuilt_etc_xml"
27 (&tc).ModuleTypeUnderTestFactory = PrebuiltEtcXmlFactory
28 bp2build.RunBp2BuildTestCase(t, registerXmlModuleTypes, tc)
29}
30
31func registerXmlModuleTypes(ctx android.RegistrationContext) {
32}
33
34func TestXmlPrebuiltEtcSimple(t *testing.T) {
35 runXmlPrebuiltEtcTestCase(t, bp2build.Bp2buildTestCase{
36 Description: "prebuilt_etc_xml - simple example",
37 Filesystem: map[string]string{},
38 Blueprint: `
39prebuilt_etc_xml {
40 name: "foo",
41 src: "fooSrc",
42 filename: "fooFileName",
43 sub_dir: "fooDir",
44 schema: "foo.dtd",
45}
46`,
47 ExpectedBazelTargets: []string{
48 bp2build.MakeBazelTarget("prebuilt_xml", "foo", bp2build.AttrNameToString{
49 "src": `"fooSrc"`,
50 "filename": `"fooFileName"`,
51 "dir": `"etc/fooDir"`,
52 "schema": `"foo.dtd"`,
53 })}})
54}
55
56func TestXmlPrebuiltEtcFilenameFromSrc(t *testing.T) {
57 runXmlPrebuiltEtcTestCase(t, bp2build.Bp2buildTestCase{
58 Description: "prebuilt_etc_xml - filenameFromSrc True ",
59 Filesystem: map[string]string{},
60 Blueprint: `
61prebuilt_etc_xml {
62 name: "foo",
63 src: "fooSrc",
64 filename_from_src: true,
65 sub_dir: "fooDir",
66 schema: "foo.dtd",
67}
68`,
69 ExpectedBazelTargets: []string{
70 bp2build.MakeBazelTarget("prebuilt_xml", "foo", bp2build.AttrNameToString{
71 "src": `"fooSrc"`,
72 "filename": `"fooSrc"`,
73 "dir": `"etc/fooDir"`,
74 "schema": `"foo.dtd"`,
75 })}})
76}
77
78func TestXmlPrebuiltEtcFilenameAndFilenameFromSrc(t *testing.T) {
79 runXmlPrebuiltEtcTestCase(t, bp2build.Bp2buildTestCase{
80 Description: "prebuilt_etc_xml - filename provided and filenameFromSrc True ",
81 Filesystem: map[string]string{},
82 Blueprint: `
83prebuilt_etc_xml {
84 name: "foo",
85 src: "fooSrc",
86 filename: "fooFileName",
87 filename_from_src: true,
88 sub_dir: "fooDir",
89 schema: "foo.dtd",
90}
91`,
92 ExpectedBazelTargets: []string{
93 bp2build.MakeBazelTarget("prebuilt_xml", "foo", bp2build.AttrNameToString{
94 "src": `"fooSrc"`,
95 "filename": `"fooFileName"`,
96 "dir": `"etc/fooDir"`,
97 "schema": `"foo.dtd"`,
98 })}})
99}
100
101func TestXmlPrebuiltEtcFileNameFromSrcMultipleSrcs(t *testing.T) {
102 runXmlPrebuiltEtcTestCase(t, bp2build.Bp2buildTestCase{
103 Description: "prebuilt_etc - filename_from_src is true but there are multiple srcs",
104 Filesystem: map[string]string{},
105 Blueprint: `
106prebuilt_etc_xml {
107 name: "foo",
108 filename_from_src: true,
109 arch: {
110 arm: {
111 src: "barSrc",
112 },
113 arm64: {
114 src: "bazSrc",
115 },
116 }
117}
118`,
119 ExpectedBazelTargets: []string{
120 bp2build.MakeBazelTarget("prebuilt_xml", "foo", bp2build.AttrNameToString{
121 "filename_from_src": `True`,
122 "dir": `"etc"`,
123 "src": `select({
124 "//build/bazel/platforms/arch:arm": "barSrc",
125 "//build/bazel/platforms/arch:arm64": "bazSrc",
126 "//conditions:default": None,
127 })`,
128 })}})
129}