blob: ac9524e07247a27671925508337f27f3fae57ebb [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 {
Joe Onorato175073c2023-06-01 14:42:59 -070040 return android.PathForOutput(ctx, "blah.srcjar")
41}
42
Yu Liuf2b94012023-09-19 15:09:10 -070043func (callbacks *JavaGenLibTestCallbacks) Bp2build(ctx android.Bp2buildMutatorContext, module *GeneratedJavaLibraryModule) {
44}
45
Joe Onorato175073c2023-06-01 14:42:59 -070046func testGenLib(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult {
47 return android.GroupFixturePreparers(
48 PrepareForIntegrationTestWithJava,
49 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
50 ctx.RegisterModuleType("test_java_gen_lib", JavaGenLibTestFactory)
51 }),
52 ).
53 ExtendWithErrorHandler(errorHandler).
54 RunTestWithBp(t, bp)
55}
56
57func TestGenLib(t *testing.T) {
58 bp := `
59 test_java_gen_lib {
60 name: "javagenlibtest",
61 foo: "bar", // Note: This won't parse if the property didn't get added
62 }
63 `
64 result := testGenLib(t, android.FixtureExpectsNoErrors, bp)
65
66 javagenlibtest := result.ModuleForTests("javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule)
67 android.AssertPathsEndWith(t, "Generated_srcjars", []string{"/blah.srcjar"}, javagenlibtest.Library.properties.Generated_srcjars)
68}