1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from mozunit
import main
9 from mozbuild
.android_version_code
import (
10 android_version_code_v0
,
11 android_version_code_v1
,
15 class TestAndroidVersionCode(unittest
.TestCase
):
16 def test_android_version_code_v0(self
):
17 # From https://treeherder.mozilla.org/#/jobs?repo=mozilla-central&revision=e25de9972a77.
18 buildid
= "20150708104620"
20 arm_api11
= 2015070821
23 android_version_code_v0(
24 buildid
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
29 android_version_code_v0(
30 buildid
, cpu_arch
="armeabi-v7a", min_sdk
=11, max_sdk
=None
35 android_version_code_v0(buildid
, cpu_arch
="x86", min_sdk
=9, max_sdk
=None),
39 def test_android_version_code_v1(self
):
40 buildid
= "20150825141628"
41 arm_api16
= 0b01111000001000000001001001110001
42 arm64_api21
= 0b01111000001000000001001001110100
43 x86_api9
= 0b01111000001000000001001001110100
45 android_version_code_v1(
46 buildid
, cpu_arch
="armeabi-v7a", min_sdk
=16, max_sdk
=None
51 android_version_code_v1(
52 buildid
, cpu_arch
="arm64-v8a", min_sdk
=21, max_sdk
=None
57 android_version_code_v1(buildid
, cpu_arch
="x86", min_sdk
=9, max_sdk
=None),
61 def test_android_version_code_v1_underflow(self
):
62 """Verify that it is an error to ask for v1 codes predating the cutoff."""
63 buildid
= "201508010000" # Earliest possible.
64 arm_api9
= 0b01111000001000000000000000000000
66 android_version_code_v1(
67 buildid
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
71 with self
.assertRaises(ValueError) as cm
:
72 underflow
= "201507310000" # Latest possible (valid) underflowing date.
73 android_version_code_v1(
74 underflow
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
76 self
.assertTrue("underflow" in cm
.exception
.message
)
78 def test_android_version_code_v1_running_low(self
):
79 """Verify there is an informative message if one asks for v1
80 codes that are close to overflow."""
81 with self
.assertRaises(ValueError) as cm
:
82 overflow
= "20290801000000"
83 android_version_code_v1(
84 overflow
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
86 self
.assertTrue("Running out of low order bits" in cm
.exception
.message
)
88 def test_android_version_code_v1_overflow(self
):
89 """Verify that it is an error to ask for v1 codes that actually does overflow."""
90 with self
.assertRaises(ValueError) as cm
:
91 overflow
= "20310801000000"
92 android_version_code_v1(
93 overflow
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
95 self
.assertTrue("overflow" in cm
.exception
.message
)
97 def test_android_version_code_v0_relative_v1(self
):
98 """Verify that the first v1 code is greater than the equivalent v0 code."""
99 buildid
= "20150801000000"
101 android_version_code_v1(
102 buildid
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
104 android_version_code_v0(
105 buildid
, cpu_arch
="armeabi", min_sdk
=9, max_sdk
=None
110 if __name__
== "__main__":