core/playlist: playlist_remove() can return a boolean
The collection will be using this soon to tell if a track was successfully unbanned. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
20825613e9
commit
3b5bbf14af
|
@ -115,10 +115,10 @@ bool playlist_add(enum playlist_t plist, struct track *track)
|
|||
return true;
|
||||
}
|
||||
|
||||
void playlist_remove(enum playlist_t plist, struct track *track)
|
||||
bool playlist_remove(enum playlist_t plist, struct track *track)
|
||||
{
|
||||
if (!track)
|
||||
return;
|
||||
if (!track || !playlist_has(plist, track))
|
||||
return false;
|
||||
|
||||
index_remove(&playlist_db, playlist_names[plist],
|
||||
track->tr_dbe.dbe_index);
|
||||
|
@ -126,11 +126,12 @@ void playlist_remove(enum playlist_t plist, struct track *track)
|
|||
queue_remove_all(&playlist_q, track);
|
||||
if (plist == PL_BANNED)
|
||||
queue_add(collection_get_queue(), track);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool playlist_has(enum playlist_t plist, struct track *track)
|
||||
{
|
||||
if (!track)
|
||||
if (!track || __playlist_is_dynamic(plist))
|
||||
return false;
|
||||
return index_has(&playlist_db, playlist_names[plist], track->tr_dbe.dbe_index);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ void playlist_fixup_collection();
|
|||
bool playlist_add(enum playlist_t, struct track *);
|
||||
|
||||
/* Called to remove a track from a playlist. */
|
||||
void playlist_remove(enum playlist_t, struct track *);
|
||||
bool playlist_remove(enum playlist_t, struct track *);
|
||||
|
||||
|
||||
/* Called to check if a specific track is in the playlist. */
|
||||
|
|
|
@ -79,27 +79,26 @@ static void test_remove()
|
|||
struct track *track = track_get(0);
|
||||
|
||||
/* The important thing here is that we don't crash */
|
||||
playlist_remove(PL_FAVORITED, NULL);
|
||||
test_equal(playlist_remove(PL_FAVORITED, NULL), (bool)false);
|
||||
|
||||
playlist_select(PL_FAVORITED);
|
||||
test_equal(queue_size(q), 2);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)true);
|
||||
playlist_remove(PL_FAVORITED, track);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)true);
|
||||
test_equal(playlist_remove(PL_FAVORITED, track), (bool)true);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(queue_size(q), 1);
|
||||
|
||||
playlist_remove(PL_FAVORITED, track);
|
||||
test_equal(playlist_remove(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(queue_size(q), 1);
|
||||
playlist_remove(PL_FAVORITED, track_get(1));
|
||||
test_equal(playlist_remove(PL_FAVORITED, track_get(1)), (bool)true);
|
||||
test_equal(queue_size(q), 0);
|
||||
|
||||
track = track_get(2);
|
||||
playlist_select(PL_BANNED);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_size(c), 12);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)true);
|
||||
playlist_remove(PL_BANNED, track);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)false);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)true);
|
||||
test_equal(playlist_remove(PL_BANNED, track), (bool)true);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)false);
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(queue_size(c), 13);
|
||||
}
|
||||
|
@ -107,19 +106,21 @@ static void test_remove()
|
|||
static void test_dynamic()
|
||||
{
|
||||
struct queue *q = playlist_get_queue();
|
||||
struct db_entry *track, *next;
|
||||
struct db_entry *dbe, *next;
|
||||
unsigned int i, average = 0;
|
||||
struct track *track;
|
||||
|
||||
/* Set play count to (track_number - 1) (average = 6) */
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
TRACK(track)->tr_count = TRACK(track)->tr_track - 1;
|
||||
average += TRACK(track)->tr_count;
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
TRACK(dbe)->tr_count = TRACK(dbe)->tr_track - 1;
|
||||
average += TRACK(dbe)->tr_count;
|
||||
}
|
||||
average /= track_db_get()->db_size;
|
||||
|
||||
/* Only one unplayed track (tr_track == 1) */
|
||||
playlist_select(PL_UNPLAYED);
|
||||
test_equal(playlist_add(PL_UNPLAYED, track_get(1)), (bool)false);
|
||||
test_equal(playlist_add(PL_UNPLAYED, track_get(1)), (bool)false);
|
||||
test_equal(playlist_remove(PL_UNPLAYED, queue_at(q, 0)), (bool)false);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_at(q, 0)->tr_track, 1);
|
||||
test_equal(queue_at(q, 0)->tr_count, 0);
|
||||
|
@ -129,8 +130,11 @@ static void test_dynamic()
|
|||
test_equal(playlist_add(PL_LEAST_PLAYED, track_get(0)), (bool)false);
|
||||
test_equal(queue_size(q), 5);
|
||||
for (i = 0; i < queue_size(q); i++) {
|
||||
test_loop_equal(queue_at(q, i)->tr_track, i + 2, i);
|
||||
test_loop_equal(queue_at(q, i)->tr_count, i + 1, i);
|
||||
track = queue_at(q, i);
|
||||
test_loop_equal(track->tr_track, i + 2, i);
|
||||
test_loop_equal(track->tr_count, i + 1, i);
|
||||
test_loop_equal(playlist_remove(PL_LEAST_PLAYED, track),
|
||||
(bool)false, i);
|
||||
} test_loop_passed();
|
||||
|
||||
/* Six tracks have tr_count > average */
|
||||
|
@ -138,8 +142,11 @@ static void test_dynamic()
|
|||
test_equal(playlist_add(PL_MOST_PLAYED, track_get(0)), (bool)false);
|
||||
test_equal(queue_size(q), 6);
|
||||
for (i = 0; i < queue_size(q); i++) {
|
||||
test_loop_equal(queue_at(q, i)->tr_track, i + 8, i);
|
||||
test_loop_equal(queue_at(q, i)->tr_count, i + 7, i);
|
||||
track = queue_at(q, i);
|
||||
test_loop_equal(track->tr_track, i + 8, i);
|
||||
test_loop_equal(track->tr_count, i + 7, i);
|
||||
test_loop_equal(playlist_remove(PL_MOST_PLAYED, track),
|
||||
(bool)false, i);
|
||||
} test_loop_passed();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue