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
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
39func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(module *GeneratedJavaLibraryModule, ctx android.ModuleContext) (android.Path, android.Path) {
40	return android.PathForOutput(ctx, "blah.srcjar"), android.PathForOutput(ctx, "blah.pb")
41}
42
43func testGenLib(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult {
44	return android.GroupFixturePreparers(
45		PrepareForIntegrationTestWithJava,
46		android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
47			ctx.RegisterModuleType("test_java_gen_lib", JavaGenLibTestFactory)
48		}),
49	).
50		ExtendWithErrorHandler(errorHandler).
51		RunTestWithBp(t, bp)
52}
53
54func TestGenLib(t *testing.T) {
55	bp := `
56				test_java_gen_lib {
57					name: "javagenlibtest",
58                    foo: "bar",  // Note: This won't parse if the property didn't get added
59				}
60			`
61	result := testGenLib(t, android.FixtureExpectsNoErrors, bp)
62
63	javagenlibtest := result.ModuleForTests("javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule)
64	android.AssertPathsEndWith(t, "Generated_srcjars", []string{"/blah.srcjar"}, javagenlibtest.Library.properties.Generated_srcjars)
65}
66