2016-08-14 10:20:15 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/idle.h>
|
|
|
|
#include <core/playlist.h>
|
|
|
|
#include <core/settings.h>
|
|
|
|
#include <core/tags/artist.h>
|
|
|
|
#include <core/tags/library.h>
|
|
|
|
#include <core/tags/tags.h>
|
|
|
|
#include <tests/test.h>
|
|
|
|
|
|
|
|
void test_user()
|
|
|
|
{
|
|
|
|
struct database *db = pl_user_db_get();
|
|
|
|
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 0);
|
|
|
|
g_assert_true( playlist_new(PL_USER, "Test Playlist"));
|
|
|
|
g_assert_false(playlist_new(PL_USER, "Test Playlist"));
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 1);
|
|
|
|
|
|
|
|
g_assert_false(playlist_get_random(PL_USER, "Test Playlist"));
|
|
|
|
playlist_set_random(PL_USER, "Test Playlist", true);
|
|
|
|
g_assert_true(playlist_get_random(PL_USER, "Test Playlist"));
|
|
|
|
playlist_set_random(PL_USER, "Test Playlist", false);
|
|
|
|
g_assert_false(playlist_get_random(PL_USER, "Test Playlist"));
|
|
|
|
|
|
|
|
g_assert_cmpuint(playlist_get_id(PL_USER, "Test Playlist"), ==, 0);
|
|
|
|
g_assert_cmpuint(playlist_get_id(PL_USER, "No Playlist"), ==,
|
|
|
|
(unsigned int)-1);
|
|
|
|
|
|
|
|
g_assert_cmpstr_free(playlist_get_name(PL_USER, 0), ==, "Test Playlist");
|
|
|
|
g_assert_null(playlist_get_name(PL_USER, 1));
|
|
|
|
|
2016-08-30 13:40:55 -04:00
|
|
|
g_assert(playlist_cur() != playlist_get(PL_USER, "Test Playlist"));
|
2016-08-14 10:20:15 -04:00
|
|
|
g_assert_true( playlist_select(PL_USER, "Test Playlist"));
|
2016-08-30 13:40:55 -04:00
|
|
|
g_assert(playlist_cur() == playlist_get(PL_USER, "Test Playlist"));
|
2016-08-14 10:20:15 -04:00
|
|
|
g_assert_false(playlist_select(PL_USER, "No Playlist"));
|
|
|
|
|
|
|
|
g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 0);
|
|
|
|
g_assert_false(playlist_has( PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_true( playlist_add( PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_false(playlist_add( PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_true( playlist_has( PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 1);
|
|
|
|
|
|
|
|
playlist_update(PL_USER, "Test Playlist");
|
|
|
|
pl_user_deinit();
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 0);
|
|
|
|
pl_user_init(NULL);
|
|
|
|
while (idle_run_task()) {};
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 1);
|
|
|
|
|
|
|
|
g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 1);
|
|
|
|
g_assert_true( playlist_has( PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_true( playlist_remove(PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_false(playlist_remove(PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_false(playlist_has( PL_USER, "Test Playlist", track_get(0)));
|
|
|
|
g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 0);
|
|
|
|
|
|
|
|
g_assert_true( playlist_delete(PL_USER, "Test Playlist"));
|
|
|
|
g_assert_false(playlist_delete(PL_USER, "Test Playlist"));
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 0);
|
|
|
|
g_assert_cmpuint(db_actual_size(db), ==, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
idle_init_sync();
|
|
|
|
settings_init();
|
|
|
|
tags_init();
|
|
|
|
playlist_init(NULL);
|
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Core/Playlists/User", test_user);
|
|
|
|
ret = g_test_run();
|
|
|
|
|
|
|
|
playlist_deinit();
|
|
|
|
tags_deinit();
|
|
|
|
settings_deinit();
|
|
|
|
idle_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|