blob: 27c48d3802ce582ed30a8a3c1cf72989c0f18db4 [file] [log] [blame]
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.provider.cts;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.UserDictionary;
import android.test.AndroidTestCase;
import java.util.ArrayList;
import java.util.Locale;
/**
* NOTE: user dictionary is now accessible only by the current spellchecker and keyboard, so this
* test make sure they are not accessible by apps.
*/
public class UserDictionary_WordsTest extends AndroidTestCase {
private ContentResolver mContentResolver;
private ArrayList<Uri> mAddedBackup;
private static final String[] WORDS_PROJECTION = new String[] {
UserDictionary.Words._ID,
UserDictionary.Words.WORD,
UserDictionary.Words.FREQUENCY,
UserDictionary.Words.LOCALE };
private static final int ID_INDEX = 0;
private static final int WORD_INDEX = 1;
private static final int FREQUENCY_INDEX = 2;
private static final int LOCALE_INDEX = 3;
@Override
protected void setUp() throws Exception {
super.setUp();
mContentResolver = mContext.getContentResolver();
mAddedBackup = new ArrayList<Uri>();
}
@Override
protected void tearDown() throws Exception {
for (Uri row : mAddedBackup) {
mContentResolver.delete(row, null, null);
}
mAddedBackup.clear();
super.tearDown();
}
@SuppressWarnings("deprecation")
public void testAddWord_deprecated() throws Exception {
String word = "UserDictionary_WordsTest";
int frequency = 1;
UserDictionary.Words.addWord(getContext(), word, frequency,
UserDictionary.Words.LOCALE_TYPE_ALL);
Cursor cursor = mContentResolver.query(UserDictionary.Words.CONTENT_URI, WORDS_PROJECTION,
UserDictionary.Words.WORD + "='" + word + "'", null, null);
assertFalse("cursor is not empty", cursor.moveToFirst());
cursor.close();
}
public void testAddWord() throws Exception {
assertWord("testWord1", 42, null, Locale.KOREA, 42);
assertWord("testWord2", -3007, "tw2", Locale.JAPAN, 0);
assertWord("testWord3", 1337, "tw3", Locale.US, 255);
}
private void assertWord(String word, int frequency, String shortcut, Locale locale,
int expectedFrequency) {
UserDictionary.Words.addWord(mContext, word, frequency, shortcut, locale);
Cursor cursor = mContentResolver.query(UserDictionary.Words.CONTENT_URI, WORDS_PROJECTION,
UserDictionary.Words.WORD + "='" + word + "'", null, null);
assertFalse("cursor is not empty", cursor.moveToFirst());
cursor.close();
}
}