aidl_library_test.go 3.1 KB

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