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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, 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;
76 in_data = g_new (guint8, 512);
77 out_data = g_new (guint8, 512);
78 for (i = 0; i < 512; i++)
82 G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512,
83 (GDestroyNotify) g_free));
85 output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (out_data, 512,
86 (GReallocFunc) g_realloc, (GDestroyNotify) g_free));
89 loop = g_main_loop_new (NULL, FALSE);
91 bin = gst_pipeline_new ("bin");
93 src = gst_element_factory_make ("giostreamsrc", "src");
94 fail_unless (src != NULL);
95 g_object_set (G_OBJECT (src), "stream", input, NULL);
97 sink = gst_element_factory_make ("giostreamsink", "sink");
98 fail_unless (sink != NULL);
99 g_object_set (G_OBJECT (sink), "stream", output, NULL);
101 gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
103 fail_unless (gst_element_link_many (src, sink, NULL));
105 bus = gst_element_get_bus (bin);
106 bus_watch = gst_bus_add_watch (bus, message_handler, loop);
107 gst_object_unref (bus);
109 gst_element_set_state (bin, GST_STATE_PAUSED);
110 gst_element_get_state (bin, NULL, NULL, -1);
112 fail_unless (gst_element_query_duration (bin, GST_FORMAT_BYTES, &duration));
113 fail_unless_equals_int (duration, 512);
115 gst_element_set_state (bin, GST_STATE_PLAYING);
117 g_main_loop_run (loop);
119 gst_element_set_state (bin, GST_STATE_NULL);
121 fail_unless (got_eos);
124 out_data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output));
126 for (i = 0; i < 512; i++)
127 fail_unless_equals_int (in_data[i], out_data[i]);
129 gst_element_set_state (bin, GST_STATE_PAUSED);
130 gst_element_get_state (bin, NULL, NULL, -1);
132 fail_unless (gst_element_query_duration (bin, GST_FORMAT_BYTES, &duration));
133 fail_unless_equals_int (duration, 512);
135 gst_element_set_state (bin, GST_STATE_PLAYING);
137 g_main_loop_run (loop);
139 gst_element_set_state (bin, GST_STATE_NULL);
140 gst_object_unref (bin);
142 fail_unless (got_eos);
144 g_object_unref (input);
145 g_object_unref (output);
147 g_main_loop_unref (loop);
148 g_source_remove (bus_watch);
156 Suite *s = suite_create ("gio");
157 TCase *tc_chain = tcase_create ("general");
159 suite_add_tcase (s, tc_chain);
160 tcase_add_test (tc_chain, test_memory_stream);
166 main (int argc, char **argv)
170 Suite *s = gio_testsuite ();
171 SRunner *sr = srunner_create (s);
173 gst_check_init (&argc, &argv);
175 srunner_run_all (sr, CK_NORMAL);
176 nf = srunner_ntests_failed (sr);