use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBWriterTest method testMoveQueueItem.
public void testMoveQueueItem() throws InterruptedException, ExecutionException, TimeoutException {
final int NUM_ITEMS = 10;
Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<>());
for (int i = 0; i < NUM_ITEMS; i++) {
FeedItem item = new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.PLAYED, feed);
feed.getItems().add(item);
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
for (FeedItem item : feed.getItems()) {
assertTrue(item.getId() != 0);
}
for (int from = 0; from < NUM_ITEMS; from++) {
for (int to = 0; to < NUM_ITEMS; to++) {
if (from == to) {
continue;
}
Log.d(TAG, String.format("testMoveQueueItem: From=%d, To=%d", from, to));
final long fromID = feed.getItems().get(from).getId();
adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setQueue(feed.getItems());
adapter.close();
DBWriter.moveQueueItem(from, to, false).get(TIMEOUT, TimeUnit.SECONDS);
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor queue = adapter.getQueueIDCursor();
assertTrue(queue.getCount() == NUM_ITEMS);
assertTrue(queue.moveToPosition(from));
assertFalse(queue.getLong(0) == fromID);
assertTrue(queue.moveToPosition(to));
assertTrue(queue.getLong(0) == fromID);
queue.close();
adapter.close();
}
}
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBWriterTest method playbackHistorySetup.
private FeedMedia playbackHistorySetup(Date playbackCompletionDate) {
final Context context = getInstrumentation().getTargetContext();
Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<FeedItem>());
FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
FeedMedia media = new FeedMedia(0, item, 10, 0, 1, "mime", null, "url", false, playbackCompletionDate, 0, 0);
feed.getItems().add(item);
item.setMedia(media);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
assertTrue(media.getId() != 0);
return media;
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class MainActivityTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Context context = getInstrumentation().getTargetContext();
uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
// create new database
PodDBAdapter.init(context);
PodDBAdapter.deleteDatabase();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
// override first launch preference
// do this BEFORE calling getActivity()!
prefs = getInstrumentation().getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit();
solo = new Solo(getInstrumentation(), getActivity());
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBWriterTest method testClearQueue.
public void testClearQueue() throws InterruptedException, ExecutionException, TimeoutException {
final int NUM_ITEMS = 10;
Feed feed = queueTestSetupMultipleItems(NUM_ITEMS);
DBWriter.clearQueue().get(TIMEOUT, TimeUnit.SECONDS);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor cursor = adapter.getQueueIDCursor();
assertFalse(cursor.moveToFirst());
cursor.close();
adapter.close();
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBWriterTest method testAddItemToPlaybackHistoryAlreadyPlayed.
public void testAddItemToPlaybackHistoryAlreadyPlayed() throws ExecutionException, InterruptedException, TimeoutException {
final long OLD_DATE = 0;
FeedMedia media = playbackHistorySetup(new Date(OLD_DATE));
DBWriter.addItemToPlaybackHistory(media).get(TIMEOUT, TimeUnit.SECONDS);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
media = DBReader.getFeedMedia(media.getId());
adapter.close();
assertNotNull(media);
assertNotNull(media.getPlaybackCompletionDate());
assertFalse(OLD_DATE == media.getPlaybackCompletionDate().getTime());
}
Aggregations