]> git.sesse.net Git - vlc/blob - src/control/testapi.c
Don't include config.h from the headers - refs #297.
[vlc] / src / control / testapi.c
1 /*
2  * testapi.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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include <vlc/libvlc.h>
28
29 #undef NDEBUG
30 #include <assert.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35
36 static libvlc_exception_t ex;
37
38 static void catch (void)
39 {
40     if (libvlc_exception_raised (&ex))
41     {
42          fprintf (stderr, "Exception: %s\n",
43                   libvlc_exception_get_message (&ex));
44          abort ();
45     }
46
47     assert (libvlc_exception_get_message (&ex) == NULL);
48     libvlc_exception_clear (&ex);
49 }
50
51 static void test_core (const char ** argv, int argc);
52 static void test_media_list (const char ** argv, int argc);
53
54 static void test_core (const char ** argv, int argc)
55 {
56     libvlc_instance_t *vlc;
57     int id;
58
59     libvlc_exception_init (&ex);
60     vlc = libvlc_new (argc, argv, &ex);
61     catch ();
62
63     libvlc_playlist_clear (vlc, &ex);
64     catch ();
65
66     id = libvlc_playlist_add_extended (vlc, "/dev/null", "Test", 0, NULL,
67                                        &ex);
68     catch ();
69
70     libvlc_playlist_clear (vlc, &ex);
71     catch ();
72
73     libvlc_retain (vlc);
74     libvlc_release (vlc, &ex);
75     catch ();
76     libvlc_release (vlc, &ex);
77     catch ();
78 }
79
80 static void test_media_list (const char ** argv, int argc)
81 {
82     libvlc_instance_t *vlc;
83     libvlc_media_descriptor_t *md;
84     libvlc_media_list_t *ml;
85
86     libvlc_exception_init (&ex);
87     vlc = libvlc_new (argc, argv, &ex);
88     catch ();
89
90     ml = libvlc_media_list_new (vlc, &ex);
91     catch ();
92
93     md = libvlc_media_descriptor_new (vlc, "/dev/null", &ex);
94     catch ();
95
96     libvlc_media_list_add_media_descriptor (ml, md, &ex);
97     catch ();
98     libvlc_media_list_add_media_descriptor (ml, md, &ex);
99     catch ();
100
101     assert( libvlc_media_list_count (ml, &ex) == 2 );
102     catch ();
103
104     libvlc_media_descriptor_release (md);
105
106     libvlc_media_list_release (ml);
107
108     libvlc_release (vlc, &ex);
109     catch ();
110 }
111
112 int main (int argc, char *argv[])
113 {
114     const char *args[argc + 3];
115     int nlibvlc_args = sizeof (args) / sizeof (args[0]);
116
117     alarm (30); /* Make sure "make check" does not get stuck */
118
119     args[0] = "-vvv";
120     args[1] = "-I";
121     args[2] = "-dummy";
122     args[3] = "--plugin-path=../modules";
123     for (int i = 1; i < argc; i++)
124         args[i + 3] = argv[i];
125
126     test_core (args, nlibvlc_args);
127
128     test_media_list (args, nlibvlc_args);
129     return 0;
130 }