blob: 951d4c4a7c143565790fb820d9d8be8970b26c23 [file] [log] [blame]
Zhomart Mukhamejanov72a4d462018-04-26 15:49:08 -07001#!/usr/bin/env python3
2#
3# Copyright (C) 2018 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"""
18Tests gen_update_config.py
19"""
20
21import os.path
22import unittest
23from gen_update_config import GenUpdateConfig
24
25
26class GenUpdateConfigTest(unittest.TestCase): # pylint: disable=missing-docstring
27
28 def test_ab_install_type_streaming(self):
29 """tests if streaming property files' offset and size are generated properly"""
30 config, package = self._generate_config()
31 property_files = config['ab_streaming_metadata']['property_files']
32 self.assertEqual(len(property_files), 5)
33 with open(package, 'rb') as pkg_file:
34 for prop in property_files:
35 filename, offset, size = prop['filename'], prop['offset'], prop['size']
36 pkg_file.seek(offset)
37 data = pkg_file.read(size).decode('ascii')
38 # data in the archive are just uppercase filenames without extension
39 expected_data = filename.split('.')[0].upper()
40 self.assertEqual(data, expected_data)
41
42 @staticmethod
43 def _generate_config():
44 """Generates JSON config from ota_002_package.zip."""
45 ota_package = os.path.join(os.path.dirname(__file__),
46 '../tests/res/raw/ota_002_package.zip')
47 gen = GenUpdateConfig(ota_package,
48 'file:///foo.bar',
49 GenUpdateConfig.AB_INSTALL_TYPE_STREAMING)
50 gen.run()
51 return gen.config, ota_package
52
53
54if __name__ == '__main__':
55 unittest.main()