source: trunk/third/gnome-vfs/test/test-directory.c @ 15858

Revision 15858, 4.4 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15857, which included commits to RCS files with non-trunk default branches.
Line 
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
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@comm2000.it> */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <stdio.h>
29
30#include <gnome.h>
31
32#include "gnome-vfs.h"
33
34
35static int measure_speed = 0;
36
37struct poptOption options[] = {
38        {
39                "measure-speed",
40                'm',
41                POPT_ARG_NONE,
42                &measure_speed,
43                0,
44                "Measure speed without displaying anything",
45                NULL
46        },
47        {
48                NULL,
49                0,
50                0,
51                NULL,
52                0,
53                NULL,
54                NULL
55        }
56};
57
58
59
60static void
61show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
62{
63        fprintf (stderr, "%s `%s': %s\n",
64                 what, text_uri, gnome_vfs_result_to_string (result));
65        if (result != GNOME_VFS_OK)
66                exit (1);
67}
68
69static const gchar *
70type_to_string (GnomeVFSFileType type)
71{
72        switch (type) {
73        case GNOME_VFS_FILE_TYPE_UNKNOWN:
74                return "Unknown";
75        case GNOME_VFS_FILE_TYPE_REGULAR:
76                return "Regular";
77        case GNOME_VFS_FILE_TYPE_DIRECTORY:
78                return "Directory";
79        case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
80                return "Symbolic Link";
81        case GNOME_VFS_FILE_TYPE_FIFO:
82                return "FIFO";
83        case GNOME_VFS_FILE_TYPE_SOCKET:
84                return "Socket";
85        case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
86                return "Character device";
87        case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
88                return "Block device";
89        default:
90                return "???";
91        }
92}
93
94static void
95print_list (GList *list)
96{
97        GnomeVFSFileInfo *info;
98        GList *node;
99
100        if (list == NULL) {
101                printf ("  (No files)\n");
102                return;
103        }
104
105        for (node = list; node != NULL; node = node->next) {
106                const gchar *mime_type;
107       
108                info = node->data;
109
110                mime_type = gnome_vfs_file_info_get_mime_type (info);
111                if (mime_type == NULL)
112                        mime_type = "(Unknown)";
113
114                printf ("  File `%s'%s%s%s (%s, %s), size %ld, mode %04o\n",
115                        info->name,
116                        GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link: " : "",
117                        GNOME_VFS_FILE_INFO_SYMLINK (info) ? info->symlink_name : "",
118                        GNOME_VFS_FILE_INFO_SYMLINK (info) ? " ]" : "",
119                        type_to_string (info->type),
120                        mime_type,
121                        (glong) info->size,
122                        info->permissions);
123        }
124}
125
126int
127main (int argc, char **argv)
128{
129        GList *list;
130        GnomeVFSResult result;
131        GTimer *timer;
132        const char **args;
133        gchar *text_uri;
134        poptContext popt_context;
135
136        popt_context = poptGetContext ("test-directory", argc, argv,
137                                       options, 0);
138
139        while (poptGetNextOpt (popt_context) != -1)
140                ;
141
142        args = poptGetArgs (popt_context);
143        if (args == NULL || args[1] != NULL) {
144                fprintf (stderr, "Usage: %s [<options>] <uri>\n", argv[0]);
145                return 1;
146        }
147
148        text_uri = g_strdup (args[0]);
149
150        poptFreeContext (popt_context);
151
152        gnome_vfs_init ();
153
154        printf ("Loading directory...");
155        fflush (stdout);
156
157        if (measure_speed) {
158                timer = g_timer_new ();
159                g_timer_start (timer);
160        } else {
161                timer = NULL;
162        }
163
164        /* Load with no filters and without requesting any metadata.  */
165        result = gnome_vfs_directory_list_load
166                (&list, text_uri,
167                 (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
168                  | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE
169                  | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
170                 NULL);
171
172        if (result == GNOME_VFS_OK && measure_speed) {
173                gdouble elapsed_seconds;
174                guint num_entries;
175
176                g_timer_stop (timer);
177                elapsed_seconds = g_timer_elapsed (timer, NULL);
178                num_entries = g_list_length (list);
179                printf ("\n%.5f seconds for %d unsorted entries, %.5f entries/sec.\n",
180                        elapsed_seconds, num_entries,
181                        (double) num_entries / elapsed_seconds);
182        }
183
184        if (!measure_speed) {
185                printf ("Ok\n");
186
187                show_result (result, "load_directory", text_uri);
188
189                printf ("Listing for `%s':\n", text_uri);
190                print_list (list);
191        }
192
193        printf ("Destroying.\n");
194        gnome_vfs_file_info_list_free (list);
195
196        printf ("Done.\n");
197
198        g_free (text_uri);
199
200        return 0;
201}
Note: See TracBrowser for help on using the repository browser.