1
/* GIO - GLib Input, Output and Streaming Library
3
* Copyright (C) 2006-2007 Red Hat, Inc.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General
16
* Public License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
* Boston, MA 02111-1307, USA.
20
* Author: Alexander Larsson <alexl@redhat.com>
36
/* Fill test data with 0..200, repeadedly.
37
* This is not a power of two to avoid possible
38
* effects with base-2 i/o buffer sizes that could
40
#define DATA_MODULO 200
42
static GMainLoop *main_loop;
45
verify_block (guchar *data, guchar *start, gsize size)
53
for (i = 0; i < size; i++)
70
allocate_block (gsize size)
76
data = g_malloc (size);
78
for (i = 0; i < size; i++)
89
check_query_info_res (GFileInfo *info,
97
g_print ("error querying info: %s\n", error->message);
101
if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
103
g_print ("couldn't read size attribute\n");
107
file_size = g_file_info_get_size (info);
108
if (file_size != expected_size)
110
g_print ("wrong file size\n");
116
check_query_info_out (GFileOutputStream *out, gsize expected_size)
122
info = g_file_output_stream_query_info (out, "*", NULL, &error);
124
check_query_info_res (info, error, expected_size);
128
create_file (GFile *file, gsize size)
130
GFileOutputStream *out;
135
data = allocate_block (size);
138
out = g_file_replace (file, NULL, FALSE, 0, NULL, &error);
141
g_print ("error creating file: %s\n", error->message);
145
check_query_info_out (out, 0);
147
if (!g_output_stream_write_all (G_OUTPUT_STREAM (out),
152
g_print ("error writing to file: %s\n", error->message);
156
check_query_info_out (out, written);
160
g_print ("not all data written to file\n");
164
g_output_stream_close (G_OUTPUT_STREAM (out), NULL, NULL);
170
check_query_info (GFileInputStream *in, gsize expected_size)
176
info = g_file_input_stream_query_info (in, "*", NULL, &error);
178
check_query_info_res (info, error, expected_size);
182
async_cb (GObject *source_object,
191
g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (source_object),
194
check_query_info_res (info, error, 100*1000);
196
g_main_loop_quit (main_loop);
200
main (int argc, char *argv[])
203
GFileInputStream *in;
209
gboolean do_create_file;
213
do_create_file = FALSE;
217
if (strcmp(argv[1], "-c") == 0)
219
do_create_file = TRUE;
227
g_print ("need file arg");
231
file = g_file_new_for_commandline_arg (argv[1]);
234
create_file (file, 100*1000);
238
in = g_file_read (file, NULL, &error);
241
g_print ("error reading file: %s\n", error->message);
245
check_query_info (in, 100*1000);
247
buffer = malloc (100*1000);
253
res = g_input_stream_read (G_INPUT_STREAM (in),
262
g_print ("error reading: %s\n", error->message);
266
if (!verify_block (buffer, &start, res))
268
g_print ("error in block starting at %d\n", (int)read_size);
274
check_query_info (in, 100*1000);
278
if (read_size != 100*1000)
280
g_print ("Didn't read entire file\n");
284
main_loop = g_main_loop_new (NULL, FALSE);
286
g_file_input_stream_query_info_async (in, "*",
290
g_main_loop_run (main_loop);
292
g_print ("ALL OK\n");