ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / test / test-find-directory.c
1 /* test-mime.c - Test for the gnome_vfs_find_directory call
2    Virtual File System Library
3
4    Copyright (C) 2000 Eazel
5
6    The Gnome Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10
11    The Gnome Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public
17    License along with the Gnome Library; see the file COPYING.LIB.  If not,
18    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.
20
21    Author: Pavel Cisler <pavel@eazel.com>
22 */
23
24 #include <config.h>
25
26 #include <glib/gmessages.h>
27 #include <libgnomevfs/gnome-vfs-find-directory.h>
28 #include <libgnomevfs/gnome-vfs-init.h>
29 #include <libgnomevfs/gnome-vfs-uri.h>
30 #include <stdio.h>
31 #include <string.h>
32
33 int
34 main (int argc, char **argv)
35 {
36         GnomeVFSURI *uri;
37         GnomeVFSURI *result;
38         GnomeVFSResult error;
39         char *path;
40         gboolean create;
41
42         create = FALSE;
43
44         if (!gnome_vfs_init ()) {
45                 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
46                 return 1;
47         }
48
49         if (argc == 1) {
50                 fprintf (stderr, "Usage: %s [-create] near_uri \n", *argv);
51                 return 1;
52         }
53
54
55         ++argv;
56
57         if (strcmp (*argv, "-create") == 0) {
58                 create = TRUE;
59                 ++argv;
60         }
61
62         uri = gnome_vfs_uri_new (*argv);
63         error = gnome_vfs_find_directory (uri, GNOME_VFS_DIRECTORY_KIND_TRASH, &result, create, 
64                 TRUE, 0777);
65         if (error == GNOME_VFS_OK) {
66                 path = gnome_vfs_uri_to_string (result, GNOME_VFS_URI_HIDE_NONE);
67                 g_print ("found trash at %s\n", path);
68                 g_free (path);
69                 error = gnome_vfs_find_directory (uri, GNOME_VFS_DIRECTORY_KIND_TRASH, 
70                         &result, FALSE, FALSE, 0777);
71                 if (error == GNOME_VFS_OK) {
72                         path = gnome_vfs_uri_to_string (result, GNOME_VFS_URI_HIDE_NONE);
73                         g_print ("found it again in a cached entry at %s\n", path);
74                         g_free (path);
75                 } else {
76                         g_print ("error %s finding cached trash entry near %s\n", gnome_vfs_result_to_string (error),
77                                 *argv);
78                 }
79         } else {
80                 g_print ("error %s finding trash near %s\n", gnome_vfs_result_to_string (error),
81                         *argv);
82         }
83         
84         return 0;
85 }