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 17package com.android.systemui.statusbar.phone; 18 19import android.support.test.runner.AndroidJUnit4; 20import android.test.suitebuilder.annotation.SmallTest; 21 22import com.android.systemui.SysuiTestCase; 23import com.android.systemui.statusbar.phone.DozeParameters.IntInOutMatcher; 24import org.junit.Test; 25import org.junit.runner.RunWith; 26 27import static junit.framework.Assert.assertTrue; 28import static junit.framework.Assert.assertFalse; 29import static junit.framework.Assert.fail; 30 31@SmallTest 32@RunWith(AndroidJUnit4.class) 33public class DozeParametersTest extends SysuiTestCase { 34 35 @Test 36 public void test_inOutMatcher_defaultIn() { 37 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("*"); 38 39 assertTrue(intInOutMatcher.isIn(1)); 40 assertTrue(intInOutMatcher.isIn(-1)); 41 assertTrue(intInOutMatcher.isIn(0)); 42 } 43 44 @Test 45 public void test_inOutMatcher_defaultOut() { 46 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!*"); 47 48 assertFalse(intInOutMatcher.isIn(1)); 49 assertFalse(intInOutMatcher.isIn(-1)); 50 assertFalse(intInOutMatcher.isIn(0)); 51 } 52 53 @Test 54 public void test_inOutMatcher_someIn() { 55 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("1,2,3,!*"); 56 57 assertTrue(intInOutMatcher.isIn(1)); 58 assertTrue(intInOutMatcher.isIn(2)); 59 assertTrue(intInOutMatcher.isIn(3)); 60 61 assertFalse(intInOutMatcher.isIn(0)); 62 assertFalse(intInOutMatcher.isIn(4)); 63 } 64 65 @Test 66 public void test_inOutMatcher_someOut() { 67 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,!2,!3,*"); 68 69 assertFalse(intInOutMatcher.isIn(1)); 70 assertFalse(intInOutMatcher.isIn(2)); 71 assertFalse(intInOutMatcher.isIn(3)); 72 73 assertTrue(intInOutMatcher.isIn(0)); 74 assertTrue(intInOutMatcher.isIn(4)); 75 } 76 77 @Test 78 public void test_inOutMatcher_mixed() { 79 IntInOutMatcher intInOutMatcher = new IntInOutMatcher("!1,2,!3,*"); 80 81 assertFalse(intInOutMatcher.isIn(1)); 82 assertTrue(intInOutMatcher.isIn(2)); 83 assertFalse(intInOutMatcher.isIn(3)); 84 85 assertTrue(intInOutMatcher.isIn(0)); 86 assertTrue(intInOutMatcher.isIn(4)); 87 } 88 89 @Test 90 public void test_inOutMatcher_failEmpty() { 91 try { 92 new IntInOutMatcher(""); 93 fail("Expected IllegalArgumentException"); 94 } catch (IllegalArgumentException e) { 95 // expected 96 } 97 } 98 99 @Test 100 public void test_inOutMatcher_failNull() { 101 try { 102 new IntInOutMatcher(null); 103 fail("Expected IllegalArgumentException"); 104 } catch (IllegalArgumentException e) { 105 // expected 106 } 107 } 108 109 @Test 110 public void test_inOutMatcher_failEmptyClause() { 111 try { 112 new IntInOutMatcher("!1,*,"); 113 fail("Expected IllegalArgumentException"); 114 } catch (IllegalArgumentException e) { 115 // expected 116 } 117 } 118 119 @Test 120 public void test_inOutMatcher_failDuplicate() { 121 try { 122 new IntInOutMatcher("!1,*,!1"); 123 fail("Expected IllegalArgumentException"); 124 } catch (IllegalArgumentException e) { 125 // expected 126 } 127 } 128 129 @Test 130 public void test_inOutMatcher_failDuplicateDefault() { 131 try { 132 new IntInOutMatcher("!1,*,*"); 133 fail("Expected IllegalArgumentException"); 134 } catch (IllegalArgumentException e) { 135 // expected 136 } 137 } 138 139 @Test 140 public void test_inOutMatcher_failMalformedNot() { 141 try { 142 new IntInOutMatcher("!,*"); 143 fail("Expected IllegalArgumentException"); 144 } catch (IllegalArgumentException e) { 145 // expected 146 } 147 } 148 149 @Test 150 public void test_inOutMatcher_failText() { 151 try { 152 new IntInOutMatcher("!abc,*"); 153 fail("Expected IllegalArgumentException"); 154 } catch (IllegalArgumentException e) { 155 // expected 156 } 157 } 158 159 @Test 160 public void test_inOutMatcher_failContradiction() { 161 try { 162 new IntInOutMatcher("1,!1,*"); 163 fail("Expected IllegalArgumentException"); 164 } catch (IllegalArgumentException e) { 165 // expected 166 } 167 } 168 169 @Test 170 public void test_inOutMatcher_failContradictionDefault() { 171 try { 172 new IntInOutMatcher("1,*,!*"); 173 fail("Expected IllegalArgumentException"); 174 } catch (IllegalArgumentException e) { 175 // expected 176 } 177 } 178 179 @Test 180 public void test_inOutMatcher_failMissingDefault() { 181 try { 182 new IntInOutMatcher("1"); 183 fail("Expected IllegalArgumentException"); 184 } catch (IllegalArgumentException e) { 185 // expected 186 } 187 } 188 189} 190