Daniel Norman | 6d82fa3 | 2019-03-22 17:53:04 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 17 | import os.path |
| 18 | |
Daniel Norman | 6d82fa3 | 2019-03-22 17:53:04 -0700 | [diff] [blame] | 19 | import test_utils |
| 20 | from merge_target_files import ( |
| 21 | read_config_list, validate_config_lists, default_system_item_list, |
| 22 | default_other_item_list, default_system_misc_info_keys) |
| 23 | |
| 24 | |
| 25 | class MergeTargetFilesTest(test_utils.ReleaseToolsTestCase): |
| 26 | |
| 27 | def setUp(self): |
| 28 | self.testdata_dir = test_utils.get_testdata_dir() |
| 29 | |
| 30 | def test_read_config_list(self): |
| 31 | system_item_list_file = os.path.join(self.testdata_dir, |
| 32 | 'merge_config_system_item_list') |
| 33 | system_item_list = read_config_list(system_item_list_file) |
| 34 | expected_system_item_list = [ |
| 35 | 'META/apkcerts.txt', |
| 36 | 'META/filesystem_config.txt', |
| 37 | 'META/root_filesystem_config.txt', |
| 38 | 'META/system_manifest.xml', |
| 39 | 'META/system_matrix.xml', |
| 40 | 'META/update_engine_config.txt', |
| 41 | 'PRODUCT/*', |
| 42 | 'ROOT/*', |
| 43 | 'SYSTEM/*', |
| 44 | ] |
| 45 | self.assertItemsEqual(system_item_list, expected_system_item_list) |
| 46 | |
| 47 | def test_validate_config_lists_ReturnsFalseIfMissingDefaultItem(self): |
| 48 | system_item_list = default_system_item_list[:] |
| 49 | system_item_list.remove('SYSTEM/*') |
| 50 | self.assertFalse( |
| 51 | validate_config_lists(system_item_list, default_system_misc_info_keys, |
| 52 | default_other_item_list)) |
| 53 | |
| 54 | def test_validate_config_lists_ReturnsTrueIfDefaultItemInDifferentList(self): |
| 55 | system_item_list = default_system_item_list[:] |
| 56 | system_item_list.remove('ROOT/*') |
| 57 | other_item_list = default_other_item_list[:] |
| 58 | other_item_list.append('ROOT/*') |
| 59 | self.assertTrue( |
| 60 | validate_config_lists(system_item_list, default_system_misc_info_keys, |
| 61 | other_item_list)) |
| 62 | |
| 63 | def test_validate_config_lists_ReturnsTrueIfExtraItem(self): |
| 64 | system_item_list = default_system_item_list[:] |
| 65 | system_item_list.append('MY_NEW_PARTITION/*') |
| 66 | self.assertTrue( |
| 67 | validate_config_lists(system_item_list, default_system_misc_info_keys, |
| 68 | default_other_item_list)) |
| 69 | |
| 70 | def test_validate_config_lists_ReturnsFalseIfBadSystemMiscInfoKeys(self): |
| 71 | for bad_key in ['dynamic_partition_list', 'super_partition_groups']: |
| 72 | system_misc_info_keys = default_system_misc_info_keys[:] |
| 73 | system_misc_info_keys.append(bad_key) |
| 74 | self.assertFalse( |
| 75 | validate_config_lists(default_system_item_list, system_misc_info_keys, |
| 76 | default_other_item_list)) |