4 * Copyright 2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 /* This code tries to load the passed Geany plugin
25 * (passed as path, e.g. pluginname.so) and looks up some symbols.
26 * Example use case for this tool is to test whether a plugin is
27 * loadable and defines all required symbols.
29 * This file is not built during the normal build process, instead
30 * compile it on your with the following command in the root of the Geany source tree:
32 * cc -o plugin_test scripts/plugin_test.c `pkg-config --cflags --libs glib-2.0 gmodule-2.0`
40 static gboolean
tp_check_version(GModule
*module
)
42 /* TODO implement me */
47 static void tp_close_module(GModule
*module
)
49 if (! g_module_close(module
))
50 g_warning("%s: %s", g_module_name(module
), g_module_error());
54 /* Emulate loading a plugin and looking up some symbols,
55 * similar to what Geany would do on loading the plugin.
57 static gboolean
test_plugin(const gchar
*filename
)
60 void (*plugin_set_info
)(void*);
61 void (*init
) (void *data
);
62 void (*cleanup
) (void);
64 g_return_val_if_fail(filename
, FALSE
);
65 g_return_val_if_fail(g_module_supported(), FALSE
);
67 module
= g_module_open(filename
, G_MODULE_BIND_LOCAL
);
70 g_warning("Can't load plugin: %s", g_module_error());
74 if (! tp_check_version(module
))
76 tp_close_module(module
);
80 g_module_symbol(module
, "plugin_set_info", (void *) &plugin_set_info
);
81 if (plugin_set_info
== NULL
)
83 g_warning("No plugin_set_info() defined for \"%s\" - consider fixing the plugin!", filename
);
84 tp_close_module(module
);
88 g_module_symbol(module
, "plugin_init", (void *) &init
);
91 g_warning("Plugin '%s' has no plugin_init() function - consider fixing the plugin!", filename
);
92 tp_close_module(module
);
96 g_module_symbol(module
, "plugin_cleanup", (void *) &cleanup
);
99 g_warning("Plugin '%s' has no plugin_cleanup() function - there may be memory leaks!", filename
);
102 tp_close_module(module
);
108 gint
main(gint argc
, gchar
**argv
)
113 g_set_prgname("plugin_test");
114 /* we could perform better argument processing here as well as more error checking but
115 * it's probably not worth at all */
116 for (i
= 1; i
< argc
; i
++)
118 if (! test_plugin(argv
[i
]))