source: trunk/third/gnome-vfs/test/test-module-selftest.c @ 17128

Revision 17128, 3.4 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17127, which included commits to RCS files with non-trunk default branches.
RevLine 
[17127]1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/* test-module-selftest.c - Test program for the GNOME Virtual File System.
4
5   Copyright (C) 1999 Free Software Foundation
6   Copyright (C) 2000, 2001 Eazel, Inc.
7
8   The Gnome Library is free software; you can redistribute it and/or
9   modify it under the terms of the GNU Library General Public License as
10   published by the Free Software Foundation; either version 2 of the
11   License, or (at your option) any later version.
12
13   The Gnome Library is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   Library General Public License for more details.
17
18   You should have received a copy of the GNU Library General Public
19   License along with the Gnome Library; see the file COPYING.LIB.  If not,
20   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21   Boston, MA 02111-1307, USA.
22
23   Authors:
24        Mike Fleming <mfleming@eazel.com>
25*/
26
27
28/*
29 * This program executes module self-test code
30 */
31
32#include <config.h>
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include "gnome-vfs.h"
38#include "gnome-vfs-private-utils.h"
39#include <glib.h>
40#include <gmodule.h>
41
42/* List of modules that have self-test code */
43static const char *self_test_modules[] = {
44        "http",
45        NULL
46};
47
48static void
49stop_after_log (const char *domain, GLogLevelFlags level,
50        const char *message, gpointer data)
51{
52        void (* saved_handler) (int);
53       
54        g_log_default_handler (domain, level, message, data);
55
56        saved_handler = signal (SIGINT, SIG_IGN);
57        raise (SIGINT);
58        signal (SIGINT, saved_handler);
59}
60
61static void
62make_asserts_break (const char *domain)
63{
64        g_log_set_handler
65                (domain,
66                 (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING),
67                 stop_after_log, NULL);
68}
69
70
71typedef gboolean (*TestFunc)(void);
72
73/* Note that, while this initialized gnome-vfs, it does
74 * not guarentee that gnome-vfs actually loads and initializes
75 * the modules in question
76 */
77int
78main (int argc, char **argv)
79{
80        int i;
81        GModule *module;
82        TestFunc test_func;
83        gboolean result;
84        gboolean running_result;
85
86        make_asserts_break ("GLib");
87        make_asserts_break ("GnomeVFS");
88
89        /* Initialize the libraries we use. */
90        g_thread_init (NULL);
91        gnome_vfs_init ();
92
93        running_result = TRUE;
94        for (i=0 ; self_test_modules[i] != NULL ; i++) {
95                char *module_path;
96                char *dummy_uri_string;
97                GnomeVFSURI *uri;
98       
99                printf ("Module self-test: '%s'\n", self_test_modules[i]);
100                module_path = g_module_build_path (MODULES_PATH, self_test_modules[i]);
101                module = g_module_open (module_path, G_MODULE_BIND_LAZY);
102                g_free (module_path);
103                module_path = NULL;
104
105                if (module == NULL) {
106                        fprintf (stderr, "Couldn't load module '%s'\n", self_test_modules[i]);
107                        continue;
108                }
109
110                g_module_symbol (module, "vfs_module_self_test", (gpointer *) &test_func);
111
112                if (test_func == NULL) {
113                        fprintf (stderr, "Module had no self-test func '%s'\n", self_test_modules[i]);
114                        continue;
115                }
116
117                dummy_uri_string = g_strdup_printf ("%s:///", self_test_modules[i]);
118
119                /* force normal initializing of the module by creating a URI
120                 * for that scheme
121                 */
122                uri = gnome_vfs_uri_new (dummy_uri_string);
123                gnome_vfs_uri_unref (uri);
124
125                g_free (dummy_uri_string);
126               
127                result = test_func();
128
129                fprintf (stderr, "%s: %s\n", self_test_modules[i], result ? "PASS" : "FAIL");
130
131                running_result = running_result && result;
132        }
133
134        exit (running_result ? 0 : -1);
135}
136
Note: See TracBrowser for help on using the repository browser.