]> git.sesse.net Git - vlc/blob - test/libvlc/media_list.c
a8e5f024937ba06177db49c17f7c9c9592b1ce74
[vlc] / test / libvlc / media_list.c
1 /*
2  * media_list.c - libvlc smoke test
3  *
4  * $Id$
5  */
6
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  **********************************************************************/
23
24 #include "test.h"
25
26 static void test_media_list (const char ** argv, int argc)
27 {
28     libvlc_instance_t *vlc;
29     libvlc_media_t *md1, *md2, *md3, *md4;
30     libvlc_media_list_t *ml;
31     int ret;
32
33     log ("Testing media_list\n");
34
35     libvlc_exception_init (&ex);
36     vlc = libvlc_new (argc, argv);
37     assert (vlc != NULL);
38
39     ml = libvlc_media_list_new (vlc);
40     assert (ml != NULL);
41
42     md1 = libvlc_media_new (vlc, "/dev/null");
43     assert (md1 != NULL);
44     md2 = libvlc_media_new (vlc, "/dev/null");
45     assert (md2 != NULL);
46     md3 = libvlc_media_new (vlc, "/dev/null");
47     assert (md3 != NULL);
48
49     ret = libvlc_media_list_add_media (ml, md1);
50     assert (!ret);
51     ret = libvlc_media_list_add_media (ml, md2);
52     assert (!ret);
53
54     assert( libvlc_media_list_count (ml) == 2 );
55     assert( libvlc_media_list_index_of_item (ml, md1) == 0 );
56     assert( libvlc_media_list_index_of_item (ml, md2) == 1 );
57
58     ret = libvlc_media_list_remove_index (ml, 0);  /* removing first item */
59     assert (!ret);
60
61     /* test if second item was moved on first place */
62     assert( libvlc_media_list_index_of_item (ml, md2) == 0 );
63     ret = libvlc_media_list_add_media (ml, md1); /* add 2 items */
64     assert (!ret);
65     ret = libvlc_media_list_add_media (ml, md1);
66     assert (!ret);
67
68     /* there should be 3 pieces */
69     assert( libvlc_media_list_count (ml) == 3 );
70
71     ret = libvlc_media_list_insert_media (ml, md3, 2);
72     assert (!ret);
73
74     /* there should be 4 pieces */
75     assert( libvlc_media_list_count (ml) == 4 );
76
77     /* test inserting on right place */
78     assert( libvlc_media_list_index_of_item (ml, md3) == 2 );
79
80     /* test right returning descriptor*/
81     assert ( libvlc_media_list_item_at_index (ml, 0) == md2 );
82
83     assert ( libvlc_media_list_item_at_index (ml, 2) == md3 );
84
85     /* test if give exceptions, when it should */
86     /* have 4 items, so index 4 should give exception */
87     ret = libvlc_media_list_remove_index (ml, 4);
88     assert (ret == -1);
89
90     ret = libvlc_media_list_remove_index (ml, 100);
91     assert (ret == -1);
92
93     ret = libvlc_media_list_remove_index (ml, -1);
94     assert (ret == -1);
95
96     /* getting non valid items */
97     libvlc_media_t * p_non_exist =
98         libvlc_media_list_item_at_index (ml, 4);
99     assert (p_non_exist == NULL);
100
101     p_non_exist = libvlc_media_list_item_at_index (ml, 100);
102     assert (p_non_exist == NULL);
103
104     p_non_exist = libvlc_media_list_item_at_index (ml, -1);
105     assert (p_non_exist == NULL);
106
107     md4 = libvlc_media_new (vlc, "/dev/null");
108     assert (md4 != NULL);
109
110     /* try to find non inserted item */
111     int i_non_exist = 0;
112     i_non_exist = libvlc_media_list_index_of_item (ml, md4);
113     assert ( i_non_exist == -1 );
114
115     libvlc_media_release (md1);
116     libvlc_media_release (md2);
117     libvlc_media_release (md3);
118     libvlc_media_release (md4);
119
120     libvlc_media_list_release (ml);
121
122     libvlc_release (vlc);
123     catch ();
124 }
125
126 int main (void)
127 {
128     test_init();
129
130     test_media_list (test_defaults_args, test_defaults_nargs);
131
132     return 0;
133 }