diff --git a/gio/ChangeLog b/gio/ChangeLog index ba94549f5..faf85aea9 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,17 @@ +2008-06-29 Matthias Clasen + + * tests/Makefile.am: + * tests/memory-output-stream.c: Add some tests for + GMemoryOutputStream. + +2008-06-29 Matthias Clasen + + Bug 540423 – unrecoverable error after g_seekable_truncate(seekable, + 0, ...) + + * gmemoryoutputstream.c (array_resize): Handle truncation to + zero correctly. Reported by Akira Tagoh + 2008-06-29 Matthias Clasen * gmemoryoutputstream.c: Trivial doc fixes diff --git a/gio/gmemoryoutputstream.c b/gio/gmemoryoutputstream.c index 9349e229b..ebb91ab3c 100644 --- a/gio/gmemoryoutputstream.c +++ b/gio/gmemoryoutputstream.c @@ -326,7 +326,7 @@ array_resize (GMemoryOutputStream *ostream, len = priv->len; data = priv->realloc_fn (priv->data, size); - if (!data) + if (size > 0 && !data) { if (allow_partial && priv->pos < priv->len) diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index 6f3c65025..308dbd6d3 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -16,15 +16,24 @@ progs_ldadd = \ $(top_builddir)/gio/libgio-2.0.la -TEST_PROGS += memory-input-stream g-file g-file-info data-input-stream data-output-stream +TEST_PROGS += \ + memory-input-stream \ + memory-output-stream \ + g-file \ + g-file-info \ + data-input-stream \ + data-output-stream if OS_UNIX -TEST_PROGS += live-g-file +TEST_PROGS += live-g-file endif memory_input_stream_SOURCES = memory-input-stream.c memory_input_stream_LDADD = $(progs_ldadd) +memory_output_stream_SOURCES = memory-output-stream.c +memory_output_stream_LDADD = $(progs_ldadd) + g_file_SOURCES = g-file.c g_file_LDADD = $(progs_ldadd) diff --git a/gio/tests/memory-output-stream.c b/gio/tests/memory-output-stream.c new file mode 100644 index 000000000..f0b5ff501 --- /dev/null +++ b/gio/tests/memory-output-stream.c @@ -0,0 +1,91 @@ +/* GLib testing framework examples and tests + * Copyright (C) 2008 Red Hat, Inc. + * Author: Matthias Clasen + * + * This work is provided "as is"; redistribution and modification + * in whole or in part, in any medium, physical or electronic is + * permitted without restriction. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In no event shall the authors or contributors be liable for any + * direct, indirect, incidental, special, exemplary, or consequential + * damages (including, but not limited to, procurement of substitute + * goods or services; loss of use, data, or profits; or business + * interruption) however caused and on any theory of liability, whether + * in contract, strict liability, or tort (including negligence or + * otherwise) arising in any way out of the use of this software, even + * if advised of the possibility of such damage. + */ +#include +#include +#include +#include + +static void +test_truncate (void) +{ + GOutputStream *mo; + GDataOutputStream *o; + int i; + GError *error = NULL; + + g_test_bug ("540423"); + + mo = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); + o = g_data_output_stream_new (mo); + for (i = 0; i < 1000; i++) + { + g_data_output_stream_put_byte (o, 1, NULL, &error); + g_assert (error == NULL); + } + g_seekable_truncate (G_SEEKABLE (mo), 0, NULL, &error); + g_assert (error == NULL); + for (i = 0; i < 2000; i++) + { + g_data_output_stream_put_byte (o, 1, NULL, &error); + g_assert (error == NULL); + } + + g_object_unref (o); + g_object_unref (mo); +} + +static void +test_data_size (void) +{ + GOutputStream *mo; + GDataOutputStream *o; + int pos; + + g_test_bug ("540459"); + + mo = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); + o = g_data_output_stream_new (mo); + g_data_output_stream_put_byte (o, 1, NULL, NULL); + pos = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)); + g_assert_cmpint (pos, ==, 1); + + g_seekable_seek (G_SEEKABLE (mo), 0, G_SEEK_CUR, NULL, NULL); + pos = g_seekable_tell (G_SEEKABLE (mo)); + g_assert_cmpint (pos, ==, 1); + + g_object_unref (o); + g_object_unref (mo); +} + +int +main (int argc, + char *argv[]) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + g_test_bug_base ("http://bugzilla.gnome.org/"); + + g_test_add_func ("/memory-output-stream/truncate", test_truncate); + g_test_add_func ("/memory-output-stream/get-data-size", test_data_size); + + return g_test_run(); +}