use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBCleanupTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
context = getInstrumentation().getTargetContext();
destFolder = context.getExternalCacheDir();
cleanupDestFolder(destFolder);
assertNotNull(destFolder);
assertTrue(destFolder.exists());
assertTrue(destFolder.canWrite());
// create new database
PodDBAdapter.init(context);
PodDBAdapter.deleteDatabase();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
prefEdit.putString(UserPreferences.PREF_EPISODE_CACHE_SIZE, Integer.toString(EPISODE_CACHE_SIZE));
prefEdit.putString(UserPreferences.PREF_EPISODE_CLEANUP, Integer.toString(cleanupAlgorithm));
prefEdit.commit();
UserPreferences.init(context);
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBCleanupTests method populateItems.
protected void populateItems(final int numItems, Feed feed, List<FeedItem> items, List<File> files, int itemState, boolean addToQueue, boolean addToFavorites) throws IOException {
for (int i = 0; i < numItems; i++) {
Date itemDate = new Date(numItems - i);
Date playbackCompletionDate = null;
if (itemState == FeedItem.PLAYED) {
playbackCompletionDate = itemDate;
}
FeedItem item = new FeedItem(0, "title", "id", "link", itemDate, itemState, feed);
File f = new File(destFolder, "file " + i);
assertTrue(f.createNewFile());
files.add(f);
item.setMedia(new FeedMedia(0, item, 1, 0, 1L, "m", f.getAbsolutePath(), "url", true, playbackCompletionDate, 0, 0));
items.add(item);
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
if (addToQueue) {
adapter.setQueue(items);
}
if (addToFavorites) {
adapter.setFavorites(items);
}
adapter.close();
assertTrue(feed.getId() != 0);
for (FeedItem item : items) {
assertTrue(item.getId() != 0);
assertTrue(item.getMedia().getId() != 0);
}
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBNullCleanupAlgorithmTest method testPerformAutoCleanupShouldNotDelete.
/**
* A test with no items in the queue, but multiple items downloaded.
* The null algorithm should never delete any items, even if they're played and not in the queue.
* @throws IOException
*/
@FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDelete() throws IOException {
final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
Feed feed = new Feed("url", null, "title");
List<FeedItem> items = new ArrayList<>();
feed.setItems(items);
List<File> files = new ArrayList<>();
for (int i = 0; i < NUM_ITEMS; i++) {
FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
File f = new File(destFolder, "file " + i);
assertTrue(f.createNewFile());
files.add(f);
item.setMedia(new FeedMedia(0, item, 1, 0, 1L, "m", f.getAbsolutePath(), "url", true, new Date(NUM_ITEMS - i), 0, 0));
items.add(item);
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
assertTrue(feed.getId() != 0);
for (FeedItem item : items) {
assertTrue(item.getId() != 0);
assertTrue(item.getMedia().getId() != 0);
}
DBTasks.performAutoCleanup(context);
for (int i = 0; i < files.size(); i++) {
assertTrue(files.get(i).exists());
}
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class PlaybackSonicTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
context = getInstrumentation().getTargetContext();
PodDBAdapter.init(context);
PodDBAdapter.deleteDatabase();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().clear().putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false).putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).putBoolean(UserPreferences.PREF_SONIC, true).commit();
solo = new Solo(getInstrumentation(), getActivity());
uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
// create database
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class PlaybackTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
context = getInstrumentation().getTargetContext();
PodDBAdapter.init(context);
PodDBAdapter.deleteDatabase();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().clear().putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false).putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).commit();
solo = new Solo(getInstrumentation(), getActivity());
uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
// create database
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
}
Aggregations