Make unit tests create temporary files in the cache directory.
Change-Id: I90791b364b441bc4e8e221d9e668372d15591719main
parent
035b260058
commit
6def28d1da
|
@ -188,7 +188,7 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
|
||||||
|
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
file = File.createTempFile("testReadAndWrite", ".dict");
|
file = File.createTempFile("testReadAndWrite", ".dict", getContext().getCacheDir());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, "IOException while creating a temporary file: " + e);
|
Log.d(TAG, "IOException while creating a temporary file: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import android.preference.PreferenceManager;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -76,34 +78,43 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRandomWords() {
|
public void testRandomWords() {
|
||||||
Log.d(TAG, "This test can be used for profiling.");
|
File dictFile = null;
|
||||||
Log.d(TAG, "Usage: please set UserHisotoryDictionary.PROFILE_SAVE_RESTORE to true.");
|
|
||||||
final int numberOfWords = 1000;
|
|
||||||
final Random random = new Random(123456);
|
|
||||||
List<String> words = generateWords(numberOfWords, random);
|
|
||||||
|
|
||||||
final String locale = "testRandomWords";
|
|
||||||
final UserHistoryDictionary dict = UserHistoryDictionary.getInstance(getContext(),
|
|
||||||
locale, mPrefs);
|
|
||||||
dict.isTest = true;
|
|
||||||
|
|
||||||
addToDict(dict, words);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "waiting for adding the word ...");
|
Log.d(TAG, "This test can be used for profiling.");
|
||||||
Thread.sleep(2000);
|
Log.d(TAG, "Usage: please set UserHisotoryDictionary.PROFILE_SAVE_RESTORE to true.");
|
||||||
} catch (InterruptedException e) {
|
final int numberOfWords = 1000;
|
||||||
Log.d(TAG, "InterruptedException: " + e);
|
final Random random = new Random(123456);
|
||||||
}
|
List<String> words = generateWords(numberOfWords, random);
|
||||||
|
|
||||||
// write to file
|
final String locale = "testRandomWords";
|
||||||
dict.close();
|
final String fileName = "UserHistoryDictionary." + locale + ".dict";
|
||||||
|
dictFile = new File(getContext().getFilesDir(), fileName);
|
||||||
|
final UserHistoryDictionary dict = UserHistoryDictionary.getInstance(getContext(),
|
||||||
|
locale, mPrefs);
|
||||||
|
dict.isTest = true;
|
||||||
|
|
||||||
try {
|
addToDict(dict, words);
|
||||||
Log.d(TAG, "waiting for writing ...");
|
|
||||||
Thread.sleep(5000);
|
try {
|
||||||
} catch (InterruptedException e) {
|
Log.d(TAG, "waiting for adding the word ...");
|
||||||
Log.d(TAG, "InterruptedException: " + e);
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.d(TAG, "InterruptedException: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// write to file
|
||||||
|
dict.close();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Log.d(TAG, "waiting for writing ...");
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.d(TAG, "InterruptedException: " + e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (dictFile != null) {
|
||||||
|
dictFile.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
|
||||||
final String message) {
|
final String message) {
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
file = File.createTempFile("runReadAndWrite", ".dict");
|
file = File.createTempFile("runReadAndWrite", ".dict", getContext().getCacheDir());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "IOException: " + e);
|
Log.e(TAG, "IOException: " + e);
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
|
||||||
final FormatSpec.FormatOptions formatOptions, final String message) {
|
final FormatSpec.FormatOptions formatOptions, final String message) {
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
file = File.createTempFile("runReadUnigrams", ".dict");
|
file = File.createTempFile("runReadUnigrams", ".dict", getContext().getCacheDir());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "IOException: " + e);
|
Log.e(TAG, "IOException: " + e);
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,8 @@ public class BinaryDictIOTests extends AndroidTestCase {
|
||||||
public void testGetTerminalPosition() {
|
public void testGetTerminalPosition() {
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
file = File.createTempFile("testGetTerminalPosition", ".dict");
|
file = File.createTempFile("testGetTerminalPosition", ".dict",
|
||||||
|
getContext().getCacheDir());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -561,7 +562,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
|
||||||
public void testDeleteWord() {
|
public void testDeleteWord() {
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
file = File.createTempFile("testDeleteWord", ".dict");
|
file = File.createTempFile("testDeleteWord", ".dict", getContext().getCacheDir());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue