98 lines
2.7 KiB
C
98 lines
2.7 KiB
C
/*
|
|
* 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();
|
|
struct playlist *playlist;
|
|
|
|
g_assert_cmpuint(db->db_size, ==, 0);
|
|
playlist = playlist_new(PL_USER, "Test Playlist");
|
|
g_assert_nonnull(playlist);
|
|
g_assert_cmpuint(playlist->pl_id, ==, 0);
|
|
|
|
g_assert_null(playlist_new(PL_USER, "Test Playlist"));
|
|
g_assert_cmpuint(db->db_size, ==, 1);
|
|
|
|
g_assert_false(playlist->pl_random);
|
|
playlist_set_random(playlist, true);
|
|
g_assert_true(playlist->pl_random);
|
|
playlist_set_random(playlist, false);
|
|
g_assert_false(playlist->pl_random);
|
|
|
|
g_assert(playlist_current() != playlist);
|
|
g_assert_false(playlist_select(playlist));
|
|
g_assert(playlist_current() != playlist);
|
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
|
g_assert_false(playlist_has(playlist, track_get(0)));
|
|
g_assert_true( playlist_add(playlist, track_get(0)));
|
|
g_assert_false(playlist_add(playlist, track_get(0)));
|
|
g_assert_true( playlist_has(playlist, track_get(0)));
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
|
|
|
g_assert_true(playlist_select(playlist));
|
|
g_assert(playlist_current() == playlist);
|
|
g_assert_false(playlist_select(playlist));
|
|
g_assert_false(playlist_select(NULL));
|
|
|
|
g_assert(playlist_next() == track_get(0));
|
|
g_assert_true(playlist_has(playlist, track_get(0)));
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
|
|
|
playlist_selected(track_get(0));
|
|
playlist_played(track_get(0));
|
|
|
|
pl_user_deinit();
|
|
g_assert_cmpuint(db->db_size, ==, 0);
|
|
pl_user_init();
|
|
while (idle_run_task()) {};
|
|
g_assert_cmpuint(db->db_size, ==, 1);
|
|
|
|
playlist = playlist_lookup(PL_USER, "Test Playlist");
|
|
g_assert_nonnull(playlist);
|
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
|
g_assert_true( playlist_has( playlist, track_get(0)));
|
|
g_assert_true( playlist_remove(playlist, track_get(0)));
|
|
g_assert_false(playlist_remove(playlist, track_get(0)));
|
|
g_assert_false(playlist_has( playlist, track_get(0)));
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
|
|
|
g_assert_true(playlist_delete(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;
|
|
}
|