• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2024 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 java
16
17import (
18	"android/soong/android"
19	"fmt"
20	"testing"
21)
22
23var checkContainerMatch = func(t *testing.T, name string, container string, expected bool, actual bool) {
24	errorMessage := fmt.Sprintf("module %s container %s value differ", name, container)
25	android.AssertBoolEquals(t, errorMessage, expected, actual)
26}
27
28func TestJavaContainersModuleProperties(t *testing.T) {
29	t.Parallel()
30	result := android.GroupFixturePreparers(
31		prepareForJavaTest,
32	).RunTestWithBp(t, `
33		java_library {
34			name: "foo",
35			srcs: ["A.java"],
36		}
37		java_library {
38			name: "foo_vendor",
39			srcs: ["A.java"],
40			vendor: true,
41			sdk_version: "current",
42		}
43		java_library {
44			name: "foo_soc_specific",
45			srcs: ["A.java"],
46			soc_specific: true,
47			sdk_version: "current",
48		}
49		java_library {
50			name: "foo_product_specific",
51			srcs: ["A.java"],
52			product_specific: true,
53			sdk_version: "current",
54		}
55		java_test {
56			name: "foo_cts_test",
57			srcs: ["A.java"],
58			test_suites: [
59				"cts",
60			],
61		}
62		java_test {
63			name: "foo_non_cts_test",
64			srcs: ["A.java"],
65			test_suites: [
66				"general-tests",
67			],
68		}
69		java_library {
70			name: "bar",
71			static_libs: [
72				"framework-minus-apex",
73			],
74		}
75		java_library {
76			name: "baz",
77			static_libs: [
78				"bar",
79			],
80		}
81	`)
82
83	testcases := []struct {
84		moduleName         string
85		isSystemContainer  bool
86		isVendorContainer  bool
87		isProductContainer bool
88		isCts              bool
89		isUnstable         bool
90	}{
91		{
92			moduleName:         "foo",
93			isSystemContainer:  true,
94			isVendorContainer:  false,
95			isProductContainer: false,
96			isCts:              false,
97			isUnstable:         false,
98		},
99		{
100			moduleName:         "foo_vendor",
101			isSystemContainer:  false,
102			isVendorContainer:  true,
103			isProductContainer: false,
104			isCts:              false,
105			isUnstable:         false,
106		},
107		{
108			moduleName:         "foo_soc_specific",
109			isSystemContainer:  false,
110			isVendorContainer:  true,
111			isProductContainer: false,
112			isCts:              false,
113			isUnstable:         false,
114		},
115		{
116			moduleName:         "foo_product_specific",
117			isSystemContainer:  false,
118			isVendorContainer:  false,
119			isProductContainer: true,
120			isCts:              false,
121			isUnstable:         false,
122		},
123		{
124			moduleName:         "foo_cts_test",
125			isSystemContainer:  false,
126			isVendorContainer:  false,
127			isProductContainer: false,
128			isCts:              true,
129			isUnstable:         false,
130		},
131		{
132			moduleName:         "foo_non_cts_test",
133			isSystemContainer:  false,
134			isVendorContainer:  false,
135			isProductContainer: false,
136			isCts:              false,
137			isUnstable:         false,
138		},
139		{
140			moduleName:         "bar",
141			isSystemContainer:  true,
142			isVendorContainer:  false,
143			isProductContainer: false,
144			isCts:              false,
145			isUnstable:         true,
146		},
147		{
148			moduleName:         "baz",
149			isSystemContainer:  true,
150			isVendorContainer:  false,
151			isProductContainer: false,
152			isCts:              false,
153			isUnstable:         true,
154		},
155	}
156
157	for _, c := range testcases {
158		m := result.ModuleForTests(t, c.moduleName, "android_common")
159		containers, _ := android.OtherModuleProvider(result.TestContext.OtherModuleProviderAdaptor(), m.Module(), android.ContainersInfoProvider)
160		belongingContainers := containers.BelongingContainers()
161		checkContainerMatch(t, c.moduleName, "system", c.isSystemContainer, android.InList(android.SystemContainer, belongingContainers))
162		checkContainerMatch(t, c.moduleName, "vendor", c.isVendorContainer, android.InList(android.VendorContainer, belongingContainers))
163		checkContainerMatch(t, c.moduleName, "product", c.isProductContainer, android.InList(android.ProductContainer, belongingContainers))
164		checkContainerMatch(t, c.moduleName, "cts", c.isCts, android.InList(android.CtsContainer, belongingContainers))
165		checkContainerMatch(t, c.moduleName, "unstable", c.isUnstable, android.InList(android.UnstableContainer, belongingContainers))
166	}
167}
168