use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBWriterTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
// create new database
PodDBAdapter.init(getInstrumentation().getTargetContext());
PodDBAdapter.deleteDatabase();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class PlaybackServiceTaskManagerTest method writeTestQueue.
private List<FeedItem> writeTestQueue(String pref) {
final Context c = getInstrumentation().getTargetContext();
final int NUM_ITEMS = 10;
Feed f = new Feed(0, null, "title", "link", "d", null, null, null, null, "id", null, "null", "url", false);
f.setItems(new ArrayList<>());
for (int i = 0; i < NUM_ITEMS; i++) {
f.getItems().add(new FeedItem(0, pref + i, pref + i, "link", new Date(), FeedItem.PLAYED, f));
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(f);
adapter.setQueue(f.getItems());
adapter.close();
for (FeedItem item : f.getItems()) {
assertTrue(item.getId() != 0);
}
return f.getItems();
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBCleanupTests method testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia.
/**
* Reproduces a bug where DBTasks.performAutoCleanup(android.content.Context) would use the ID of the FeedItem in the
* call to DBWriter.deleteFeedMediaOfItem instead of the ID of the FeedMedia. This would cause the wrong item to be deleted.
* @throws IOException
*/
@FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue_withFeedsWithNoMedia() throws IOException {
// add feed with no enclosures so that item ID != media ID
saveFeedlist(1, 10, false);
// add candidate for performAutoCleanup
List<Feed> feeds = saveFeedlist(1, 1, true);
FeedMedia m = feeds.get(0).getItems().get(0).getMedia();
m.setDownloaded(true);
m.setFile_url("file");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setMedia(m);
adapter.close();
testPerformAutoCleanupShouldNotDeleteBecauseInQueue();
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBNullCleanupAlgorithmTest 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(UserPreferences.EPISODE_CLEANUP_NULL));
prefEdit.commit();
UserPreferences.init(context);
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method saveQueue.
private List<FeedItem> saveQueue(int numItems) {
if (numItems <= 0) {
throw new IllegalArgumentException("numItems<=0");
}
List<Feed> feeds = saveFeedlist(numItems, numItems, false);
List<FeedItem> allItems = new ArrayList<>();
for (Feed f : feeds) {
allItems.addAll(f.getItems());
}
// take random items from every feed
Random random = new Random();
List<FeedItem> queue = new ArrayList<>();
while (queue.size() < numItems) {
int index = random.nextInt(numItems);
if (!queue.contains(allItems.get(index))) {
queue.add(allItems.get(index));
}
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setQueue(queue);
adapter.close();
return queue;
}
Aggregations