1# Copyright (C) 2023 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 15load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 16load(":sdk_library.bzl", "JavaSdkLibraryInfo", "java_sdk_library") 17 18def _basic_java_sdk_library_test_impl(ctx): 19 env = analysistest.begin(ctx) 20 java_sdk_library_target = analysistest.target_under_test(env) 21 22 asserts.true( 23 env, 24 java_sdk_library_target[JavaSdkLibraryInfo].public.is_source, 25 "Public api surface file should be source, not generated", 26 ) 27 28 asserts.equals( 29 env, 30 expected = "public.txt", 31 actual = java_sdk_library_target[JavaSdkLibraryInfo].public.basename, 32 msg = "Public api surface file not correct", 33 ) 34 35 asserts.true( 36 env, 37 java_sdk_library_target[JavaSdkLibraryInfo].system.is_source, 38 "System api surface file should be source, not generated", 39 ) 40 41 asserts.equals( 42 env, 43 expected = "system.txt", 44 actual = java_sdk_library_target[JavaSdkLibraryInfo].system.basename, 45 msg = "System api surface file not correct", 46 ) 47 48 asserts.true( 49 env, 50 java_sdk_library_target[JavaSdkLibraryInfo].test.is_source, 51 "Test api surface file should be source, not generated", 52 ) 53 54 asserts.equals( 55 env, 56 expected = "test.txt", 57 actual = java_sdk_library_target[JavaSdkLibraryInfo].test.basename, 58 msg = "Test api surface file not correct", 59 ) 60 61 asserts.true( 62 env, 63 java_sdk_library_target[JavaSdkLibraryInfo].module_lib.is_source, 64 "Module_lib api surface file should be source, not generated", 65 ) 66 67 asserts.equals( 68 env, 69 expected = "module_lib.txt", 70 actual = java_sdk_library_target[JavaSdkLibraryInfo].module_lib.basename, 71 msg = "Module_lib api surface file not correct", 72 ) 73 74 asserts.true( 75 env, 76 java_sdk_library_target[JavaSdkLibraryInfo].system_server.is_source, 77 "System_server api surface file should be source, not generated", 78 ) 79 80 asserts.equals( 81 env, 82 expected = "system_server.txt", 83 actual = java_sdk_library_target[JavaSdkLibraryInfo].system_server.basename, 84 msg = "System_server api surface file not correct", 85 ) 86 87 return analysistest.end(env) 88 89basic_java_sdk_library_test = analysistest.make( 90 _basic_java_sdk_library_test_impl, 91) 92 93def test_checked_in_api_surface_files(): 94 name = "checked_in_api_surface_files_test" 95 java_sdk_library( 96 name = name + "_target", 97 public = "public.txt", 98 system = "system.txt", 99 test = "test.txt", 100 module_lib = "module_lib.txt", 101 system_server = "system_server.txt", 102 ) 103 basic_java_sdk_library_test( 104 name = name, 105 target_under_test = name + "_target", 106 ) 107 return name 108 109def java_sdk_library_test_suite(name): 110 native.test_suite( 111 name = name, 112 tests = [ 113 test_checked_in_api_surface_files(), 114 ], 115 ) 116