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 result := android.GroupFixturePreparers( 29 prepareForTestWithSystemServerClasspath, 30 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 41func TestPlatformSystemServerClasspath_ClasspathFragmentPaths(t *testing.T) { 42 result := android.GroupFixturePreparers( 43 prepareForTestWithSystemServerClasspath, 44 android.FixtureWithRootAndroidBp(` 45 platform_systemserverclasspath { 46 name: "platform-systemserverclasspath", 47 } 48 `), 49 ).RunTest(t) 50 51 p := result.Module("platform-systemserverclasspath", "android_common").(*platformSystemServerClasspathModule) 52 android.AssertStringEquals(t, "output filepath", "systemserverclasspath.pb", p.ClasspathFragmentBase.outputFilepath.Base()) 53 android.AssertPathRelativeToTopEquals(t, "install filepath", "out/soong/target/product/test_device/system/etc/classpaths", p.ClasspathFragmentBase.installDirPath) 54} 55 56func TestPlatformSystemServerClasspathModule_AndroidMkEntries(t *testing.T) { 57 preparer := android.GroupFixturePreparers( 58 prepareForTestWithSystemServerClasspath, 59 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"}, 81 "LOCAL_INSTALLED_MODULE_STEM": {"systemserverclasspath.pb"}, 82 // Output and Install paths are tested separately in TestPlatformSystemServerClasspath_ClasspathFragmentPaths 83 } 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} 98 99func TestSystemServerClasspathFragmentWithoutContents(t *testing.T) { 100 prepareForTestWithSystemServerClasspath. 101 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( 102 `\QEither contents or standalone_contents needs to be non-empty\E`)). 103 RunTestWithBp(t, ` 104 systemserverclasspath_fragment { 105 name: "systemserverclasspath-fragment", 106 } 107 `) 108} 109