use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method testGetFeedListSortOrder.
public void testGetFeedListSortOrder() {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
Feed feed1 = new Feed(0, null, "A", "link", "d", null, null, null, "rss", "A", null, "", "", true);
Feed feed2 = new Feed(0, null, "b", "link", "d", null, null, null, "rss", "b", null, "", "", true);
Feed feed3 = new Feed(0, null, "C", "link", "d", null, null, null, "rss", "C", null, "", "", true);
Feed feed4 = new Feed(0, null, "d", "link", "d", null, null, null, "rss", "d", null, "", "", true);
adapter.setCompleteFeed(feed1);
adapter.setCompleteFeed(feed2);
adapter.setCompleteFeed(feed3);
adapter.setCompleteFeed(feed4);
assertTrue(feed1.getId() != 0);
assertTrue(feed2.getId() != 0);
assertTrue(feed3.getId() != 0);
assertTrue(feed4.getId() != 0);
adapter.close();
List<Feed> saved = DBReader.getFeedList();
assertNotNull(saved);
assertEquals("Wrong size: ", 4, saved.size());
assertEquals("Wrong id of feed 1: ", feed1.getId(), saved.get(0).getId());
assertEquals("Wrong id of feed 2: ", feed2.getId(), saved.get(1).getId());
assertEquals("Wrong id of feed 3: ", feed3.getId(), saved.get(2).getId());
assertEquals("Wrong id of feed 4: ", feed4.getId(), saved.get(3).getId());
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method saveDownloadedItems.
private List<FeedItem> saveDownloadedItems(int numItems) {
if (numItems <= 0) {
throw new IllegalArgumentException("numItems<=0");
}
List<Feed> feeds = saveFeedlist(numItems, numItems, true);
List<FeedItem> items = new ArrayList<>();
for (Feed f : feeds) {
items.addAll(f.getItems());
}
List<FeedItem> downloaded = new ArrayList<>();
Random random = new Random();
while (downloaded.size() < numItems) {
int i = random.nextInt(numItems);
if (!downloaded.contains(items.get(i))) {
FeedItem item = items.get(i);
item.getMedia().setDownloaded(true);
item.getMedia().setFile_url("file" + i);
downloaded.add(item);
}
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setFeedItemlist(downloaded);
adapter.close();
return downloaded;
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class PlaybackServiceMediaPlayerTest method writeTestPlayable.
private Playable writeTestPlayable(String downloadUrl, String fileUrl) {
final Context c = getInstrumentation().getTargetContext();
Feed f = new Feed(0, null, "f", "l", "d", null, null, null, null, "i", null, null, "l", false);
FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, null, null);
f.setPreferences(prefs);
f.setItems(new ArrayList<>());
FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f);
f.getItems().add(i);
FeedMedia media = new FeedMedia(0, i, 0, 0, 0, "audio/wav", fileUrl, downloadUrl, fileUrl != null, null, 0, 0);
i.setMedia(media);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(f);
assertTrue(media.getId() != 0);
adapter.close();
return media;
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class PlaybackServiceMediaPlayerTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
assertionError = null;
final Context context = getInstrumentation().getTargetContext();
// create new database
PodDBAdapter.init(context);
PodDBAdapter.deleteDatabase();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
httpServer = new HTTPBin();
httpServer.start();
File cacheDir = context.getExternalFilesDir("testFiles");
if (cacheDir == null)
cacheDir = context.getExternalFilesDir("testFiles");
File dest = new File(cacheDir, PLAYABLE_DEST_URL);
assertNotNull(cacheDir);
assertTrue(cacheDir.canWrite());
assertTrue(cacheDir.canRead());
if (!dest.exists()) {
InputStream i = getInstrumentation().getContext().getAssets().open("testfile.mp3");
OutputStream o = new FileOutputStream(new File(cacheDir, PLAYABLE_DEST_URL));
IOUtils.copy(i, o);
o.flush();
o.close();
i.close();
}
PLAYABLE_LOCAL_URL = "file://" + dest.getAbsolutePath();
assertEquals(0, httpServer.serveFile(dest));
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class PlaybackServiceTaskManagerTest 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();
}
Aggregations