1 /*
2  * Copyright (C) 2020 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.classifier;
18 
19 import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.mockito.ArgumentMatchers.anyDouble;
24 import static org.mockito.ArgumentMatchers.anyInt;
25 
26 import android.testing.AndroidTestingRunner;
27 import android.view.MotionEvent;
28 
29 import androidx.test.filters.SmallTest;
30 
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 
36 @SmallTest
37 @RunWith(AndroidTestingRunner.class)
38 public class PointerCountClassifierTest extends ClassifierTest {
39 
40     private FalsingClassifier mClassifier;
41 
42     @Before
setup()43     public void setup() {
44         super.setup();
45         mClassifier = new PointerCountClassifier(getDataProvider());
46     }
47 
48     @After
tearDown()49     public void tearDown() {
50         super.tearDown();
51     }
52 
53     @Test
testPass_noPointer()54     public void testPass_noPointer() {
55         assertThat(mClassifier.classifyGesture(anyInt(), anyDouble(), anyDouble()).isFalse())
56                 .isFalse();
57     }
58 
59     @Test
testPass_singlePointer()60     public void testPass_singlePointer() {
61         mClassifier.onTouchEvent(appendDownEvent(1, 1));
62         assertThat(mClassifier.classifyGesture(anyInt(), anyDouble(), anyDouble()).isFalse())
63                 .isFalse();
64     }
65 
66     @Test
testFail_multiPointer()67     public void testFail_multiPointer() {
68         MotionEvent.PointerProperties[] pointerProperties =
69                 MotionEvent.PointerProperties.createArray(2);
70         pointerProperties[0].id = 0;
71         pointerProperties[1].id = 1;
72         MotionEvent.PointerCoords[] pointerCoords = MotionEvent.PointerCoords.createArray(2);
73         MotionEvent motionEvent = MotionEvent.obtain(
74                 1, 1, MotionEvent.ACTION_DOWN, 2, pointerProperties, pointerCoords, 0, 0, 0, 0, 0,
75                 0,
76                 0, 0);
77         mClassifier.onTouchEvent(motionEvent);
78         motionEvent.recycle();
79         assertThat(mClassifier.classifyGesture(Classifier.GENERIC, 0.5, 1).isFalse())
80                 .isTrue();
81     }
82 
83     @Test
testPass_multiPointerDragDown()84     public void testPass_multiPointerDragDown() {
85         MotionEvent.PointerProperties[] pointerProperties =
86                 MotionEvent.PointerProperties.createArray(2);
87         pointerProperties[0].id = 0;
88         pointerProperties[1].id = 1;
89         MotionEvent.PointerCoords[] pointerCoords = MotionEvent.PointerCoords.createArray(2);
90         MotionEvent motionEvent = MotionEvent.obtain(
91                 1, 1, MotionEvent.ACTION_DOWN, 2, pointerProperties, pointerCoords, 0, 0, 0, 0, 0,
92                 0,
93                 0, 0);
94         mClassifier.onTouchEvent(motionEvent);
95         motionEvent.recycle();
96         assertThat(mClassifier.classifyGesture(QUICK_SETTINGS, 0.5, 0).isFalse()).isFalse();
97     }
98 }
99