blob: 0bb455bb31a39d0b50ec957be8674f859f1336b6 [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) {
46 config := TestConfig(buildDir, nil)
47 config.inMake = true // Enable androidmk Singleton
48
49 ctx := NewTestContext()
50 ctx.RegisterSingletonType("androidmk", SingletonFactoryAdaptor(AndroidMkSingleton))
51 ctx.RegisterModuleType("custom", ModuleFactoryAdaptor(customModuleFactory))
52 ctx.Register()
53
54 bp := `
55 custom {
56 name: "foo",
57 required: ["bar"],
58 host_required: ["baz"],
59 target_required: ["qux"],
60 }
61 `
62
63 ctx.MockFileSystem(map[string][]byte{
64 "Android.bp": []byte(bp),
65 })
66
67 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
68 FailIfErrored(t, errs)
69 _, errs = ctx.PrepareBuildActions(config)
70 FailIfErrored(t, errs)
71
72 m := ctx.ModuleForTests("foo", "").Module().(*customModule)
73
74 assertEqual := func(expected interface{}, actual interface{}) {
75 if !reflect.DeepEqual(expected, actual) {
76 t.Errorf("%q expected, but got %q", expected, actual)
77 }
78 }
79 assertEqual([]string{"bar"}, m.data.Required)
80 assertEqual([]string{"baz"}, m.data.Host_required)
81 assertEqual([]string{"qux"}, m.data.Target_required)
82}