blob: 7f52fd108f1b109d5c34c34d2f515b77c9e6ab8b [file] [log] [blame]
Joe Onorato175073c2023-06-01 14:42:59 -07001// 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
15package java
16
17import (
18 "testing"
19
20 "android/soong/android"
21)
22
23func JavaGenLibTestFactory() android.Module {
24 callbacks := &JavaGenLibTestCallbacks{}
25 return GeneratedJavaLibraryModuleFactory("test_java_gen_lib", callbacks, &callbacks.properties)
26}
27
28type JavaGenLibTestProperties struct {
29 Foo string
30}
31
32type JavaGenLibTestCallbacks struct {
33 properties JavaGenLibTestProperties
34}
35
36func (callbacks *JavaGenLibTestCallbacks) DepsMutator(module *GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext) {
37}
38
Joe Onorato6fe59eb2023-07-16 13:20:33 -070039func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(module *GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path {
40 module.AddAconfigIntermediate(android.PathForOutput(ctx, "aconfig_cache_file"))
Joe Onorato175073c2023-06-01 14:42:59 -070041 return android.PathForOutput(ctx, "blah.srcjar")
42}
43
44func testGenLib(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult {
45 return android.GroupFixturePreparers(
46 PrepareForIntegrationTestWithJava,
47 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
48 ctx.RegisterModuleType("test_java_gen_lib", JavaGenLibTestFactory)
49 }),
50 ).
51 ExtendWithErrorHandler(errorHandler).
52 RunTestWithBp(t, bp)
53}
54
55func TestGenLib(t *testing.T) {
56 bp := `
57 test_java_gen_lib {
58 name: "javagenlibtest",
59 foo: "bar", // Note: This won't parse if the property didn't get added
60 }
61 `
62 result := testGenLib(t, android.FixtureExpectsNoErrors, bp)
63
64 javagenlibtest := result.ModuleForTests("javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule)
65 android.AssertPathsEndWith(t, "Generated_srcjars", []string{"/blah.srcjar"}, javagenlibtest.Library.properties.Generated_srcjars)
66}