Initialize Tizen 2.3
[framework/multimedia/gstreamer0.10.git] / wearable / tests / check / pipelines / stress.c
1 /* GStreamer
2  * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20
21 #include <gst/check/gstcheck.h>
22
23 static int playing = 1;
24 static int quit = 0;
25
26 static gboolean
27 change_state_timeout (gpointer data)
28 {
29   GstElement *pipeline = (GstElement *) data;
30
31   if (quit)
32     return FALSE;
33
34   if (playing) {
35     playing = 0;
36     gst_element_set_state (pipeline, GST_STATE_NULL);
37   } else {
38     playing = 1;
39     gst_element_set_state (pipeline, GST_STATE_PLAYING);
40   }
41
42   return TRUE;
43 }
44
45 static gboolean
46 quit_timeout (gpointer data)
47 {
48   quit = 1;
49   return FALSE;
50 }
51
52 GST_START_TEST (test_stress_preroll)
53 {
54   GstElement *fakesrc, *fakesink;
55   GstElement *pipeline;
56
57   fakesrc = gst_element_factory_make ("fakesrc", NULL);
58   fakesink = gst_element_factory_make ("fakesink", NULL);
59   pipeline = gst_element_factory_make ("pipeline", NULL);
60
61   g_return_if_fail (fakesrc && fakesink && pipeline);
62
63   g_object_set (G_OBJECT (fakesink), "preroll-queue-len", 4, NULL);
64
65   gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
66   gst_element_link (fakesrc, fakesink);
67
68   gst_element_set_state (pipeline, GST_STATE_PLAYING);
69
70   g_timeout_add (500, &change_state_timeout, pipeline);
71   g_timeout_add (10000, &quit_timeout, NULL);
72
73   while (!quit) {
74     g_main_context_iteration (NULL, TRUE);
75   }
76
77   gst_element_set_state (pipeline, GST_STATE_NULL);
78   gst_object_unref (pipeline);
79 }
80
81 GST_END_TEST;
82
83 GST_START_TEST (test_stress)
84 {
85   GstElement *fakesrc, *fakesink, *pipeline;
86   gint i;
87
88   fakesrc = gst_element_factory_make ("fakesrc", NULL);
89   fakesink = gst_element_factory_make ("fakesink", NULL);
90   pipeline = gst_element_factory_make ("pipeline", NULL);
91
92   g_return_if_fail (fakesrc && fakesink && pipeline);
93
94   gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
95   gst_element_link (fakesrc, fakesink);
96
97   i = 100;
98   while (i--) {
99     gst_element_set_state (pipeline, GST_STATE_PAUSED);
100     gst_element_set_state (pipeline, GST_STATE_PLAYING);
101
102     gst_element_set_state (pipeline, GST_STATE_PAUSED);
103     gst_element_set_state (pipeline, GST_STATE_PLAYING);
104     gst_element_set_state (pipeline, GST_STATE_PAUSED);
105     gst_element_set_state (pipeline, GST_STATE_READY);
106     gst_element_set_state (pipeline, GST_STATE_PLAYING);
107     gst_element_set_state (pipeline, GST_STATE_PAUSED);
108     gst_element_set_state (pipeline, GST_STATE_READY);
109     gst_element_set_state (pipeline, GST_STATE_PAUSED);
110     gst_element_set_state (pipeline, GST_STATE_NULL);
111   }
112
113   gst_object_unref (pipeline);
114 }
115
116 GST_END_TEST;
117
118 static Suite *
119 stress_suite (void)
120 {
121   Suite *s = suite_create ("stress");
122   TCase *tc_chain = tcase_create ("linear");
123
124   /* Completely disable timeout for this test */
125   tcase_set_timeout (tc_chain, 0);
126
127   suite_add_tcase (s, tc_chain);
128   tcase_add_test (tc_chain, test_stress);
129   tcase_add_test (tc_chain, test_stress_preroll);
130
131   return s;
132 }
133
134 GST_CHECK_MAIN (stress);