1 /* 2 * Copyright (C) 2009 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 android.gesture.cts; 17 18 19 import android.gesture.Gesture; 20 import android.gesture.GestureLibrary; 21 import android.gesture.Prediction; 22 23 import java.util.ArrayList; 24 import java.util.Set; 25 26 /** 27 * Tests for {@link GestureLibrary}. 28 * <p/> 29 * Most {@link GestureLibrary} methods are tested by {@link GestureStorageTester} 30 */ 31 public class GestureLibraryTest extends GestureStorageTester { 32 33 private GestureLibrary mLibrary = null; 34 35 private static class GestureLibraryFacade implements GestureStorageAccessor { 36 37 private GestureLibrary mGestureLibrary; 38 39 public GestureLibraryFacade(GestureLibrary gestureLibrary) { 40 mGestureLibrary = gestureLibrary; 41 } 42 43 public void addGesture(String entryName, Gesture gesture) { 44 mGestureLibrary.addGesture(entryName, gesture); 45 } 46 47 public Set<String> getGestureEntries() { 48 return mGestureLibrary.getGestureEntries(); 49 } 50 51 public ArrayList<Gesture> getGestures(String entryName) { 52 return mGestureLibrary.getGestures(entryName); 53 } 54 55 public int getOrientationStyle() { 56 return mGestureLibrary.getOrientationStyle(); 57 } 58 59 public int getSequenceType() { 60 return mGestureLibrary.getSequenceType(); 61 } 62 63 public ArrayList<Prediction> recognize(Gesture gesture) { 64 return mGestureLibrary.recognize(gesture); 65 } 66 67 public void removeEntry(String entryName) { 68 mGestureLibrary.removeEntry(entryName); 69 } 70 71 public void removeGesture(String entryName, Gesture gesture) { 72 mGestureLibrary.removeGesture(entryName, gesture); 73 } 74 75 public void setOrientationStyle(int style) { 76 mGestureLibrary.setOrientationStyle(style); 77 } 78 79 public void setSequenceType(int type) { 80 mGestureLibrary.setSequenceType(type); 81 } 82 } 83 84 private static class GestureLibraryStub extends GestureLibrary { 85 86 @Override 87 public boolean load() { 88 throw new UnsupportedOperationException(); 89 } 90 91 @Override 92 public boolean save() { 93 throw new UnsupportedOperationException(); 94 } 95 } 96 97 @Override 98 protected GestureStorageAccessor createFixture() { 99 if (mLibrary == null) { 100 mLibrary = new GestureLibraryStub(); 101 } 102 return new GestureLibraryFacade(mLibrary); 103 } 104 105 /** 106 * Tests {@link GestureLibrary#isReadOnly()}. 107 * <p/> 108 * Verifies default is false. 109 */ 110 public void testIsReadOnly() { 111 assertFalse(mLibrary.isReadOnly()); 112 } 113 } 114