blob: a744b976aa71500a9d60975a9bd9fc22394df744 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001# Copyright 2015 The Bazel Authors. All rights reserved.
Alex Humeskya4ecde62015-05-21 17:08:42 +00002#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Unit tests for stubify_application_manifest."""
16
17import unittest
18from xml.etree import ElementTree
19
20from tools.android.build_split_manifest import BuildSplitManifest
21
22
23MAIN_MANIFEST = """
24<manifest
25 xmlns:android="http://schemas.android.com/apk/res/android"
26 package="com.google.package"
27 android:versionCode="1"
28 android:versionName="1.0">
29</manifest>
30"""
31
Alex Humesky3632f302017-01-26 23:05:28 +000032NO_VERSION_MANIFEST = """
33<manifest
34 xmlns:android="http://schemas.android.com/apk/res/android"
35 package="com.google.package" >
36</manifest>
37"""
38
Alex Humeskya4ecde62015-05-21 17:08:42 +000039
40class BuildSplitManifestTest(unittest.TestCase):
41
42 def testNoPackageOveride(self):
43 split = BuildSplitManifest(MAIN_MANIFEST, None, "split", False)
44 manifest = ElementTree.fromstring(split)
45 self.assertEqual("com.google.package",
46 manifest.get("package"))
47
48 def testPackageOveride(self):
49 split = BuildSplitManifest(MAIN_MANIFEST, "package.other", "split", False)
50 manifest = ElementTree.fromstring(split)
51 self.assertEqual("package.other",
52 manifest.get("package"))
53
54 def testSplitName(self):
55 split = BuildSplitManifest(MAIN_MANIFEST, None, "my.little.splony", False)
56 manifest = ElementTree.fromstring(split)
57 self.assertEqual("my.little.splony", manifest.get("split"))
58
Alex Humesky3632f302017-01-26 23:05:28 +000059 def testManifestWithNoVersion(self):
60 split = BuildSplitManifest(NO_VERSION_MANIFEST, None, "split", False)
61 manifest = ElementTree.fromstring(split)
62 self.assertEqual(None, manifest.get("android:versionCode"))
63 self.assertEqual(None, manifest.get("android:versionName"))
64
Alex Humeskya4ecde62015-05-21 17:08:42 +000065
66if __name__ == "__main__":
67 unittest.main()