xml_conversion_test.go 3.6 KB

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