blob: 90afdc7d149fcae43e468dd6e5961cb56ea2b3ff [file] [log] [blame]
Tao Baoa7054ee2017-12-08 14:42:16 -08001#
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17from __future__ import print_function
18
19import unittest
20
21from sign_target_files_apks import EditTags, RewriteProps
22
23
24class SignTargetFilesApksTest(unittest.TestCase):
25
26 def test_EditTags(self):
27 self.assertEqual(EditTags('dev-keys'), ('release-keys'))
28 self.assertEqual(EditTags('test-keys'), ('release-keys'))
29
30 # Multiple tags.
31 self.assertEqual(EditTags('abc,dev-keys,xyz'), ('abc,release-keys,xyz'))
32
33 # Tags are sorted.
34 self.assertEqual(EditTags('xyz,abc,dev-keys,xyz'), ('abc,release-keys,xyz'))
35
36 def test_RewriteProps(self):
37 props = (
38 ('', '\n'),
39 ('ro.build.fingerprint=foo/bar/dev-keys',
40 'ro.build.fingerprint=foo/bar/release-keys\n'),
41 ('ro.build.thumbprint=foo/bar/dev-keys',
42 'ro.build.thumbprint=foo/bar/release-keys\n'),
43 ('ro.vendor.build.fingerprint=foo/bar/dev-keys',
44 'ro.vendor.build.fingerprint=foo/bar/release-keys\n'),
45 ('ro.vendor.build.thumbprint=foo/bar/dev-keys',
46 'ro.vendor.build.thumbprint=foo/bar/release-keys\n'),
47 ('# comment line 1', '# comment line 1\n'),
48 ('ro.bootimage.build.fingerprint=foo/bar/dev-keys',
49 'ro.bootimage.build.fingerprint=foo/bar/release-keys\n'),
50 ('ro.build.description='
51 'sailfish-user 8.0.0 OPR6.170623.012 4283428 dev-keys',
52 'ro.build.description='
53 'sailfish-user 8.0.0 OPR6.170623.012 4283428 release-keys\n'),
54 ('ro.build.tags=dev-keys', 'ro.build.tags=release-keys\n'),
55 ('# comment line 2', '# comment line 2\n'),
56 ('ro.build.display.id=OPR6.170623.012 dev-keys',
57 'ro.build.display.id=OPR6.170623.012\n'),
58 ('# comment line 3', '# comment line 3\n'),
59 )
60
61 # Assert the case for each individual line.
62 for input, output in props:
63 self.assertEqual(RewriteProps(input), output)
64
65 # Concatenate all the input lines.
66 self.assertEqual(RewriteProps('\n'.join([prop[0] for prop in props])),
67 ''.join([prop[1] for prop in props]))