blob: 59fc14d97bee409ace658c125f48598001028c81 [file] [log] [blame]
Adrian Roos5ed42b62018-12-19 17:10:22 +01001#!/usr/bin/env python
2
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the 'License');
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an 'AS IS' BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import unittest
18
19import apilint
20
21def cls(pkg, name):
22 return apilint.Class(apilint.Package(999, "package %s {" % pkg, None), 999,
23 "public final class %s {" % name, None)
24
25_ri = apilint._retry_iterator
26
27c1 = cls("android.app", "ActivityManager")
28c2 = cls("android.app", "Notification")
29c3 = cls("android.app", "Notification.Action")
30c4 = cls("android.graphics", "Bitmap")
31
32class UtilTests(unittest.TestCase):
33 def test_retry_iterator(self):
34 it = apilint._retry_iterator([1, 2, 3, 4])
35 self.assertEqual(it.next(), 1)
36 self.assertEqual(it.next(), 2)
37 self.assertEqual(it.next(), 3)
38 it.send("retry")
39 self.assertEqual(it.next(), 3)
40 self.assertEqual(it.next(), 4)
41 with self.assertRaises(StopIteration):
42 it.next()
43
44 def test_retry_iterator_one(self):
45 it = apilint._retry_iterator([1])
46 self.assertEqual(it.next(), 1)
47 it.send("retry")
48 self.assertEqual(it.next(), 1)
49 with self.assertRaises(StopIteration):
50 it.next()
51
52 def test_retry_iterator_one(self):
53 it = apilint._retry_iterator([1])
54 self.assertEqual(it.next(), 1)
55 it.send("retry")
56 self.assertEqual(it.next(), 1)
57 with self.assertRaises(StopIteration):
58 it.next()
59
60 def test_skip_to_matching_class_found(self):
61 it = _ri([c1, c2, c3, c4])
62 self.assertEquals(apilint._parse_to_matching_class(it, c3),
63 c3)
64 self.assertEqual(it.next(), c4)
65
66 def test_skip_to_matching_class_not_found(self):
67 it = _ri([c1, c2, c3, c4])
68 self.assertEquals(apilint._parse_to_matching_class(it, cls("android.content", "ContentProvider")),
69 None)
70 self.assertEqual(it.next(), c4)
71
72if __name__ == "__main__":
73 unittest.main()