1 /*****************************************************************************
2 * dialog.c: test VLC core dialogs
3 *****************************************************************************
4 * Copyright © 2016 VLC authors, VideoLAN and VideoLabs
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
26 #include "../../../lib/libvlc_internal.h"
28 #include <vlc_common.h>
29 #include <vlc_plugin.h>
30 #include <vlc_modules.h>
31 #include <vlc_dialog.h>
32 #include <vlc_interrupt.h>
33 #include <vlc_keystore.h>
38 #define TITLE "VLC Dialogs test"
41 * Build and exec qt dialog test:
43 * $ make test_src_interface_dialog
44 * $ ./test_src_interface_dialog -a
50 const char *psz_username
;
57 display_error_cb(void *p_data
, const char *psz_title
, const char *psz_text
)
60 printf("error message: title: '%s', text: '%s'\n", psz_title
, psz_text
);
64 display_login_cb(void *p_data
, vlc_dialog_id
*p_id
, const char *psz_title
,
65 const char *psz_text
, const char *psz_default_username
,
68 struct cb_answer
*p_ans
= p_data
;
69 printf("login dialog: title: '%s', text: '%s', "
70 "default_username: '%s', b_ask_store: %d\n",
71 psz_title
, psz_text
, psz_default_username
, b_ask_store
);
74 vlc_dialog_id_dismiss(p_id
);
75 else if (p_ans
->psz_username
!= NULL
)
76 vlc_dialog_id_post_login(p_id
, p_ans
->psz_username
, "", false);
80 display_question_cb(void *p_data
, vlc_dialog_id
*p_id
, const char *psz_title
,
81 const char *psz_text
, vlc_dialog_question_type i_type
,
82 const char *psz_cancel
, const char *psz_action1
,
83 const char *psz_action2
)
85 struct cb_answer
*p_ans
= p_data
;
86 printf("question dialog: title: '%s', text: '%s', "
87 "type: %d, cancel: '%s', action1: '%s', action2: '%s'\n",
88 psz_title
, psz_text
, i_type
, psz_cancel
, psz_action1
, psz_action2
);
91 vlc_dialog_id_dismiss(p_id
);
92 else if (p_ans
->i_action
> 0)
93 vlc_dialog_id_post_action(p_id
, p_ans
->i_action
);
97 display_progress_cb(void *p_data
, vlc_dialog_id
*p_id
, const char *psz_title
,
98 const char *psz_text
, bool b_indeterminate
,
99 float f_position
, const char *psz_cancel
)
101 struct cb_answer
*p_ans
= p_data
;
102 printf("progress dialog: title: '%s', text: '%s', "
103 "indeterminate: %d, position: %f, cancel: '%s'\n",
104 psz_title
, psz_text
, b_indeterminate
, f_position
, psz_cancel
);
106 if (p_ans
->b_dismiss
)
107 vlc_dialog_id_dismiss(p_id
);
110 static void cancel_cb(void *p_data
, vlc_dialog_id
*p_id
)
113 vlc_dialog_id_dismiss(p_id
);
116 static void update_progress_cb(void *p_data
, vlc_dialog_id
*p_id
, float f_position
,
117 const char *psz_text
)
121 printf("update_progress: %f, text: %s\n", f_position
, psz_text
);
125 set_answer(struct cb_answer
*p_ans
, bool b_dismiss
, const char *psz_username
,
130 p_ans
->b_dismiss
= b_dismiss
;
131 p_ans
->psz_username
= psz_username
;
132 p_ans
->i_action
= i_action
;
137 test_dialogs(vlc_object_t
*p_obj
, struct cb_answer
*p_ans
,
138 mtime_t i_dialog_wait
)
140 set_answer(p_ans
, false, NULL
, 0);
141 int i_ret
= vlc_dialog_display_error(p_obj
, TITLE
,
142 "%d/ Testing login...", 1);
143 assert(i_ret
== VLC_SUCCESS
);
146 char *psz_user
, *psz_passwd
;
148 set_answer(p_ans
, false, "Click OK", 0);
149 i_ret
= vlc_dialog_wait_login(p_obj
, &psz_user
, &psz_passwd
,
150 &b_store
, "Click OK", TITLE
, "Click OK");
151 assert(i_ret
== 1 && strcmp(psz_user
, "Click OK") == 0);
155 set_answer(p_ans
, true, NULL
, 0);
156 i_ret
= vlc_dialog_wait_login(p_obj
, &psz_user
, &psz_passwd
,
157 &b_store
, "Click Cancel", TITLE
, "Click Cancel");
160 set_answer(p_ans
, false, NULL
, 0);
161 i_ret
= vlc_dialog_display_error(p_obj
, TITLE
,
162 "%d/ Testing question...", 2);
163 assert(i_ret
== VLC_SUCCESS
);
165 set_answer(p_ans
, false, NULL
, 1);
166 i_ret
= vlc_dialog_wait_question(p_obj
,
167 VLC_DIALOG_QUESTION_NORMAL
,
168 "Cancel", "Action1", "Action2", TITLE
,
172 set_answer(p_ans
, false, NULL
, 2);
173 i_ret
= vlc_dialog_wait_question(p_obj
,
174 VLC_DIALOG_QUESTION_NORMAL
,
175 "Cancel", "Action1", "Action2", TITLE
,
179 set_answer(p_ans
, true, NULL
, 0);
180 i_ret
= vlc_dialog_wait_question(p_obj
,
181 VLC_DIALOG_QUESTION_NORMAL
,
182 "Cancel", "Action1", "Action2", TITLE
,
186 set_answer(p_ans
, false, NULL
, 0);
187 i_ret
= vlc_dialog_display_error(p_obj
, TITLE
,
188 "%d/ Testing critical waiting error...", 3);
189 assert(i_ret
== VLC_SUCCESS
);
191 set_answer(p_ans
, true, NULL
, 0);
192 i_ret
= vlc_dialog_wait_question(p_obj
,
193 VLC_DIALOG_QUESTION_CRITICAL
,
194 "OK", NULL
, NULL
, TITLE
,
198 set_answer(p_ans
, false, NULL
, 0);
199 i_ret
= vlc_dialog_display_error(p_obj
, TITLE
,
200 "%d/ Testing progress dialog...", 4);
201 assert(i_ret
== VLC_SUCCESS
);
203 set_answer(p_ans
, false, NULL
, 0);
204 p_id
= vlc_dialog_display_progress(p_obj
, true,
205 0.5f
/* should be ignored */,
207 "Indeterminate non cancellable dialog "
208 "for %" PRId64
" us", i_dialog_wait
);
209 assert(p_id
!= NULL
);
210 msleep(i_dialog_wait
);
211 vlc_dialog_release(p_obj
, p_id
);
212 assert(i_ret
== VLC_SUCCESS
);
214 set_answer(p_ans
, true, NULL
, 0);
215 float f_position
= 0.5f
;
216 p_id
= vlc_dialog_display_progress(p_obj
, true,
217 f_position
/* should be ignored */,
219 "Indeterminate cancellable dialog.\n"
221 assert(p_id
!= NULL
);
222 while(!vlc_dialog_is_cancelled(p_obj
, p_id
))
223 msleep(i_dialog_wait
/ 30);
224 vlc_dialog_release(p_obj
, p_id
);
226 set_answer(p_ans
, false, NULL
, 0);
227 p_id
= vlc_dialog_display_progress(p_obj
, false, f_position
, NULL
, TITLE
,
228 "Non cancellable dialog in progress");
229 assert(p_id
!= NULL
);
230 while (f_position
<= 1.0f
)
232 msleep(i_dialog_wait
/ 30);
234 i_ret
= vlc_dialog_update_progress(p_obj
, p_id
, f_position
);
235 assert(i_ret
== VLC_SUCCESS
);
237 vlc_dialog_release(p_obj
, p_id
);
240 set_answer(p_ans
, false, NULL
, 0);
241 p_id
= vlc_dialog_display_progress(p_obj
, false, f_position
, NULL
, TITLE
,
242 "Non cancellable dialog in progress.\n"
243 "float value: %f", f_position
);
244 assert(p_id
!= NULL
);
245 while (f_position
<= 1.0f
)
247 msleep(i_dialog_wait
/ 30);
249 i_ret
= vlc_dialog_update_progress_text(p_obj
, p_id
, f_position
,
250 "Non cancellable dialog in progress.\n"
251 "float value: %f", f_position
);
252 assert(i_ret
== VLC_SUCCESS
);
254 vlc_dialog_release(p_obj
, p_id
);
256 set_answer(p_ans
, false, NULL
, 0);
257 i_ret
= vlc_dialog_display_error(p_obj
, TITLE
,
258 "%d/ Testing 2 modal dialogs at a time...", 5);
260 assert(i_ret
== VLC_SUCCESS
);
262 set_answer(p_ans
, true, NULL
, 0);
263 p_id
= vlc_dialog_display_progress(p_obj
, true,
264 f_position
/* should be ignored */,
266 "Indeterminate cancellable dialog.\n"
268 assert(p_id
!= NULL
);
270 set_answer(p_ans
, true, NULL
, 0);
271 i_ret
= vlc_dialog_wait_question(p_obj
,
272 VLC_DIALOG_QUESTION_CRITICAL
,
273 "OK", NULL
, NULL
, TITLE
,
276 while(!vlc_dialog_is_cancelled(p_obj
, p_id
))
277 msleep(i_dialog_wait
/ 30);
278 vlc_dialog_release(p_obj
, p_id
);
282 main(int i_argc
, char *ppsz_argv
[])
284 bool b_test_all
= i_argc
> 1 && strcmp(ppsz_argv
[1], "-a") == 0;
289 setenv("VLC_PLUGIN_PATH", "../modules", 1);
291 libvlc_instance_t
*p_libvlc
= libvlc_new(0, NULL
);
292 assert(p_libvlc
!= NULL
);
294 printf("testing dialog callbacks\n");
295 const vlc_dialog_cbs cbs
= {
296 .pf_display_error
= display_error_cb
,
297 .pf_display_login
= display_login_cb
,
298 .pf_display_question
= display_question_cb
,
299 .pf_display_progress
= display_progress_cb
,
300 .pf_cancel
= cancel_cb
,
301 .pf_update_progress
= update_progress_cb
,
303 struct cb_answer ans
= { 0 };
304 vlc_dialog_provider_set_callbacks(p_libvlc
->p_libvlc_int
, &cbs
, &ans
);
305 test_dialogs(VLC_OBJECT(p_libvlc
->p_libvlc_int
), &ans
, 100000);
306 vlc_dialog_provider_set_callbacks(p_libvlc
->p_libvlc_int
, NULL
, NULL
);
308 libvlc_release(p_libvlc
);
312 printf("testing Qt dialog callbacks\n");
313 static const char *args
[] = {
314 "--no-qt-privacy-ask", /* avoid dialog that ask for privacy */
316 libvlc_instance_t
*p_libvlc
= libvlc_new(1, args
);
317 assert(p_libvlc
!= NULL
);
319 int i_ret
= libvlc_InternalAddIntf(p_libvlc
->p_libvlc_int
, "qt");
320 assert(i_ret
== VLC_SUCCESS
);
321 test_dialogs(VLC_OBJECT(p_libvlc
->p_libvlc_int
), NULL
, 3000000);
323 libvlc_release(p_libvlc
);