diff options
Diffstat (limited to 'scripts/manifest_fixer_test.py')
-rwxr-xr-x | scripts/manifest_fixer_test.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py index f6fcaafe5..199b279cd 100755 --- a/scripts/manifest_fixer_test.py +++ b/scripts/manifest_fixer_test.py @@ -521,12 +521,55 @@ class AddNoCodeApplicationTest(unittest.TestCase): self.assert_xml_equal(output, manifest_input) def test_has_application_has_code_true(self): - """ Do nothing if there's already an application elemeent even if its + """ Do nothing if there's already an application element even if its hasCode attribute is true. """ manifest_input = self.manifest_tmpl % ' <application android:hasCode="true"/>\n' output = self.run_test(manifest_input) self.assert_xml_equal(output, manifest_input) +class AddTestOnlyApplicationTest(unittest.TestCase): + """Unit tests for set_test_only_flag_to_true function.""" + + def assert_xml_equal(self, output, expected): + self.assertEqual(ET.canonicalize(output), ET.canonicalize(expected)) + + def run_test(self, input_manifest): + doc = minidom.parseString(input_manifest) + manifest_fixer.set_test_only_flag_to_true(doc) + output = io.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' + '%s' + '</manifest>\n') + + def test_no_application(self): + manifest_input = self.manifest_tmpl % '' + expected = self.manifest_tmpl % ' <application android:testOnly="true"/>\n' + output = self.run_test(manifest_input) + self.assert_xml_equal(output, expected) + + def test_has_application_no_test_only(self): + manifest_input = self.manifest_tmpl % ' <application/>\n' + expected = self.manifest_tmpl % ' <application android:testOnly="true"/>\n' + output = self.run_test(manifest_input) + self.assert_xml_equal(output, expected) + + def test_has_application_test_only_true(self): + """ If there's already an application element.""" + manifest_input = self.manifest_tmpl % ' <application android:testOnly="true"/>\n' + output = self.run_test(manifest_input) + self.assert_xml_equal(output, manifest_input) + + def test_has_application_test_only_false(self): + """ If there's already an application element with the testOnly attribute as false.""" + manifest_input = self.manifest_tmpl % ' <application android:testOnly="false"/>\n' + output = self.run_test(manifest_input) + self.assert_xml_equal(output, manifest_input) + if __name__ == '__main__': unittest.main(verbosity=2) |