core/playlist: Move playlist_remove() out of the playlist namespace
I also remove redundant unit tests. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
0e3d6251d3
commit
4e6028cf6e
|
@ -142,14 +142,19 @@ void playlist_add(const gchar *name, struct track *track)
|
|||
}
|
||||
}
|
||||
|
||||
void playlist :: del(struct track *track, const std::string &name)
|
||||
void playlist_remove(const gchar *name, struct track *track)
|
||||
{
|
||||
index_remove(&playlist_db, name.c_str(), track->tr_dbe.dbe_index);
|
||||
if (!track || !name)
|
||||
return;
|
||||
|
||||
if (playlist_has(name, track)) {
|
||||
index_remove(&playlist_db, name, track->tr_dbe.dbe_index);
|
||||
if (cur_plist == name)
|
||||
queue_remove_all(&playlist_q, track);
|
||||
if (name == "Banned")
|
||||
if (string_compare(name, "Banned") == 0)
|
||||
queue_add(collection_get_queue(), track);
|
||||
}
|
||||
}
|
||||
|
||||
bool playlist_has(const gchar *name, struct track *track)
|
||||
{
|
||||
|
|
|
@ -115,7 +115,7 @@ public:
|
|||
|
||||
tab_selected_ids(ids);
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
playlist :: del(track_get(ids[i]), cur);
|
||||
playlist_remove(cur.c_str(), track_get(ids[i]));
|
||||
return true;
|
||||
}
|
||||
} *p_tab;
|
||||
|
@ -131,7 +131,7 @@ static void on_ban()
|
|||
audio :: next();
|
||||
}
|
||||
} else
|
||||
playlist :: del(track, "Banned");
|
||||
playlist_remove("Banned", track);
|
||||
}
|
||||
|
||||
static void on_favorite()
|
||||
|
@ -140,7 +140,7 @@ static void on_favorite()
|
|||
if (o_fav->get_active())
|
||||
playlist_add("Favorites", track);
|
||||
else
|
||||
playlist :: del(track, "Favorites");
|
||||
playlist_remove("Favorites", track);
|
||||
}
|
||||
|
||||
static void playlist_added(struct queue *queue, unsigned int pos)
|
||||
|
|
|
@ -26,17 +26,6 @@ extern "C" {
|
|||
namespace playlist
|
||||
{
|
||||
|
||||
/**
|
||||
* Remove a track from a playlist.
|
||||
*
|
||||
* Tracks removed from the Banned playlist will be added back
|
||||
* to the library queue.
|
||||
*
|
||||
* @param track The track to remove.
|
||||
* @param name The name of the playlist to remove from.
|
||||
*/
|
||||
void del(struct track *, const std::string &);
|
||||
|
||||
/**
|
||||
* Use to access specific tracks in a playlist.
|
||||
*
|
||||
|
@ -57,6 +46,9 @@ void playlist_deinit();
|
|||
/* Called to add a track to a playlist. */
|
||||
void playlist_add(const gchar *, struct track *);
|
||||
|
||||
/* Called to remove a track from a playlist. */
|
||||
void playlist_remove(const gchar *, struct track *);
|
||||
|
||||
|
||||
/* Called to check if a specific track is in the playlist. */
|
||||
bool playlist_has(const gchar *, struct track *);
|
||||
|
|
|
@ -10,8 +10,6 @@ extern "C" {
|
|||
#include <core/playlist.h>
|
||||
#include "test.h"
|
||||
|
||||
static index_entry *IDX_NULL = NULL;
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
queue *q = playlist_get_queue();
|
||||
|
@ -77,6 +75,40 @@ static void test_add()
|
|||
test_equal(playlist_has("Banned", track), true);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_size(c), 12);
|
||||
}
|
||||
|
||||
static void test_remove()
|
||||
{
|
||||
struct queue *c = collection_get_queue();
|
||||
struct queue *q = playlist_get_queue();
|
||||
struct track *track = track_get(0);
|
||||
|
||||
/* The important thing here is that we don't crash */
|
||||
playlist_remove(NULL, track);
|
||||
playlist_remove("Favorites", NULL);
|
||||
playlist_remove("No Playlist", track);
|
||||
|
||||
playlist_select("Favorites");
|
||||
test_equal(queue_size(q), 2);
|
||||
test_equal(playlist_has("Favorites", track), true);
|
||||
playlist_remove("Favorites", track);
|
||||
test_equal(playlist_has("Favorites", track), false);
|
||||
test_equal(queue_size(q), 1);
|
||||
|
||||
playlist_remove("Favorites", track);
|
||||
test_equal(queue_size(q), 1);
|
||||
playlist_remove("Favorites", track_get(1));
|
||||
test_equal(queue_size(q), 0);
|
||||
|
||||
track = track_get(2);
|
||||
playlist_select("Banned");
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_size(c), 12);
|
||||
test_equal(playlist_has("Banned", track), true);
|
||||
playlist_remove("Banned", track);
|
||||
test_equal(playlist_has("Banned", track), false);
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(queue_size(c), 13);
|
||||
|
||||
playlist_deinit();
|
||||
collection_deinit();
|
||||
|
@ -114,72 +146,6 @@ static void test_queue()
|
|||
test_equal(queue_size(q), (unsigned)12);
|
||||
}
|
||||
|
||||
static void test_add_old()
|
||||
{
|
||||
queue *l = collection_get_queue();
|
||||
queue *q = playlist_get_queue();
|
||||
index_entry *ent;
|
||||
|
||||
playlist_select("Favorites");
|
||||
|
||||
playlist_add("Banned", track_get(5));
|
||||
ent = playlist :: get_tracks("Banned");
|
||||
test_equal(set_size(&ent->ie_set), (size_t)5);
|
||||
test_equal(queue_size(q), (unsigned)8);
|
||||
test_equal(queue_size(l), (unsigned)19);
|
||||
|
||||
playlist_add("Favorites", track_get(16));
|
||||
playlist_add("Favorites", track_get(5));
|
||||
ent = playlist :: get_tracks("Favorites");
|
||||
test_equal(set_size(&ent->ie_set), (size_t)9);
|
||||
test_equal(queue_size(q), (unsigned)9);
|
||||
|
||||
playlist_add("No Playlist", track_get(6));
|
||||
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
|
||||
}
|
||||
|
||||
static void test_delete()
|
||||
{
|
||||
index_entry *ent;
|
||||
queue *l = collection_get_queue();
|
||||
queue *q = playlist_get_queue();
|
||||
|
||||
playlist :: del(track_get(5), "Banned");
|
||||
ent = playlist :: get_tracks("Banned");
|
||||
test_equal(set_size(&ent->ie_set), (size_t)4);
|
||||
test_equal(queue_size(q), (unsigned)9);
|
||||
test_equal(queue_size(l), (unsigned)20);
|
||||
|
||||
playlist :: del(track_get(5), "Favorites");
|
||||
ent = playlist :: get_tracks("Favorites");
|
||||
test_equal(set_size(&ent->ie_set), (size_t)8);
|
||||
test_equal(queue_size(q), (unsigned)8);
|
||||
|
||||
playlist :: del(track_get(6), "No Playlist");
|
||||
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
|
||||
}
|
||||
|
||||
|
||||
static void test_has()
|
||||
{
|
||||
struct track *track;
|
||||
|
||||
test_equal(playlist_has("Favorites", NULL), false);
|
||||
test_equal(playlist_has(NULL, track_get(0)), false);
|
||||
|
||||
for (unsigned int i = 0; i < 24; i++) {
|
||||
track = track_get(i);
|
||||
test_loop_equal(playlist_has("Banned", track),
|
||||
(i <= 3) ? true : false, i);
|
||||
} test_loop_passed();
|
||||
|
||||
for (unsigned int i = 0; i < 24; i++) {
|
||||
track = track_get(i);
|
||||
test_loop_equal(playlist_has("Favorites", track),
|
||||
(i >= 16) ? true : false, i);
|
||||
} test_loop_passed();
|
||||
}
|
||||
|
||||
static void test_deinit()
|
||||
{
|
||||
struct queue *q = playlist_get_queue();
|
||||
|
@ -196,9 +162,7 @@ static void test_deinit()
|
|||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Playlist Initialization", test_init),
|
||||
UNIT_TEST("Playlist Add Track", test_add),
|
||||
UNIT_TEST("Playlist Remove Track", test_remove),
|
||||
UNIT_TEST("Playlist Queue", test_queue),
|
||||
UNIT_TEST("Playlist Add", test_add_old),
|
||||
UNIT_TEST("Playlist Delete", test_delete),
|
||||
UNIT_TEST("Playlist Has", test_has),
|
||||
UNIT_TEST("Playlist Deinit", test_deinit),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue