blob: ebbe3a5eebdf2a8681640c2459a75db34bee14a6 [file] [log] [blame]
Paul Duffinbb7f1ac2021-03-29 22:18:45 +01001// Copyright (C) 2021 The Android Open Source Project
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 java
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/dexpreopt"
22)
23
24// Contains some simple tests for platform_bootclasspath.
25
26var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
27 PrepareForTestWithJavaDefaultModules,
28 dexpreopt.PrepareForTestByEnablingDexpreopt,
29)
30
31func TestPlatformBootclasspath(t *testing.T) {
Paul Duffinb432df92021-03-22 22:09:42 +000032 preparer := android.GroupFixturePreparers(
33 prepareForTestWithPlatformBootclasspath,
34 dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
35 android.FixtureWithRootAndroidBp(`
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010036 platform_bootclasspath {
37 name: "platform-bootclasspath",
38 }
Paul Duffinb432df92021-03-22 22:09:42 +000039
40 java_library {
41 name: "bar",
42 srcs: ["a.java"],
43 system_modules: "none",
44 sdk_version: "none",
45 compile_dex: true,
46 }
47 `),
48 )
49
50 var addSourceBootclassPathModule = android.FixtureAddTextFile("source/Android.bp", `
51 java_library {
52 name: "foo",
53 srcs: ["a.java"],
54 system_modules: "none",
55 sdk_version: "none",
56 compile_dex: true,
57 }
58 `)
59
60 var addPrebuiltBootclassPathModule = android.FixtureAddTextFile("prebuilt/Android.bp", `
61 java_import {
62 name: "foo",
63 jars: ["a.jar"],
64 compile_dex: true,
65 prefer: false,
66 }
67 `)
68
69 var addPrebuiltPreferredBootclassPathModule = android.FixtureAddTextFile("prebuilt/Android.bp", `
70 java_import {
71 name: "foo",
72 jars: ["a.jar"],
73 compile_dex: true,
74 prefer: true,
75 }
76 `)
77
78 t.Run("missing", func(t *testing.T) {
79 preparer.
80 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`"platform-bootclasspath" depends on undefined module "foo"`)).
81 RunTest(t)
82 })
83
84 t.Run("source", func(t *testing.T) {
85 result := android.GroupFixturePreparers(
86 preparer,
87 addSourceBootclassPathModule,
88 ).RunTest(t)
89
90 CheckPlatformBootclasspathModules(t, result, "platform-bootclasspath", []string{
91 "platform:foo",
92 "platform:bar",
93 })
94 })
95
96 t.Run("prebuilt", func(t *testing.T) {
97 result := android.GroupFixturePreparers(
98 preparer,
99 addPrebuiltBootclassPathModule,
100 ).RunTest(t)
101
102 CheckPlatformBootclasspathModules(t, result, "platform-bootclasspath", []string{
103 "platform:prebuilt_foo",
104 "platform:bar",
105 })
106 })
107
108 t.Run("source+prebuilt - source preferred", func(t *testing.T) {
109 result := android.GroupFixturePreparers(
110 preparer,
111 addSourceBootclassPathModule,
112 addPrebuiltBootclassPathModule,
113 ).RunTest(t)
114
115 CheckPlatformBootclasspathModules(t, result, "platform-bootclasspath", []string{
116 "platform:foo",
117 "platform:bar",
118 })
119 })
120
121 t.Run("source+prebuilt - prebuilt preferred", func(t *testing.T) {
122 result := android.GroupFixturePreparers(
123 preparer,
124 addSourceBootclassPathModule,
125 addPrebuiltPreferredBootclassPathModule,
126 ).RunTest(t)
127
128 CheckPlatformBootclasspathModules(t, result, "platform-bootclasspath", []string{
129 "platform:prebuilt_foo",
130 "platform:bar",
131 })
132 })
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100133}