[vlc-devel] [RFC PATCH 3/5] dialog: add an extra test
Thomas Guillem
thomas at gllm.fr
Thu Jan 28 19:11:58 CET 2016
It's not run by default since it needs user interaction.
---
test/Makefile.am | 3 +
test/src/interface/dialog.c | 192 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 195 insertions(+)
create mode 100644 test/src/interface/dialog.c
diff --git a/test/Makefile.am b/test/Makefile.am
index 0c68780..cd9a3b7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -38,6 +38,7 @@ EXTRA_PROGRAMS = \
test_libvlc_meta \
test_libvlc_media_list_player \
test_src_input_stream_net \
+ test_src_interface_dialog \ #disabled since it need user interaction
$(NULL)
#check_DATA = samples/test.sample samples/meta.sample
@@ -92,6 +93,8 @@ test_src_input_stream_net_CFLAGS = $(AM_CFLAGS) -DTEST_NET
test_src_input_stream_net_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_misc_bits_SOURCES = src/misc/bits.c
test_src_misc_bits_LDADD = $(LIBVLC)
+test_src_interface_dialog_SOURCES = src/interface/dialog.c
+test_src_interface_dialog_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_modules_packetizer_hxxx_SOURCES = modules/packetizer/hxxx.c
test_modules_packetizer_hxxx_LDADD = $(LIBVLC)
test_modules_packetizer_hxxx_LDFLAGS = -no-install -static # WTF
diff --git a/test/src/interface/dialog.c b/test/src/interface/dialog.c
new file mode 100644
index 0000000..5292777
--- /dev/null
+++ b/test/src/interface/dialog.c
@@ -0,0 +1,192 @@
+/*****************************************************************************
+ * dialog.c: test VLC core dialogs
+ *****************************************************************************
+ * Copyright © 2016 VLC authors, VideoLAN and VideoLabs
+ *
+ * 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 <vlc/vlc.h>
+
+#include "../../../lib/libvlc_internal.h"
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_modules.h>
+#include <vlc_dialog.h>
+#include <vlc_interrupt.h>
+#include <vlc_keystore.h>
+
+#undef NDEBUG
+#include <assert.h>
+
+#define TITLE "VLC Dialogs test"
+
+/*
+ * Build and exec test:
+ * $ cd vlc/test
+ * $ make test_src_interface_dialog
+ * $ ./test_src_interface_dialog
+ */
+
+static void
+test_dialogs(vlc_object_t *p_obj)
+{
+ int i_ret = vlc_dialog_display_error(p_obj, TITLE,
+ "%d/ Testing login...", 1);
+ assert(i_ret == VLC_SUCCESS);
+
+ vlc_dialog_id *p_id;
+ char *psz_user, *psz_passwd;
+ bool b_store;
+ i_ret = vlc_dialog_wait_login(p_obj, &psz_user, &psz_passwd,
+ &b_store, "Click OK", TITLE, "Click OK");
+ assert(i_ret == 1 && strcmp(psz_user, "Click OK") == 0);
+ free(psz_user);
+ free(psz_passwd);
+
+ i_ret = vlc_dialog_wait_login(p_obj, &psz_user, &psz_passwd,
+ &b_store, "Click Cancel", TITLE, "Click Cancel");
+ assert(i_ret == 0);
+
+ i_ret = vlc_dialog_display_error(p_obj, TITLE,
+ "%d/ Testing question...", 2);
+ assert(i_ret == VLC_SUCCESS);
+
+ i_ret = vlc_dialog_wait_question(p_obj,
+ VLC_DIALOG_QUESTION_NORMAL,
+ "Cancel", "Action1", "Action2", TITLE,
+ "Click Action1");
+ assert(i_ret == 1);
+
+ i_ret = vlc_dialog_wait_question(p_obj,
+ VLC_DIALOG_QUESTION_NORMAL,
+ "Cancel", "Action1", "Action2", TITLE,
+ "Click Action2");
+ assert(i_ret == 2);
+
+ i_ret = vlc_dialog_wait_question(p_obj,
+ VLC_DIALOG_QUESTION_NORMAL,
+ "Cancel", "Action1", "Action2", TITLE,
+ "Click Cancel");
+ assert(i_ret == 0);
+
+ i_ret = vlc_dialog_display_error(p_obj, TITLE,
+ "%d/ Testing critical waiting error...", 3);
+ assert(i_ret == VLC_SUCCESS);
+
+ i_ret = vlc_dialog_wait_question(p_obj,
+ VLC_DIALOG_QUESTION_CRITICAL,
+ "OK", NULL, NULL, TITLE,
+ "Error");
+ assert(i_ret == 0);
+
+ i_ret = vlc_dialog_display_error(p_obj, TITLE,
+ "%d/ Testing progress dialog...", 4);
+ assert(i_ret == VLC_SUCCESS);
+ p_id = vlc_dialog_display_progress(p_obj, true,
+ 0.5f /* should be ignored */,
+ NULL, TITLE,
+ "Indeterminate non cancellable dialog "
+ "for 3seconds");
+ assert(p_id != NULL);
+ sleep(3);
+ vlc_dialog_id_release(p_id);
+ assert(i_ret == VLC_SUCCESS);
+
+ float f_position = 0.5f;
+ p_id = vlc_dialog_display_progress(p_obj, true,
+ f_position /* should be ignored */,
+ "Cancel", TITLE,
+ "Indeterminate cancellable dialog.\n"
+ "Cancel It!");
+ assert(p_id != NULL);
+ while(!vlc_dialog_id_cancelled(p_id))
+ msleep(100000);
+ vlc_dialog_id_release(p_id);
+
+ p_id = vlc_dialog_display_progress(p_obj, false, f_position, NULL, TITLE,
+ "Non cancellable dialog in progress");
+ assert(p_id != NULL);
+ while (f_position <= 1.0f)
+ {
+ usleep(100000);
+ f_position += 0.02f;
+ i_ret = vlc_dialog_id_update_progress(p_id, f_position);
+ assert(i_ret == VLC_SUCCESS);
+ }
+ vlc_dialog_id_release(p_id);
+
+ f_position = 0.5f;
+ p_id = vlc_dialog_display_progress(p_obj, false, f_position, NULL, TITLE,
+ "Non cancellable dialog in progress.\n"
+ "float value: %f", f_position);
+ assert(p_id != NULL);
+ while (f_position <= 1.0f)
+ {
+ usleep(100000);
+ f_position += 0.02f;
+ i_ret = vlc_dialog_id_update_progress_text(p_id, f_position,
+ "Non cancellable dialog in progress.\n"
+ "float value: %f", f_position);
+ assert(i_ret == VLC_SUCCESS);
+ }
+ vlc_dialog_id_release(p_id);
+
+ i_ret = vlc_dialog_display_error(p_obj, TITLE,
+ "%d/ Testing 2 modal dialogs at a time...", 5);
+
+ assert(i_ret == VLC_SUCCESS);
+
+ p_id = vlc_dialog_display_progress(p_obj, true,
+ f_position /* should be ignored */,
+ "Cancel", TITLE,
+ "Indeterminate cancellable dialog.\n"
+ "Cancel It!");
+ assert(p_id != NULL);
+ i_ret = vlc_dialog_wait_question(p_obj,
+ VLC_DIALOG_QUESTION_CRITICAL,
+ "OK", NULL, NULL, TITLE,
+ "Error");
+ assert(i_ret == 0);
+ while(!vlc_dialog_id_cancelled(p_id))
+ msleep(100000);
+ vlc_dialog_id_release(p_id);
+}
+
+int
+main(void)
+{
+ setenv("VLC_PLUGIN_PATH", "../modules", 1);
+
+ static const char *test_defaults_args[] = {
+ "-v",
+ "--no-qt-privacy-ask", /* avoid dialog that ask for privacy */
+ };
+
+ libvlc_instance_t *p_libvlc = libvlc_new(2, test_defaults_args);
+ assert(p_libvlc != NULL);
+ int i_ret = libvlc_InternalAddIntf(p_libvlc->p_libvlc_int, "qt");
+ assert(i_ret == VLC_SUCCESS);
+
+ test_dialogs(VLC_OBJECT(p_libvlc->p_libvlc_int));
+
+ libvlc_release(p_libvlc);
+
+ return 0;
+}
--
2.7.0.rc3
More information about the vlc-devel
mailing list