summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <matthiasc@src.gnome.org>2008-01-07 06:14:40 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-01-07 06:14:40 +0000
commit3cbcbee7a6a72510453126472463c4dd6cb77134 (patch)
tree59b7690e4e0a94437762040a64f568589c1c23f4
parent3905f1452887b591eb3685ffad6c66cbab203840 (diff)
Add some tests
svn path=/trunk/; revision=6257
-rw-r--r--gio/ChangeLog8
-rw-r--r--gio/Makefile.am2
-rw-r--r--gio/tests/Makefile.am22
-rw-r--r--gio/tests/memory-input-stream.c78
4 files changed, 108 insertions, 2 deletions
diff --git a/gio/ChangeLog b/gio/ChangeLog
index 54702f6ff..ad7c85e01 100644
--- a/gio/ChangeLog
+++ b/gio/ChangeLog
@@ -1,5 +1,11 @@
2008-01-06 Matthias Clasen <mclasen@redhat.com>
+ * tests/*: Add a test for memory input streams.
+
+ * Makefile.am: Add tests to SUBDIRS.
+
+2008-01-06 Matthias Clasen <mclasen@redhat.com>
+
* glocalfilemonitor.c:
* glocaldirectorymonitor.c: Mark property nicks and blurbs
for translation.
@@ -34,7 +40,7 @@
* gio.symbols:
* gmemoryinputstream.[ch]:
- Improve API so that you can use multile chunks
+ Improve API so that you can use multiple chunks
of memory and custom destroy functions. (#506374)
2008-01-03 Alexander Larsson <alexl@redhat.com>
diff --git a/gio/Makefile.am b/gio/Makefile.am
index c0b09f222..96df96c29 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.decl
NULL =
-SUBDIRS=
+SUBDIRS=tests
if OS_UNIX
SUBDIRS += xdgmime
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
new file mode 100644
index 000000000..65134751c
--- /dev/null
+++ b/gio/tests/Makefile.am
@@ -0,0 +1,22 @@
+include $(top_srcdir)/Makefile.decl
+
+INCLUDES = \
+ -g \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/glib \
+ -I$(top_srcdir)/gmodule \
+ -I$(top_srcdir)/gobject \
+ -I$(top_srcdir)/gio \
+ $(GLIB_DEBUG_FLAGS)
+
+noinst_PROGRAMS = $(TEST_PROGS)
+progs_ldadd = \
+ $(top_builddir)/glib/libglib-2.0.la \
+ $(top_builddir)/gobject/libgobject-2.0.la \
+ $(top_builddir)/gio/libgio-2.0.la
+
+
+TEST_PROGS += memory-input-stream
+memory_input_stream_SOURCES = memory-input-stream.c
+memory_input_stream_LDADD = $(progs_ldadd)
+
diff --git a/gio/tests/memory-input-stream.c b/gio/tests/memory-input-stream.c
new file mode 100644
index 000000000..247613c6d
--- /dev/null
+++ b/gio/tests/memory-input-stream.c
@@ -0,0 +1,78 @@
+/* GLib testing framework examples and tests
+ * Copyright (C) 2007 Imendio AB
+ * Authors: Tim Janik
+ *
+ * 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 <glib/gtestutils.h>
+#include <glib/glib.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+test_read_chunks (void)
+{
+ const char *data1 = "abcdefghijklmnopqrstuvwxyz";
+ const char *data2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ const char *result = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ char buffer[128];
+ gsize bytes_read, pos, len, chunk_size;
+ GError *error = NULL;
+ GInputStream *stream;
+ gboolean res;
+
+ stream = g_memory_input_stream_new ();
+
+ g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (stream),
+ data1, -1, NULL);
+ g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (stream),
+ data2, -1, NULL);
+ len = strlen (data1) + strlen (data2);
+
+ for (chunk_size = 1; chunk_size < len - 1; chunk_size++)
+ {
+ pos = 0;
+ while (pos < len)
+ {
+ bytes_read = g_input_stream_read (stream, buffer, chunk_size, NULL, &error);
+ g_assert (error == NULL);
+ g_assert_cmpint (bytes_read, ==, MIN (chunk_size, len - pos));
+ g_assert (strncmp (buffer, result + pos, bytes_read) == 0);
+
+ pos += bytes_read;
+ }
+
+ g_assert_cmpint (pos, ==, len);
+ res = g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, &error);
+ g_assert_cmpint (res, ==, TRUE);
+ g_assert (error == NULL);
+ }
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/memory-input-stream/read-chunks", test_read_chunks);
+
+ return g_test_run();
+}