systemserver_classpath_fragment_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (C) 2021 The Android Open Source Project
  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 java
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. )
  19. var prepareForTestWithSystemServerClasspath = android.GroupFixturePreparers(
  20. PrepareForTestWithJavaDefaultModules,
  21. )
  22. func TestPlatformSystemServerClasspathVariant(t *testing.T) {
  23. result := android.GroupFixturePreparers(
  24. prepareForTestWithSystemServerClasspath,
  25. android.FixtureWithRootAndroidBp(`
  26. platform_systemserverclasspath {
  27. name: "platform-systemserverclasspath",
  28. }
  29. `),
  30. ).RunTest(t)
  31. variants := result.ModuleVariantsForTests("platform-systemserverclasspath")
  32. android.AssertIntEquals(t, "expect 1 variant", 1, len(variants))
  33. }
  34. func TestPlatformSystemServerClasspath_ClasspathFragmentPaths(t *testing.T) {
  35. result := android.GroupFixturePreparers(
  36. prepareForTestWithSystemServerClasspath,
  37. android.FixtureWithRootAndroidBp(`
  38. platform_systemserverclasspath {
  39. name: "platform-systemserverclasspath",
  40. }
  41. `),
  42. ).RunTest(t)
  43. p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
  44. android.AssertStringEquals(t, "output filepath", "systemserverclasspath.pb", p.ClasspathFragmentBase.outputFilepath.Base())
  45. android.AssertPathRelativeToTopEquals(t, "install filepath", "out/soong/target/product/test_device/system/etc/classpaths", p.ClasspathFragmentBase.installDirPath)
  46. }
  47. func TestPlatformSystemServerClasspathModule_AndroidMkEntries(t *testing.T) {
  48. preparer := android.GroupFixturePreparers(
  49. prepareForTestWithSystemServerClasspath,
  50. android.FixtureWithRootAndroidBp(`
  51. platform_systemserverclasspath {
  52. name: "platform-systemserverclasspath",
  53. }
  54. `),
  55. )
  56. t.Run("AndroidMkEntries", func(t *testing.T) {
  57. result := preparer.RunTest(t)
  58. p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
  59. entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)
  60. android.AssertIntEquals(t, "AndroidMkEntries count", 1, len(entries))
  61. })
  62. t.Run("classpath-fragment-entry", func(t *testing.T) {
  63. result := preparer.RunTest(t)
  64. want := map[string][]string{
  65. "LOCAL_MODULE": {"platform-systemserverclasspath"},
  66. "LOCAL_MODULE_CLASS": {"ETC"},
  67. "LOCAL_INSTALLED_MODULE_STEM": {"systemserverclasspath.pb"},
  68. // Output and Install paths are tested separately in TestPlatformSystemServerClasspath_ClasspathFragmentPaths
  69. }
  70. p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
  71. entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)
  72. got := entries[0]
  73. for k, expectedValue := range want {
  74. if value, ok := got.EntryMap[k]; ok {
  75. android.AssertDeepEquals(t, k, expectedValue, value)
  76. } else {
  77. t.Errorf("No %s defined, saw %q", k, got.EntryMap)
  78. }
  79. }
  80. })
  81. }
  82. func TestSystemServerClasspathFragmentWithoutContents(t *testing.T) {
  83. prepareForTestWithSystemServerClasspath.
  84. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
  85. `\QEither contents or standalone_contents needs to be non-empty\E`)).
  86. RunTestWithBp(t, `
  87. systemserverclasspath_fragment {
  88. name: "systemserverclasspath-fragment",
  89. }
  90. `)
  91. }