blob: 83ae51c4ac9ebbd9e716b805a4dd8b99e1cb0517 [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 (
Jiyong Park5a8d1be2018-04-25 22:57:34 +090018 "os"
19 "testing"
Colin Crossff6c33d2019-10-02 16:01:35 -070020
21 "android/soong/android"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070022 "android/soong/etc"
Jiyong Park5a8d1be2018-04-25 22:57:34 +090023)
24
Colin Crossff6c33d2019-10-02 16:01:35 -070025func TestMain(m *testing.M) {
Paul Duffinec74f812021-03-18 01:42:49 +000026 os.Exit(m.Run())
Colin Crossff6c33d2019-10-02 16:01:35 -070027}
28
Paul Duffinec74f812021-03-18 01:42:49 +000029var emptyFixtureFactory = android.NewFixtureFactory(nil)
30
31func testXml(t *testing.T, bp string) *android.TestResult {
32 fs := android.MockFS{
Colin Cross98be1bb2019-12-13 20:41:13 -080033 "foo.xml": nil,
34 "foo.dtd": nil,
35 "bar.xml": nil,
36 "bar.xsd": nil,
37 "baz.xml": nil,
38 }
Jiyong Park5a8d1be2018-04-25 22:57:34 +090039
Paul Duffinec74f812021-03-18 01:42:49 +000040 return emptyFixtureFactory.RunTest(t,
41 android.PrepareForTestWithArchMutator,
42 etc.PrepareForTestWithPrebuiltEtc,
43 PreparerForTestWithXmlBuildComponents,
44 fs.AddToFixture(),
45 android.FixtureWithRootAndroidBp(bp),
46 )
Jooyung Hana0171822019-07-22 15:48:36 +090047}
48
Jiyong Park5a8d1be2018-04-25 22:57:34 +090049// Minimal test
50func TestPrebuiltEtcXml(t *testing.T) {
Paul Duffinec74f812021-03-18 01:42:49 +000051 result := testXml(t, `
Jiyong Park5a8d1be2018-04-25 22:57:34 +090052 prebuilt_etc_xml {
53 name: "foo.xml",
54 src: "foo.xml",
55 schema: "foo.dtd",
56 }
57 prebuilt_etc_xml {
58 name: "bar.xml",
59 src: "bar.xml",
60 schema: "bar.xsd",
61 }
Jooyung Hana0171822019-07-22 15:48:36 +090062 prebuilt_etc_xml {
63 name: "baz.xml",
64 src: "baz.xml",
65 }
Jiyong Park5a8d1be2018-04-25 22:57:34 +090066 `)
67
Jooyung Hana0171822019-07-22 15:48:36 +090068 for _, tc := range []struct {
69 rule, input, schemaType, schema string
70 }{
71 {rule: "xmllint-dtd", input: "foo.xml", schemaType: "dtd", schema: "foo.dtd"},
72 {rule: "xmllint-xsd", input: "bar.xml", schemaType: "xsd", schema: "bar.xsd"},
73 {rule: "xmllint-minimal", input: "baz.xml"},
74 } {
75 t.Run(tc.schemaType, func(t *testing.T) {
Paul Duffinec74f812021-03-18 01:42:49 +000076 rule := result.ModuleForTests(tc.input, "android_arm64_armv8-a").Rule(tc.rule)
77 android.AssertStringEquals(t, "input", tc.input, rule.Input.String())
Jooyung Hana0171822019-07-22 15:48:36 +090078 if tc.schemaType != "" {
Paul Duffinec74f812021-03-18 01:42:49 +000079 android.AssertStringEquals(t, "schema", tc.schema, rule.Args[tc.schemaType])
Jooyung Hana0171822019-07-22 15:48:36 +090080 }
81 })
Jiyong Park5a8d1be2018-04-25 22:57:34 +090082 }
Jooyung Hana0171822019-07-22 15:48:36 +090083
Paul Duffinec74f812021-03-18 01:42:49 +000084 m := result.ModuleForTests("foo.xml", "android_arm64_armv8-a").Module().(*prebuiltEtcXml)
85 android.AssertPathRelativeToTopEquals(t, "installDir", "out/soong/target/product/test_device/system/etc", m.InstallDirPath())
Jiyong Park5a8d1be2018-04-25 22:57:34 +090086}