be4764a94444dd17dd2f9c23882eafc55b4b511b
[platform/upstream/gstreamer.git] / testsuite / parse / parse1.c
1 /*
2  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3  *
4  * parse1.c: Test various parsing stuff
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 #include <unistd.h>
25
26 /* variables used by the TEST_* macros */
27 static gint test = 0;
28 static guint iterations;
29 static GstElement *cur = NULL;
30 static GError *error = NULL;
31
32 /* variables needed for checking */
33 static gint i;
34 static gboolean b;
35 static gchar *s;
36
37 #define TEST_CHECK_FAIL(condition) G_STMT_START{                        \
38   if (condition) {                                                      \
39     g_print ("TEST %2d line %3d    OK\n", test, __LINE__);              \
40   } else {                                                              \
41     g_print ("TEST %2d line %3d  FAILED : %s\n", test, __LINE__,        \
42         #condition);                                                    \
43     return -test;                                                       \
44   }                                                                     \
45 }G_STMT_END
46
47 #define TEST_START(pipeline) G_STMT_START{                              \
48   g_print ("TEST %2d line %3d  START   : %s\n", ++test, __LINE__,       \
49       pipeline);                                                        \
50   cur = gst_parse_launch (pipeline, &error);                            \
51   if (error == NULL) {                                                  \
52     g_print ("TEST %2d line %3d CREATED\n", test, __LINE__);            \
53   } else {                                                              \
54     g_print ("TEST %2d line %3d  FAILED  : %s\n", test, __LINE__,       \
55         error->message);                                                \
56     g_error_free (error);                                               \
57     return -test;                                                       \
58   }                                                                     \
59 }G_STMT_END
60
61 #define TEST_OK G_STMT_START{                                           \
62   gst_object_unref (GST_OBJECT (cur));                                  \
63   cur = NULL;                                                           \
64   g_print ("TEST %2d line %3d COMPLETE\n", test, __LINE__);             \
65 }G_STMT_END
66
67 #define TEST_RUN G_STMT_START{                                          \
68   alarm(10);                                                            \
69   g_print ("TEST %2d line %3d   RUN\n", test, __LINE__);                \
70   if (gst_element_set_state (cur, GST_STATE_PLAYING)                    \
71       == GST_STATE_FAILURE) {                                           \
72     g_print ("TEST %2d line %3d  FAILED  : "                            \
73         "pipeline could not be set to PLAYING\n", test, __LINE__);      \
74     return -test;                                                       \
75   }                                                                     \
76   iterations = 0;                                                       \
77   while (gst_bin_iterate (GST_BIN (cur))) iterations++;                 \
78   if (gst_element_set_state (cur, GST_STATE_NULL)                       \
79       == GST_STATE_FAILURE) {                                           \
80     g_print ("TEST %2d line %3d  FAILED  : "                            \
81         "pipeline could not be reset to state NULL\n", test, __LINE__); \
82     return -test;                                                       \
83   }                                                                     \
84   g_print ("TEST %2d line %3d STOPPED  : %u iterations\n",              \
85       test, __LINE__, iterations);                                      \
86   alarm(0);                                                             \
87 }G_STMT_END
88
89 #define PIPELINE1  "fakesrc"
90 #define PIPELINE2  "fakesrc name=donald num-buffers= 27 silent =TruE sizetype = 3 eos  =    falSe data=   Subbuffer\\ data"
91 #define PIPELINE3  "fakesrc identity fakesink"
92 #define PIPELINE4  "fakesrc num-buffers=4 .src ! identity !.sink identity .src ! .sink fakesink"
93 #define PIPELINE5  "fakesrc num-buffers=4 name=src identity name=id1 identity name = id2 fakesink name =sink src. ! id1. id1.! id2.sink id2.src!sink.sink"
94 #define PIPELINE6  "pipeline.(name=\"john\" fakesrc num-buffers=4 ( thread. ( ! queue ! identity !{ queue ! fakesink }) ))"
95 #define PIPELINE7  "fakesrc num-buffers=4 ! tee name=tee .src%d! fakesink tee.src%d ! fakesink fakesink name =\"foo\" tee.src%d ! foo."
96 /* aggregator is borked
97 #define PIPELINE8  "fakesrc num-buffers=4 ! tee name=tee1 .src0,src1 ! .sink0, sink1 aggregator ! fakesink"
98 */
99 #define PIPELINE8  "fakesrc num-buffers=4 ! fakesink"
100 #define PIPELINE9  "fakesrc num-buffers=4 ! test. fakesink name=test"
101 #define PIPELINE10 "( fakesrc num-buffers=\"4\" ! ) identity ! fakesink"
102 #define PIPELINE11 "fakesink name = sink identity name=id ( fakesrc num-buffers=\"4\" ! id. ) id. ! sink."
103 #define PIPELINE12 "fakesrc num-buffers=4 name=a:b  a:b. ! fakesink"
104
105 gint
106 main (gint argc, gchar * argv[])
107 {
108   gst_init (&argc, &argv);
109
110   /**
111    * checks:
112    * - specifying an element works :)
113    * - if only 1 element is requested, no bin is returned, but the element
114    */
115   TEST_START (PIPELINE1);
116   TEST_CHECK_FAIL (G_OBJECT_TYPE (cur) == g_type_from_name ("GstFakeSrc"));
117   TEST_OK;
118
119   /**
120    * checks:
121    * - properties works
122    * - string, int, boolean and enums can be properly set
123    *   (note: eos should be false)
124    * - first test of escaping strings
125    */
126   TEST_START (PIPELINE2);
127   g_object_get (G_OBJECT (cur), "name", &s, "num-buffers", &i, "silent", &b,
128       NULL);
129   TEST_CHECK_FAIL (strcmp (s, "donald") == 0);
130   TEST_CHECK_FAIL (i == 27);
131   TEST_CHECK_FAIL (b == TRUE);
132   g_object_get (G_OBJECT (cur), "eos", &b, "sizetype", &i, NULL);
133   TEST_CHECK_FAIL (i == 3);
134   TEST_CHECK_FAIL (b == FALSE);
135   g_object_get (G_OBJECT (cur), "data", &i, NULL);
136   TEST_CHECK_FAIL (i == 2);
137   TEST_OK;
138
139   /**
140    * checks:
141    * - specifying multiple elements without links works
142    * - if multiple toplevel elements exist, a pipeline is returned
143    */
144   TEST_START (PIPELINE3);
145   TEST_CHECK_FAIL (GST_BIN (cur)->numchildren == 3);    /* a bit hacky here */
146   TEST_CHECK_FAIL (GST_IS_PIPELINE (cur));
147   TEST_OK;
148
149   /**
150    * checks:
151    * - test default link "!"
152    * - test if specifying pads on links works
153    */
154   TEST_START (PIPELINE4);
155   TEST_RUN;
156   TEST_OK;
157
158   /**
159    * checks:
160    * - test if appending the links works, too
161    * - check if the pipeline constructed works the same as the one before (how?)
162    */
163   TEST_START (PIPELINE5);
164   TEST_RUN;
165   TEST_OK;
166
167   /**
168    * checks:
169    * - test various types of bins
170    * - test if linking across bins works
171    * - test if escaping strings works
172    */
173   TEST_START (PIPELINE6);
174   TEST_CHECK_FAIL (GST_IS_PIPELINE (cur));
175   g_object_get (G_OBJECT (cur), "name", &s, NULL);
176   TEST_CHECK_FAIL (strcmp (s, "john") == 0);
177   TEST_RUN;
178   TEST_OK;
179
180   /**
181    * checks:
182    * - test request pads
183    */
184   TEST_START (PIPELINE7);
185   TEST_RUN;
186   TEST_OK;
187
188   /**
189    * checks:
190    * - multiple pads on 1 link
191    */
192   TEST_START (PIPELINE8);
193   TEST_RUN;
194   TEST_OK;
195
196   /**
197    * checks:
198    * - failed in grammar.y cvs version 1.17
199    */
200   TEST_START (PIPELINE9);
201   TEST_RUN;
202   TEST_OK;
203
204   /**
205    * checks:
206    * - failed in grammar.y cvs version 1.17
207    */
208   TEST_START (PIPELINE10);
209   TEST_RUN;
210   TEST_OK;
211
212   /**
213    * checks:
214    * - failed in grammar.y cvs version 1.18
215    */
216   TEST_START (PIPELINE11);
217   TEST_RUN;
218   TEST_OK;
219
220   /**
221    * checks:
222    * - fails because a:b. is not a valid element reference in parse.l cvs rev 1.29
223    */
224   TEST_START (PIPELINE12);
225   TEST_RUN;
226   TEST_OK;
227
228   return 0;
229 }