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