|
Packit |
ae235b |
/* GLib testing framework examples and tests
|
|
Packit |
ae235b |
* Copyright (C) 2008 Red Hat, Inc.
|
|
Packit |
ae235b |
* Author: Matthias Clasen
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This work is provided "as is"; redistribution and modification
|
|
Packit |
ae235b |
* in whole or in part, in any medium, physical or electronic is
|
|
Packit |
ae235b |
* permitted without restriction.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This work is distributed in the hope that it will be useful,
|
|
Packit |
ae235b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
ae235b |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* In no event shall the authors or contributors be liable for any
|
|
Packit |
ae235b |
* direct, indirect, incidental, special, exemplary, or consequential
|
|
Packit |
ae235b |
* damages (including, but not limited to, procurement of substitute
|
|
Packit |
ae235b |
* goods or services; loss of use, data, or profits; or business
|
|
Packit |
ae235b |
* interruption) however caused and on any theory of liability, whether
|
|
Packit |
ae235b |
* in contract, strict liability, or tort (including negligence or
|
|
Packit |
ae235b |
* otherwise) arising in any way out of the use of this software, even
|
|
Packit |
ae235b |
* if advised of the possibility of such damage.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
#include <glib/glib.h>
|
|
Packit |
ae235b |
#include <gio/gio.h>
|
|
Packit |
ae235b |
#include <stdlib.h>
|
|
Packit |
ae235b |
#include <string.h>
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_truncate (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
GDataOutputStream *o;
|
|
Packit |
ae235b |
int i;
|
|
Packit |
ae235b |
GError *error = NULL;
|
|
Packit |
ae235b |
guint8 *data;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_test_bug ("540423");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mo = g_memory_output_stream_new_resizable ();
|
|
Packit |
ae235b |
g_assert (g_seekable_can_truncate (G_SEEKABLE (mo)));
|
|
Packit |
ae235b |
o = g_data_output_stream_new (mo);
|
|
Packit |
ae235b |
for (i = 0; i < 1000; i++)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
g_data_output_stream_put_byte (o, 1, NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 1000);
|
|
Packit |
ae235b |
g_seekable_truncate (G_SEEKABLE (mo), 0, NULL, &error);
|
|
Packit |
ae235b |
g_assert_cmpuint (g_seekable_tell (G_SEEKABLE (mo)), ==, 1000);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 0);
|
|
Packit |
ae235b |
for (i = 0; i < 2000; i++)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
g_data_output_stream_put_byte (o, 2, NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 3000);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data = (guint8 *)g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* The 1's written initially were lost when we truncated to 0
|
|
Packit |
ae235b |
* and then started writing at position 1000.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
for (i = 0; i < 1000; i++)
|
|
Packit |
ae235b |
g_assert_cmpuint (data[i], ==, 0);
|
|
Packit |
ae235b |
for (i = 1000; i < 3000; i++)
|
|
Packit |
ae235b |
g_assert_cmpuint (data[i], ==, 2);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_test_bug ("720080");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_seekable_truncate (G_SEEKABLE (mo), 8192, NULL, &error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 8192);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data = (guint8 *)g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
for (i = 3000; i < 8192; i++)
|
|
Packit |
ae235b |
g_assert_cmpuint (data[i], ==, 0);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_unref (o);
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_seek_fixed (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
GError *error;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mo = g_memory_output_stream_new (g_new (gchar, 100), 100, NULL, g_free);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (G_IS_SEEKABLE (mo));
|
|
Packit |
ae235b |
g_assert (g_seekable_can_seek (G_SEEKABLE (mo)));
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 0);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
error = NULL;
|
|
Packit |
ae235b |
g_assert (!g_seekable_seek (G_SEEKABLE (mo), 222, G_SEEK_CUR, NULL, &error));
|
|
Packit |
ae235b |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
|
Packit |
ae235b |
g_clear_error (&error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 0);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 26, G_SEEK_SET, NULL, &error));
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 26);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 20, G_SEEK_CUR, NULL, &error));
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 46);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (!g_seekable_seek (G_SEEKABLE (mo), 200, G_SEEK_CUR, NULL, &error));
|
|
Packit |
ae235b |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
|
Packit |
ae235b |
g_clear_error (&error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 46);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (!g_seekable_seek (G_SEEKABLE (mo), 1, G_SEEK_END, NULL, &error));
|
|
Packit |
ae235b |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
|
Packit |
ae235b |
g_clear_error (&error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 46);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 0, G_SEEK_END, NULL, &error));
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 100);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), -1, G_SEEK_END, NULL, &error));
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 99);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_seek_resizable_stream (GOutputStream *mo)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GError *error;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (G_IS_SEEKABLE (mo));
|
|
Packit |
ae235b |
g_assert (g_seekable_can_seek (G_SEEKABLE (mo)));
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 0);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
error = NULL;
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 222, G_SEEK_CUR, NULL, &error));
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 222);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 26, G_SEEK_SET, NULL, &error));
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 26);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 20, G_SEEK_CUR, NULL, &error));
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 46);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 200, G_SEEK_CUR, NULL, &error));
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 246);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 1, G_SEEK_END, NULL, &error));
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 1);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert (g_seekable_seek (G_SEEKABLE (mo), 0, G_SEEK_END, NULL, &error));
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 0);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* The 'end' is still zero, so this should fail */
|
|
Packit |
ae235b |
g_assert (!g_seekable_seek (G_SEEKABLE (mo), -1, G_SEEK_END, NULL, &error));
|
|
Packit |
ae235b |
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
|
Packit |
ae235b |
g_clear_error (&error);
|
|
Packit |
ae235b |
g_assert_cmpint (g_seekable_tell (G_SEEKABLE (mo)), ==, 0);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_seek_resizable (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
gint i;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* For resizable streams, the initially allocated size is purely an
|
|
Packit |
ae235b |
* implementation detail. We should not be able to tell the
|
|
Packit |
ae235b |
* difference based on the seek API, so make a bunch of streams with
|
|
Packit |
ae235b |
* different sizes and subject them to the same test.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
for (i = 0; i < 1024; i++)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
mo = g_memory_output_stream_new (g_malloc (i), i, g_realloc, g_free);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
test_seek_resizable_stream (mo);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 0);
|
|
Packit |
ae235b |
/* No writes = no resizes */
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, i);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_data_size (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
GDataOutputStream *o;
|
|
Packit |
ae235b |
int pos;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_test_bug ("540459");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mo = g_memory_output_stream_new_resizable ();
|
|
Packit |
ae235b |
o = g_data_output_stream_new (mo);
|
|
Packit |
ae235b |
g_data_output_stream_put_byte (o, 1, NULL, NULL);
|
|
Packit |
ae235b |
pos = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
g_assert_cmpint (pos, ==, 1);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_seekable_seek (G_SEEKABLE (mo), 0, G_SEEK_CUR, NULL, NULL);
|
|
Packit |
ae235b |
pos = g_seekable_tell (G_SEEKABLE (mo));
|
|
Packit |
ae235b |
g_assert_cmpint (pos, ==, 1);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_test_bug ("540461");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_seekable_seek (G_SEEKABLE (mo), 0, G_SEEK_SET, NULL, NULL);
|
|
Packit |
ae235b |
pos = g_seekable_tell (G_SEEKABLE (mo));
|
|
Packit |
ae235b |
g_assert_cmpint (pos, ==, 0);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
pos = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
g_assert_cmpint (pos, ==, 1);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert_cmpint (g_memory_output_stream_get_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 16);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_unref (o);
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_properties (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
GDataOutputStream *o;
|
|
Packit |
ae235b |
int i;
|
|
Packit |
ae235b |
GError *error = NULL;
|
|
Packit |
ae235b |
gsize data_size_fun;
|
|
Packit |
ae235b |
gsize data_size_prop = 0;
|
|
Packit |
ae235b |
gpointer data_fun;
|
|
Packit |
ae235b |
gpointer data_prop;
|
|
Packit |
ae235b |
gpointer func;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_test_bug ("605733");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mo = (GOutputStream*) g_object_new (G_TYPE_MEMORY_OUTPUT_STREAM,
|
|
Packit |
ae235b |
"realloc-function", g_realloc,
|
|
Packit |
ae235b |
"destroy-function", g_free,
|
|
Packit |
ae235b |
NULL);
|
|
Packit |
ae235b |
o = g_data_output_stream_new (mo);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
for (i = 0; i < 1000; i++)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
g_data_output_stream_put_byte (o, 1, NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data_size_fun = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
g_object_get (mo, "data-size", &data_size_prop, NULL);
|
|
Packit |
ae235b |
g_assert_cmpint (data_size_fun, ==, data_size_prop);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data_fun = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
g_object_get (mo, "data", &data_prop, NULL);
|
|
Packit |
ae235b |
g_assert_cmphex (GPOINTER_TO_SIZE (data_fun), ==, GPOINTER_TO_SIZE (data_prop));
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_get (mo, "realloc-function", &func, NULL);
|
|
Packit |
ae235b |
g_assert (func == g_realloc);
|
|
Packit |
ae235b |
g_object_get (mo, "destroy-function", &func, NULL);
|
|
Packit |
ae235b |
g_assert (func == g_free);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data_size_fun = g_memory_output_stream_get_size (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
g_object_get (mo, "size", &data_size_prop, NULL);
|
|
Packit |
ae235b |
g_assert_cmpint (data_size_fun, ==, data_size_prop);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_unref (o);
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_write_bytes (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
GBytes *bytes, *bytes2;
|
|
Packit |
ae235b |
GError *error = NULL;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mo = (GOutputStream*) g_object_new (G_TYPE_MEMORY_OUTPUT_STREAM,
|
|
Packit |
ae235b |
"realloc-function", g_realloc,
|
|
Packit |
ae235b |
"destroy-function", g_free,
|
|
Packit |
ae235b |
NULL);
|
|
Packit |
ae235b |
bytes = g_bytes_new_static ("hello world!", strlen ("hello world!") + 1);
|
|
Packit |
ae235b |
g_output_stream_write_bytes (mo, bytes, NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_output_stream_close (mo, NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
bytes2 = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (mo));
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
g_assert (g_bytes_equal (bytes, bytes2));
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_bytes_unref (bytes);
|
|
Packit |
ae235b |
g_bytes_unref (bytes2);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_steal_as_bytes (void)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GOutputStream *mo;
|
|
Packit |
ae235b |
GDataOutputStream *o;
|
|
Packit |
ae235b |
GError *error = NULL;
|
|
Packit |
ae235b |
GBytes *bytes;
|
|
Packit |
ae235b |
gsize size;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mo = (GOutputStream*) g_object_new (G_TYPE_MEMORY_OUTPUT_STREAM,
|
|
Packit |
ae235b |
"realloc-function", g_realloc,
|
|
Packit |
ae235b |
"destroy-function", g_free,
|
|
Packit |
ae235b |
NULL);
|
|
Packit |
ae235b |
o = g_data_output_stream_new (mo);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_data_output_stream_put_string (o, "hello ", NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_data_output_stream_put_string (o, "world!", NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_data_output_stream_put_byte (o, '\0', NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_output_stream_close ((GOutputStream*) o, NULL, &error);
|
|
Packit |
ae235b |
g_assert_no_error (error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
bytes = g_memory_output_stream_steal_as_bytes ((GMemoryOutputStream*)mo);
|
|
Packit |
ae235b |
g_object_unref (mo);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert_cmpint (g_bytes_get_size (bytes), ==, strlen ("hello world!") + 1);
|
|
Packit |
ae235b |
g_assert_cmpstr (g_bytes_get_data (bytes, &size), ==, "hello world!");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_bytes_unref (bytes);
|
|
Packit |
ae235b |
g_object_unref (o);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
int
|
|
Packit |
ae235b |
main (int argc,
|
|
Packit |
ae235b |
char *argv[])
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
g_test_init (&argc, &argv, NULL);
|
|
Packit |
ae235b |
g_test_bug_base ("http://bugzilla.gnome.org/");
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/truncate", test_truncate);
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/seek/fixed", test_seek_fixed);
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/seek/resizable", test_seek_resizable);
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/get-data-size", test_data_size);
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/properties", test_properties);
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/write-bytes", test_write_bytes);
|
|
Packit |
ae235b |
g_test_add_func ("/memory-output-stream/steal_as_bytes", test_steal_as_bytes);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_test_run();
|
|
Packit |
ae235b |
}
|