blob: e8fa49c2bb562c70e46324687f3dc04bc0c5da30 [file] [log] [blame]
Jiyong Park5a8d1be2018-04-25 22:57:34 +09001// 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 xml
16
17import (
18 "android/soong/android"
19 "io/ioutil"
20 "os"
21 "testing"
22)
23
24func testXml(t *testing.T, bp string) *android.TestContext {
25 config, buildDir := setup(t)
26 defer teardown(buildDir)
27 ctx := android.NewTestArchContext()
28 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
29 ctx.RegisterModuleType("prebuilt_etc_xml", android.ModuleFactoryAdaptor(PrebuiltEtcXmlFactory))
30 ctx.Register()
31 mockFiles := map[string][]byte{
32 "Android.bp": []byte(bp),
33 "foo.xml": nil,
34 "foo.dtd": nil,
35 "bar.xml": nil,
36 "bar.xsd": nil,
37 }
38 ctx.MockFileSystem(mockFiles)
39 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
40 android.FailIfErrored(t, errs)
41 _, errs = ctx.PrepareBuildActions(config)
42 android.FailIfErrored(t, errs)
43
44 return ctx
45}
46
47func setup(t *testing.T) (config android.Config, buildDir string) {
48 buildDir, err := ioutil.TempDir("", "soong_xml_test")
49 if err != nil {
50 t.Fatal(err)
51 }
52
53 config = android.TestArchConfig(buildDir, nil)
54
55 return
56}
57
58func teardown(buildDir string) {
59 os.RemoveAll(buildDir)
60}
61
62// Minimal test
63func TestPrebuiltEtcXml(t *testing.T) {
64 ctx := testXml(t, `
65 prebuilt_etc_xml {
66 name: "foo.xml",
67 src: "foo.xml",
68 schema: "foo.dtd",
69 }
70 prebuilt_etc_xml {
71 name: "bar.xml",
72 src: "bar.xml",
73 schema: "bar.xsd",
74 }
75 `)
76
77 xmllint := ctx.ModuleForTests("foo.xml", "android_common").Rule("xmllint")
78 input := xmllint.Input.String()
79 if input != "foo.xml" {
80 t.Errorf("input expected %q != got %q", "foo.xml", input)
81 }
82 schema := xmllint.Args["dtd"]
83 if schema != "foo.dtd" {
84 t.Errorf("dtd expected %q != got %q", "foo.dtdl", schema)
85 }
86}