Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1 | // Copyright 2020 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 android |
| 16 | |
| 17 | import ( |
| 18 | "reflect" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func Test_mergeApexVariations(t *testing.T) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 23 | const ( |
| 24 | ForPrebuiltApex = true |
| 25 | NotForPrebuiltApex = false |
| 26 | ) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 27 | tests := []struct { |
| 28 | name string |
| 29 | in []ApexInfo |
| 30 | wantMerged []ApexInfo |
| 31 | wantAliases [][2]string |
| 32 | }{ |
| 33 | { |
| 34 | name: "single", |
| 35 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 36 | { |
| 37 | ApexVariationName: "foo", |
| 38 | MinSdkVersion: FutureApiLevel, |
| 39 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 40 | ForPrebuiltApex: NotForPrebuiltApex, |
| 41 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 42 | }, |
| 43 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 44 | { |
| 45 | ApexVariationName: "apex10000", |
| 46 | MinSdkVersion: FutureApiLevel, |
| 47 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 48 | ForPrebuiltApex: NotForPrebuiltApex, |
| 49 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 50 | }, |
| 51 | wantAliases: [][2]string{ |
| 52 | {"foo", "apex10000"}, |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "merge", |
| 57 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 58 | { |
| 59 | ApexVariationName: "foo", |
| 60 | MinSdkVersion: FutureApiLevel, |
| 61 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 62 | ForPrebuiltApex: NotForPrebuiltApex, |
| 63 | }, |
| 64 | { |
| 65 | ApexVariationName: "bar", |
| 66 | MinSdkVersion: FutureApiLevel, |
| 67 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 68 | ForPrebuiltApex: NotForPrebuiltApex, |
| 69 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 70 | }, |
| 71 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 72 | { |
| 73 | ApexVariationName: "apex10000", |
| 74 | MinSdkVersion: FutureApiLevel, |
| 75 | InApexVariants: []string{"foo", "bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 76 | }}, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 77 | wantAliases: [][2]string{ |
Liz Kammer | 7eed538 | 2022-04-21 11:13:45 -0400 | [diff] [blame] | 78 | {"foo", "apex10000"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 79 | {"bar", "apex10000"}, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 80 | }, |
| 81 | }, |
| 82 | { |
| 83 | name: "don't merge version", |
| 84 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 85 | { |
| 86 | ApexVariationName: "foo", |
| 87 | MinSdkVersion: FutureApiLevel, |
| 88 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 89 | ForPrebuiltApex: NotForPrebuiltApex, |
| 90 | }, |
| 91 | { |
| 92 | ApexVariationName: "bar", |
| 93 | MinSdkVersion: uncheckedFinalApiLevel(30), |
| 94 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 95 | ForPrebuiltApex: NotForPrebuiltApex, |
| 96 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 97 | }, |
| 98 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 99 | { |
| 100 | ApexVariationName: "apex10000", |
| 101 | MinSdkVersion: FutureApiLevel, |
| 102 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 103 | ForPrebuiltApex: NotForPrebuiltApex, |
| 104 | }, |
| 105 | { |
| 106 | ApexVariationName: "apex30", |
| 107 | MinSdkVersion: uncheckedFinalApiLevel(30), |
| 108 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 109 | ForPrebuiltApex: NotForPrebuiltApex, |
| 110 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 111 | }, |
| 112 | wantAliases: [][2]string{ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 113 | {"foo", "apex10000"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 114 | {"bar", "apex30"}, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 115 | }, |
| 116 | }, |
| 117 | { |
| 118 | name: "merge updatable", |
| 119 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 120 | { |
| 121 | ApexVariationName: "foo", |
| 122 | MinSdkVersion: FutureApiLevel, |
| 123 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 124 | ForPrebuiltApex: NotForPrebuiltApex, |
| 125 | }, |
| 126 | { |
| 127 | ApexVariationName: "bar", |
| 128 | MinSdkVersion: FutureApiLevel, |
| 129 | Updatable: true, |
| 130 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 131 | ForPrebuiltApex: NotForPrebuiltApex, |
| 132 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 133 | }, |
| 134 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 135 | { |
| 136 | ApexVariationName: "apex10000", |
| 137 | MinSdkVersion: FutureApiLevel, |
| 138 | Updatable: true, |
| 139 | InApexVariants: []string{"foo", "bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 140 | ForPrebuiltApex: NotForPrebuiltApex, |
| 141 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 142 | }, |
| 143 | wantAliases: [][2]string{ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 144 | {"foo", "apex10000"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 145 | {"bar", "apex10000"}, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 146 | }, |
| 147 | }, |
| 148 | { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 149 | name: "don't merge when for prebuilt_apex", |
| 150 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 151 | { |
| 152 | ApexVariationName: "foo", |
| 153 | MinSdkVersion: FutureApiLevel, |
| 154 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 155 | ForPrebuiltApex: NotForPrebuiltApex, |
| 156 | }, |
| 157 | { |
| 158 | ApexVariationName: "bar", |
| 159 | MinSdkVersion: FutureApiLevel, |
| 160 | Updatable: true, |
| 161 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 162 | ForPrebuiltApex: NotForPrebuiltApex, |
| 163 | }, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 164 | // This one should not be merged in with the others because it is for |
| 165 | // a prebuilt_apex. |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 166 | { |
| 167 | ApexVariationName: "baz", |
| 168 | MinSdkVersion: FutureApiLevel, |
| 169 | Updatable: true, |
| 170 | InApexVariants: []string{"baz"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 171 | ForPrebuiltApex: ForPrebuiltApex, |
| 172 | }, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 173 | }, |
| 174 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 175 | { |
| 176 | ApexVariationName: "apex10000", |
| 177 | MinSdkVersion: FutureApiLevel, |
| 178 | Updatable: true, |
| 179 | InApexVariants: []string{"foo", "bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 180 | ForPrebuiltApex: NotForPrebuiltApex, |
| 181 | }, |
| 182 | { |
| 183 | ApexVariationName: "baz", |
| 184 | MinSdkVersion: FutureApiLevel, |
| 185 | Updatable: true, |
| 186 | InApexVariants: []string{"baz"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 187 | ForPrebuiltApex: ForPrebuiltApex, |
| 188 | }, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 189 | }, |
| 190 | wantAliases: [][2]string{ |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 191 | {"foo", "apex10000"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 192 | {"bar", "apex10000"}, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 193 | }, |
| 194 | }, |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 195 | { |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 196 | name: "merge different UsePlatformApis but don't allow using platform api", |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 197 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 198 | { |
| 199 | ApexVariationName: "foo", |
| 200 | MinSdkVersion: FutureApiLevel, |
| 201 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 202 | ForPrebuiltApex: NotForPrebuiltApex, |
| 203 | }, |
| 204 | { |
| 205 | ApexVariationName: "bar", |
| 206 | MinSdkVersion: FutureApiLevel, |
| 207 | UsePlatformApis: true, |
| 208 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 209 | ForPrebuiltApex: NotForPrebuiltApex, |
| 210 | }, |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 211 | }, |
| 212 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 213 | { |
| 214 | ApexVariationName: "apex10000", |
| 215 | MinSdkVersion: FutureApiLevel, |
| 216 | InApexVariants: []string{"foo", "bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 217 | ForPrebuiltApex: NotForPrebuiltApex, |
| 218 | }, |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 219 | }, |
| 220 | wantAliases: [][2]string{ |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 221 | {"foo", "apex10000"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 222 | {"bar", "apex10000"}, |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 223 | }, |
| 224 | }, |
| 225 | { |
| 226 | name: "merge same UsePlatformApis and allow using platform api", |
| 227 | in: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 228 | { |
| 229 | ApexVariationName: "foo", |
| 230 | MinSdkVersion: FutureApiLevel, |
| 231 | UsePlatformApis: true, |
| 232 | InApexVariants: []string{"foo"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 233 | ForPrebuiltApex: NotForPrebuiltApex, |
| 234 | }, |
| 235 | { |
| 236 | ApexVariationName: "bar", |
| 237 | MinSdkVersion: FutureApiLevel, |
| 238 | UsePlatformApis: true, |
| 239 | InApexVariants: []string{"bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 240 | ForPrebuiltApex: NotForPrebuiltApex, |
| 241 | }, |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 242 | }, |
| 243 | wantMerged: []ApexInfo{ |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 244 | { |
| 245 | ApexVariationName: "apex10000", |
| 246 | MinSdkVersion: FutureApiLevel, |
| 247 | UsePlatformApis: true, |
| 248 | InApexVariants: []string{"foo", "bar"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 249 | ForPrebuiltApex: NotForPrebuiltApex, |
| 250 | }, |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 251 | }, |
| 252 | wantAliases: [][2]string{ |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 253 | {"foo", "apex10000"}, |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 254 | {"bar", "apex10000"}, |
Jiyong Park | 9477c26 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 255 | }, |
| 256 | }, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 257 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 258 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 259 | for _, tt := range tests { |
| 260 | t.Run(tt.name, func(t *testing.T) { |
Colin Cross | 9132ced | 2024-04-15 15:32:38 -0700 | [diff] [blame] | 261 | gotMerged, gotAliases := mergeApexVariations(tt.in) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 262 | if !reflect.DeepEqual(gotMerged, tt.wantMerged) { |
| 263 | t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged) |
| 264 | } |
| 265 | if !reflect.DeepEqual(gotAliases, tt.wantAliases) { |
| 266 | t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases) |
| 267 | } |
| 268 | }) |
| 269 | } |
| 270 | } |