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. 14load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") 15load("//build/bazel/rules/android:manifest_fixer_internal.bzl", manifest_fixer_for_testing = "manifest_fixer_internal") 16load("//build/bazel/rules/common:api.bzl", "api") 17 18def _target_sdk_version_override_test_impl(ctx): 19 env = unittest.begin(ctx) 20 platform_sdk_codename = "Tiramisu" 21 platform_sdk_version = "33" 22 platform_version_active_codenames = [platform_sdk_codename] 23 24 # Schema: (Input targetSdkVersion, PlatformSdkFinal, Is unbundled app build) -> Expected targetSdkVersion 25 _VERSIONS_UNDER_TEST = { 26 ("29", False, False): "29", 27 ("30", False, True): "30", 28 ("current", False, True): str(api.FUTURE_API_LEVEL), 29 ("30", True, False): "30", 30 ("30", True, True): "30", 31 ("Tiramisu", True, True): "33", 32 ("current", True, True): "33", 33 } 34 for (target_sdk_version, platform_sdk_final, is_unbundled_app_build), expected_target_sdk_version in _VERSIONS_UNDER_TEST.items(): 35 platform_sdk_variables = struct( 36 platform_sdk_codename = platform_sdk_codename, 37 platform_sdk_final = platform_sdk_final, 38 platform_sdk_version = platform_sdk_version, 39 platform_version_active_codenames = platform_version_active_codenames, 40 ) 41 asserts.equals( 42 env, 43 expected_target_sdk_version, 44 manifest_fixer_for_testing.target_sdk_version_for_manifest_fixer( 45 target_sdk_version, 46 platform_sdk_variables, 47 is_unbundled_app_build, 48 ), 49 ("unexpected target SDK version for manifest fixer %s with input target" + 50 "SDK version %s, platform SDK variables %s and is_unbundled_app_build %s") % ( 51 expected_target_sdk_version, 52 target_sdk_version, 53 platform_sdk_variables, 54 is_unbundled_app_build, 55 ), 56 ) 57 return unittest.end(env) 58 59target_sdk_version_override_test = unittest.make(_target_sdk_version_override_test_impl) 60 61def manifest_fixer_test_suite(name): 62 unittest.suite( 63 name, 64 target_sdk_version_override_test, 65 ) 66