tests: Build core/playlists/library test with ctest
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
487274ff00
commit
9b7c45634c
|
@ -2,9 +2,7 @@
|
|||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/playlist.h>
|
||||
#include <core/playlists/artist.h>
|
||||
#include <core/playlists/library.h>
|
||||
#include <core/playlists/system.h>
|
||||
|
||||
|
||||
struct playlist_type *playlist_types[] = {
|
||||
[PL_SYSTEM] = &pl_system,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define OCARINA_CORE_PLAYLIST_H
|
||||
|
||||
#include <core/playlists/artist.h>
|
||||
#include <core/playlists/library.h>
|
||||
#include <core/playlists/system.h>
|
||||
#include <core/queue.h>
|
||||
|
||||
|
|
|
@ -6,3 +6,4 @@ endfunction()
|
|||
|
||||
playlist_unit_test(System)
|
||||
playlist_unit_test(Artist)
|
||||
playlist_unit_test(Library)
|
||||
|
|
|
@ -13,6 +13,6 @@ def PlaylistTest(name):
|
|||
core_objs += [ env.Object("../../../core/playlists/generic.c") ]
|
||||
core_objs += [ env.Object("../../../core/playlists/system.c") ]
|
||||
core_objs += [ env.Object("../../../core/playlists/artist.c") ]
|
||||
res += [ PlaylistTest("library") ]
|
||||
core_objs += [ env.Object("../../../core/playlists/library.c") ]
|
||||
|
||||
Return("res")
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/playlists/library.h>
|
||||
#include <core/playlists/system.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/library.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <tests/test.h>
|
||||
|
@ -13,95 +12,97 @@ void test_library()
|
|||
struct playlist *playlist;
|
||||
struct library *library;
|
||||
|
||||
idle_init_sync();
|
||||
tags_init();
|
||||
pl_system_init(NULL);
|
||||
pl_library_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
g_assert_false(playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg"));
|
||||
|
||||
test_equal(pl_library.pl_new("tests/Music/Hyrule Symphony/01 - Title Theme.ogg"), (bool)false);
|
||||
|
||||
test_equal((void *)pl_library.pl_get_queue("tests/Music"), NULL);
|
||||
test_equal(pl_library.pl_new("tests/Music"), (bool)true);
|
||||
test_equal(pl_library.pl_new("tests/Music"), (bool)false);
|
||||
test_not_equal((void *)pl_library.pl_get_queue("tests/Music"), NULL);
|
||||
g_assert_null(playlist_get_queue(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_true(playlist_new(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_false(playlist_new(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_nonnull(playlist_get_queue(PL_LIBRARY, "tests/Music"));
|
||||
|
||||
library = library_get(0);
|
||||
playlist = library->li_playlist;
|
||||
test_not_equal((void *)library, NULL);
|
||||
test_not_equal((void *)playlist, NULL);
|
||||
g_assert_nonnull(library);
|
||||
g_assert_nonnull(library->li_playlist);
|
||||
|
||||
test_equal(queue_size(&playlist->pl_queue), 0);
|
||||
g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 0);
|
||||
while (idle_run_task()) {};
|
||||
test_equal(queue_size(&playlist->pl_queue), 48);
|
||||
test_equal(queue_size(pl_system.pl_get_queue("Unplayed")), 48);
|
||||
test_equal(queue_size(pl_system.pl_get_queue("Collection")), 48);
|
||||
g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 48);
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 48);
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 48);
|
||||
|
||||
test_equal(pl_library.pl_add_track("tests/Music", track_get(0)), (bool)false);
|
||||
test_equal(pl_library.pl_add_track("tests/Music", track_get(1)), (bool)false);
|
||||
test_equal(pl_library.pl_remove_track("tests/Music", track_get(0)), (bool)false);
|
||||
test_equal(pl_library.pl_remove_track("tests/Music", track_get(1)), (bool)false);
|
||||
g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(0)));
|
||||
g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(1)));
|
||||
g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(0)));
|
||||
g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(1)));
|
||||
|
||||
pl_library_deinit();
|
||||
test_equal((void *)pl_library.pl_get_queue("tests/Music"), NULL);
|
||||
test_equal((void *)library->li_playlist, NULL);
|
||||
g_assert_null(playlist_get_queue(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_null(library->li_playlist);
|
||||
pl_library_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
playlist = (struct playlist *)library->li_playlist;
|
||||
|
||||
test_not_equal(library->li_playlist, NULL);
|
||||
test_not_equal((void *)pl_library.pl_get_queue("tests/Music"), NULL);
|
||||
test_equal(queue_size(&playlist->pl_queue), 48);
|
||||
test_equal((void *)pl_library.pl_get_queue("tests/Music"),
|
||||
(void *)&playlist->pl_queue);
|
||||
g_assert_nonnull(library->li_playlist);
|
||||
g_assert_nonnull(playlist_get_queue(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 48);
|
||||
g_assert(playlist_get_queue(PL_LIBRARY, "tests/Music"));
|
||||
|
||||
test_equal(pl_library.pl_add_track("tests/Music", track_get(0)), (bool)false);
|
||||
test_equal(pl_library.pl_add_track("tests/Music", track_get(1)), (bool)false);
|
||||
test_equal(pl_library.pl_remove_track("tests/Music", track_get(0)), (bool)false);
|
||||
test_equal(pl_library.pl_remove_track("tests/Music", track_get(1)), (bool)false);
|
||||
test_equal(queue_size(&playlist->pl_queue), 48);
|
||||
g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(0)));
|
||||
g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(1)));
|
||||
g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(0)));
|
||||
g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(1)));
|
||||
g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 48);
|
||||
|
||||
test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)false);
|
||||
pl_library.pl_set_flag("tests/Music", Q_RANDOM, true);
|
||||
test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)true);
|
||||
pl_library.pl_set_flag("tests/Music", Q_RANDOM, false);
|
||||
test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)false);
|
||||
g_assert_false(playlist_get_random(PL_LIBRARY, "tests/Music"));
|
||||
playlist_set_random(PL_LIBRARY, "tests/Music", true);
|
||||
g_assert_true(playlist_get_random(PL_LIBRARY, "tests/Music"));
|
||||
playlist_set_random(PL_LIBRARY, "tests/Music", false);
|
||||
g_assert_false(playlist_get_random(PL_LIBRARY, "tests/Music"));
|
||||
|
||||
test_equal(g_slist_length(playlist->pl_queue.q_sort), 3);
|
||||
pl_library.pl_sort("tests/Music", COMPARE_ARTIST, true);
|
||||
test_equal(g_slist_length(playlist->pl_queue.q_sort), 1);
|
||||
pl_library.pl_sort("tests/Music", COMPARE_YEAR, false);
|
||||
test_equal(g_slist_length(playlist->pl_queue.q_sort), 2);
|
||||
pl_library.pl_sort("tests/Music", COMPARE_TRACK, false);
|
||||
test_equal(g_slist_length(playlist->pl_queue.q_sort), 3);
|
||||
playlist = library->li_playlist;
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 3);
|
||||
playlist_sort(PL_LIBRARY, "tests/Music", COMPARE_ARTIST, true);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 1);
|
||||
playlist_sort(PL_LIBRARY, "tests/Music", COMPARE_YEAR, false);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 2);
|
||||
playlist_sort(PL_LIBRARY, "tests/Music", COMPARE_TRACK, false);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 3);
|
||||
|
||||
g_rename("tests/Music/Hyrule Symphony/", "tests/Hyrule Symphony/");
|
||||
pl_library.pl_update("tests/Music");
|
||||
playlist_update(PL_LIBRARY, "tests/Music");
|
||||
while (idle_run_task()) {}
|
||||
test_equal(db_actual_size(track_db_get()), 48);
|
||||
test_equal(track_db_get()->db_size, 35);
|
||||
test_equal(queue_size(&playlist->pl_queue), 35);
|
||||
g_assert_cmpuint(db_actual_size(track_db_get()), ==, 48);
|
||||
g_assert_cmpuint(track_db_get()->db_size, ==, 35);
|
||||
g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 35);
|
||||
|
||||
g_rename("tests/Hyrule Symphony", "tests/Music/Hyrule Symphony/");
|
||||
pl_library.pl_update("tests/Music");
|
||||
playlist_update(PL_LIBRARY, "tests/Music");
|
||||
while (idle_run_task()) {}
|
||||
test_equal(db_actual_size(track_db_get()), 61);
|
||||
test_equal(track_db_get()->db_size, 48);
|
||||
test_equal(queue_size(&playlist->pl_queue), 48);
|
||||
g_assert_cmpuint(db_actual_size(track_db_get()), ==, 61);
|
||||
g_assert_cmpuint(track_db_get()->db_size, ==, 48);
|
||||
g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 48);
|
||||
|
||||
test_equal(pl_library.pl_delete("tests/Music"), (bool)true);
|
||||
test_equal(pl_library.pl_delete("tests/Music"), (bool)false);
|
||||
test_equal((void *)library_get(0), NULL);
|
||||
test_equal(queue_size(pl_system.pl_get_queue("Unplayed")), 0);
|
||||
test_equal(queue_size(pl_system.pl_get_queue("Collection")), 0);
|
||||
test_equal(track_db_get()->db_size, 0);
|
||||
|
||||
pl_library_deinit();
|
||||
pl_system_deinit();
|
||||
tags_deinit();
|
||||
idle_deinit();
|
||||
g_assert_true( playlist_delete(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_false(playlist_delete(PL_LIBRARY, "tests/Music"));
|
||||
g_assert_null(library_get(0));
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 0);
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 0);
|
||||
g_assert_cmpuint(track_db_get()->db_size, ==, 0);
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Library Playlists", test_library),
|
||||
);
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
idle_init_sync();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Core/Playlists/Library", test_library);
|
||||
ret = g_test_run();
|
||||
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
idle_deinit();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue