cvdsub: use VLC_TS_INVALID (refs #3135)
[vlc/solaris.git] / test / libvlc / media_list.c
blobfb176972f346f5132040e3101742d18e22300d97
1 /*
2 * media_list.c - libvlc smoke test
4 * $Id$
5 */
7 /**********************************************************************
8 * Copyright (C) 2007 RĂ©mi Denis-Courmont. *
9 * This program is free software; you can redistribute and/or modify *
10 * it under the terms of the GNU General Public License as published *
11 * by the Free Software Foundation; version 2 of the license, or (at *
12 * your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17 * See the GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, you can get it from: *
21 * http://www.gnu.org/copyleft/gpl.html *
22 **********************************************************************/
24 #include "test.h"
26 static void test_media_list (const char ** argv, int argc)
28 libvlc_instance_t *vlc;
29 libvlc_media_t *md1, *md2, *md3, *md4;
30 libvlc_media_list_t *ml;
32 log ("Testing media_list\n");
34 libvlc_exception_init (&ex);
35 vlc = libvlc_new (argc, argv, &ex);
36 catch ();
38 ml = libvlc_media_list_new (vlc, &ex);
39 catch ();
41 md1 = libvlc_media_new (vlc, "/dev/null", &ex);
42 catch ();
43 md2 = libvlc_media_new (vlc, "/dev/null", &ex);
44 catch ();
45 md3 = libvlc_media_new (vlc, "/dev/null", &ex);
46 catch ();
48 libvlc_media_list_add_media (ml, md1, &ex);
49 catch ();
50 libvlc_media_list_add_media (ml, md2, &ex);
51 catch ();
53 assert( libvlc_media_list_count (ml, &ex) == 2 );
54 catch ();
56 assert( libvlc_media_list_index_of_item (ml, md1, &ex) == 0 );
57 catch ();
59 assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 1 );
60 catch ();
62 libvlc_media_list_remove_index (ml, 0, &ex); /* removing first item */
63 catch ();
65 /* test if second item was moved on first place */
66 assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 0 );
67 catch ();
69 libvlc_media_list_add_media (ml, md1, &ex); /* add 2 items */
70 catch ();
71 libvlc_media_list_add_media (ml, md1, &ex);
72 catch ();
74 /* there should be 3 pieces */
75 assert( libvlc_media_list_count (ml, &ex) == 3 );
76 catch ();
78 libvlc_media_list_insert_media (ml, md3, 2, &ex);
79 catch ();
81 /* there should be 4 pieces */
82 assert( libvlc_media_list_count (ml, &ex) == 4 );
83 catch ();
85 /* test inserting on right place */
86 assert( libvlc_media_list_index_of_item (ml, md3, &ex) == 2 );
87 catch ();
89 /* test right returning descriptor*/
90 assert ( libvlc_media_list_item_at_index (ml, 0, &ex) == md2 );
91 catch ();
93 assert ( libvlc_media_list_item_at_index (ml, 2, &ex) == md3 );
94 catch ();
96 /* test if give exceptions, when it should */
97 /* have 4 items, so index 4 should give exception */
98 libvlc_media_list_remove_index (ml, 4, &ex);
99 assert (have_exception ());
101 libvlc_media_list_remove_index (ml, 100, &ex);
102 assert (have_exception ());
104 libvlc_media_list_remove_index (ml, -1, &ex);
105 assert (have_exception ());
107 /* getting non valid items */
108 libvlc_media_t * p_non_exist =
109 libvlc_media_list_item_at_index (ml, 4, &ex);
110 assert (have_exception ());
112 p_non_exist = libvlc_media_list_item_at_index (ml, 100, &ex);
113 assert (have_exception ());
115 p_non_exist = libvlc_media_list_item_at_index (ml, -1, &ex);
116 assert (have_exception ());
118 md4 = libvlc_media_new (vlc, "/dev/null", &ex);
119 catch ();
121 /* try to find non inserted item */
122 int i_non_exist = 0;
123 i_non_exist = libvlc_media_list_index_of_item (ml, md4, &ex);
124 assert ( i_non_exist == -1 );
126 libvlc_media_release (md1);
127 libvlc_media_release (md2);
128 libvlc_media_release (md3);
129 libvlc_media_release (md4);
131 libvlc_media_list_release (ml);
133 libvlc_release (vlc);
134 catch ();
137 int main (void)
139 test_init();
141 test_media_list (test_defaults_args, test_defaults_nargs);
143 return 0;