1# Lint as: python3
2#
3# Copyright (C) 2021 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"""Tests for target_file_handler."""
18
19import unittest
20from target_file_handler import *
21
22class BuildFileHandlerTest(unittest.TestCase):
23
24  def test_target_file_handler_get_hash(self):
25    """Test TargetFileHandler could get hash from target file."""
26    build_file = './testdata/base_build_target-files.zip'
27    handler = TargetFileHandler(build_file)
28    deqp_deps = ['/system/deqp_dependency_file_a.so', '/vendor/deqp_dependency_file_b.so',
29                 '/vendor/file_not_exists.so']
30    hash_dict = handler.get_file_hash(deqp_deps)
31
32    self.assertEqual(hash_dict['/system/deqp_dependency_file_a.so'],
33                     hash(b'placeholder\nplaceholder\n'))
34    self.assertEqual(hash_dict['/vendor/deqp_dependency_file_b.so'],
35                     hash(b'placeholder\nplaceholder\nplaceholder\n\n'))
36    self.assertEqual(len(hash_dict), 2)
37
38if __name__ == '__main__':
39  unittest.main()
40