Qt: make PLModel::getItem return rootItem as well, add id getter to PLItem
[vlc.git] / test / native / libvlc.c
blob35564a344d7b7e85add0cc6274dd733e37c19ea1
1 #include "../pyunit.h"
2 #include <vlc/libvlc.h>
4 PyObject *exception_test( PyObject *self, PyObject *args )
6 libvlc_exception_t exception;
8 libvlc_exception_init( &exception );
9 ASSERT( !libvlc_exception_raised( &exception) , "Exception raised" );
10 ASSERT( !libvlc_exception_get_message( &exception) , "Exception raised" );
12 libvlc_exception_raise( &exception, NULL );
13 ASSERT( !libvlc_exception_get_message( &exception), "Unexpected message" );
14 ASSERT( libvlc_exception_raised( &exception), "Exception not raised" );
16 libvlc_exception_raise( &exception, "test" );
17 ASSERT( libvlc_exception_get_message( &exception), "No Message" );
18 ASSERT( libvlc_exception_raised( &exception), "Exception not raised" );
20 libvlc_exception_clear( &exception );
21 ASSERT( !libvlc_exception_raised( &exception ), "Exception not cleared" );
23 Py_INCREF( Py_None );
24 return Py_None;
27 PyObject *create_destroy( PyObject *self, PyObject *args )
29 libvlc_instance_t *p_i1, *p_i2;
30 char *argv1[] = { "vlc", "--quiet" };
31 char *argv2[]= { "vlc", "-vvv" };
32 int id1,id2;
34 printf( "\n" );
36 libvlc_exception_t exception;
37 libvlc_exception_init( &exception );
39 /* Create and destroy a single instance */
40 fprintf( stderr, "Create 1\n" );
41 p_i1 = libvlc_new( 2, argv1, &exception );
42 ASSERT( p_i1 != NULL, "Instance creation failed" );
43 ASSERT_NOEXCEPTION;
44 id1 = libvlc_get_vlc_id( p_i1 );
45 libvlc_release( p_i1, &exception );
46 ASSERT_NOEXCEPTION;
48 /* Create and destroy two instances */
49 fprintf( stderr, "Create 2\n" );
50 p_i1 = libvlc_new( 2, argv1, &exception );
51 ASSERT( p_i1 != NULL, "Instance creation failed" );
52 ASSERT_NOEXCEPTION;
54 fprintf( stderr, "Create 3\n" );
55 p_i2 = libvlc_new( 2, argv2, &exception );
56 ASSERT( p_i2 != NULL, "Instance creation failed" );
57 ASSERT_NOEXCEPTION;
59 fprintf( stderr, "Destroy 1\n" );
60 libvlc_release( p_i1, &exception );
61 ASSERT_NOEXCEPTION;
62 fprintf( stderr, "Destroy 2\n" );
63 libvlc_release( p_i2, &exception );
64 ASSERT_NOEXCEPTION;
66 /* Deinit */
67 fprintf( stderr, "Create 4\n" );
68 p_i1 = libvlc_new( 2, argv1, &exception );
69 ASSERT_NOEXCEPTION;
70 id2 = libvlc_get_vlc_id( p_i1 );
72 ASSERT( id1 == id2, "libvlc object ids do not match after deinit" );
74 Py_INCREF( Py_None );
75 return Py_None;
78 PyObject *playlist_test( PyObject *self, PyObject *args )
80 libvlc_instance_t *p_instance;
81 char *argv[] = { "vlc", "--quiet" };
82 int i_id, i_playing, i_items;
84 libvlc_exception_t exception;
85 libvlc_exception_init( &exception );
87 p_instance = libvlc_new( 2, argv, &exception );
88 ASSERT_NOEXCEPTION;
90 /* Initial status */
91 libvlc_playlist_play( p_instance, 0, 0, argv, &exception );
92 ASSERT( libvlc_exception_raised( &exception ),
93 "Playlist empty and exception not raised" );
95 libvlc_exception_clear( &exception );
97 i_playing = libvlc_playlist_isplaying( p_instance, &exception );
98 ASSERT_NOEXCEPTION;
99 ASSERT( i_playing == 0, "Playlist shouldn't be running" );
100 i_items = libvlc_playlist_items_count( p_instance, &exception );
101 ASSERT_NOEXCEPTION;
102 ASSERT( i_items == 0, "Playlist should be empty" );
104 /* Add 1 item */
105 libvlc_exception_clear( &exception );
106 i_id = libvlc_playlist_add( p_instance, "test" , NULL , &exception );
107 ASSERT_NOEXCEPTION;
108 ASSERT( i_id > 0 , "Returned identifier is <= 0" );
109 i_items = libvlc_playlist_items_count( p_instance, &exception );
110 ASSERT_NOEXCEPTION;
111 ASSERT( i_items == 1, "Playlist should have 1 item" );
112 i_playing = libvlc_playlist_isplaying( p_instance, &exception );
113 ASSERT_NOEXCEPTION;
114 ASSERT( i_playing == 0, "Playlist shouldn't be running" );
116 /* */
118 Py_INCREF( Py_None );
119 return Py_None;
122 PyObject *vlm_test( PyObject *self, PyObject *args )
124 libvlc_instance_t *p_instance;
125 char *argv[] = { "vlc", "--quiet" };
126 char *ppsz_empty[] = {};
127 libvlc_exception_t exception;
128 libvlc_exception_init( &exception );
130 p_instance = libvlc_new( 2, argv, &exception );
131 ASSERT_NOEXCEPTION;
133 /* Test that working on unexisting streams fail */
134 libvlc_vlm_set_enabled( p_instance, "test", 1, &exception );
135 ASSERT_EXCEPTION;
136 libvlc_exception_clear( &exception );
137 libvlc_vlm_set_input( p_instance, "test", "input", &exception );
138 ASSERT_EXCEPTION;
139 libvlc_exception_clear( &exception );
140 libvlc_vlm_del_media( p_instance, "test", &exception );
141 ASSERT_EXCEPTION;
142 libvlc_exception_clear( &exception );
144 /******* Broadcast *******/
145 /* Now create a media */
146 libvlc_vlm_add_broadcast( p_instance, "test", "input_test", "output_test",
147 0, ppsz_empty, 1, 1, &exception );
148 ASSERT_NOEXCEPTION;
149 libvlc_exception_clear( &exception );
151 /* Change its parameters */
152 libvlc_vlm_set_enabled( p_instance, "test", 0, &exception );
153 ASSERT_NOEXCEPTION;
154 libvlc_exception_clear( &exception );
155 libvlc_vlm_set_output( p_instance, "test", "output_test2", &exception );
156 ASSERT_NOEXCEPTION;
157 libvlc_exception_clear( &exception );
159 /* Check the parameters */
160 fprintf( stderr, "The code for this is not written yet\n");
162 /* Control it a bit */
163 fprintf( stderr, "The code for this is not written yet\n");
165 /* Try to delete it */
166 libvlc_vlm_del_media( p_instance, "test", &exception );
167 ASSERT_NOEXCEPTION;
168 libvlc_exception_clear( &exception );
170 libvlc_vlm_del_media( p_instance, "test", &exception );
171 ASSERT_EXCEPTION;
172 libvlc_exception_clear( &exception );
174 /******* VOD *******/
176 Py_INCREF( Py_None );
177 return Py_None;