]> git.sesse.net Git - vlc/blob - test/native/libvlc.c
Fix some bugs
[vlc] / test / native / libvlc.c
1 #include "../pyunit.h"
2 #include <vlc/libvlc.h>
3
4 static PyObject *exception_test( PyObject *self, PyObject *args )
5 {
6      libvlc_exception_t exception;
7
8      libvlc_exception_init( &exception );
9      ASSERT( !libvlc_exception_raised( &exception) , "Exception raised" );
10      ASSERT( !libvlc_exception_get_message( &exception) , "Exception raised" );
11
12      libvlc_exception_raise( &exception, NULL );
13      ASSERT( !libvlc_exception_get_message( &exception), "Unexpected message" );
14      ASSERT( libvlc_exception_raised( &exception), "Exception not raised" );
15
16      libvlc_exception_raise( &exception, "test" );
17      ASSERT( libvlc_exception_get_message( &exception), "No Message" );
18      ASSERT( libvlc_exception_raised( &exception), "Exception not raised" );
19
20      libvlc_exception_clear( &exception );
21      ASSERT( !libvlc_exception_raised( &exception ), "Exception not cleared" );
22
23      Py_INCREF( Py_None );
24      return Py_None;
25 }
26
27 static PyObject *create_destroy( PyObject *self, PyObject *args )
28 {
29     libvlc_instance_t *p_instance;
30     char *argv[] = { "vlc", "--quiet" };
31
32     libvlc_exception_t exception;
33     libvlc_exception_init( &exception );
34
35     p_instance = libvlc_new( 2, argv, &exception );
36
37     ASSERT( p_instance != NULL, "Instance creation failed" );
38
39     ASSERT( !libvlc_exception_raised( &exception ),
40              "Exception raised while creating instance" );
41
42     libvlc_destroy( p_instance );
43      
44     Py_INCREF( Py_None );
45     return Py_None;
46 }
47
48 static PyObject *playlist_test( PyObject *self, PyObject *args )
49 {
50     libvlc_instance_t *p_instance;
51     char *argv[] = { "vlc", "--quiet" };
52     int i_id, i_playing, i_items;
53
54     libvlc_exception_t exception;
55     libvlc_exception_init( &exception );
56
57     p_instance = libvlc_new( 2, argv, &exception );
58     ASSERT_NOEXCEPTION;
59
60     /* Initial status */
61     libvlc_playlist_play( p_instance, 0, 0, argv, &exception );
62     ASSERT( libvlc_exception_raised( &exception ), 
63             "Playlist empty and exception not raised" );
64
65     libvlc_exception_clear( &exception );
66
67     i_playing  = libvlc_playlist_isplaying( p_instance, &exception  );
68     ASSERT_NOEXCEPTION;
69     ASSERT( i_playing == 0, "Playlist shouldn't be running" );
70     i_items = libvlc_playlist_items_count( p_instance, &exception );
71     ASSERT_NOEXCEPTION;
72     ASSERT( i_items == 0, "Playlist should be empty" );
73
74     /* Add 1 item */
75     libvlc_exception_clear( &exception );
76     i_id = libvlc_playlist_add( p_instance, "test" , NULL , &exception );
77     ASSERT_NOEXCEPTION;
78     ASSERT( i_id > 0 , "Returned identifier is <= 0" );
79     i_items = libvlc_playlist_items_count( p_instance, &exception );
80     ASSERT_NOEXCEPTION;
81     ASSERT( i_items == 1, "Playlist should have 1 item" );
82     i_playing  = libvlc_playlist_isplaying( p_instance, &exception  );
83     ASSERT_NOEXCEPTION;
84     ASSERT( i_playing == 0, "Playlist shouldn't be running" );
85
86     /* */ 
87     
88     Py_INCREF( Py_None );
89     return Py_None;
90 }
91
92 static PyObject *vlm_test( PyObject *self, PyObject *args )
93 {
94     libvlc_instance_t *p_instance;
95     char *argv[] = { "vlc", "--quiet" };
96     libvlc_exception_t exception;
97     libvlc_exception_init( &exception );
98
99     p_instance = libvlc_new( 2, argv, &exception );
100     ASSERT_NOEXCEPTION;
101    
102     libvlc_vlm_set_enabled( p_instance, "test", 1, &exception );
103     ASSERT_EXCEPTION;
104     libvlc_exception_clear( &exception );
105
106     Py_INCREF( Py_None );
107     return Py_None;
108 }
109
110 static PyMethodDef native_libvlc_test_methods[] = {
111    DEF_METHOD( create_destroy, "Create and destroy" )
112    DEF_METHOD( exception_test, "Test Exception handling" )
113    DEF_METHOD( playlist_test, "Test Playlist interaction" )
114    DEF_METHOD( vlm_test, "Test VLM" )
115    { NULL, NULL, 0, NULL }
116 };
117
118 DECLARE_MODULE( native_libvlc_test )