aidl_library_test.go 3.2 KB

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