blob: 60a639b4b4daebb2fc129e90e31b628400f3b0fe [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{
Jiyong Park9477c262021-06-22 20:23:05 +090036 {"foo", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070037 },
38 wantMerged: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090039 {"apex10000", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070040 },
41 wantAliases: [][2]string{
42 {"foo", "apex10000"},
43 },
44 },
45 {
46 name: "merge",
47 in: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090048 {"foo", FutureApiLevel, false, false, SdkRefs{{"baz", "1"}}, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
49 {"bar", FutureApiLevel, false, false, SdkRefs{{"baz", "1"}}, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070050 },
51 wantMerged: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090052 {"apex10000_baz_1", FutureApiLevel, false, false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, false}},
Colin Crossaede88c2020-08-11 12:17:01 -070053 wantAliases: [][2]string{
54 {"bar", "apex10000_baz_1"},
55 {"foo", "apex10000_baz_1"},
56 },
57 },
58 {
59 name: "don't merge version",
60 in: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090061 {"foo", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
62 {"bar", uncheckedFinalApiLevel(30), false, false, nil, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070063 },
64 wantMerged: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090065 {"apex30", uncheckedFinalApiLevel(30), false, false, nil, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
66 {"apex10000", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070067 },
68 wantAliases: [][2]string{
69 {"bar", "apex30"},
70 {"foo", "apex10000"},
71 },
72 },
73 {
74 name: "merge updatable",
75 in: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090076 {"foo", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
77 {"bar", FutureApiLevel, true, false, nil, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070078 },
79 wantMerged: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090080 {"apex10000", FutureApiLevel, true, false, nil, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070081 },
82 wantAliases: [][2]string{
83 {"bar", "apex10000"},
84 {"foo", "apex10000"},
85 },
86 },
87 {
88 name: "don't merge sdks",
89 in: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090090 {"foo", FutureApiLevel, false, false, SdkRefs{{"baz", "1"}}, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
91 {"bar", FutureApiLevel, false, false, SdkRefs{{"baz", "2"}}, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070092 },
93 wantMerged: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +090094 {"apex10000_baz_2", FutureApiLevel, false, false, SdkRefs{{"baz", "2"}}, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
95 {"apex10000_baz_1", FutureApiLevel, false, false, SdkRefs{{"baz", "1"}}, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
Colin Crossaede88c2020-08-11 12:17:01 -070096 },
97 wantAliases: [][2]string{
98 {"bar", "apex10000_baz_2"},
99 {"foo", "apex10000_baz_1"},
100 },
101 },
Paul Duffin064b70c2020-11-02 17:32:38 +0000102 {
103 name: "don't merge when for prebuilt_apex",
104 in: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +0900105 {"foo", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
106 {"bar", FutureApiLevel, true, false, nil, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
Paul Duffin064b70c2020-11-02 17:32:38 +0000107 // This one should not be merged in with the others because it is for
108 // a prebuilt_apex.
Jiyong Park9477c262021-06-22 20:23:05 +0900109 {"baz", FutureApiLevel, true, false, nil, []string{"baz"}, []string{"baz"}, nil, ForPrebuiltApex},
Paul Duffin064b70c2020-11-02 17:32:38 +0000110 },
111 wantMerged: []ApexInfo{
Jiyong Park9477c262021-06-22 20:23:05 +0900112 {"apex10000", FutureApiLevel, true, false, nil, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, NotForPrebuiltApex},
113 {"baz", FutureApiLevel, true, false, nil, []string{"baz"}, []string{"baz"}, nil, ForPrebuiltApex},
Paul Duffin064b70c2020-11-02 17:32:38 +0000114 },
115 wantAliases: [][2]string{
116 {"bar", "apex10000"},
117 {"foo", "apex10000"},
118 },
119 },
Jiyong Park9477c262021-06-22 20:23:05 +0900120 {
121 name: "don't merge different UsePlatformApis",
122 in: []ApexInfo{
123 {"foo", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
124 {"bar", FutureApiLevel, false, true, nil, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
125 },
126 wantMerged: []ApexInfo{
127 {"apex10000_private", FutureApiLevel, false, true, nil, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex},
128 {"apex10000", FutureApiLevel, false, false, nil, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex},
129 },
130 wantAliases: [][2]string{
131 {"bar", "apex10000_private"},
132 {"foo", "apex10000"},
133 },
134 },
Colin Crossaede88c2020-08-11 12:17:01 -0700135 }
Paul Duffin064b70c2020-11-02 17:32:38 +0000136
Colin Crossaede88c2020-08-11 12:17:01 -0700137 for _, tt := range tests {
138 t.Run(tt.name, func(t *testing.T) {
Paul Duffind210afa2021-03-16 17:31:20 +0000139 config := TestConfig(t.TempDir(), nil, "", nil)
Colin Cross9f720ce2020-10-02 10:26:04 -0700140 ctx := &configErrorWrapper{config: config}
141 gotMerged, gotAliases := mergeApexVariations(ctx, tt.in)
Colin Crossaede88c2020-08-11 12:17:01 -0700142 if !reflect.DeepEqual(gotMerged, tt.wantMerged) {
143 t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged)
144 }
145 if !reflect.DeepEqual(gotAliases, tt.wantAliases) {
146 t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases)
147 }
148 })
149 }
150}