| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "testing" | 
|  | 19 |  | 
|  | 20 | "android/soong/android" | 
|  | 21 | ) | 
|  | 22 |  | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 23 | var prepareForTestWithSystemServerClasspath = android.GroupFixturePreparers( | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 24 | PrepareForTestWithJavaDefaultModules, | 
|  | 25 | ) | 
|  | 26 |  | 
| satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 27 | func TestPlatformSystemServerClasspathVariant(t *testing.T) { | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 28 | result := android.GroupFixturePreparers( | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 29 | prepareForTestWithSystemServerClasspath, | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 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 |  | 
| satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 41 | func TestPlatformSystemServerClasspath_ClasspathFragmentPaths(t *testing.T) { | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 42 | result := android.GroupFixturePreparers( | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 43 | prepareForTestWithSystemServerClasspath, | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 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) | 
| satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 52 | android.AssertStringEquals(t, "output filepath", "systemserverclasspath.pb", p.ClasspathFragmentBase.outputFilepath.Base()) | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 53 | android.AssertPathRelativeToTopEquals(t, "install filepath", "out/soong/target/product/test_device/system/etc/classpaths", p.ClasspathFragmentBase.installDirPath) | 
|  | 54 | } | 
|  | 55 |  | 
| satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 56 | func TestPlatformSystemServerClasspathModule_AndroidMkEntries(t *testing.T) { | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 57 | preparer := android.GroupFixturePreparers( | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 58 | prepareForTestWithSystemServerClasspath, | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 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"}, | 
| satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 81 | "LOCAL_INSTALLED_MODULE_STEM": {"systemserverclasspath.pb"}, | 
|  | 82 | // Output and Install paths are tested separately in TestPlatformSystemServerClasspath_ClasspathFragmentPaths | 
| satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 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 | } | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 98 |  | 
| satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 99 | func TestSystemServerClasspathFragmentWithoutContents(t *testing.T) { | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 100 | prepareForTestWithSystemServerClasspath. | 
|  | 101 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( | 
| Jiakai Zhang | cee9e19 | 2021-10-29 19:46:45 +0000 | [diff] [blame] | 102 | `\QEither contents or standalone_contents needs to be non-empty\E`)). | 
| satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 103 | RunTestWithBp(t, ` | 
|  | 104 | systemserverclasspath_fragment { | 
|  | 105 | name: "systemserverclasspath-fragment", | 
|  | 106 | } | 
|  | 107 | `) | 
|  | 108 | } |