blob: 71f802043efb87b5276bb129a171946371893efa [file] [log] [blame]
Jooyung Han12df5fb2019-07-11 16:18:47 +09001// Copyright 2019 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 android
16
17import (
18 "io"
19 "reflect"
20 "testing"
21)
22
23type customModule struct {
24 ModuleBase
25 data AndroidMkData
26}
27
28func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) {
29}
30
31func (m *customModule) AndroidMk() AndroidMkData {
32 return AndroidMkData{
33 Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
34 m.data = data
35 },
36 }
37}
38
39func customModuleFactory() Module {
40 module := &customModule{}
41 InitAndroidModule(module)
42 return module
43}
44
45func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
Jooyung Han12df5fb2019-07-11 16:18:47 +090046 bp := `
47 custom {
48 name: "foo",
49 required: ["bar"],
50 host_required: ["baz"],
51 target_required: ["qux"],
52 }
53 `
54
Colin Cross98be1bb2019-12-13 20:41:13 -080055 config := TestConfig(buildDir, nil, bp, nil)
56 config.inMake = true // Enable androidmk Singleton
57
58 ctx := NewTestContext()
59 ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
60 ctx.RegisterModuleType("custom", customModuleFactory)
61 ctx.Register(config)
Jooyung Han12df5fb2019-07-11 16:18:47 +090062
63 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
64 FailIfErrored(t, errs)
65 _, errs = ctx.PrepareBuildActions(config)
66 FailIfErrored(t, errs)
67
68 m := ctx.ModuleForTests("foo", "").Module().(*customModule)
69
70 assertEqual := func(expected interface{}, actual interface{}) {
71 if !reflect.DeepEqual(expected, actual) {
72 t.Errorf("%q expected, but got %q", expected, actual)
73 }
74 }
75 assertEqual([]string{"bar"}, m.data.Required)
76 assertEqual([]string{"baz"}, m.data.Host_required)
77 assertEqual([]string{"qux"}, m.data.Target_required)
78}