blob: a59a29318ee4fac9ae7baaf6c9936a73889c9373 [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 +000029func testXml(t *testing.T, bp string) *android.TestResult {
30 fs := android.MockFS{
Colin Cross98be1bb2019-12-13 20:41:13 -080031 "foo.xml": nil,
32 "foo.dtd": nil,
33 "bar.xml": nil,
34 "bar.xsd": nil,
35 "baz.xml": nil,
36 }
Jiyong Park5a8d1be2018-04-25 22:57:34 +090037
Paul Duffin89648f92021-03-20 00:36:55 +000038 return android.GroupFixturePreparers(
Paul Duffinec74f812021-03-18 01:42:49 +000039 android.PrepareForTestWithArchMutator,
40 etc.PrepareForTestWithPrebuiltEtc,
41 PreparerForTestWithXmlBuildComponents,
42 fs.AddToFixture(),
43 android.FixtureWithRootAndroidBp(bp),
Paul Duffin89648f92021-03-20 00:36:55 +000044 ).RunTest(t)
Jooyung Hana0171822019-07-22 15:48:36 +090045}
46
Jiyong Park5a8d1be2018-04-25 22:57:34 +090047// Minimal test
48func TestPrebuiltEtcXml(t *testing.T) {
Paul Duffinec74f812021-03-18 01:42:49 +000049 result := testXml(t, `
Jiyong Park5a8d1be2018-04-25 22:57:34 +090050 prebuilt_etc_xml {
51 name: "foo.xml",
52 src: "foo.xml",
53 schema: "foo.dtd",
54 }
55 prebuilt_etc_xml {
56 name: "bar.xml",
57 src: "bar.xml",
58 schema: "bar.xsd",
59 }
Jooyung Hana0171822019-07-22 15:48:36 +090060 prebuilt_etc_xml {
61 name: "baz.xml",
62 src: "baz.xml",
63 }
Jiyong Park5a8d1be2018-04-25 22:57:34 +090064 `)
65
Jooyung Hana0171822019-07-22 15:48:36 +090066 for _, tc := range []struct {
67 rule, input, schemaType, schema string
68 }{
69 {rule: "xmllint-dtd", input: "foo.xml", schemaType: "dtd", schema: "foo.dtd"},
70 {rule: "xmllint-xsd", input: "bar.xml", schemaType: "xsd", schema: "bar.xsd"},
71 {rule: "xmllint-minimal", input: "baz.xml"},
72 } {
73 t.Run(tc.schemaType, func(t *testing.T) {
Paul Duffinec74f812021-03-18 01:42:49 +000074 rule := result.ModuleForTests(tc.input, "android_arm64_armv8-a").Rule(tc.rule)
75 android.AssertStringEquals(t, "input", tc.input, rule.Input.String())
Jooyung Hana0171822019-07-22 15:48:36 +090076 if tc.schemaType != "" {
Paul Duffinec74f812021-03-18 01:42:49 +000077 android.AssertStringEquals(t, "schema", tc.schema, rule.Args[tc.schemaType])
Jooyung Hana0171822019-07-22 15:48:36 +090078 }
79 })
Jiyong Park5a8d1be2018-04-25 22:57:34 +090080 }
Jooyung Hana0171822019-07-22 15:48:36 +090081
Paul Duffinec74f812021-03-18 01:42:49 +000082 m := result.ModuleForTests("foo.xml", "android_arm64_armv8-a").Module().(*prebuiltEtcXml)
83 android.AssertPathRelativeToTopEquals(t, "installDir", "out/soong/target/product/test_device/system/etc", m.InstallDirPath())
Jiyong Park5a8d1be2018-04-25 22:57:34 +090084}