blob: 3b05f9013a33eeb57a6ef7d25e102777ea726fc3 [file] [log] [blame]
Ulya Trafimovich5f364b62020-06-30 12:39:01 +01001#!/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
Ulya Trafimovich8130c482020-10-07 15:17:13 +010030contexts = [
31 '--host-context-for-sdk', '28', 'PCL[out/zdir/z.jar]',
32 '--target-context-for-sdk', '28', 'PCL[/system/z.jar]',
33 '--host-context-for-sdk', '29', 'PCL[out/xdir/x.jar]#PCL[out/ydir/y.jar]',
34 '--target-context-for-sdk', '29', 'PCL[/system/x.jar]#PCL[/product/y.jar]',
35 '--host-context-for-sdk', 'any', 'PCL[out/adir/a.jar]#PCL[out/bdir/b.jar]',
36 '--target-context-for-sdk', 'any', 'PCL[/system/a.jar]#PCL[/product/b.jar]',
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010037]
38
39class ConstructContextTest(unittest.TestCase):
40 def test_construct_context_28(self):
Ulya Trafimovich8130c482020-10-07 15:17:13 +010041 args = ['--target-sdk-version', '28'] + contexts
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010042 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]'
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010046 '#PCL[out/bdir/b.jar]}'
47 ' ; '
48 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/x.jar]'
49 '#PCL[/product/y.jar]'
50 '#PCL[/system/a.jar]'
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010051 '#PCL[/product/b.jar]}')
52 self.assertEqual(result, expect)
53
54 def test_construct_context_29(self):
Ulya Trafimovich8130c482020-10-07 15:17:13 +010055 args = ['--target-sdk-version', '29'] + contexts
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010056 result = construct_contexts(args)
57 expect = ('class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/adir/a.jar]'
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010058 '#PCL[out/bdir/b.jar]}'
59 ' ; '
60 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/a.jar]'
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010061 '#PCL[/product/b.jar]}')
62 self.assertEqual(result, expect)
63
64 def test_construct_context_S(self):
Ulya Trafimovich8130c482020-10-07 15:17:13 +010065 args = ['--target-sdk-version', 'S'] + contexts
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010066 result = construct_contexts(args)
67 expect = ('class_loader_context_arg=--class-loader-context=PCL[]{PCL[out/adir/a.jar]'
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010068 '#PCL[out/bdir/b.jar]}'
69 ' ; '
70 'stored_class_loader_context_arg=--stored-class-loader-context=PCL[]{PCL[/system/a.jar]'
Ulya Trafimovich5f364b62020-06-30 12:39:01 +010071 '#PCL[/product/b.jar]}')
72 self.assertEqual(result, expect)
73
74if __name__ == '__main__':
75 unittest.main(verbosity=2)