5 * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
24 #include <gst/check/gstbufferstraw.h>
27 static gboolean got_eos = FALSE;
30 message_handler (GstBus * bus, GstMessage * msg, gpointer data)
32 GMainLoop *loop = (GMainLoop *) data;
34 switch (GST_MESSAGE_TYPE (msg)) {
37 g_main_loop_quit (loop);
39 case GST_MESSAGE_ERROR:{
43 gst_message_parse_error (msg, &err, &debug);
46 /* Will abort the check */
47 g_warning ("Error: %s\n", err->message);
50 g_main_loop_quit (loop);
60 GST_START_TEST (test_memory_stream)
64 GstElement *src, *sink;
66 GMemoryInputStream *input;
67 GMemoryOutputStream *output;
71 GstFormat fmt = GST_FORMAT_BYTES;
77 in_data = g_new (guint8, 512);
78 out_data = g_new (guint8, 512);
79 for (i = 0; i < 512; i++)
83 G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512,
84 (GDestroyNotify) g_free));
86 output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (out_data, 512,
87 (GReallocFunc) g_realloc, (GDestroyNotify) g_free));
90 loop = g_main_loop_new (NULL, FALSE);
92 bin = gst_pipeline_new ("bin");
94 src = gst_element_factory_make ("giostreamsrc", "src");
95 fail_unless (src != NULL);
96 g_object_set (G_OBJECT (src), "stream", input, NULL);
98 sink = gst_element_factory_make ("giostreamsink", "sink");
99 fail_unless (sink != NULL);
100 g_object_set (G_OBJECT (sink), "stream", output, NULL);
102 gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
104 fail_unless (gst_element_link_many (src, sink, NULL));
106 bus = gst_element_get_bus (bin);
107 bus_watch = gst_bus_add_watch (bus, message_handler, loop);
108 gst_object_unref (bus);
110 gst_element_set_state (bin, GST_STATE_PAUSED);
111 gst_element_get_state (bin, NULL, NULL, -1);
113 fail_unless (gst_element_query_duration (bin, &fmt, &duration));
114 fail_unless_equals_int (duration, 512);
116 gst_element_set_state (bin, GST_STATE_PLAYING);
118 g_main_loop_run (loop);
120 gst_element_set_state (bin, GST_STATE_NULL);
122 fail_unless (got_eos);
125 out_data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output));
127 for (i = 0; i < 512; i++)
128 fail_unless_equals_int (in_data[i], out_data[i]);
130 gst_element_set_state (bin, GST_STATE_PAUSED);
131 gst_element_get_state (bin, NULL, NULL, -1);
133 fail_unless (gst_element_query_duration (bin, &fmt, &duration));
134 fail_unless_equals_int (duration, 512);
136 gst_element_set_state (bin, GST_STATE_PLAYING);
138 g_main_loop_run (loop);
140 gst_element_set_state (bin, GST_STATE_NULL);
141 gst_object_unref (bin);
143 fail_unless (got_eos);
145 g_object_unref (input);
146 g_object_unref (output);
148 g_main_loop_unref (loop);
149 g_source_remove (bus_watch);
157 Suite *s = suite_create ("gio");
158 TCase *tc_chain = tcase_create ("general");
160 suite_add_tcase (s, tc_chain);
161 tcase_add_test (tc_chain, test_memory_stream);
167 main (int argc, char **argv)
171 Suite *s = gio_testsuite ();
172 SRunner *sr = srunner_create (s);
174 gst_check_init (&argc, &argv);
176 srunner_run_all (sr, CK_NORMAL);
177 nf = srunner_ntests_failed (sr);