summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-02-27 12:59:47 +0000
committerAlexander Larsson <alexl@src.gnome.org>2009-02-27 12:59:47 +0000
commit28713ed6b20cb617bce93e639b764617a118e1dd (patch)
tree8e840db7df291d1c60a55eb0aba9364ae89bde73 /test
parent4c1cbdac8d59b1bf53319bc9e5a165c8b11adacb (diff)
downloadgvfs-28713ed6b20cb617bce93e639b764617a118e1dd.tar.gz
Add (de)marshalling functions for GFileInfos.
2009-02-27 Alexander Larsson <alexl@redhat.com> * common/Makefile.am: * common/gvfsfileinfo.[ch]: Add (de)marshalling functions for GFileInfos. * common/gvfsdaemonprotocol.h: Add protocol extensions for query info over streams * client/gdaemonfileinputstream.c: Support sync query_info. * daemon/Makefile.am: * daemon/gvfsjobqueryinforead.[ch]: * daemon/gvfsbackend.h: Added query info job and backend call for input streams * daemon/gvfsbackendtest.c: Implement query_info_on_read * daemon/gvfschannel.[ch]: Add g_vfs_channel_send_info * daemon/gvfsreadchannel.c: (read_channel_handle_request): Handle query info * test/Makefile.am: * test/test-query-info-stream.c: Add test for stream query info. svn path=/trunk/; revision=2257
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am1
-rw-r--r--test/test-query-info-stream.c226
2 files changed, 227 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 7ddcd8ca..70c0cb7a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -10,6 +10,7 @@ AM_LDFLAGS = \
$(GLIB_LIBS)
noinst_PROGRAMS = \
+ test-query-info-stream \
benchmark-gvfs-small-files \
benchmark-gvfs-big-files \
benchmark-posix-small-files \
diff --git a/test/test-query-info-stream.c b/test/test-query-info-stream.c
new file mode 100644
index 00000000..6bd7ffcb
--- /dev/null
+++ b/test/test-query-info-stream.c
@@ -0,0 +1,226 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2006-2007 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
+
+
+#include <config.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <locale.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+/* Fill test data with 0..200, repeadedly.
+ * This is not a power of two to avoid possible
+ * effects with base-2 i/o buffer sizes that could
+ * hide bugs */
+#define DATA_MODULO 200
+
+static gboolean
+verify_block (guchar *data, guchar *start, gsize size)
+{
+ guchar d;
+ gsize i;
+
+ d = 0;
+ if (start)
+ d = *start;
+ for (i = 0; i < size; i++)
+ {
+ if (data[i] != d)
+ return FALSE;
+
+ d++;
+ if (d >= DATA_MODULO)
+ d = 0;
+ }
+
+ if (start)
+ *start = d;
+
+ return TRUE;
+}
+
+static guchar *
+allocate_block (gsize size)
+{
+ guchar *data;
+ gsize i;
+ guchar d;
+
+ data = g_malloc (size);
+ d = 0;
+ for (i = 0; i < size; i++)
+ {
+ data[i] = d;
+ d++;
+ if (d >= DATA_MODULO)
+ d = 0;
+ }
+ return data;
+}
+
+static void
+create_file (GFile *file, gsize size)
+{
+ guchar *data;
+ GError *error;
+
+ data = allocate_block (size);
+
+ error = NULL;
+ if (!g_file_replace_contents (file,
+ (char *)data,
+ size,
+ NULL, FALSE, 0,
+ NULL, NULL, &error))
+ {
+ g_print ("error creating file: %s\n", error->message);
+ exit (1);
+ }
+ g_free (data);
+}
+
+static void
+check_query_info (GFileInputStream *in)
+{
+ GFileInfo *info;
+ GError *error;
+ goffset file_size;
+
+ error = NULL;
+ info = g_file_input_stream_query_info (in, "*", NULL, &error);
+ if (info == NULL)
+ {
+ g_print ("error querying info: %s\n", error->message);
+ exit (1);
+ }
+
+ if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
+ {
+ g_print ("couldn't read size attribute\n");
+ exit (1);
+ }
+
+ file_size = g_file_info_get_size (info);
+ g_print ("file size: %d\n", (int)file_size);
+ if (file_size != 100*1000)
+ {
+ g_print ("wrong file size\n");
+ exit (1);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ GFile *file;
+ GFileInputStream *in;
+ GError *error;
+ gssize res;
+ gsize read_size;
+ guchar *buffer;
+ guchar start;
+ gboolean do_create_file;
+
+ g_type_init ();
+
+ do_create_file = FALSE;
+
+ if (argc > 1)
+ {
+ if (strcmp(argv[1], "-c") == 0)
+ {
+ do_create_file = TRUE;
+ argc--;
+ argv++;
+ }
+ }
+
+ if (argc != 2)
+ {
+ g_print ("need file arg");
+ return 1;
+ }
+
+ file = g_file_new_for_commandline_arg (argv[1]);
+
+ if (do_create_file)
+ create_file (file, 100*1000);
+
+ error = NULL;
+
+ in = g_file_read (file, NULL, &error);
+ if (in == NULL)
+ {
+ g_print ("error reading file: %s\n", error->message);
+ exit (1);
+ }
+
+ check_query_info (in);
+
+ buffer = malloc (100*1000);
+
+ start = 0;
+ read_size = 0;
+ do
+ {
+ res = g_input_stream_read (G_INPUT_STREAM (in),
+ buffer,
+ 150,
+ NULL, &error);
+ if (res == 0)
+ break;
+
+ if (res < 0)
+ {
+ g_print ("error reading: %s\n", error->message);
+ exit (1);
+ }
+
+ g_print ("res: %d\n", (int)res);
+
+ if (!verify_block (buffer, &start, res))
+ {
+ g_print ("error in block starting at %d\n", (int)read_size);
+ exit (1);
+ }
+
+ read_size += res;
+
+ check_query_info (in);
+ }
+ while (1);
+
+ if (read_size != 100*1000)
+ {
+ g_print ("Didn't read entire file\n");
+ exit (1);
+ }
+
+
+ return 0;
+}