• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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)
22
23var prepareForTestWithSystemServerClasspath = android.GroupFixturePreparers(
24	PrepareForTestWithJavaDefaultModules,
25)
26
27func TestPlatformSystemServerClasspathVariant(t *testing.T) {
28	t.Parallel()
29	result := android.GroupFixturePreparers(
30		prepareForTestWithSystemServerClasspath,
31		android.FixtureWithRootAndroidBp(`
32			platform_systemserverclasspath {
33				name: "platform-systemserverclasspath",
34			}
35		`),
36	).RunTest(t)
37
38	variants := result.ModuleVariantsForTests("platform-systemserverclasspath")
39	android.AssertIntEquals(t, "expect 1 variant", 1, len(variants))
40}
41
42func TestPlatformSystemServerClasspath_ClasspathFragmentPaths(t *testing.T) {
43	t.Parallel()
44	result := android.GroupFixturePreparers(
45		prepareForTestWithSystemServerClasspath,
46		android.FixtureWithRootAndroidBp(`
47			platform_systemserverclasspath {
48				name: "platform-systemserverclasspath",
49			}
50		`),
51	).RunTest(t)
52
53	p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
54	android.AssertStringEquals(t, "output filepath", "systemserverclasspath.pb", p.ClasspathFragmentBase.outputFilepath.Base())
55	android.AssertPathRelativeToTopEquals(t, "install filepath", "out/target/product/test_device/system/etc/classpaths", p.ClasspathFragmentBase.installDirPath)
56}
57
58func TestPlatformSystemServerClasspathModule_AndroidMkEntries(t *testing.T) {
59	t.Parallel()
60	preparer := android.GroupFixturePreparers(
61		prepareForTestWithSystemServerClasspath,
62		android.FixtureWithRootAndroidBp(`
63			platform_systemserverclasspath {
64				name: "platform-systemserverclasspath",
65			}
66		`),
67	)
68
69	t.Run("AndroidMkEntries", func(t *testing.T) {
70		result := preparer.RunTest(t)
71
72		p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
73
74		entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)
75		android.AssertIntEquals(t, "AndroidMkEntries count", 1, len(entries))
76	})
77
78	t.Run("classpath-fragment-entry", func(t *testing.T) {
79		result := preparer.RunTest(t)
80
81		want := map[string][]string{
82			"LOCAL_MODULE":                {"platform-systemserverclasspath"},
83			"LOCAL_MODULE_CLASS":          {"ETC"},
84			"LOCAL_INSTALLED_MODULE_STEM": {"systemserverclasspath.pb"},
85			// Output and Install paths are tested separately in TestPlatformSystemServerClasspath_ClasspathFragmentPaths
86		}
87
88		p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
89
90		entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)
91		got := entries[0]
92		for k, expectedValue := range want {
93			if value, ok := got.EntryMap[k]; ok {
94				android.AssertDeepEquals(t, k, expectedValue, value)
95			} else {
96				t.Errorf("No %s defined, saw %q", k, got.EntryMap)
97			}
98		}
99	})
100}
101
102func TestSystemServerClasspathFragmentWithoutContents(t *testing.T) {
103	t.Parallel()
104	prepareForTestWithSystemServerClasspath.
105		ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
106			`\QEither contents or standalone_contents needs to be non-empty\E`)).
107		RunTestWithBp(t, `
108			systemserverclasspath_fragment {
109				name: "systemserverclasspath-fragment",
110			}
111		`)
112}
113