upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / multifile.c
1 /* GStreamer unit test for multifile plugin
2  *
3  * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #endif
24
25 #include <glib/gstdio.h>
26 #include <unistd.h>
27
28 #include <gst/check/gstcheck.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31
32 static void
33 run_pipeline (GstElement * pipeline)
34 {
35   gst_element_set_state (pipeline, GST_STATE_PAUSED);
36   gst_element_get_state (pipeline, NULL, NULL, -1);
37   gst_element_set_state (pipeline, GST_STATE_PLAYING);
38   /* FIXME too lazy */
39   g_usleep (1000000);
40   gst_element_set_state (pipeline, GST_STATE_NULL);
41 }
42
43 static gchar *
44 g_mkdtemp (const gchar * template)
45 {
46   gchar *s;
47   gchar *tmpdir;
48
49   s = g_strdup (template);
50   tmpdir = mkdtemp (s);
51   if (tmpdir == NULL) {
52     g_free (s);
53   }
54   return tmpdir;
55 }
56
57 GST_START_TEST (test_multifilesink)
58 {
59   GstElement *pipeline;
60   GstElement *mfs;
61   int i;
62   const gchar *tmpdir;
63   gchar *my_tmpdir;
64   gchar *template;
65   gchar *mfs_pattern;
66
67   tmpdir = g_get_tmp_dir ();
68   template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
69   my_tmpdir = g_mkdtemp (template);
70   fail_if (my_tmpdir == NULL);
71
72   pipeline =
73       gst_parse_launch
74       ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink",
75       NULL);
76   fail_if (pipeline == NULL);
77   mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesink0");
78   fail_if (mfs == NULL);
79   mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
80   g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
81   g_object_unref (mfs);
82   run_pipeline (pipeline);
83   gst_object_unref (pipeline);
84
85   for (i = 0; i < 10; i++) {
86     char *s;
87
88     s = g_strdup_printf (mfs_pattern, i);
89     fail_if (g_remove (s) != 0);
90     g_free (s);
91   }
92   fail_if (g_remove (my_tmpdir) != 0);
93
94   g_free (mfs_pattern);
95   g_free (my_tmpdir);
96   g_free (template);
97 }
98
99 GST_END_TEST;
100
101 GST_START_TEST (test_multifilesrc)
102 {
103   GstElement *pipeline;
104   GstElement *mfs;
105   int i;
106   const gchar *tmpdir;
107   gchar *my_tmpdir;
108   gchar *template;
109   gchar *mfs_pattern;
110
111   tmpdir = g_get_tmp_dir ();
112   template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
113   my_tmpdir = g_mkdtemp (template);
114   fail_if (my_tmpdir == NULL);
115
116   pipeline =
117       gst_parse_launch
118       ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink",
119       NULL);
120   fail_if (pipeline == NULL);
121   mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesink0");
122   fail_if (mfs == NULL);
123   mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
124   g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
125   g_free (mfs_pattern);
126   g_object_unref (mfs);
127   run_pipeline (pipeline);
128   gst_object_unref (pipeline);
129
130   pipeline =
131       gst_parse_launch
132       ("multifilesrc ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240,framerate=10/1 ! fakesink",
133       NULL);
134   fail_if (pipeline == NULL);
135   mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesrc0");
136   fail_if (mfs == NULL);
137   mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
138   g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
139   g_object_unref (mfs);
140   run_pipeline (pipeline);
141   gst_object_unref (pipeline);
142
143   for (i = 0; i < 10; i++) {
144     char *s;
145
146     s = g_strdup_printf (mfs_pattern, i);
147     fail_if (g_remove (s) != 0);
148     g_free (s);
149   }
150   fail_if (g_remove (my_tmpdir) != 0);
151
152   g_free (mfs_pattern);
153   g_free (my_tmpdir);
154   g_free (template);
155 }
156
157 GST_END_TEST;
158
159 static Suite *
160 libvisual_suite (void)
161 {
162   Suite *s = suite_create ("multifile");
163   TCase *tc_chain = tcase_create ("general");
164
165   suite_add_tcase (s, tc_chain);
166
167   tcase_add_test (tc_chain, test_multifilesink);
168   tcase_add_test (tc_chain, test_multifilesrc);
169
170   return s;
171 }
172
173 GST_CHECK_MAIN (libvisual);