Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 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 | |
| 19 | import sys |
| 20 | import unittest |
| 21 | |
| 22 | import construct_context as cc |
| 23 | |
| 24 | sys.dont_write_bytecode = True |
| 25 | |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 26 | |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 27 | def construct_contexts(arglist): |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 28 | args = cc.parse_args(arglist) |
| 29 | return cc.construct_contexts(args) |
| 30 | |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 31 | |
Ulya Trafimovich | 8130c48 | 2020-10-07 15:17:13 +0100 | [diff] [blame] | 32 | contexts = [ |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 33 | '--host-context-for-sdk', |
| 34 | '28', |
| 35 | 'PCL[out/zdir/z.jar]', |
| 36 | '--target-context-for-sdk', |
| 37 | '28', |
| 38 | 'PCL[/system/z.jar]', |
| 39 | '--host-context-for-sdk', |
| 40 | '29', |
| 41 | 'PCL[out/xdir/x.jar]#PCL[out/ydir/y.jar]', |
| 42 | '--target-context-for-sdk', |
| 43 | '29', |
| 44 | 'PCL[/system/x.jar]#PCL[/product/y.jar]', |
| 45 | '--host-context-for-sdk', |
| 46 | 'any', |
| 47 | 'PCL[out/adir/a.jar]#PCL[out/bdir/b.jar]', |
| 48 | '--target-context-for-sdk', |
| 49 | 'any', |
| 50 | 'PCL[/system/a.jar]#PCL[/product/b.jar]', |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 51 | ] |
| 52 | |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 53 | #pylint: disable=line-too-long |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 54 | class ConstructContextTest(unittest.TestCase): |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 55 | |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 56 | def test_construct_context_28(self): |
| 57 | args = ['--target-sdk-version', '28'] + contexts |
| 58 | result = construct_contexts(args) |
| 59 | expect = ( |
| 60 | 'class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/xdir/x.jar]#PCL[out/ydir/y.jar]#PCL[out/adir/a.jar]#PCL[out/bdir/b.jar]}' |
| 61 | ' ; ' |
| 62 | 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/x.jar]#PCL[/product/y.jar]#PCL[/system/a.jar]#PCL[/product/b.jar]}') |
| 63 | self.assertEqual(result, expect) |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 64 | |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 65 | def test_construct_context_29(self): |
| 66 | args = ['--target-sdk-version', '29'] + contexts |
| 67 | result = construct_contexts(args) |
| 68 | expect = ( |
| 69 | 'class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/adir/a.jar]#PCL[out/bdir/b.jar]}' |
| 70 | ' ; ' |
| 71 | 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/a.jar]#PCL[/product/b.jar]}') |
| 72 | self.assertEqual(result, expect) |
| 73 | |
| 74 | def test_construct_context_S(self): |
| 75 | args = ['--target-sdk-version', 'S'] + contexts |
| 76 | result = construct_contexts(args) |
| 77 | expect = ( |
| 78 | 'class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/adir/a.jar]#PCL[out/bdir/b.jar]}' |
| 79 | ' ; ' |
| 80 | 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/a.jar]#PCL[/product/b.jar]}') |
| 81 | self.assertEqual(result, expect) |
| 82 | #pylint: enable=line-too-long |
Ulya Trafimovich | 5f364b6 | 2020-06-30 12:39:01 +0100 | [diff] [blame] | 83 | |
| 84 | if __name__ == '__main__': |
Spandan Das | ec555f1 | 2021-08-25 18:42:40 +0000 | [diff] [blame^] | 85 | unittest.main(verbosity=2) |