blob: ba328e7b17caae9eedd6529eff209dd01f48354c [file] [log] [blame]
satayev95e9c5b2021-04-29 11:50:26 +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)
22
satayev9366a052021-05-17 21:13:44 +010023var prepareForTestWithSystemServerClasspath = android.GroupFixturePreparers(
satayev95e9c5b2021-04-29 11:50:26 +010024 PrepareForTestWithJavaDefaultModules,
25)
26
satayev227e7452021-05-20 21:35:06 +010027func TestPlatformSystemServerClasspathVariant(t *testing.T) {
satayev95e9c5b2021-04-29 11:50:26 +010028 result := android.GroupFixturePreparers(
satayev9366a052021-05-17 21:13:44 +010029 prepareForTestWithSystemServerClasspath,
satayev95e9c5b2021-04-29 11:50:26 +010030 android.FixtureWithRootAndroidBp(`
31 platform_systemserverclasspath {
32 name: "platform-systemserverclasspath",
33 }
34 `),
35 ).RunTest(t)
36
37 variants := result.ModuleVariantsForTests("platform-systemserverclasspath")
38 android.AssertIntEquals(t, "expect 1 variant", 1, len(variants))
39}
40
satayev227e7452021-05-20 21:35:06 +010041func TestPlatformSystemServerClasspath_ClasspathFragmentPaths(t *testing.T) {
satayev95e9c5b2021-04-29 11:50:26 +010042 result := android.GroupFixturePreparers(
satayev9366a052021-05-17 21:13:44 +010043 prepareForTestWithSystemServerClasspath,
satayev95e9c5b2021-04-29 11:50:26 +010044 android.FixtureWithRootAndroidBp(`
45 platform_systemserverclasspath {
46 name: "platform-systemserverclasspath",
47 }
48 `),
49 ).RunTest(t)
50
51 p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
satayev227e7452021-05-20 21:35:06 +010052 android.AssertStringEquals(t, "output filepath", "systemserverclasspath.pb", p.ClasspathFragmentBase.outputFilepath.Base())
satayev95e9c5b2021-04-29 11:50:26 +010053 android.AssertPathRelativeToTopEquals(t, "install filepath", "out/soong/target/product/test_device/system/etc/classpaths", p.ClasspathFragmentBase.installDirPath)
54}
55
satayev227e7452021-05-20 21:35:06 +010056func TestPlatformSystemServerClasspathModule_AndroidMkEntries(t *testing.T) {
satayev95e9c5b2021-04-29 11:50:26 +010057 preparer := android.GroupFixturePreparers(
satayev9366a052021-05-17 21:13:44 +010058 prepareForTestWithSystemServerClasspath,
satayev95e9c5b2021-04-29 11:50:26 +010059 android.FixtureWithRootAndroidBp(`
60 platform_systemserverclasspath {
61 name: "platform-systemserverclasspath",
62 }
63 `),
64 )
65
66 t.Run("AndroidMkEntries", func(t *testing.T) {
67 result := preparer.RunTest(t)
68
69 p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
70
71 entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)
72 android.AssertIntEquals(t, "AndroidMkEntries count", 1, len(entries))
73 })
74
75 t.Run("classpath-fragment-entry", func(t *testing.T) {
76 result := preparer.RunTest(t)
77
78 want := map[string][]string{
79 "LOCAL_MODULE": {"platform-systemserverclasspath"},
80 "LOCAL_MODULE_CLASS": {"ETC"},
satayev227e7452021-05-20 21:35:06 +010081 "LOCAL_INSTALLED_MODULE_STEM": {"systemserverclasspath.pb"},
82 // Output and Install paths are tested separately in TestPlatformSystemServerClasspath_ClasspathFragmentPaths
satayev95e9c5b2021-04-29 11:50:26 +010083 }
84
85 p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule)
86
87 entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)
88 got := entries[0]
89 for k, expectedValue := range want {
90 if value, ok := got.EntryMap[k]; ok {
91 android.AssertDeepEquals(t, k, expectedValue, value)
92 } else {
93 t.Errorf("No %s defined, saw %q", k, got.EntryMap)
94 }
95 }
96 })
97}
satayev9366a052021-05-17 21:13:44 +010098
satayev227e7452021-05-20 21:35:06 +010099func TestSystemServerClasspathFragmentWithoutContents(t *testing.T) {
satayev9366a052021-05-17 21:13:44 +0100100 prepareForTestWithSystemServerClasspath.
101 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000102 `\QEither contents or standalone_contents needs to be non-empty\E`)).
satayev9366a052021-05-17 21:13:44 +0100103 RunTestWithBp(t, `
104 systemserverclasspath_fragment {
105 name: "systemserverclasspath-fragment",
106 }
107 `)
108}