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 | func testXml(t *testing.T, bp string) *android.TestResult { |
| 30 | fs := android.MockFS{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 31 | "foo.xml": nil, |
| 32 | "foo.dtd": nil, |
| 33 | "bar.xml": nil, |
| 34 | "bar.xsd": nil, |
| 35 | "baz.xml": nil, |
| 36 | } |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 37 | |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 38 | return android.GroupFixturePreparers( |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame] | 39 | android.PrepareForTestWithArchMutator, |
| 40 | etc.PrepareForTestWithPrebuiltEtc, |
| 41 | PreparerForTestWithXmlBuildComponents, |
| 42 | fs.AddToFixture(), |
| 43 | android.FixtureWithRootAndroidBp(bp), |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 44 | ).RunTest(t) |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 45 | } |
| 46 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 47 | // Minimal test |
| 48 | func TestPrebuiltEtcXml(t *testing.T) { |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame] | 49 | result := testXml(t, ` |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 50 | 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 Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 60 | prebuilt_etc_xml { |
| 61 | name: "baz.xml", |
| 62 | src: "baz.xml", |
| 63 | } |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 64 | `) |
| 65 | |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 66 | 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 Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame] | 74 | rule := result.ModuleForTests(tc.input, "android_arm64_armv8-a").Rule(tc.rule) |
| 75 | android.AssertStringEquals(t, "input", tc.input, rule.Input.String()) |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 76 | if tc.schemaType != "" { |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame] | 77 | android.AssertStringEquals(t, "schema", tc.schema, rule.Args[tc.schemaType]) |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 78 | } |
| 79 | }) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 80 | } |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 81 | |
Paul Duffin | ec74f81 | 2021-03-18 01:42:49 +0000 | [diff] [blame] | 82 | 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 Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 84 | } |