• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.launcher3.allapps;
17 
18 import android.content.ComponentName;
19 import android.test.InstrumentationTestCase;
20 
21 import com.android.launcher3.AppInfo;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 /**
27  * Unit tests for {@link DefaultAppSearchAlgorithm}
28  */
29 public class DefaultAppSearchAlgorithmTest extends InstrumentationTestCase {
30 
31     private List<AppInfo> mAppsList;
32     private DefaultAppSearchAlgorithm mAlgorithm;
33 
34     @Override
setUp()35     protected void setUp() throws Exception {
36         super.setUp();
37         mAppsList = new ArrayList<>();
38         getInstrumentation().runOnMainSync(new Runnable() {
39             @Override
40             public void run() {
41                 mAlgorithm = new DefaultAppSearchAlgorithm(mAppsList);
42             }
43         });
44     }
45 
testMatches()46     public void testMatches() {
47         assertTrue(mAlgorithm.matches(getInfo("white cow"), "cow"));
48         assertTrue(mAlgorithm.matches(getInfo("whiteCow"), "cow"));
49         assertTrue(mAlgorithm.matches(getInfo("whiteCOW"), "cow"));
50         assertTrue(mAlgorithm.matches(getInfo("whitecowCOW"), "cow"));
51         assertTrue(mAlgorithm.matches(getInfo("white2cow"), "cow"));
52 
53         assertFalse(mAlgorithm.matches(getInfo("whitecow"), "cow"));
54         assertFalse(mAlgorithm.matches(getInfo("whitEcow"), "cow"));
55 
56         assertTrue(mAlgorithm.matches(getInfo("whitecowCow"), "cow"));
57         assertTrue(mAlgorithm.matches(getInfo("whitecow cow"), "cow"));
58         assertFalse(mAlgorithm.matches(getInfo("whitecowcow"), "cow"));
59         assertFalse(mAlgorithm.matches(getInfo("whit ecowcow"), "cow"));
60 
61         assertTrue(mAlgorithm.matches(getInfo("cats&dogs"), "dog"));
62         assertTrue(mAlgorithm.matches(getInfo("cats&Dogs"), "dog"));
63         assertTrue(mAlgorithm.matches(getInfo("cats&Dogs"), "&"));
64 
65         assertTrue(mAlgorithm.matches(getInfo("2+43"), "43"));
66         assertFalse(mAlgorithm.matches(getInfo("2+43"), "3"));
67 
68         assertTrue(mAlgorithm.matches(getInfo("Q"), "q"));
69         assertTrue(mAlgorithm.matches(getInfo("  Q"), "q"));
70 
71         // match lower case words
72         assertTrue(mAlgorithm.matches(getInfo("elephant"), "e"));
73 
74     }
75 
getInfo(String title)76     private AppInfo getInfo(String title) {
77         AppInfo info = new AppInfo();
78         info.title = title;
79         info.componentName = new ComponentName("Test", title);
80         return info;
81     }
82 }
83