ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / test / test-module-selftest.c
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 <libgnomevfs/gnome-vfs-init.h>
38 #include <libgnomevfs/gnome-vfs-private-utils.h>
39 #include <gmodule.h>
40
41 /* List of modules that have self-test code */
42 static const char *self_test_modules[] = {
43         "http",
44         NULL
45 };
46
47 static void
48 stop_after_log (const char *domain, GLogLevelFlags level, 
49         const char *message, gpointer data)
50 {
51         void (* saved_handler) (int);
52         
53         g_log_default_handler (domain, level, message, data);
54
55         saved_handler = signal (SIGINT, SIG_IGN);
56         raise (SIGINT);
57         signal (SIGINT, saved_handler);
58 }
59
60 static void
61 make_asserts_break (const char *domain)
62 {
63         g_log_set_handler
64                 (domain, 
65                  (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING),
66                  stop_after_log, NULL);
67 }
68
69
70 typedef gboolean (*TestFunc)(void);
71
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
75  */ 
76 int
77 main (int argc, char **argv)
78 {
79         int i;
80         GModule *module;
81         TestFunc test_func;
82         gboolean result;
83         gboolean running_result;
84
85         make_asserts_break ("GLib");
86         make_asserts_break ("GnomeVFS");
87
88         /* Initialize the libraries we use. */
89         gnome_vfs_init ();
90
91         running_result = TRUE;
92         for (i=0 ; self_test_modules[i] != NULL ; i++) {
93                 char *module_path;
94                 char *dummy_uri_string;
95                 GnomeVFSURI *uri;
96         
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);
101                 module_path = NULL;
102
103                 if (module == NULL) {
104                         fprintf (stderr, "Couldn't load module '%s'\n", self_test_modules[i]);
105                         continue;
106                 }
107
108                 g_module_symbol (module, "vfs_module_self_test", (gpointer *) &test_func);
109
110                 if (test_func == NULL) {
111                         fprintf (stderr, "Module had no self-test func '%s'\n", self_test_modules[i]);
112                         continue;
113                 }
114
115                 dummy_uri_string = g_strdup_printf ("%s:///", self_test_modules[i]);
116
117                 /* force normal initializing of the module by creating a URI
118                  * for that scheme
119                  */
120                 uri = gnome_vfs_uri_new (dummy_uri_string);
121                 gnome_vfs_uri_unref (uri);
122
123                 g_free (dummy_uri_string);
124                 
125                 result = test_func();
126
127                 fprintf (stderr, "%s: %s\n", self_test_modules[i], result ? "PASS" : "FAIL");
128
129                 running_result = running_result && result;
130         }
131
132         exit (running_result ? 0 : -1);
133 }
134