2 * media_list.c - libvlc smoke test
6 /**********************************************************************
7 * Copyright (C) 2007 RĂ©mi Denis-Courmont. *
8 * This program is free software; you can redistribute and/or modify *
9 * it under the terms of the GNU General Public License as published *
10 * by the Free Software Foundation; version 2 of the license, or (at *
11 * your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
16 * See the GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, you can get it from: *
20 * http://www.gnu.org/copyleft/gpl.html *
21 **********************************************************************/
25 static void test_media_list (const char ** argv
, int argc
)
27 libvlc_instance_t
*vlc
;
28 libvlc_media_t
*md
, *md1
, *md2
, *md3
, *md4
;
29 libvlc_media_list_t
*ml
;
32 test_log ("Testing media_list\n");
34 vlc
= libvlc_new (argc
, argv
);
37 ml
= libvlc_media_list_new();
40 md1
= libvlc_media_new_path (vlc
, "/dev/null");
42 md2
= libvlc_media_new_path (vlc
, "/dev/null");
44 md3
= libvlc_media_new_path (vlc
, "/dev/null");
47 ret
= libvlc_media_list_add_media (ml
, md1
);
49 ret
= libvlc_media_list_add_media (ml
, md2
);
52 assert( libvlc_media_list_count (ml
) == 2 );
53 assert( libvlc_media_list_index_of_item (ml
, md1
) == 0 );
54 assert( libvlc_media_list_index_of_item (ml
, md2
) == 1 );
56 ret
= libvlc_media_list_remove_index (ml
, 0); /* removing first item */
59 /* test if second item was moved on first place */
60 assert( libvlc_media_list_index_of_item (ml
, md2
) == 0 );
61 ret
= libvlc_media_list_add_media (ml
, md1
); /* add 2 items */
63 ret
= libvlc_media_list_add_media (ml
, md1
);
66 /* there should be 3 pieces */
67 assert( libvlc_media_list_count (ml
) == 3 );
69 ret
= libvlc_media_list_insert_media (ml
, md3
, 2);
72 /* there should be 4 pieces */
73 assert( libvlc_media_list_count (ml
) == 4 );
75 /* test inserting on right place */
76 assert( libvlc_media_list_index_of_item (ml
, md3
) == 2 );
78 /* test right returning descriptor*/
79 md
= libvlc_media_list_item_at_index (ml
, 0);
81 libvlc_media_release(md
);
83 md
= libvlc_media_list_item_at_index (ml
, 2);
85 libvlc_media_release(md
);
87 /* test if give errors, when it should */
88 /* have 4 items, so index 4 should give error */
89 ret
= libvlc_media_list_remove_index (ml
, 4);
92 ret
= libvlc_media_list_remove_index (ml
, 100);
95 ret
= libvlc_media_list_remove_index (ml
, -1);
98 /* getting non valid items */
99 libvlc_media_t
* p_non_exist
=
100 libvlc_media_list_item_at_index (ml
, 4);
101 assert (p_non_exist
== NULL
);
103 p_non_exist
= libvlc_media_list_item_at_index (ml
, 100);
104 assert (p_non_exist
== NULL
);
106 p_non_exist
= libvlc_media_list_item_at_index (ml
, -1);
107 assert (p_non_exist
== NULL
);
109 md4
= libvlc_media_new_path (vlc
, "/dev/null");
110 assert (md4
!= NULL
);
112 /* try to find non inserted item */
114 i_non_exist
= libvlc_media_list_index_of_item (ml
, md4
);
115 assert ( i_non_exist
== -1 );
117 libvlc_media_release (md1
);
118 libvlc_media_release (md2
);
119 libvlc_media_release (md3
);
120 libvlc_media_release (md4
);
122 libvlc_media_list_release (ml
);
124 libvlc_release (vlc
);
131 test_media_list (test_defaults_args
, test_defaults_nargs
);