Home | History | Annotate | Download | only in quicksearchbox
      1 /*
      2  * Copyright (C) 2010 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.quicksearchbox;
     18 
     19 import junit.framework.Assert;
     20 
     21 /**
     22  * Test utilities for {@link ShortcutCursor}.
     23  */
     24 public class SuggestionCursorUtil extends Assert {
     25 
     26     public static void assertNoSuggestions(SuggestionCursor suggestions) {
     27         assertNoSuggestions("", suggestions);
     28     }
     29 
     30     public static void assertNoSuggestions(String message, SuggestionCursor suggestions) {
     31         assertNotNull(suggestions);
     32         assertEquals(message, 0, suggestions.getCount());
     33     }
     34 
     35     public static void assertSameSuggestion(String message, int position,
     36             SuggestionCursor expected, SuggestionCursor observed) {
     37         message +=  " at position " + position;
     38         expected.moveTo(position);
     39         observed.moveTo(position);
     40         assertEquals(message + ", source", expected.getSuggestionSource(),
     41                 observed.getSuggestionSource());
     42         assertEquals(message + ", shortcutId", expected.getShortcutId(),
     43                 observed.getShortcutId());
     44         assertEquals(message + ", spinnerWhileRefreshing", expected.isSpinnerWhileRefreshing(),
     45                 observed.isSpinnerWhileRefreshing());
     46         assertEquals(message + ", format", expected.getSuggestionFormat(),
     47                 observed.getSuggestionFormat());
     48         assertEquals(message + ", icon1", expected.getSuggestionIcon1(),
     49                 observed.getSuggestionIcon1());
     50         assertEquals(message + ", icon2", expected.getSuggestionIcon2(),
     51                 observed.getSuggestionIcon2());
     52         assertEquals(message + ", text1", expected.getSuggestionText1(),
     53                 observed.getSuggestionText1());
     54         assertEquals(message + ", text2", expected.getSuggestionText2(),
     55                 observed.getSuggestionText2());
     56         assertEquals(message + ", text2Url", expected.getSuggestionText2Url(),
     57                 observed.getSuggestionText2Url());
     58         assertEquals(message + ", action", expected.getSuggestionIntentAction(),
     59                 observed.getSuggestionIntentAction());
     60         assertEquals(message + ", data", expected.getSuggestionIntentDataString(),
     61                 observed.getSuggestionIntentDataString());
     62         assertEquals(message + ", extraData", expected.getSuggestionIntentExtraData(),
     63                 observed.getSuggestionIntentExtraData());
     64         assertEquals(message + ", query", expected.getSuggestionQuery(),
     65                 observed.getSuggestionQuery());
     66         assertEquals(message + ", displayQuery", expected.getSuggestionDisplayQuery(),
     67                 observed.getSuggestionDisplayQuery());
     68         assertEquals(message + ", logType", expected.getSuggestionLogType(),
     69                 observed.getSuggestionLogType());
     70     }
     71 
     72     public static void assertSameSuggestions(SuggestionCursor expected, SuggestionCursor observed) {
     73         assertSameSuggestions("", expected, observed);
     74     }
     75 
     76     public static void assertSameSuggestions(
     77             String message, SuggestionCursor expected, SuggestionCursor observed) {
     78         assertNotNull(expected);
     79         assertNotNull(message, observed);
     80         assertEquals(message + ", count", expected.getCount(), observed.getCount());
     81         assertEquals(message + ", userQuery", expected.getUserQuery(), observed.getUserQuery());
     82         int count = expected.getCount();
     83         for (int i = 0; i < count; i++) {
     84             assertSameSuggestion(message, i, expected, observed);
     85         }
     86     }
     87 
     88     public static ListSuggestionCursor slice(SuggestionCursor cursor, int start, int length) {
     89         ListSuggestionCursor out = new ListSuggestionCursor(cursor.getUserQuery());
     90         for (int i = start; i < start + length; i++) {
     91             out.add(new SuggestionPosition(cursor, i));
     92         }
     93         return out;
     94     }
     95 }
     96