From c08f46fdfc5f20e000852c5f53d9010d8fd1ad14 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 18 Jun 2018 11:01:00 +0900 Subject: add --uses-library option to manifest_fixer.py `--uses-library foo` adds element to the manifest. When there is already a uses-library element with the same name, then the hand-written element is respected. Test: m -j Test: build/soong/scripts/manifest_fixer_test.py Change-Id: Ia5e989d3c3c3fba7cc9015a6d16dac70464282a8 --- scripts/manifest_fixer_test.py | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'scripts/manifest_fixer_test.py') diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py index ccfa8fbe9..54a3784a9 100755 --- a/scripts/manifest_fixer_test.py +++ b/scripts/manifest_fixer_test.py @@ -158,5 +158,92 @@ class RaiseMinSdkVersionTest(unittest.TestCase): self.assertEqual(output, expected) + +class AddUsesLibrariesTest(unittest.TestCase): + """Unit tests for add_uses_libraries function.""" + + def run_test(self, input_manifest, new_uses_libraries): + doc = minidom.parseString(input_manifest) + manifest_fixer.add_uses_libraries(doc, new_uses_libraries) + output = StringIO.StringIO() + manifest_fixer.write_xml(output, doc) + return output.getvalue() + + manifest_tmpl = ( + '\n' + '\n' + ' \n' + '%s' + ' \n' + '\n') + + def uses_libraries(self, name_required_pairs): + ret = '' + for name, required in name_required_pairs: + ret += ( + ' \n' + ) % (name, required) + + return ret + + def test_empty(self): + """Empty new_uses_libraries must not touch the manifest.""" + manifest_input = self.manifest_tmpl % self.uses_libraries([ + ('foo', 'true'), + ('bar', 'false')]) + expected = manifest_input + output = self.run_test(manifest_input, []) + self.assertEqual(output, expected) + + def test_not_overwrite(self): + """new_uses_libraries must not overwrite existing tags.""" + manifest_input = self.manifest_tmpl % self.uses_libraries([ + ('foo', 'true'), + ('bar', 'false')]) + expected = manifest_input + output = self.run_test(manifest_input, ['foo', 'bar']) + self.assertEqual(output, expected) + + def test_add(self): + """New names are added with 'required:true'.""" + manifest_input = self.manifest_tmpl % self.uses_libraries([ + ('foo', 'true'), + ('bar', 'false')]) + expected = self.manifest_tmpl % self.uses_libraries([ + ('foo', 'true'), + ('bar', 'false'), + ('baz', 'true'), + ('qux', 'true')]) + output = self.run_test(manifest_input, ['bar', 'baz', 'qux']) + self.assertEqual(output, expected) + + def test_no_application(self): + """When there is no tag, the tag is added.""" + manifest_input = ( + '\n' + '\n' + '\n') + expected = self.manifest_tmpl % self.uses_libraries([ + ('foo', 'true'), + ('bar', 'true')]) + output = self.run_test(manifest_input, ['foo', 'bar']) + self.assertEqual(output, expected) + + def test_empty_application(self): + """Even when here is an empty tag, the libs are added.""" + manifest_input = ( + '\n' + '\n' + ' \n' + '\n') + expected = self.manifest_tmpl % self.uses_libraries([ + ('foo', 'true'), + ('bar', 'true')]) + output = self.run_test(manifest_input, ['foo', 'bar']) + self.assertEqual(output, expected) + + if __name__ == '__main__': unittest.main() -- cgit v1.2.3-59-g8ed1b