xml_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. package xml
  15. import (
  16. "os"
  17. "testing"
  18. "android/soong/android"
  19. "android/soong/etc"
  20. )
  21. func TestMain(m *testing.M) {
  22. os.Exit(m.Run())
  23. }
  24. func testXml(t *testing.T, bp string) *android.TestResult {
  25. fs := android.MockFS{
  26. "foo.xml": nil,
  27. "foo.dtd": nil,
  28. "bar.xml": nil,
  29. "bar.xsd": nil,
  30. "baz.xml": nil,
  31. }
  32. return android.GroupFixturePreparers(
  33. android.PrepareForTestWithArchMutator,
  34. etc.PrepareForTestWithPrebuiltEtc,
  35. PreparerForTestWithXmlBuildComponents,
  36. fs.AddToFixture(),
  37. android.FixtureWithRootAndroidBp(bp),
  38. ).RunTest(t)
  39. }
  40. // Minimal test
  41. func TestPrebuiltEtcXml(t *testing.T) {
  42. result := testXml(t, `
  43. prebuilt_etc_xml {
  44. name: "foo.xml",
  45. src: "foo.xml",
  46. schema: "foo.dtd",
  47. }
  48. prebuilt_etc_xml {
  49. name: "bar.xml",
  50. src: "bar.xml",
  51. schema: "bar.xsd",
  52. }
  53. prebuilt_etc_xml {
  54. name: "baz.xml",
  55. src: "baz.xml",
  56. }
  57. `)
  58. for _, tc := range []struct {
  59. rule, input, schemaType, schema string
  60. }{
  61. {rule: "xmllint-dtd", input: "foo.xml", schemaType: "dtd", schema: "foo.dtd"},
  62. {rule: "xmllint-xsd", input: "bar.xml", schemaType: "xsd", schema: "bar.xsd"},
  63. {rule: "xmllint-minimal", input: "baz.xml"},
  64. } {
  65. t.Run(tc.schemaType, func(t *testing.T) {
  66. rule := result.ModuleForTests(tc.input, "android_arm64_armv8-a").Rule(tc.rule)
  67. android.AssertStringEquals(t, "input", tc.input, rule.Input.String())
  68. if tc.schemaType != "" {
  69. android.AssertStringEquals(t, "schema", tc.schema, rule.Args[tc.schemaType])
  70. }
  71. })
  72. }
  73. m := result.ModuleForTests("foo.xml", "android_arm64_armv8-a").Module().(*prebuiltEtcXml)
  74. android.AssertPathRelativeToTopEquals(t, "installDir", "out/soong/target/product/test_device/system/etc", m.InstallDirPath())
  75. }