| Paul Duffin | 001b234 | 2021-03-11 18:43:31 +0000 | [diff] [blame] | 1 | // Copyright 2021 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 sdk | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "testing" | 
|  | 19 |  | 
|  | 20 | "android/soong/android" | 
|  | 21 | "android/soong/java" | 
|  | 22 | ) | 
|  | 23 |  | 
| Paul Duffin | fcf7985 | 2022-07-20 14:18:24 +0000 | [diff] [blame] | 24 | func testSnapshotWithCompatConfig(t *testing.T, sdk string) { | 
| Paul Duffin | 001b234 | 2021-03-11 18:43:31 +0000 | [diff] [blame] | 25 | result := android.GroupFixturePreparers( | 
|  | 26 | prepareForSdkTestWithJava, | 
|  | 27 | java.PrepareForTestWithPlatformCompatConfig, | 
| Paul Duffin | fcf7985 | 2022-07-20 14:18:24 +0000 | [diff] [blame] | 28 | prepareForSdkTestWithApex, | 
|  | 29 | ).RunTestWithBp(t, sdk+` | 
| Paul Duffin | 001b234 | 2021-03-11 18:43:31 +0000 | [diff] [blame] | 30 | platform_compat_config { | 
|  | 31 | name: "myconfig", | 
|  | 32 | } | 
|  | 33 | `) | 
|  | 34 |  | 
|  | 35 | CheckSnapshot(t, result, "mysdk", "", | 
| Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 36 | checkAndroidBpContents(` | 
| Paul Duffin | 001b234 | 2021-03-11 18:43:31 +0000 | [diff] [blame] | 37 | // This is auto-generated. DO NOT EDIT. | 
|  | 38 |  | 
| Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 39 | apex_contributions_defaults { | 
|  | 40 | name: "mysdk.contributions", | 
|  | 41 | contents: ["prebuilt_myconfig"], | 
|  | 42 | } | 
|  | 43 |  | 
| Paul Duffin | 001b234 | 2021-03-11 18:43:31 +0000 | [diff] [blame] | 44 | prebuilt_platform_compat_config { | 
|  | 45 | name: "myconfig", | 
|  | 46 | prefer: false, | 
|  | 47 | visibility: ["//visibility:public"], | 
|  | 48 | metadata: "compat_configs/myconfig/myconfig_meta.xml", | 
|  | 49 | } | 
|  | 50 | `), | 
|  | 51 | checkAllCopyRules(` | 
|  | 52 | .intermediates/myconfig/android_common/myconfig_meta.xml -> compat_configs/myconfig/myconfig_meta.xml | 
|  | 53 | `), | 
| Paul Duffin | 1822a0a | 2021-03-21 12:56:33 +0000 | [diff] [blame] | 54 | snapshotTestChecker(checkSnapshotWithoutSource, | 
|  | 55 | func(t *testing.T, result *android.TestResult) { | 
|  | 56 | // Make sure that the snapshot metadata is collated by the platform compat config singleton. | 
|  | 57 | java.CheckMergedCompatConfigInputs(t, result, "snapshot module", "snapshot/compat_configs/myconfig/myconfig_meta.xml") | 
|  | 58 | }), | 
|  | 59 |  | 
|  | 60 | snapshotTestChecker(checkSnapshotWithSourcePreferred, | 
|  | 61 | func(t *testing.T, result *android.TestResult) { | 
|  | 62 | // Make sure that the snapshot metadata is collated by the platform compat config singleton. | 
|  | 63 | java.CheckMergedCompatConfigInputs(t, result, "snapshot module", | 
|  | 64 | "out/soong/.intermediates/myconfig/android_common/myconfig_meta.xml", | 
| Paul Duffin | 1822a0a | 2021-03-21 12:56:33 +0000 | [diff] [blame] | 65 | ) | 
|  | 66 | }), | 
|  | 67 |  | 
|  | 68 | snapshotTestChecker(checkSnapshotPreferredWithSource, | 
|  | 69 | func(t *testing.T, result *android.TestResult) { | 
|  | 70 | // Make sure that the snapshot metadata is collated by the platform compat config singleton. | 
|  | 71 | java.CheckMergedCompatConfigInputs(t, result, "snapshot module", | 
| Paul Duffin | 1822a0a | 2021-03-21 12:56:33 +0000 | [diff] [blame] | 72 | "snapshot/compat_configs/myconfig/myconfig_meta.xml", | 
|  | 73 | ) | 
|  | 74 | }), | 
| Paul Duffin | 001b234 | 2021-03-11 18:43:31 +0000 | [diff] [blame] | 75 | ) | 
|  | 76 | } | 
| Paul Duffin | fcf7985 | 2022-07-20 14:18:24 +0000 | [diff] [blame] | 77 |  | 
|  | 78 | func TestSnapshotWithCompatConfig(t *testing.T) { | 
|  | 79 | testSnapshotWithCompatConfig(t, ` | 
|  | 80 | sdk { | 
|  | 81 | name: "mysdk", | 
|  | 82 | compat_configs: ["myconfig"], | 
|  | 83 | } | 
|  | 84 | `) | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | func TestSnapshotWithCompatConfig_Apex(t *testing.T) { | 
|  | 88 | testSnapshotWithCompatConfig(t, ` | 
|  | 89 | apex { | 
|  | 90 | name: "myapex", | 
|  | 91 | key: "myapex.key", | 
|  | 92 | min_sdk_version: "2", | 
|  | 93 | compat_configs: ["myconfig"], | 
|  | 94 | } | 
|  | 95 |  | 
|  | 96 | sdk { | 
|  | 97 | name: "mysdk", | 
|  | 98 | apexes: ["myapex"], | 
|  | 99 | } | 
|  | 100 | `) | 
|  | 101 | } |