]> git.sesse.net Git - vlc/blob - test/native/libvlc.c
More VLM API stuff
[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     char *ppsz_empty[] = {};
97     libvlc_exception_t exception;
98     libvlc_exception_init( &exception );
99
100     p_instance = libvlc_new( 2, argv, &exception );
101     ASSERT_NOEXCEPTION;
102   
103     /* Test that working on unexisting streams fail */
104     libvlc_vlm_set_enabled( p_instance, "test", 1, &exception );
105     ASSERT_EXCEPTION;
106     libvlc_exception_clear( &exception );
107     libvlc_vlm_set_input( p_instance, "test", "input", &exception );
108     ASSERT_EXCEPTION;
109     libvlc_exception_clear( &exception );
110     libvlc_vlm_del_media( p_instance, "test", &exception );
111     ASSERT_EXCEPTION;
112     libvlc_exception_clear( &exception );
113
114     /*******  Broadcast *******/
115     /* Now create a media */
116     libvlc_vlm_add_broadcast( p_instance, "test", "input_test", "output_test",
117                               0, ppsz_empty, 1, 1, &exception );
118     ASSERT_NOEXCEPTION;
119     libvlc_exception_clear( &exception );
120
121     /* Change its parameters */
122     libvlc_vlm_set_enabled( p_instance, "test", 0, &exception );
123     ASSERT_NOEXCEPTION;
124     libvlc_exception_clear( &exception );
125     libvlc_vlm_set_output( p_instance, "test", "output_test2", &exception );
126     ASSERT_NOEXCEPTION;
127     libvlc_exception_clear( &exception );
128
129     /* Check the parameters */
130     fprintf( stderr, "The code for this is not written yet\n");
131
132     /* Control it a bit */
133     fprintf( stderr, "The code for this is not written yet\n");
134
135     /* Try to delete it */
136     libvlc_vlm_del_media( p_instance, "test", &exception );
137     ASSERT_NOEXCEPTION;
138     libvlc_exception_clear( &exception );
139
140     libvlc_vlm_del_media( p_instance, "test", &exception );
141     ASSERT_EXCEPTION;
142     libvlc_exception_clear( &exception );
143
144     /*******  VOD *******/
145
146     Py_INCREF( Py_None );
147     return Py_None;
148 }
149
150 static PyMethodDef native_libvlc_test_methods[] = {
151    DEF_METHOD( create_destroy, "Create and destroy" )
152    DEF_METHOD( exception_test, "Test Exception handling" )
153    DEF_METHOD( playlist_test, "Test Playlist interaction" )
154    DEF_METHOD( vlm_test, "Test VLM" )
155    { NULL, NULL, 0, NULL }
156 };
157
158 DECLARE_MODULE( native_libvlc_test )