decoder: cc: detect/auto raise reorder depth
[vlc.git] / test / libvlc / media_list.c
blob743390a2c8dbf73831ceca0bd6f274a6fc47ec9c
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 *md, *md1, *md2, *md3, *md4;
30 libvlc_media_list_t *ml;
31 int ret;
33 log ("Testing media_list\n");
35 vlc = libvlc_new (argc, argv);
36 assert (vlc != NULL);
38 ml = libvlc_media_list_new (vlc);
39 assert (ml != NULL);
41 md1 = libvlc_media_new_path (vlc, "/dev/null");
42 assert (md1 != NULL);
43 md2 = libvlc_media_new_path (vlc, "/dev/null");
44 assert (md2 != NULL);
45 md3 = libvlc_media_new_path (vlc, "/dev/null");
46 assert (md3 != NULL);
48 ret = libvlc_media_list_add_media (ml, md1);
49 assert (!ret);
50 ret = libvlc_media_list_add_media (ml, md2);
51 assert (!ret);
53 assert( libvlc_media_list_count (ml) == 2 );
54 assert( libvlc_media_list_index_of_item (ml, md1) == 0 );
55 assert( libvlc_media_list_index_of_item (ml, md2) == 1 );
57 ret = libvlc_media_list_remove_index (ml, 0); /* removing first item */
58 assert (!ret);
60 /* test if second item was moved on first place */
61 assert( libvlc_media_list_index_of_item (ml, md2) == 0 );
62 ret = libvlc_media_list_add_media (ml, md1); /* add 2 items */
63 assert (!ret);
64 ret = libvlc_media_list_add_media (ml, md1);
65 assert (!ret);
67 /* there should be 3 pieces */
68 assert( libvlc_media_list_count (ml) == 3 );
70 ret = libvlc_media_list_insert_media (ml, md3, 2);
71 assert (!ret);
73 /* there should be 4 pieces */
74 assert( libvlc_media_list_count (ml) == 4 );
76 /* test inserting on right place */
77 assert( libvlc_media_list_index_of_item (ml, md3) == 2 );
79 /* test right returning descriptor*/
80 md = libvlc_media_list_item_at_index (ml, 0);
81 assert(md == md2);
82 libvlc_media_release(md);
84 md = libvlc_media_list_item_at_index (ml, 2);
85 assert(md == md3);
86 libvlc_media_release(md);
88 /* test if give errors, when it should */
89 /* have 4 items, so index 4 should give error */
90 ret = libvlc_media_list_remove_index (ml, 4);
91 assert (ret == -1);
93 ret = libvlc_media_list_remove_index (ml, 100);
94 assert (ret == -1);
96 ret = libvlc_media_list_remove_index (ml, -1);
97 assert (ret == -1);
99 /* getting non valid items */
100 libvlc_media_t * p_non_exist =
101 libvlc_media_list_item_at_index (ml, 4);
102 assert (p_non_exist == NULL);
104 p_non_exist = libvlc_media_list_item_at_index (ml, 100);
105 assert (p_non_exist == NULL);
107 p_non_exist = libvlc_media_list_item_at_index (ml, -1);
108 assert (p_non_exist == NULL);
110 md4 = libvlc_media_new_path (vlc, "/dev/null");
111 assert (md4 != NULL);
113 /* try to find non inserted item */
114 int i_non_exist = 0;
115 i_non_exist = libvlc_media_list_index_of_item (ml, md4);
116 assert ( i_non_exist == -1 );
118 libvlc_media_release (md1);
119 libvlc_media_release (md2);
120 libvlc_media_release (md3);
121 libvlc_media_release (md4);
123 libvlc_media_list_release (ml);
125 libvlc_release (vlc);
128 int main (void)
130 test_init();
132 test_media_list (test_defaults_args, test_defaults_nargs);
134 return 0;