| | 155 | /* This one is an internal API. We use it here to run tests that |
|---|
| | 156 | * don't depends on playback, and only test the event framework */ |
|---|
| | 157 | extern void libvlc_event_send( libvlc_event_manager_t *, libvlc_event_t *); |
|---|
| | 158 | |
|---|
| | 159 | static void test_events_dummy_callback( const libvlc_event_t * event, void * user_data) |
|---|
| | 160 | { |
|---|
| | 161 | vlc_bool_t * callback_was_called = user_data; |
|---|
| | 162 | *callback_was_called = VLC_TRUE; |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | static void test_events_callback_and_detach( const libvlc_event_t * event, void * user_data) |
|---|
| | 166 | { |
|---|
| | 167 | vlc_bool_t * callback_was_called = user_data; |
|---|
| | 168 | libvlc_event_manager_t *em; |
|---|
| | 169 | |
|---|
| | 170 | em = libvlc_media_instance_event_manager (event->p_obj, &ex); |
|---|
| | 171 | catch(); |
|---|
| | 172 | |
|---|
| | 173 | libvlc_event_detach (em, event->type, test_events_callback_and_detach, user_data, &ex); |
|---|
| | 174 | *callback_was_called = VLC_TRUE; |
|---|
| | 175 | } |
|---|
| | 176 | |
|---|
| | 177 | static void test_event_type_reception( libvlc_event_manager_t * em, libvlc_event_type_t event_type, vlc_bool_t * callback_was_called ) |
|---|
| | 178 | { |
|---|
| | 179 | libvlc_event_t event; |
|---|
| | 180 | event.type = event_type; |
|---|
| | 181 | *callback_was_called = VLC_FALSE; |
|---|
| | 182 | libvlc_event_send (em, &event); |
|---|
| | 183 | assert (*callback_was_called); |
|---|
| | 184 | } |
|---|
| | 185 | |
|---|
| | 186 | static void test_events (const char ** argv, int argc) |
|---|
| | 187 | { |
|---|
| | 188 | libvlc_instance_t *vlc; |
|---|
| | 189 | libvlc_media_instance_t *mi; |
|---|
| | 190 | libvlc_event_manager_t *em; |
|---|
| | 191 | vlc_bool_t callback_was_called; |
|---|
| | 192 | libvlc_exception_t ex; |
|---|
| | 193 | libvlc_event_type_t mi_events[] = { |
|---|
| | 194 | libvlc_MediaInstancePlayed, |
|---|
| | 195 | libvlc_MediaInstancePaused, |
|---|
| | 196 | libvlc_MediaInstanceReachedEnd, |
|---|
| | 197 | libvlc_MediaInstanceEncounteredError, |
|---|
| | 198 | libvlc_MediaInstanceTimeChanged, |
|---|
| | 199 | libvlc_MediaInstancePositionChanged, |
|---|
| | 200 | }; |
|---|
| | 201 | int i, mi_events_len = sizeof(mi_events)/sizeof(*mi_events); |
|---|
| | 202 | |
|---|
| | 203 | log ("Testing events\n"); |
|---|
| | 204 | |
|---|
| | 205 | libvlc_exception_init (&ex); |
|---|
| | 206 | vlc = libvlc_new (argc, argv, &ex); |
|---|
| | 207 | catch (); |
|---|
| | 208 | |
|---|
| | 209 | mi = libvlc_media_instance_new (vlc, &ex); |
|---|
| | 210 | catch (); |
|---|
| | 211 | |
|---|
| | 212 | em = libvlc_media_instance_event_manager (mi, &ex); |
|---|
| | 213 | |
|---|
| | 214 | log ("Testing attaching to Media Instance\n"); |
|---|
| | 215 | |
|---|
| | 216 | for (i = 0; i < mi_events_len; i++) { |
|---|
| | 217 | libvlc_event_attach (em, mi_events[i], test_events_dummy_callback, &callback_was_called, &ex); |
|---|
| | 218 | catch (); |
|---|
| | 219 | } |
|---|
| | 220 | |
|---|
| | 221 | log ("Testing event reception\n"); |
|---|
| | 222 | |
|---|
| | 223 | for (i = 0; i < mi_events_len; i++) |
|---|
| | 224 | test_event_type_reception (em, mi_events[i], &callback_was_called); |
|---|
| | 225 | |
|---|
| | 226 | log ("Testing event detaching while in the event callback\n"); |
|---|
| | 227 | |
|---|
| | 228 | libvlc_event_t event; |
|---|
| | 229 | event.type = mi_events[mi_events_len-1]; |
|---|
| | 230 | callback_was_called = VLC_FALSE; |
|---|
| | 231 | |
|---|
| | 232 | libvlc_event_detach (em, mi_events[mi_events_len-1], test_events_dummy_callback, &callback_was_called, &ex); |
|---|
| | 233 | catch (); |
|---|
| | 234 | |
|---|
| | 235 | libvlc_event_attach (em, mi_events[mi_events_len-1], test_events_callback_and_detach, &callback_was_called, &ex); |
|---|
| | 236 | catch (); |
|---|
| | 237 | |
|---|
| | 238 | libvlc_event_send (em, &event); |
|---|
| | 239 | assert( callback_was_called ); |
|---|
| | 240 | |
|---|
| | 241 | callback_was_called = VLC_FALSE; |
|---|
| | 242 | libvlc_event_send (em, &event); |
|---|
| | 243 | assert( !callback_was_called ); |
|---|
| | 244 | |
|---|
| | 245 | libvlc_event_detach (em, mi_events[i], test_events_callback_and_detach, &callback_was_called, &ex); |
|---|
| | 246 | catch (); |
|---|
| | 247 | |
|---|
| | 248 | /* Detach the other events */ |
|---|
| | 249 | for (i = 0; i < mi_events_len - 1; i++) { |
|---|
| | 250 | libvlc_event_detach (em, mi_events[i], test_events_dummy_callback, &callback_was_called, &ex); |
|---|
| | 251 | catch (); |
|---|
| | 252 | } |
|---|
| | 253 | |
|---|
| | 254 | libvlc_media_instance_release (mi); |
|---|
| | 255 | catch (); |
|---|
| | 256 | |
|---|
| | 257 | libvlc_release (vlc); |
|---|
| | 258 | catch (); |
|---|
| | 259 | } |
|---|
| | 260 | |
|---|