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