ocarina/tests/core/playlist.c

123 lines
4.3 KiB
C
Raw Normal View History

/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/idle.h>
#include <core/playlist.h>
#include <core/settings.h>
#include <core/tags/tags.h>
static void test_null()
{
g_assert_null(playlist_new(PL_MAX_TYPE, "NULL"));
g_assert_null(playlist_new(PL_MAX_TYPE, NULL));
g_assert_false(playlist_delete(NULL));
g_assert_null(playlist_lookup(PL_MAX_TYPE, "NULL"));
g_assert_null(playlist_lookup(PL_MAX_TYPE, NULL));
g_assert_null(playlist_get(PL_MAX_TYPE, 0));
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
g_assert_false(playlist_select(NULL));
g_assert(playlist_current() == playlist_lookup(PL_SYSTEM, "Collection"));
g_assert_false(playlist_add(NULL, NULL));
g_assert_false(playlist_add(NULL, track_get(0)));
g_assert_false(playlist_has(NULL, NULL));
g_assert_false(playlist_has(NULL, track_get(0)));
g_assert_cmpuint(playlist_size(NULL), ==, 0);
g_assert_false(playlist_remove(NULL, NULL));
g_assert_false(playlist_remove(NULL, track_get(0)));
g_assert_false(playlist_get_random(NULL));
playlist_set_random(NULL, true);
g_assert_false(playlist_get_random(NULL));
g_assert_false(playlist_sort(NULL, COMPARE_TRACK, true));
g_assert_false(playlist_sort(NULL, COMPARE_TRACK, false));
playlist_generic_save(NULL, NULL, PL_SAVE_ALL);
playlist_generic_load(NULL, NULL, PL_SAVE_ALL);
}
static void test_save_load()
{
struct playlist p = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test", 0, NULL);
struct playlist q = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test 2", 0, NULL);
struct playlist r = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test", 0, NULL);
struct playlist s = DEFINE_PLAYLIST(PL_MAX_TYPE, "Test 2", 0, NULL);
struct file f = FILE_INIT("test.playlist", 0);
unsigned int i;
for (i = 0; i < 13; i++) {
queue_add(&p.pl_queue, track_get(i));
queue_add(&q.pl_queue, track_get(i));
}
queue_set_flag(&p.pl_queue, Q_RANDOM);
queue_sort(&p.pl_queue, COMPARE_TRACK, true);
p.pl_queue.q_cur.it_pos = 3;
q.pl_queue.q_cur.it_pos = 4;
g_assert_false(file_exists(&f));
g_assert_true( file_open(&f, OPEN_WRITE));
playlist_generic_save(&p, &f, PL_SAVE_METADATA);
playlist_generic_save(&q, &f, PL_SAVE_ALL);
file_close(&f);
g_assert_true(file_open(&f, OPEN_READ));
playlist_generic_load(&r, &f, PL_SAVE_METADATA);
playlist_generic_load(&s, &f, PL_SAVE_ALL);
file_close(&f);
g_assert_true(queue_has_flag(&r.pl_queue, Q_RANDOM));
g_assert_cmpuint(r.pl_queue.q_cur.it_pos, ==, 3);
g_assert_cmpuint(g_slist_length(r.pl_queue.q_sort), ==, 1);
g_assert_cmpuint(GPOINTER_TO_UINT(r.pl_queue.q_sort->data),
==, COMPARE_TRACK);
g_assert_cmpuint(g_queue_get_length(&r.pl_queue.q_tracks), ==, 0);
g_assert_false(queue_has_flag(&s.pl_queue, Q_RANDOM));
g_assert_cmpuint(s.pl_queue.q_cur.it_pos, ==, 4);
g_assert(queue_iter_val(&s.pl_queue.q_cur) == queue_at(&q.pl_queue, 4));
g_assert_cmpuint(g_slist_length(s.pl_queue.q_sort), ==, 0);
g_assert_cmpuint(g_queue_get_length(&s.pl_queue.q_tracks), ==, 13);
}
int main(int argc, char **argv)
{
struct library *library;
int ret;
idle_init_sync();
settings_init();
tags_init();
playlist_init(NULL, NULL);
while (idle_run_task()) {};
library = library_find("tests/Music");
track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
track_add(library, "tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
track_add(library, "tests/Music/Hyrule Symphony/03 - Hyrule Field.ogg");
track_add(library, "tests/Music/Hyrule Symphony/04 - Hyrule Castle.ogg");
track_add(library, "tests/Music/Hyrule Symphony/05 - Lon Lon Ranch.ogg");
track_add(library, "tests/Music/Hyrule Symphony/06 - Kakariko Village.ogg");
track_add(library, "tests/Music/Hyrule Symphony/07 - Death Mountain.ogg");
track_add(library, "tests/Music/Hyrule Symphony/08 - Zora's Domain.ogg");
track_add(library, "tests/Music/Hyrule Symphony/09 - Gerudo Valley.ogg");
track_add(library, "tests/Music/Hyrule Symphony/10 - Ganondorf.ogg");
track_add(library, "tests/Music/Hyrule Symphony/11 - Princess Zelda.ogg");
track_add(library, "tests/Music/Hyrule Symphony/12 - Ocarina Medley.ogg");
track_add(library,
"tests/Music/Hyrule Symphony/13 - The Legend of Zelda Medley.ogg");
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Core/Playlist/NULL", test_null);
g_test_add_func("/Core/Playlist/Save and Load", test_save_load);
ret = g_test_run();
playlist_deinit();
tags_deinit();
settings_deinit();
idle_deinit();
return ret;
}