Contribs: add libbluray
[vlc/asuraparaju-public.git] / test / libvlc / events.c
blob1ec047e7b580a6a359cb253836314f5c3f950ca5
1 /*
2 * events.c - libvlc smoke test
4 * $Id$
5 */
7 /**********************************************************************
8 * Copyright (C) 2007 RĂ©mi Denis-Courmont. *
9 * Copyright (C) 2008 Pierre d'Herbemont. *
10 * This program is free software; you can redistribute and/or modify *
11 * it under the terms of the GNU General Public License as published *
12 * by the Free Software Foundation; version 2 of the license, or (at *
13 * your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
18 * See the GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, you can get it from: *
22 * http://www.gnu.org/copyleft/gpl.html *
23 **********************************************************************/
25 #include "test.h"
27 /* This one is an internal API. We use it here to run tests that
28 * don't depends on playback, and only test the event framework */
29 extern void libvlc_event_send( libvlc_event_manager_t *, libvlc_event_t *);
31 static void test_events_dummy_callback( const libvlc_event_t * event, void * user_data)
33 (void)event;
34 bool * callback_was_called = user_data;
35 *callback_was_called = true;
38 static void test_events_callback_and_detach( const libvlc_event_t * event, void * user_data)
40 bool * callback_was_called = user_data;
41 libvlc_event_manager_t *em;
43 em = libvlc_media_player_event_manager (event->p_obj);
45 libvlc_event_detach (em, event->type, test_events_callback_and_detach, user_data);
46 *callback_was_called = true;
49 static void test_event_type_reception( libvlc_event_manager_t * em, libvlc_event_type_t event_type, bool * callback_was_called )
51 libvlc_event_t event;
52 event.type = event_type;
53 *callback_was_called = false;
54 libvlc_event_send (em, &event);
55 assert (*callback_was_called);
58 #include <string.h>
60 static void test_events (const char ** argv, int argc)
62 libvlc_instance_t *vlc;
63 libvlc_media_player_t *mi;
64 libvlc_event_manager_t *em;
65 bool callback_was_called;
66 libvlc_event_type_t mi_events[] = {
67 libvlc_MediaPlayerNothingSpecial,
68 libvlc_MediaPlayerOpening,
69 libvlc_MediaPlayerBuffering,
70 libvlc_MediaPlayerPlaying,
71 libvlc_MediaPlayerPaused,
72 libvlc_MediaPlayerStopped,
73 libvlc_MediaPlayerEndReached,
74 libvlc_MediaPlayerEncounteredError,
75 libvlc_MediaPlayerTimeChanged,
76 libvlc_MediaPlayerPositionChanged,
78 int mi_events_len = sizeof(mi_events)/sizeof(*mi_events);
80 log ("Testing events\n");
82 vlc = libvlc_new (argc, argv);
83 assert (vlc != NULL);
85 mi = libvlc_media_player_new (vlc);
86 assert (mi != NULL);
88 em = libvlc_media_player_event_manager (mi);
90 for( int i = 0; i < 0x700; i++ )
91 strlen(libvlc_event_type_name( i ));
93 log ("+ Testing attaching to Media Instance\n");
95 for (int i = 0; i < mi_events_len; i++) {
96 int ret;
98 ret = libvlc_event_attach (em, mi_events[i],
99 test_events_dummy_callback,
100 &callback_was_called);
101 assert(ret == 0);
104 log ("+ Testing event reception\n");
106 for (int i = 0; i < mi_events_len; i++)
107 test_event_type_reception (em, mi_events[i], &callback_was_called);
109 log ("+ Testing event detaching while in the event callback\n");
111 libvlc_event_t event;
112 event.type = mi_events[mi_events_len-1];
113 callback_was_called = false;
115 libvlc_event_detach (em, mi_events[mi_events_len-1], test_events_dummy_callback, &callback_was_called);
117 int val = libvlc_event_attach (em, mi_events[mi_events_len-1],
118 test_events_callback_and_detach,
119 &callback_was_called);
120 assert (val == 0);
122 libvlc_event_send (em, &event);
123 assert( callback_was_called );
125 callback_was_called = false;
126 libvlc_event_send (em, &event);
127 assert( !callback_was_called );
129 log ("+ Testing regular detach()\n");
131 for (int i = 0; i < mi_events_len - 1; i++)
132 libvlc_event_detach (em, mi_events[i], test_events_dummy_callback, &callback_was_called);
134 libvlc_media_player_release (mi);
135 libvlc_release (vlc);
138 int main (void)
140 test_init();
142 test_events (test_defaults_args, test_defaults_nargs);
144 return 0;