contrib: rust: freeze the Rust version
[vlc.git] / test / libvlc / media_list.c
blobf2cb1e734e8832a479aa1565f2b699462eb9b9c3
1 /*
2 * media_list.c - libvlc smoke test
4 */
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. *
12 * *
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. *
17 * *
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 **********************************************************************/
23 #include "test.h"
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;
30 int ret;
32 test_log ("Testing media_list\n");
34 vlc = libvlc_new (argc, argv);
35 assert (vlc != NULL);
37 ml = libvlc_media_list_new();
38 assert (ml != NULL);
40 md1 = libvlc_media_new_path (vlc, "/dev/null");
41 assert (md1 != NULL);
42 md2 = libvlc_media_new_path (vlc, "/dev/null");
43 assert (md2 != NULL);
44 md3 = libvlc_media_new_path (vlc, "/dev/null");
45 assert (md3 != NULL);
47 ret = libvlc_media_list_add_media (ml, md1);
48 assert (!ret);
49 ret = libvlc_media_list_add_media (ml, md2);
50 assert (!ret);
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 */
57 assert (!ret);
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 */
62 assert (!ret);
63 ret = libvlc_media_list_add_media (ml, md1);
64 assert (!ret);
66 /* there should be 3 pieces */
67 assert( libvlc_media_list_count (ml) == 3 );
69 ret = libvlc_media_list_insert_media (ml, md3, 2);
70 assert (!ret);
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);
80 assert(md == md2);
81 libvlc_media_release(md);
83 md = libvlc_media_list_item_at_index (ml, 2);
84 assert(md == md3);
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);
90 assert (ret == -1);
92 ret = libvlc_media_list_remove_index (ml, 100);
93 assert (ret == -1);
95 ret = libvlc_media_list_remove_index (ml, -1);
96 assert (ret == -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 */
113 int i_non_exist = 0;
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);
127 int main (void)
129 test_init();
131 test_media_list (test_defaults_args, test_defaults_nargs);
133 return 0;