apex_test.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. package android
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func Test_mergeApexVariations(t *testing.T) {
  20. const (
  21. ForPrebuiltApex = true
  22. NotForPrebuiltApex = false
  23. )
  24. tests := []struct {
  25. name string
  26. in []ApexInfo
  27. wantMerged []ApexInfo
  28. wantAliases [][2]string
  29. }{
  30. {
  31. name: "single",
  32. in: []ApexInfo{
  33. {"foo", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  34. },
  35. wantMerged: []ApexInfo{
  36. {"apex10000", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  37. },
  38. wantAliases: [][2]string{
  39. {"foo", "apex10000"},
  40. },
  41. },
  42. {
  43. name: "merge",
  44. in: []ApexInfo{
  45. {"foo", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  46. {"bar", FutureApiLevel, false, false, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  47. },
  48. wantMerged: []ApexInfo{
  49. {"apex10000", FutureApiLevel, false, false, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, false, nil}},
  50. wantAliases: [][2]string{
  51. {"bar", "apex10000"},
  52. {"foo", "apex10000"},
  53. },
  54. },
  55. {
  56. name: "don't merge version",
  57. in: []ApexInfo{
  58. {"foo", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  59. {"bar", uncheckedFinalApiLevel(30), false, false, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  60. },
  61. wantMerged: []ApexInfo{
  62. {"apex30", uncheckedFinalApiLevel(30), false, false, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  63. {"apex10000", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  64. },
  65. wantAliases: [][2]string{
  66. {"bar", "apex30"},
  67. {"foo", "apex10000"},
  68. },
  69. },
  70. {
  71. name: "merge updatable",
  72. in: []ApexInfo{
  73. {"foo", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  74. {"bar", FutureApiLevel, true, false, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  75. },
  76. wantMerged: []ApexInfo{
  77. {"apex10000", FutureApiLevel, true, false, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, NotForPrebuiltApex, nil},
  78. },
  79. wantAliases: [][2]string{
  80. {"bar", "apex10000"},
  81. {"foo", "apex10000"},
  82. },
  83. },
  84. {
  85. name: "don't merge when for prebuilt_apex",
  86. in: []ApexInfo{
  87. {"foo", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  88. {"bar", FutureApiLevel, true, false, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  89. // This one should not be merged in with the others because it is for
  90. // a prebuilt_apex.
  91. {"baz", FutureApiLevel, true, false, []string{"baz"}, []string{"baz"}, nil, ForPrebuiltApex, nil},
  92. },
  93. wantMerged: []ApexInfo{
  94. {"apex10000", FutureApiLevel, true, false, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, NotForPrebuiltApex, nil},
  95. {"baz", FutureApiLevel, true, false, []string{"baz"}, []string{"baz"}, nil, ForPrebuiltApex, nil},
  96. },
  97. wantAliases: [][2]string{
  98. {"bar", "apex10000"},
  99. {"foo", "apex10000"},
  100. },
  101. },
  102. {
  103. name: "merge different UsePlatformApis but don't allow using platform api",
  104. in: []ApexInfo{
  105. {"foo", FutureApiLevel, false, false, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  106. {"bar", FutureApiLevel, false, true, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  107. },
  108. wantMerged: []ApexInfo{
  109. {"apex10000", FutureApiLevel, false, false, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, NotForPrebuiltApex, nil},
  110. },
  111. wantAliases: [][2]string{
  112. {"bar", "apex10000"},
  113. {"foo", "apex10000"},
  114. },
  115. },
  116. {
  117. name: "merge same UsePlatformApis and allow using platform api",
  118. in: []ApexInfo{
  119. {"foo", FutureApiLevel, false, true, []string{"foo"}, []string{"foo"}, nil, NotForPrebuiltApex, nil},
  120. {"bar", FutureApiLevel, false, true, []string{"bar"}, []string{"bar"}, nil, NotForPrebuiltApex, nil},
  121. },
  122. wantMerged: []ApexInfo{
  123. {"apex10000", FutureApiLevel, false, true, []string{"bar", "foo"}, []string{"bar", "foo"}, nil, NotForPrebuiltApex, nil},
  124. },
  125. wantAliases: [][2]string{
  126. {"bar", "apex10000"},
  127. {"foo", "apex10000"},
  128. },
  129. },
  130. }
  131. for _, tt := range tests {
  132. t.Run(tt.name, func(t *testing.T) {
  133. config := TestConfig(t.TempDir(), nil, "", nil)
  134. ctx := &configErrorWrapper{config: config}
  135. gotMerged, gotAliases := mergeApexVariations(ctx, tt.in)
  136. if !reflect.DeepEqual(gotMerged, tt.wantMerged) {
  137. t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged)
  138. }
  139. if !reflect.DeepEqual(gotAliases, tt.wantAliases) {
  140. t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases)
  141. }
  142. })
  143. }
  144. }