blob: 78597b2347313f2a9828acc87ac9385727132230 [file] [log] [blame]
Colin Crossaede88c2020-08-11 12:17:01 -07001// 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
15package android
16
17import (
18 "reflect"
19 "testing"
20)
21
22func Test_mergeApexVariations(t *testing.T) {
Paul Duffin064b70c2020-11-02 17:32:38 +000023 const (
24 ForPrebuiltApex = true
25 NotForPrebuiltApex = false
26 )
Colin Crossaede88c2020-08-11 12:17:01 -070027 tests := []struct {
28 name string
29 in []ApexInfo
30 wantMerged []ApexInfo
31 wantAliases [][2]string
32 }{
33 {
34 name: "single",
35 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -070036 {
37 ApexVariationName: "foo",
38 MinSdkVersion: FutureApiLevel,
39 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -070040 ForPrebuiltApex: NotForPrebuiltApex,
41 },
Colin Crossaede88c2020-08-11 12:17:01 -070042 },
43 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -070044 {
45 ApexVariationName: "apex10000",
46 MinSdkVersion: FutureApiLevel,
47 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -070048 ForPrebuiltApex: NotForPrebuiltApex,
49 },
Colin Crossaede88c2020-08-11 12:17:01 -070050 },
51 wantAliases: [][2]string{
52 {"foo", "apex10000"},
53 },
54 },
55 {
56 name: "merge",
57 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -070058 {
59 ApexVariationName: "foo",
60 MinSdkVersion: FutureApiLevel,
61 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -070062 ForPrebuiltApex: NotForPrebuiltApex,
63 },
64 {
65 ApexVariationName: "bar",
66 MinSdkVersion: FutureApiLevel,
67 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -070068 ForPrebuiltApex: NotForPrebuiltApex,
69 },
Colin Crossaede88c2020-08-11 12:17:01 -070070 },
71 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -070072 {
73 ApexVariationName: "apex10000",
74 MinSdkVersion: FutureApiLevel,
75 InApexVariants: []string{"foo", "bar"},
Colin Cross9132ced2024-04-15 15:32:38 -070076 }},
Colin Crossaede88c2020-08-11 12:17:01 -070077 wantAliases: [][2]string{
Liz Kammer7eed5382022-04-21 11:13:45 -040078 {"foo", "apex10000"},
Colin Cross9132ced2024-04-15 15:32:38 -070079 {"bar", "apex10000"},
Colin Crossaede88c2020-08-11 12:17:01 -070080 },
81 },
82 {
83 name: "don't merge version",
84 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -070085 {
86 ApexVariationName: "foo",
87 MinSdkVersion: FutureApiLevel,
88 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -070089 ForPrebuiltApex: NotForPrebuiltApex,
90 },
91 {
92 ApexVariationName: "bar",
93 MinSdkVersion: uncheckedFinalApiLevel(30),
94 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -070095 ForPrebuiltApex: NotForPrebuiltApex,
96 },
Colin Crossaede88c2020-08-11 12:17:01 -070097 },
98 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -070099 {
100 ApexVariationName: "apex10000",
101 MinSdkVersion: FutureApiLevel,
102 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -0700103 ForPrebuiltApex: NotForPrebuiltApex,
104 },
105 {
106 ApexVariationName: "apex30",
107 MinSdkVersion: uncheckedFinalApiLevel(30),
108 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700109 ForPrebuiltApex: NotForPrebuiltApex,
110 },
Colin Crossaede88c2020-08-11 12:17:01 -0700111 },
112 wantAliases: [][2]string{
Colin Crossaede88c2020-08-11 12:17:01 -0700113 {"foo", "apex10000"},
Colin Cross9132ced2024-04-15 15:32:38 -0700114 {"bar", "apex30"},
Colin Crossaede88c2020-08-11 12:17:01 -0700115 },
116 },
117 {
118 name: "merge updatable",
119 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700120 {
121 ApexVariationName: "foo",
122 MinSdkVersion: FutureApiLevel,
123 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -0700124 ForPrebuiltApex: NotForPrebuiltApex,
125 },
126 {
127 ApexVariationName: "bar",
128 MinSdkVersion: FutureApiLevel,
129 Updatable: true,
130 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700131 ForPrebuiltApex: NotForPrebuiltApex,
132 },
Colin Crossaede88c2020-08-11 12:17:01 -0700133 },
134 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700135 {
136 ApexVariationName: "apex10000",
137 MinSdkVersion: FutureApiLevel,
138 Updatable: true,
139 InApexVariants: []string{"foo", "bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700140 ForPrebuiltApex: NotForPrebuiltApex,
141 },
Colin Crossaede88c2020-08-11 12:17:01 -0700142 },
143 wantAliases: [][2]string{
Colin Crossaede88c2020-08-11 12:17:01 -0700144 {"foo", "apex10000"},
Colin Cross9132ced2024-04-15 15:32:38 -0700145 {"bar", "apex10000"},
Colin Crossaede88c2020-08-11 12:17:01 -0700146 },
147 },
148 {
Paul Duffin064b70c2020-11-02 17:32:38 +0000149 name: "don't merge when for prebuilt_apex",
150 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700151 {
152 ApexVariationName: "foo",
153 MinSdkVersion: FutureApiLevel,
154 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -0700155 ForPrebuiltApex: NotForPrebuiltApex,
156 },
157 {
158 ApexVariationName: "bar",
159 MinSdkVersion: FutureApiLevel,
160 Updatable: true,
161 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700162 ForPrebuiltApex: NotForPrebuiltApex,
163 },
Paul Duffin064b70c2020-11-02 17:32:38 +0000164 // This one should not be merged in with the others because it is for
165 // a prebuilt_apex.
Colin Cross9132ced2024-04-15 15:32:38 -0700166 {
167 ApexVariationName: "baz",
168 MinSdkVersion: FutureApiLevel,
169 Updatable: true,
170 InApexVariants: []string{"baz"},
Colin Cross9132ced2024-04-15 15:32:38 -0700171 ForPrebuiltApex: ForPrebuiltApex,
172 },
Paul Duffin064b70c2020-11-02 17:32:38 +0000173 },
174 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700175 {
176 ApexVariationName: "apex10000",
177 MinSdkVersion: FutureApiLevel,
178 Updatable: true,
179 InApexVariants: []string{"foo", "bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700180 ForPrebuiltApex: NotForPrebuiltApex,
181 },
182 {
183 ApexVariationName: "baz",
184 MinSdkVersion: FutureApiLevel,
185 Updatable: true,
186 InApexVariants: []string{"baz"},
Colin Cross9132ced2024-04-15 15:32:38 -0700187 ForPrebuiltApex: ForPrebuiltApex,
188 },
Paul Duffin064b70c2020-11-02 17:32:38 +0000189 },
190 wantAliases: [][2]string{
Paul Duffin064b70c2020-11-02 17:32:38 +0000191 {"foo", "apex10000"},
Colin Cross9132ced2024-04-15 15:32:38 -0700192 {"bar", "apex10000"},
Paul Duffin064b70c2020-11-02 17:32:38 +0000193 },
194 },
Jiyong Park9477c262021-06-22 20:23:05 +0900195 {
Jiyong Parkd4a00632022-04-12 12:23:20 +0900196 name: "merge different UsePlatformApis but don't allow using platform api",
Jiyong Park9477c262021-06-22 20:23:05 +0900197 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700198 {
199 ApexVariationName: "foo",
200 MinSdkVersion: FutureApiLevel,
201 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -0700202 ForPrebuiltApex: NotForPrebuiltApex,
203 },
204 {
205 ApexVariationName: "bar",
206 MinSdkVersion: FutureApiLevel,
207 UsePlatformApis: true,
208 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700209 ForPrebuiltApex: NotForPrebuiltApex,
210 },
Jiyong Park9477c262021-06-22 20:23:05 +0900211 },
212 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700213 {
214 ApexVariationName: "apex10000",
215 MinSdkVersion: FutureApiLevel,
216 InApexVariants: []string{"foo", "bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700217 ForPrebuiltApex: NotForPrebuiltApex,
218 },
Jiyong Park9477c262021-06-22 20:23:05 +0900219 },
220 wantAliases: [][2]string{
Jiyong Parkd4a00632022-04-12 12:23:20 +0900221 {"foo", "apex10000"},
Colin Cross9132ced2024-04-15 15:32:38 -0700222 {"bar", "apex10000"},
Jiyong Parkd4a00632022-04-12 12:23:20 +0900223 },
224 },
225 {
226 name: "merge same UsePlatformApis and allow using platform api",
227 in: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700228 {
229 ApexVariationName: "foo",
230 MinSdkVersion: FutureApiLevel,
231 UsePlatformApis: true,
232 InApexVariants: []string{"foo"},
Colin Cross9132ced2024-04-15 15:32:38 -0700233 ForPrebuiltApex: NotForPrebuiltApex,
234 },
235 {
236 ApexVariationName: "bar",
237 MinSdkVersion: FutureApiLevel,
238 UsePlatformApis: true,
239 InApexVariants: []string{"bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700240 ForPrebuiltApex: NotForPrebuiltApex,
241 },
Jiyong Parkd4a00632022-04-12 12:23:20 +0900242 },
243 wantMerged: []ApexInfo{
Colin Cross9132ced2024-04-15 15:32:38 -0700244 {
245 ApexVariationName: "apex10000",
246 MinSdkVersion: FutureApiLevel,
247 UsePlatformApis: true,
248 InApexVariants: []string{"foo", "bar"},
Colin Cross9132ced2024-04-15 15:32:38 -0700249 ForPrebuiltApex: NotForPrebuiltApex,
250 },
Jiyong Parkd4a00632022-04-12 12:23:20 +0900251 },
252 wantAliases: [][2]string{
Jiyong Park9477c262021-06-22 20:23:05 +0900253 {"foo", "apex10000"},
Colin Cross9132ced2024-04-15 15:32:38 -0700254 {"bar", "apex10000"},
Jiyong Park9477c262021-06-22 20:23:05 +0900255 },
256 },
Colin Crossaede88c2020-08-11 12:17:01 -0700257 }
Paul Duffin064b70c2020-11-02 17:32:38 +0000258
Colin Crossaede88c2020-08-11 12:17:01 -0700259 for _, tt := range tests {
260 t.Run(tt.name, func(t *testing.T) {
Colin Cross9132ced2024-04-15 15:32:38 -0700261 gotMerged, gotAliases := mergeApexVariations(tt.in)
Colin Crossaede88c2020-08-11 12:17:01 -0700262 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}