1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-directory.c - Test program for directory reading in the GNOME
5 Copyright (C) 1999 Free Software Foundation
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.
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.
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.
22 Author: Ettore Perazzoli <ettore@comm2000.it> */
26 #include <glib/gstrfuncs.h>
27 #include <glib/gtimer.h>
28 #include <libgnomevfs/gnome-vfs-directory.h>
29 #include <libgnomevfs/gnome-vfs-init.h>
34 static int measure_speed = 0;
36 struct poptOption options[] = {
43 "Measure speed without displaying anything",
59 show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
61 fprintf (stderr, "%s `%s': %s\n",
62 what, text_uri, gnome_vfs_result_to_string (result));
63 if (result != GNOME_VFS_OK)
65 fprintf (stdout, "Error: %s\n",
66 gnome_vfs_result_to_string (result));
72 type_to_string (GnomeVFSFileType type)
75 case GNOME_VFS_FILE_TYPE_UNKNOWN:
77 case GNOME_VFS_FILE_TYPE_REGULAR:
79 case GNOME_VFS_FILE_TYPE_DIRECTORY:
81 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
82 return "Symbolic Link";
83 case GNOME_VFS_FILE_TYPE_FIFO:
85 case GNOME_VFS_FILE_TYPE_SOCKET:
87 case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
88 return "Character device";
89 case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
90 return "Block device";
97 print_list (GList *list)
99 GnomeVFSFileInfo *info;
103 printf (" (No files)\n");
107 for (node = list; node != NULL; node = node->next) {
108 const gchar *mime_type;
112 mime_type = gnome_vfs_file_info_get_mime_type (info);
113 if (mime_type == NULL)
114 mime_type = "(Unknown)";
116 printf (" File `%s'%s%s%s (%s, %s), size %ld, mode %04o\n",
118 GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link: " : "",
119 GNOME_VFS_FILE_INFO_SYMLINK (info) ? info->symlink_name : "",
120 GNOME_VFS_FILE_INFO_SYMLINK (info) ? " ]" : "",
121 type_to_string (info->type),
129 main (int argc, const char **argv)
132 GnomeVFSResult result;
136 poptContext popt_context;
138 popt_context = poptGetContext ("test-directory", argc,
139 (const char **) argv, options, 0);
141 while (poptGetNextOpt (popt_context) != -1)
144 args = poptGetArgs (popt_context);
145 if (args == NULL || args[1] != NULL) {
146 fprintf (stderr, "Usage: %s [<options>] <uri>\n", argv[0]);
150 text_uri = g_strdup (args[0]);
152 poptFreeContext (popt_context);
156 printf ("Loading directory...");
160 timer = g_timer_new ();
161 g_timer_start (timer);
166 /* Load with without requesting any metadata. */
167 result = gnome_vfs_directory_list_load
169 (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
170 | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE
171 | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
173 if (result == GNOME_VFS_OK && measure_speed) {
174 gdouble elapsed_seconds;
177 g_timer_stop (timer);
178 elapsed_seconds = g_timer_elapsed (timer, NULL);
179 num_entries = g_list_length (list);
180 printf ("\n%.5f seconds for %d unsorted entries, %.5f entries/sec.\n",
181 elapsed_seconds, num_entries,
182 (double) num_entries / elapsed_seconds);
185 if (!measure_speed) {
188 show_result (result, "load_directory", text_uri);
190 printf ("Listing for `%s':\n", text_uri);
194 printf ("Destroying.\n");
195 gnome_vfs_file_info_list_free (list);