blob: f5bf49942b7a7c7c45ccae6bc2ab5b17f570bf99 [file] [log] [blame]
Remi NGUYEN VAN11f162b2022-05-24 16:47:33 +09001# Copyright (C) 2022 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#
15# Licensed under the Apache License, Version 2.0 (the "License");
16# you may not use this file except in compliance with the License.
17# You may obtain a copy of the License at
18#
19# http://www.apache.org/licenses/LICENSE-2.0
20#
21# Unless required by applicable law or agreed to in writing, software
22# distributed under the License is distributed on an "AS IS" BASIS,
23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24# See the License for the specific language governing permissions and
25# limitations under the License.
26
27import gen_jarjar
28import unittest
29
30
31class TestGenJarjar(unittest.TestCase):
32 def test_gen_rules(self):
33 args = gen_jarjar.parse_arguments([
Remi NGUYEN VAN0bd90f12022-08-10 20:15:46 +090034 "jarjar-rules-generator-testjavalib.jar",
Remi NGUYEN VAN11f162b2022-05-24 16:47:33 +090035 "--prefix", "jarjar.prefix",
36 "--output", "test-output-rules.txt",
37 "--apistubs", "framework-connectivity.stubs.module_lib.jar",
Remi NGUYEN VAN0bd90f12022-08-10 20:15:46 +090038 "--unsupportedapi", ":testdata/test-unsupportedappusage.txt",
Remi NGUYEN VAN11f162b2022-05-24 16:47:33 +090039 "--excludes", "testdata/test-jarjar-excludes.txt",
40 ])
41 gen_jarjar.make_jarjar_rules(args)
42
43 with open(args.output) as out:
44 lines = out.readlines()
45
Remi NGUYEN VAN0bd90f12022-08-10 20:15:46 +090046 self.maxDiff = None
47 self.assertListEqual([
48 'rule android.net.IpSecTransform jarjar.prefix.@0\n',
49 'rule android.net.IpSecTransformTest jarjar.prefix.@0\n',
50 'rule android.net.IpSecTransformTest$* jarjar.prefix.@0\n',
51 'rule test.unsupportedappusage.OtherUnsupportedUsageClass jarjar.prefix.@0\n',
52 'rule test.unsupportedappusage.OtherUnsupportedUsageClassTest jarjar.prefix.@0\n',
53 'rule test.unsupportedappusage.OtherUnsupportedUsageClassTest$* jarjar.prefix.@0\n',
54 'rule test.utils.TestUtilClass jarjar.prefix.@0\n',
55 'rule test.utils.TestUtilClassTest jarjar.prefix.@0\n',
56 'rule test.utils.TestUtilClassTest$* jarjar.prefix.@0\n',
57 'rule test.utils.TestUtilClass$TestInnerClass jarjar.prefix.@0\n',
58 'rule test.utils.TestUtilClass$TestInnerClassTest jarjar.prefix.@0\n',
59 'rule test.utils.TestUtilClass$TestInnerClassTest$* jarjar.prefix.@0\n'
60 ], lines)
61
62 def test_gen_rules_repeated_args(self):
63 args = gen_jarjar.parse_arguments([
64 "jarjar-rules-generator-testjavalib.jar",
65 "--prefix", "jarjar.prefix",
66 "--output", "test-output-rules.txt",
67 "--apistubs", "framework-connectivity.stubs.module_lib.jar",
68 "--apistubs", "framework-connectivity-t.stubs.module_lib.jar",
69 "--unsupportedapi",
70 "testdata/test-unsupportedappusage.txt:testdata/test-other-unsupportedappusage.txt",
71 "--excludes", "testdata/test-jarjar-excludes.txt",
72 ])
73 gen_jarjar.make_jarjar_rules(args)
74
75 with open(args.output) as out:
76 lines = out.readlines()
77
78 self.maxDiff = None
Remi NGUYEN VAN11f162b2022-05-24 16:47:33 +090079 self.assertListEqual([
80 'rule test.utils.TestUtilClass jarjar.prefix.@0\n',
81 'rule test.utils.TestUtilClassTest jarjar.prefix.@0\n',
82 'rule test.utils.TestUtilClassTest$* jarjar.prefix.@0\n',
83 'rule test.utils.TestUtilClass$TestInnerClass jarjar.prefix.@0\n',
84 'rule test.utils.TestUtilClass$TestInnerClassTest jarjar.prefix.@0\n',
85 'rule test.utils.TestUtilClass$TestInnerClassTest$* jarjar.prefix.@0\n'], lines)
86
87
88if __name__ == '__main__':
89 # Need verbosity=2 for the test results parser to find results
90 unittest.main(verbosity=2)