1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* test-module-selftest.c - Test program for the GNOME Virtual File System.
5 Copyright (C) 1999 Free Software Foundation
6 Copyright (C) 2000, 2001 Eazel, Inc.
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.
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.
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.
24 Mike Fleming <mfleming@eazel.com>
29 * This program executes module self-test code
37 #include <libgnomevfs/gnome-vfs-init.h>
38 #include <libgnomevfs/gnome-vfs-private-utils.h>
41 /* List of modules that have self-test code */
42 static const char *self_test_modules[] = {
48 stop_after_log (const char *domain, GLogLevelFlags level,
49 const char *message, gpointer data)
51 void (* saved_handler) (int);
53 g_log_default_handler (domain, level, message, data);
55 saved_handler = signal (SIGINT, SIG_IGN);
57 signal (SIGINT, saved_handler);
61 make_asserts_break (const char *domain)
65 (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING),
66 stop_after_log, NULL);
70 typedef gboolean (*TestFunc)(void);
72 /* Note that, while this initialized gnome-vfs, it does
73 * not guarentee that gnome-vfs actually loads and initializes
74 * the modules in question
77 main (int argc, char **argv)
83 gboolean running_result;
85 make_asserts_break ("GLib");
86 make_asserts_break ("GnomeVFS");
88 /* Initialize the libraries we use. */
91 running_result = TRUE;
92 for (i=0 ; self_test_modules[i] != NULL ; i++) {
94 char *dummy_uri_string;
97 printf ("Module self-test: '%s'\n", self_test_modules[i]);
98 module_path = g_module_build_path (MODULES_PATH, self_test_modules[i]);
99 module = g_module_open (module_path, G_MODULE_BIND_LAZY);
100 g_free (module_path);
103 if (module == NULL) {
104 fprintf (stderr, "Couldn't load module '%s'\n", self_test_modules[i]);
108 g_module_symbol (module, "vfs_module_self_test", (gpointer *) &test_func);
110 if (test_func == NULL) {
111 fprintf (stderr, "Module had no self-test func '%s'\n", self_test_modules[i]);
115 dummy_uri_string = g_strdup_printf ("%s:///", self_test_modules[i]);
117 /* force normal initializing of the module by creating a URI
120 uri = gnome_vfs_uri_new (dummy_uri_string);
121 gnome_vfs_uri_unref (uri);
123 g_free (dummy_uri_string);
125 result = test_func();
127 fprintf (stderr, "%s: %s\n", self_test_modules[i], result ? "PASS" : "FAIL");
129 running_result = running_result && result;
132 exit (running_result ? 0 : -1);