generated_java_library_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2018 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 java
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. )
  19. func JavaGenLibTestFactory() android.Module {
  20. callbacks := &JavaGenLibTestCallbacks{}
  21. return GeneratedJavaLibraryModuleFactory("test_java_gen_lib", callbacks, &callbacks.properties)
  22. }
  23. type JavaGenLibTestProperties struct {
  24. Foo string
  25. }
  26. type JavaGenLibTestCallbacks struct {
  27. properties JavaGenLibTestProperties
  28. }
  29. func (callbacks *JavaGenLibTestCallbacks) DepsMutator(module *GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext) {
  30. }
  31. func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path {
  32. return android.PathForOutput(ctx, "blah.srcjar")
  33. }
  34. func testGenLib(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult {
  35. return android.GroupFixturePreparers(
  36. PrepareForIntegrationTestWithJava,
  37. android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
  38. ctx.RegisterModuleType("test_java_gen_lib", JavaGenLibTestFactory)
  39. }),
  40. ).
  41. ExtendWithErrorHandler(errorHandler).
  42. RunTestWithBp(t, bp)
  43. }
  44. func TestGenLib(t *testing.T) {
  45. bp := `
  46. test_java_gen_lib {
  47. name: "javagenlibtest",
  48. foo: "bar", // Note: This won't parse if the property didn't get added
  49. }
  50. `
  51. result := testGenLib(t, android.FixtureExpectsNoErrors, bp)
  52. javagenlibtest := result.ModuleForTests("javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule)
  53. android.AssertPathsEndWith(t, "Generated_srcjars", []string{"/blah.srcjar"}, javagenlibtest.Library.properties.Generated_srcjars)
  54. }