1// Copyright 2023 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 bp2build 16 17import ( 18 "testing" 19 20 "android/soong/android" 21 "android/soong/java" 22) 23 24func runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { 25 t.Helper() 26 (&tc).ModuleTypeUnderTest = "java_host_for_device" 27 (&tc).ModuleTypeUnderTestFactory = java.HostForDeviceFactory 28 RunBp2BuildTestCase(t, registrationCtxFunc, tc) 29} 30 31func runJavaHostForDeviceTestCase(t *testing.T, tc Bp2buildTestCase) { 32 t.Helper() 33 runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) { 34 ctx.RegisterModuleType("java_library", java.LibraryFactory) 35 }) 36} 37 38func TestJavaHostForDevice(t *testing.T) { 39 runJavaHostForDeviceTestCase(t, Bp2buildTestCase{ 40 Description: "java_host_for_device test", 41 Blueprint: `java_host_for_device { 42 name: "java-lib-1", 43 libs: ["java-lib-2"], 44 bazel_module: { bp2build_available: true }, 45} 46 47java_library { 48 name: "java-lib-2", 49 srcs: ["b.java"], 50 bazel_module: { bp2build_available: true }, 51}`, 52 ExpectedBazelTargets: []string{ 53 MakeBazelTarget("java_host_for_device", "java-lib-1", AttrNameToString{ 54 "exports": `[":java-lib-2"]`, 55 }), 56 MakeNeverlinkDuplicateTargetWithAttrs("java_library", "java-lib-1", AttrNameToString{ 57 "sdk_version": `"none"`, 58 }), 59 MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{ 60 "srcs": `["b.java"]`, 61 }), 62 MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"), 63 }, 64 }) 65} 66