1#!/usr/bin/env python 2# 3# Copyright (C) 2020 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17"""Unit tests for construct_context.py.""" 18 19import sys 20import unittest 21 22import construct_context as cc 23 24sys.dont_write_bytecode = True 25 26def construct_contexts(arglist): 27 args = cc.parse_args(arglist) 28 return cc.construct_contexts(args) 29 30classpaths = [ 31 '--host-classpath-for-sdk', '28', 'out/zdir/z.jar', 32 '--target-classpath-for-sdk', '28', '/system/z.jar', 33 '--host-classpath-for-sdk', '29', 'out/xdir/x.jar:out/ydir/y.jar', 34 '--target-classpath-for-sdk', '29', '/system/x.jar:/product/y.jar', 35 '--host-classpath-for-sdk', 'any', 'out/adir/a.jar:out/android.hidl.manager-V1.0-java.jar:out/bdir/b.jar', 36 '--target-classpath-for-sdk', 'any', '/system/a.jar:/system/android.hidl.manager-V1.0-java.jar:/product/b.jar', 37] 38 39class ConstructContextTest(unittest.TestCase): 40 def test_construct_context_28(self): 41 args = ['--target-sdk-version', '28'] + classpaths 42 result = construct_contexts(args) 43 expect = ('class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/xdir/x.jar]' 44 '#PCL[out/ydir/y.jar]' 45 '#PCL[out/adir/a.jar]' 46 '#PCL[out/android.hidl.manager-V1.0-java.jar]{PCL[out/android.hidl.base-V1.0-java.jar]}' 47 '#PCL[out/bdir/b.jar]}' 48 ' ; ' 49 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/x.jar]' 50 '#PCL[/product/y.jar]' 51 '#PCL[/system/a.jar]' 52 '#PCL[/system/android.hidl.manager-V1.0-java.jar]{PCL[/system/android.hidl.base-V1.0-java.jar]}' 53 '#PCL[/product/b.jar]}') 54 self.assertEqual(result, expect) 55 56 def test_construct_context_29(self): 57 args = ['--target-sdk-version', '29'] + classpaths 58 result = construct_contexts(args) 59 expect = ('class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/adir/a.jar]' 60 '#PCL[out/android.hidl.manager-V1.0-java.jar]{PCL[out/android.hidl.base-V1.0-java.jar]}' 61 '#PCL[out/bdir/b.jar]}' 62 ' ; ' 63 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/a.jar]' 64 '#PCL[/system/android.hidl.manager-V1.0-java.jar]{PCL[/system/android.hidl.base-V1.0-java.jar]}' 65 '#PCL[/product/b.jar]}') 66 self.assertEqual(result, expect) 67 68 def test_construct_context_S(self): 69 args = ['--target-sdk-version', 'S'] + classpaths 70 result = construct_contexts(args) 71 expect = ('class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/adir/a.jar]' 72 '#PCL[out/android.hidl.manager-V1.0-java.jar]{PCL[out/android.hidl.base-V1.0-java.jar]}' 73 '#PCL[out/bdir/b.jar]}' 74 ' ; ' 75 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/a.jar]' 76 '#PCL[/system/android.hidl.manager-V1.0-java.jar]{PCL[/system/android.hidl.base-V1.0-java.jar]}' 77 '#PCL[/product/b.jar]}') 78 self.assertEqual(result, expect) 79 80if __name__ == '__main__': 81 unittest.main(verbosity=2) 82