aidl_library_conversion_test.go 3.3 KB

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