don't mix tabs and spaces
[platform/upstream/gstreamer.git] / tests / old / 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__, #condition); \
42     return -test; \
43   } \
44 }G_STMT_END
45 #define TEST_START(pipeline) G_STMT_START{ \
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_STMT_END
56 #define TEST_OK G_STMT_START{ \
57   gst_object_unref (GST_OBJECT (cur)); \
58   cur = NULL; \
59   g_print ("TEST %2d line %3d COMPLETE\n", test, __LINE__); \
60 }G_STMT_END
61 #define TEST_RUN G_STMT_START{ \
62   alarm(10); \
63   g_print ("TEST %2d line %3d   RUN\n", test, __LINE__); \
64   if (gst_element_set_state (cur, GST_STATE_PLAYING) == GST_STATE_FAILURE) { \
65     g_print ("TEST %2d line %3d  FAILED  : pipeline could not be set to state PLAYING\n", test, __LINE__); \
66     return -test; \
67   } \
68   iterations = 0; \
69   while (gst_bin_iterate (GST_BIN (cur))) iterations++; \
70   if (gst_element_set_state (cur, GST_STATE_NULL) == GST_STATE_FAILURE) { \
71     g_print ("TEST %2d line %3d  FAILED  : pipeline could not be reset to state NULL\n", test, __LINE__); \
72     return -test; \
73   } \
74   g_print ("TEST %2d line %3d STOPPED  : %u iterations\n", test, __LINE__, iterations); \
75   alarm(0); \
76 }G_STMT_END
77 #define PIPELINE1  "fakesrc"
78 #define PIPELINE2  "fakesrc name=donald num-buffers= 27 silent =TruE sizetype = 3 eos  =    yesyo data=   Subbuffer\\ data"
79 #define PIPELINE3  "fakesrc identity fakesink"
80 #define PIPELINE4  "fakesrc num-buffers=4 .src ! identity !.sink identity .src ! .sink fakesink"
81 #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"
82 #define PIPELINE6  "pipeline.(name=\"john\" fakesrc num-buffers=4 ( thread. ( ! queue ! identity !{ queue ! fakesink }) ))"
83 #define PIPELINE7  "fakesrc num-buffers=4 ! tee name=tee .src%d! fakesink tee.src%d ! fakesink fakesink name =\"foo\" tee.src%d ! foo."
84 #define PIPELINE8  "fakesrc num-buffers=4 ! tee name=tee1 .src0,src1 ! .sink0, sink1 aggregator ! fakesink"
85 #define PIPELINE9  "fakesrc num-buffers=4 ! test. fakesink name=test"
86 #define PIPELINE10 "( fakesrc num-buffers=\"4\" ! ) identity ! fakesink"
87 #define PIPELINE11 "fakesink name = sink identity name=id ( fakesrc num-buffers=\"4\" ! id. ) id. ! sink."
88
89
90 gint
91 main (gint argc, gchar * argv[])
92 {
93   gst_init (&argc, &argv);
94
95   /**
96    * checks:
97    * - specifying an element works :)
98    * - if only 1 element is requested, no bin is returned, but the element
99    */
100   TEST_START (PIPELINE1);
101   TEST_CHECK_FAIL (G_OBJECT_TYPE (cur) == g_type_from_name ("GstFakeSrc"));
102   TEST_OK;
103
104   /**
105    * checks:
106    * - properties works
107    * - string, int, boolean and enums can be properly set (note: eos should be false)
108    * - first test of escaping strings
109    */
110   TEST_START (PIPELINE2);
111   g_object_get (G_OBJECT (cur), "name", &s, "num-buffers", &i, "silent", &b,
112       NULL);
113   TEST_CHECK_FAIL (strcmp (s, "donald") == 0);
114   TEST_CHECK_FAIL (i == 27);
115   TEST_CHECK_FAIL (b == TRUE);
116   g_object_get (G_OBJECT (cur), "eos", &b, "sizetype", &i, NULL);
117   TEST_CHECK_FAIL (i == 3);
118   TEST_CHECK_FAIL (b == FALSE);
119   g_object_get (G_OBJECT (cur), "data", &i, NULL);
120   TEST_CHECK_FAIL (i == 2);
121   TEST_OK;
122
123   /**
124    * checks:
125    * - specifying multiple elements without links works
126    * - if multiple toplevel elements exist, a pipeline is returned
127    */
128   TEST_START (PIPELINE3);
129   TEST_CHECK_FAIL (GST_BIN (cur)->numchildren == 3);    /* a bit hacky here */
130   TEST_CHECK_FAIL (GST_IS_PIPELINE (cur));
131   TEST_OK;
132
133   /**
134    * checks:
135    * - test default link "!"
136    * - test if specifying pads on links works
137    */
138   TEST_START (PIPELINE4);
139   TEST_RUN;
140   TEST_OK;
141
142   /**
143    * checks:
144    * - test if appending the links works, too
145    * - check if the pipeline constructed works the same as the one before
146    */
147   i = iterations;
148   TEST_START (PIPELINE5);
149   TEST_RUN;
150   TEST_CHECK_FAIL (i == iterations);
151   TEST_OK;
152
153   /**
154    * checks:
155    * - test various types of bins
156    * - test if linking across bins works
157    * - test if escaping strings works
158    */
159   TEST_START (PIPELINE6);
160   TEST_CHECK_FAIL (GST_IS_PIPELINE (cur));
161   g_object_get (G_OBJECT (cur), "name", &s, NULL);
162   TEST_CHECK_FAIL (strcmp (s, "john") == 0);
163   TEST_RUN;
164   TEST_OK;
165
166   /**
167    * checks:
168    * - test request pads
169    */
170   TEST_START (PIPELINE7);
171   TEST_RUN;
172   TEST_OK;
173
174   /**
175    * checks:
176    * - multiple pads on 1 link
177    */
178   TEST_START (PIPELINE8);
179   TEST_RUN;
180   TEST_OK;
181
182   /**
183    * checks:
184    * - failed in grammar.y cvs version 1.17
185    */
186   TEST_START (PIPELINE9);
187   TEST_RUN;
188   TEST_OK;
189
190   /**
191    * checks:
192    * - failed in grammar.y cvs version 1.17
193    */
194   TEST_START (PIPELINE10);
195   TEST_RUN;
196   TEST_OK;
197
198   /**
199    * checks:
200    * - failed in grammar.y cvs version 1.18
201    */
202   TEST_START (PIPELINE11);
203   TEST_RUN;
204   TEST_OK;
205
206   return 0;
207 }