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();
|
2016-09-09 08:35:52 -04:00
|
|
|
struct playlist *playlist;
|
2016-08-14 10:20:15 -04:00
|
|
|
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 0);
|
2016-09-09 08:35:52 -04:00
|
|
|
playlist = playlist_new(PL_USER, "Test Playlist");
|
|
|
|
g_assert_nonnull(playlist);
|
|
|
|
g_assert_null(playlist_new(PL_USER, "Test Playlist"));
|
2016-08-14 10:20:15 -04:00
|
|
|
g_assert_cmpuint(db->db_size, ==, 1);
|
|
|
|
|
2016-09-12 08:17:41 -04:00
|
|
|
g_assert_false(playlist_get_random(playlist));
|
|
|
|
playlist_set_random(playlist, true);
|
|
|
|
g_assert_true(playlist_get_random(playlist));
|
|
|
|
playlist_set_random(playlist, false);
|
|
|
|
g_assert_false(playlist_get_random(playlist));
|
2016-08-14 10:20:15 -04:00
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
2016-09-10 13:46:30 -04:00
|
|
|
g_assert_false(playlist_has(playlist, track_get(0)));
|
2016-09-10 12:08:11 -04:00
|
|
|
g_assert_true( playlist_add(playlist, track_get(0)));
|
|
|
|
g_assert_false(playlist_add(playlist, track_get(0)));
|
2016-09-10 13:46:30 -04:00
|
|
|
g_assert_true( playlist_has(playlist, track_get(0)));
|
2016-09-10 14:31:43 -04:00
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
2016-08-14 10:20:15 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-09-09 10:17:37 -04:00
|
|
|
playlist = playlist_get(PL_USER, "Test Playlist");
|
|
|
|
g_assert_nonnull(playlist);
|
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
2016-09-10 13:46:30 -04:00
|
|
|
g_assert_true( playlist_has( playlist, track_get(0)));
|
2016-09-10 13:11:18 -04:00
|
|
|
g_assert_true( playlist_remove(playlist, track_get(0)));
|
|
|
|
g_assert_false(playlist_remove(playlist, track_get(0)));
|
2016-09-10 13:46:30 -04:00
|
|
|
g_assert_false(playlist_has( playlist, track_get(0)));
|
2016-09-10 14:31:43 -04:00
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
2016-08-14 10:20:15 -04:00
|
|
|
|
2016-09-09 10:17:37 -04:00
|
|
|
g_assert_true(playlist_delete(playlist));
|
2016-08-14 10:20:15 -04:00
|
|
|
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;
|
|
|
|
}
|