3b0a3216200cb7d24aa07c050d18f29893f5210c
[platform/upstream/gstreamer.git] / tests / old / testsuite / parse / parse2.c
1 /*
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
4  * parse1.c: Test common pipelines (need various plugins)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <gst/gst.h>
22
23 #include <string.h>
24
25 /* variables used by the TEST_* macros */
26 static gint test = 0;
27 static guint iterations;
28 static GstElement *cur = NULL;
29 static GError *error = NULL;
30 static char *audio_file = NULL;
31 static char *video_file = NULL;
32
33 /* variables needed for checking */
34
35 #define TEST_CHECK_FAIL(condition) G_STMT_START{ \
36   if (condition) { \
37     g_print ("TEST %2d line %3d    OK\n", test, __LINE__); \
38   } else { \
39     g_print ("TEST %2d line %3d  FAILED : %s\n", test, __LINE__, #condition); \
40     return -test; \
41   } \
42 }G_STMT_END
43 #ifdef G_HAVE_ISO_VARARGS
44 #define TEST_START(...) G_STMT_START{ \
45   gchar *pipeline = g_strdup_printf (__VA_ARGS__); \
46   g_print ("TEST %2d line %3d  START   : %s\n", ++test, __LINE__, pipeline); \
47   cur = gst_parse_launch (pipeline, &error); \
48   if (error == NULL) { \
49     g_print ("TEST %2d line %3d CREATED\n", test, __LINE__); \
50   } else { \
51     g_print ("TEST %2d line %3d  FAILED  : %s\n", test, __LINE__, error->message); \
52     g_error_free (error); \
53     return -test; \
54   } \
55   g_free (pipeline); \
56 }G_STMT_END
57 #elif defined(G_HAVE_GNUC_VARARGS)
58 #define TEST_START(pipe...) G_STMT_START{ \
59   gchar *pipeline = g_strdup_printf ( ## pipe ); \
60   g_print ("TEST %2d line %3d  START   : %s\n", ++test, __LINE__, pipeline); \
61   cur = gst_parse_launch (pipeline, &error); \
62   if (error == NULL) { \
63     g_print ("TEST %2d line %3d CREATED\n", test, __LINE__); \
64   } else { \
65     g_print ("TEST %2d line %3d  FAILED  : %s\n", test, __LINE__, error->message); \
66     g_error_free (error); \
67     return -test; \
68   } \
69   g_free (pipeline); \
70 }G_STMT_END
71 #else
72 #error Please fix this macro here
73 #define TEST_START(pipe...) G_STMT_START{ \
74   gchar *pipeline = g_strdup_printf (__VA_ARGS__); \
75   g_print ("TEST %2d line %3d  START   : %s\n", ++test, __LINE__, pipeline); \
76   cur = gst_parse_launch (pipeline, &error); \
77   if (error == NULL) { \
78     g_print ("TEST %2d line %3d CREATED\n", test, __LINE__); \
79   } else { \
80     g_print ("TEST %2d line %3d  FAILED  : %s\n", test, __LINE__, error->message); \
81     g_error_free (error); \
82     return -test; \
83   } \
84   g_free (pipeline); \
85 }G_STMT_END
86 #endif
87 #define TEST_OK G_STMT_START{ \
88   gst_object_unref (GST_OBJECT (cur)); \
89   cur = NULL; \
90   g_print ("TEST %2d line %3d COMPLETE\n", test, __LINE__); \
91 }G_STMT_END
92 #define TEST_RUN(iters) G_STMT_START{ \
93   gint it = iters; \
94   g_print ("TEST %2d line %3d   RUN\n", test, __LINE__); \
95   if (gst_element_set_state (cur, GST_STATE_PLAYING) == GST_STATE_FAILURE) { \
96     g_print ("TEST %2d line %3d  FAILED  : pipeline could not be set to state PLAYING\n", test, __LINE__); \
97     return -test; \
98   } \
99   iterations = 0; \
100   while (gst_bin_iterate (GST_BIN (cur)) && it != 0) { \
101     iterations++; \
102     it--; \
103   } \
104   if (gst_element_set_state (cur, GST_STATE_NULL) == GST_STATE_FAILURE) { \
105     g_print ("TEST %2d line %3d  FAILED  : pipeline could not be reset to state NULL\n", test, __LINE__); \
106     return -test; \
107   } \
108   g_print ("TEST %2d line %3d STOPPED  : %u iterations\n", test, __LINE__, iterations); \
109 }G_STMT_END
110 #define TEST_FINISH G_STMT_START{ \
111   g_print("\n"); \
112   g_print("To run this test there are things required that you do not have. (see above)\n"); \
113   g_print("Please correct the above mentioned problem if you want to run this test.\n"); \
114   g_print("Currently the following tests will be ignored.\n"); \
115   g_print("\n"); \
116   exit (0); \
117 }G_STMT_END
118 #define TEST_REQUIRE(condition, error) G_STMT_START{ \
119   if (condition) { \
120     g_print ("REQUIRE line %3d    OK\n", __LINE__); \
121   } else { \
122     g_print ("REQUIRE line %3d   EXIT   : %s\n", __LINE__, (error)); \
123     TEST_FINISH; \
124   } \
125 }G_STMT_END
126 #define TEST_REQUIRE_ELEMENT(element_name) G_STMT_START{ \
127   GstElement *element = gst_element_factory_make ((element_name), NULL); \
128   if (element) { \
129     g_print ("REQUIRE line %3d    OK\n", __LINE__); \
130     gst_object_unref (GST_OBJECT (element)); \
131   } else { \
132     g_print ("REQUIRE line %3d   EXIT   : No element of type \"%s\" available. Exiting.\n", __LINE__, (element_name)); \
133     TEST_FINISH; \
134   } \
135 }G_STMT_END
136
137 #define PIPELINE1 "filesrc blocksize =8192  location=%s ! mad ! osssink"
138 #define PIPELINE2 "filesrc location=%s ! mpegdemux ! mpeg2dec ! xvimagesink"
139 #define PIPELINE3 "filesrc location=%s ! mpegdemux name = demux ! mpeg2dec ! { queue ! xvimagesink } demux.audio_00 ! mad ! osssink"
140 #define PIPELINE4 "pipeline. ( { filesrc location=%s ! spider name=spider ! { queue ! volume ! ( tee name=tee ! { queue ! ( goom ) ! colorspace ! ( xvimagesink ) } tee. ! { queue ! ( osssink ) } ) } spider. ! { queue ! colorspace ( xvimagesink ) } } )"
141 #define PIPELINE5 "pipeline. ( { filesrc location=%s ! spider name=spider ! ( tee name=tee ! { queue ! spider ! ( goom ) ! colorspace ! ( xvimagesink ) } tee. ! { queue ! volume ! ( osssink ) } ) spider. ! { queue! colorspace ( xvimagesink ) } } )"
142
143 /* FIXME: Should this run, too?
144 #define PIPELINE3 "filesrc location=%s ! mpegdemux name = demux ! mpeg2dec ! { queue ! xvimagesink } demux.audio_%%02d ! mad ! osssink"
145 */
146
147 gint
148 main (gint argc, gchar * argv[])
149 {
150   gst_init (&argc, &argv);
151
152   goto here;
153 here:
154
155   /**
156    * checks:
157    * - default playback pipeline
158    * - unsigned parameters
159    */
160   audio_file = g_build_filename (g_get_home_dir (), "music.mp3", NULL);
161   TEST_REQUIRE (g_file_test (audio_file, G_FILE_TEST_EXISTS),
162       "The following tests requires a valid mp3 file music.mp3 in your home directory.");
163   TEST_REQUIRE_ELEMENT ("mad");
164   TEST_REQUIRE_ELEMENT ("osssink");
165   TEST_START (PIPELINE1, audio_file);
166   TEST_RUN (10);
167   TEST_OK;
168
169   /**
170    * checks:
171    * - default video playback pipeline (without audio)
172    * - SOMETIMES pads
173    */
174   video_file = g_build_filename (g_get_home_dir (), "video.mpeg", NULL);
175   TEST_REQUIRE (g_file_test (video_file, G_FILE_TEST_EXISTS),
176       "The following tests requires a valid mpeg file video.mpeg in your home directory.");
177   TEST_REQUIRE_ELEMENT ("mpegdemux");
178   TEST_REQUIRE_ELEMENT ("mpeg2dec");
179   TEST_REQUIRE_ELEMENT ("xvimagesink");
180   TEST_START (PIPELINE2, video_file);
181   TEST_RUN (50);
182   TEST_OK;
183
184   /**
185    * checks:
186    * - default video playback pipeline (with audio)
187    * - more SOMETIMES pads
188    */
189   TEST_START (PIPELINE3, video_file);
190   TEST_RUN (200);
191   TEST_OK;
192
193   /**
194    * checks:
195    * - default new gst-player pipeline
196    */
197   TEST_START (PIPELINE4, video_file);
198   TEST_RUN (500);
199   TEST_OK;
200
201   /**
202    * checks:
203    * - default old gst-player pipeline
204    */
205   TEST_START (PIPELINE5, video_file);
206   TEST_RUN (500);
207   TEST_OK;
208
209   g_free (audio_file);
210   g_free (video_file);
211   return 0;
212 }