OSDN Git Service

DO NOT MERGE. Grant MMS Uri permissions as the calling UID.
[android-x86/frameworks-base.git] / packages / SystemUI / tests / src / com / android / systemui / phone / DozeParametersTests.java
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16
17 package com.android.systemui.phone;
18
19 import com.android.systemui.statusbar.phone.DozeParameters.IntInOutMatcher;
20
21 import android.test.AndroidTestCase;
22 import android.test.suitebuilder.annotation.SmallTest;
23
24 @SmallTest
25 public class DozeParametersTests extends AndroidTestCase {
26
27     public void test_inOutMatcher_defaultIn() {
28         IntInOutMatcher intInOutMatcher = new IntInOutMatcher("*");
29
30         assertTrue(intInOutMatcher.isIn(1));
31         assertTrue(intInOutMatcher.isIn(-1));
32         assertTrue(intInOutMatcher.isIn(0));
33     }
34
35     public void test_inOutMatcher_defaultOut() {
36         IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!*");
37
38         assertFalse(intInOutMatcher.isIn(1));
39         assertFalse(intInOutMatcher.isIn(-1));
40         assertFalse(intInOutMatcher.isIn(0));
41     }
42
43     public void test_inOutMatcher_someIn() {
44         IntInOutMatcher intInOutMatcher = new IntInOutMatcher("1,2,3,!*");
45
46         assertTrue(intInOutMatcher.isIn(1));
47         assertTrue(intInOutMatcher.isIn(2));
48         assertTrue(intInOutMatcher.isIn(3));
49
50         assertFalse(intInOutMatcher.isIn(0));
51         assertFalse(intInOutMatcher.isIn(4));
52     }
53
54     public void test_inOutMatcher_someOut() {
55         IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,!2,!3,*");
56
57         assertFalse(intInOutMatcher.isIn(1));
58         assertFalse(intInOutMatcher.isIn(2));
59         assertFalse(intInOutMatcher.isIn(3));
60
61         assertTrue(intInOutMatcher.isIn(0));
62         assertTrue(intInOutMatcher.isIn(4));
63     }
64
65     public void test_inOutMatcher_mixed() {
66         IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,2,!3,*");
67
68         assertFalse(intInOutMatcher.isIn(1));
69         assertTrue(intInOutMatcher.isIn(2));
70         assertFalse(intInOutMatcher.isIn(3));
71
72         assertTrue(intInOutMatcher.isIn(0));
73         assertTrue(intInOutMatcher.isIn(4));
74     }
75
76     public void test_inOutMatcher_failEmpty() {
77         try {
78             new IntInOutMatcher("");
79             fail("Expected IllegalArgumentException");
80         } catch (IllegalArgumentException e) {
81             // expected
82         }
83     }
84
85     public void test_inOutMatcher_failNull() {
86         try {
87             new IntInOutMatcher(null);
88             fail("Expected IllegalArgumentException");
89         } catch (IllegalArgumentException e) {
90             // expected
91         }
92     }
93
94     public void test_inOutMatcher_failEmptyClause() {
95         try {
96             new IntInOutMatcher("!1,*,");
97             fail("Expected IllegalArgumentException");
98         } catch (IllegalArgumentException e) {
99             // expected
100         }
101     }
102
103     public void test_inOutMatcher_failDuplicate() {
104         try {
105             new IntInOutMatcher("!1,*,!1");
106             fail("Expected IllegalArgumentException");
107         } catch (IllegalArgumentException e) {
108             // expected
109         }
110     }
111
112     public void test_inOutMatcher_failDuplicateDefault() {
113         try {
114             new IntInOutMatcher("!1,*,*");
115             fail("Expected IllegalArgumentException");
116         } catch (IllegalArgumentException e) {
117             // expected
118         }
119     }
120
121     public void test_inOutMatcher_failMalformedNot() {
122         try {
123             new IntInOutMatcher("!,*");
124             fail("Expected IllegalArgumentException");
125         } catch (IllegalArgumentException e) {
126             // expected
127         }
128     }
129
130     public void test_inOutMatcher_failText() {
131         try {
132             new IntInOutMatcher("!abc,*");
133             fail("Expected IllegalArgumentException");
134         } catch (IllegalArgumentException e) {
135             // expected
136         }
137     }
138
139     public void test_inOutMatcher_failContradiction() {
140         try {
141             new IntInOutMatcher("1,!1,*");
142             fail("Expected IllegalArgumentException");
143         } catch (IllegalArgumentException e) {
144             // expected
145         }
146     }
147
148     public void test_inOutMatcher_failContradictionDefault() {
149         try {
150             new IntInOutMatcher("1,*,!*");
151             fail("Expected IllegalArgumentException");
152         } catch (IllegalArgumentException e) {
153             // expected
154         }
155     }
156
157     public void test_inOutMatcher_failMissingDefault() {
158         try {
159             new IntInOutMatcher("1");
160             fail("Expected IllegalArgumentException");
161         } catch (IllegalArgumentException e) {
162             // expected
163         }
164     }
165
166 }