[vlc-devel] [PATCH 4/4] playlist: add unit tests for playlist repo
Romain Vimont
rom1v at videolabs.io
Thu Aug 20 17:44:23 CEST 2020
---
test/Makefile.am | 3 ++
test/src/playlist/repo.c | 113 +++++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+)
create mode 100644 test/src/playlist/repo.c
diff --git a/test/Makefile.am b/test/Makefile.am
index c2ce32d02f..56c9ed2f77 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -30,6 +30,7 @@ check_PROGRAMS = \
test_src_player \
test_src_interface_dialog \
test_src_media_source \
+ test_src_playlist_repo \
test_src_misc_bits \
test_src_misc_epg \
test_src_misc_keystore \
@@ -141,6 +142,8 @@ test_src_interface_dialog_SOURCES = src/interface/dialog.c
test_src_interface_dialog_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_media_source_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_media_source_SOURCES = src/media_source/media_source.c
+test_src_playlist_repo_LDADD = $(LIBVLCCORE) $(LIBVLC)
+test_src_playlist_repo_SOURCES = src/playlist/repo.c
test_modules_packetizer_helpers_SOURCES = modules/packetizer/helpers.c
test_modules_packetizer_helpers_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_modules_packetizer_hxxx_SOURCES = modules/packetizer/hxxx.c
diff --git a/test/src/playlist/repo.c b/test/src/playlist/repo.c
new file mode 100644
index 0000000000..dc51b5d83a
--- /dev/null
+++ b/test/src/playlist/repo.c
@@ -0,0 +1,113 @@
+/*****************************************************************************
+ * test/src/playlist_repo.c
+ *****************************************************************************
+ * Copyright (C) 2018 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "../../libvlc/test.h"
+#include "../lib/libvlc_internal.h"
+
+#include <assert.h>
+#include <vlc_common.h>
+#include <vlc_playlist.h>
+
+static const char *const libvlc_argv[] = {
+ "-v",
+ "--ignore-config",
+ "-Idummy",
+ "--no-media-library",
+};
+
+static void
+test_main_playlist(void)
+{
+ libvlc_instance_t *vlc = libvlc_new(ARRAY_SIZE(libvlc_argv), libvlc_argv);
+ assert(vlc);
+
+ libvlc_int_t *libvlc = vlc->p_libvlc_int;
+ assert(libvlc);
+
+ vlc_playlist_t *main_pl = libvlc_GetMainPlaylist(libvlc);
+ assert(main_pl);
+
+ vlc_playlist_repo_t *repo = libvlc_GetPlaylistRepo(libvlc);
+ vlc_playlist_repo_Lock(repo);
+ vlc_playlist_t *main_pl2 = vlc_playlist_repo_GetMainPlaylist(repo);
+ vlc_playlist_repo_Unlock(repo);
+
+ assert(main_pl == main_pl2);
+
+ libvlc_release(vlc);
+}
+
+static void
+test_all_playlists(void)
+{
+ libvlc_instance_t *vlc = libvlc_new(ARRAY_SIZE(libvlc_argv), libvlc_argv);
+ assert(vlc);
+
+ libvlc_int_t *libvlc = vlc->p_libvlc_int;
+ assert(libvlc);
+
+ vlc_playlist_repo_t *repo = libvlc_GetPlaylistRepo(libvlc);
+ vlc_playlist_repo_Lock(repo);
+
+ vlc_playlist_t *pl1 = vlc_playlist_repo_Create(repo, "playlist1");
+ assert(pl1);
+ assert(!strcmp("playlist1", vlc_playlist_GetId(pl1)));
+ vlc_playlist_t *pl2 = vlc_playlist_repo_Create(repo, "playlist2");
+ assert(pl2);
+ assert(pl1 != pl2);
+ assert(!strcmp("playlist2", vlc_playlist_GetId(pl2)));
+
+ vlc_playlist_t *plget1 = vlc_playlist_repo_Get(repo, "playlist1");
+ assert(plget1 == pl1);
+ vlc_playlist_t *plget2 = vlc_playlist_repo_Get(repo, "playlist2");
+ assert(plget2 == pl2);
+
+ vlc_playlist_repo_Remove(repo, "playlist1");
+ plget1 = vlc_playlist_repo_Get(repo, "playlist1");
+ assert(!plget1);
+
+ vlc_playlist_t *pl3 = vlc_playlist_repo_Create(repo, "playlist3");
+ assert(pl3);
+
+ size_t count;
+ vlc_playlist_t **playlists = vlc_playlist_repo_List(repo, &count);
+ assert(count == 2);
+ assert(playlists);
+
+ assert((playlists[0] == pl2 && playlists[1] == pl3) ||
+ (playlists[0] == pl3 && playlists[1] == pl2));
+
+ free(playlists);
+
+ vlc_playlist_repo_Unlock(repo);
+
+ libvlc_release(vlc);
+}
+
+int main(void)
+{
+ test_main_playlist();
+ test_all_playlists();
+ return 0;
+}
--
2.28.0
More information about the vlc-devel
mailing list