Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package xml |
| 16 | |
| 17 | import ( |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 18 | "os" |
| 19 | "testing" |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 22 | "android/soong/etc" |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 23 | ) |
| 24 | |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 25 | func TestMain(m *testing.M) { |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 26 | os.Exit(m.Run()) |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 29 | var emptyFixtureFactory = android.NewFixtureFactory(nil) |
| 30 | |
| 31 | func testXml(t *testing.T, bp string) *android.TestResult { |
| 32 | fs := android.MockFS{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 33 | "foo.xml": nil, |
| 34 | "foo.dtd": nil, |
| 35 | "bar.xml": nil, |
| 36 | "bar.xsd": nil, |
| 37 | "baz.xml": nil, |
| 38 | } |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 39 | |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 40 | return emptyFixtureFactory.RunTest(t, |
| 41 | android.PrepareForTestWithArchMutator, |
| 42 | etc.PrepareForTestWithPrebuiltEtc, |
| 43 | PreparerForTestWithXmlBuildComponents, |
| 44 | fs.AddToFixture(), |
| 45 | android.FixtureWithRootAndroidBp(bp), |
| 46 | ) |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 47 | } |
| 48 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 49 | // Minimal test |
| 50 | func TestPrebuiltEtcXml(t *testing.T) { |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 51 | result := testXml(t, ` |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 52 | 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 Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 62 | prebuilt_etc_xml { |
| 63 | name: "baz.xml", |
| 64 | src: "baz.xml", |
| 65 | } |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 66 | `) |
| 67 | |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 68 | 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 Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 76 | rule := result.ModuleForTests(tc.input, "android_arm64_armv8-a").Rule(tc.rule) |
| 77 | android.AssertStringEquals(t, "input", tc.input, rule.Input.String()) |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 78 | if tc.schemaType != "" { |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 79 | android.AssertStringEquals(t, "schema", tc.schema, rule.Args[tc.schemaType]) |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 80 | } |
| 81 | }) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 82 | } |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 83 | |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame^] | 84 | 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 Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 86 | } |