ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / test / test-sync.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-sync.c - Test program for synchronous operation of the GNOME
3    Virtual File System.
4
5    Copyright (C) 1999 Free Software Foundation
6
7    The Gnome Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Library General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11
12    The Gnome Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public
18    License along with the Gnome Library; see the file COPYING.LIB.  If not,
19    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.
21
22    Author: Ettore Perazzoli <ettore@gnu.org> */
23
24 #include <config.h>
25
26 #include <libgnomevfs/gnome-vfs-init.h>
27 #include <libgnomevfs/gnome-vfs-ops.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31
32 static void
33 show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
34 {
35         fprintf (stderr, "%s `%s': %s\n",
36                  what, text_uri, gnome_vfs_result_to_string (result));
37         if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF)
38                 exit (1);
39 }
40
41 int
42 main (int argc, char **argv)
43 {
44         GnomeVFSResult    result;
45         GnomeVFSHandle   *handle;
46         gchar             buffer[1024];
47         GnomeVFSFileSize  bytes_read;
48         GnomeVFSURI      *uri;
49         gchar            *text_uri;
50         gchar            *out;
51
52         if (argc != 2) {
53                 printf ("Usage: %s <uri>\n", argv[0]);
54                 return 1;
55         }
56
57         if (! gnome_vfs_init ()) {
58                 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
59                 return 1;
60         }
61
62         uri = gnome_vfs_uri_new (argv[1]);
63         if (uri == NULL) {
64                 fprintf (stderr, "URI not valid.\n");
65                 return 1;
66         }
67
68         text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
69
70         result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
71         show_result (result, "open", text_uri);
72
73         while( result==GNOME_VFS_OK ) {
74                 result = gnome_vfs_read (handle, buffer, sizeof buffer - 1,
75                                         &bytes_read);
76                 show_result (result, "read", text_uri);
77         
78                 buffer[bytes_read] = 0;
79                 write (1,buffer,bytes_read);
80                 if(!bytes_read) break;
81         }
82
83         result = gnome_vfs_file_control (handle, "file:test", &out);
84         show_result (result, "file_control", text_uri);
85         if (result == GNOME_VFS_OK) {
86                 g_print ("file_control file:test: %s\n", out);
87         } 
88                 
89         
90         
91         result = gnome_vfs_close (handle);
92         show_result (result, "close", text_uri);
93
94         g_free (text_uri);
95
96         return 0;
97 }