diff options
author | 2018-08-28 12:41:01 +0100 | |
---|---|---|
committer | 2018-08-28 12:41:01 +0100 | |
commit | d5b74996be65b6628549c18b838b1d6cffc6231e (patch) | |
tree | e2f309c52f0e6903dd09650c7f8cef053aa1d310 /scripts/manifest_fixer_test.py | |
parent | 4bd15d36e75a783ed305a8bf1cc2e90fdfb3d3cf (diff) |
Support setting android:usesNonSdkApi in manifest_fixer.py
Add new command line flag to manifest_fixer.py which will add
'android:usesNonSdkApi="true"' attribute to the <application> tag.
Bug: 113315999
Test: build/soong/scripts/manifest_fixer.py
Change-Id: If030c90a4ced3f5c5176727c579a87d0ecab6cf8
Diffstat (limited to 'scripts/manifest_fixer_test.py')
-rwxr-xr-x | scripts/manifest_fixer_test.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py index 590899719..ac72e6d44 100755 --- a/scripts/manifest_fixer_test.py +++ b/scripts/manifest_fixer_test.py @@ -310,5 +310,39 @@ class AddUsesLibrariesTest(unittest.TestCase): self.assertEqual(output, expected) +class AddUsesNonSdkApiTest(unittest.TestCase): + """Unit tests for add_uses_libraries function.""" + + def run_test(self, input_manifest): + doc = minidom.parseString(input_manifest) + manifest_fixer.add_uses_non_sdk_api(doc) + output = StringIO.StringIO() + manifest_fixer.write_xml(output, doc) + return output.getvalue() + + manifest_tmpl = ( + '<?xml version="1.0" encoding="utf-8"?>\n' + '<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n' + ' <application%s/>\n' + '</manifest>\n') + + def uses_non_sdk_api(self, value): + return ' android:usesNonSdkApi="true"' if value else '' + + def test_set_true(self): + """Empty new_uses_libraries must not touch the manifest.""" + manifest_input = self.manifest_tmpl % self.uses_non_sdk_api(False) + expected = self.manifest_tmpl % self.uses_non_sdk_api(True) + output = self.run_test(manifest_input) + self.assertEqual(output, expected) + + def test_already_set(self): + """new_uses_libraries must not overwrite existing tags.""" + manifest_input = self.manifest_tmpl % self.uses_non_sdk_api(True) + expected = manifest_input + output = self.run_test(manifest_input) + self.assertEqual(output, expected) + + if __name__ == '__main__': unittest.main() |