24 #include <core/plugin.h> 25 #include <plugin/loader.h> 26 #include <utils/system/dynamic_module/module_dl.h> 27 #include <utils/system/dynamic_module/module_manager_template.h> 41 cout <<
"Plugin name: " << p->
name() << endl;
56 cout <<
"Doh, symbol not found" << endl;
59 cout <<
"Yeah, we got the symbol" << endl;
61 PluginFactoryFunc pff = (PluginFactoryFunc)m->
get_symbol(
"plugin_factory");
62 PluginDestroyFunc pdf = (PluginDestroyFunc)m->
get_symbol(
"plugin_destroy");
64 if ((pff != NULL) && (pdf != NULL)) {
67 success = test_plugin(p);
75 cout <<
"pff == NULL" << endl;
78 cout <<
"pdf == NULL" << endl;
83 cout <<
"Could not open module" << endl;
97 main(
int argc,
char **argv)
103 cout <<
"Running plain module tests" << endl;
104 ModuleDL *m =
new ModuleDL(PLUGINDIR
"/test_splugin.so");
111 success = test_module(m);
115 cout <<
"SUCCESSFULLY tested plain module" << endl;
117 cout <<
"FAILED plain module tests, aborting further tests" << endl;
122 cout << endl << endl <<
"Running ModuleManagerTemplate tests" << endl;
123 ModuleManagerTemplate<ModuleDL> mm(PLUGINDIR);
124 Module * mod = mm.open_module(
"test_plugin.so");
126 cout <<
"Failed to retrieve module from manager" << endl;
129 cout <<
"Retrieved module from module manager" << endl;
132 success = test_module(mod);
134 cout <<
"Testing ref count" << endl;
135 cout <<
"RefCount (should be 1): " << mod->
get_ref_count() << endl;
136 cout <<
"Retrieving module twice, again" << endl;
137 mm.open_module(
"test_plugin.so");
138 mm.open_module(
"test_plugin.so");
139 cout <<
"RefCount (should be 3): " << mod->
get_ref_count() << endl;
140 cout <<
"Closing module twice" << endl;
141 mm.close_module(mod);
142 mm.close_module(mod);
143 cout <<
"RefCount (should be 1): " << mod->
get_ref_count() << endl;
144 cout <<
"Finally closing module" << endl;
145 mm.close_module(mod);
146 if (mm.module_opened(
"test_plugin.so")) {
147 cout <<
"Plugin still opened, bug!" << endl;
150 cout <<
"Plugin has been unloaded from module manager" << endl;
154 cout <<
"SUCCESSFULLY tested module manager" << endl;
156 cout <<
"FAILED module manager tests, aborting further tests" << endl;
161 cout << endl << endl <<
"Running PluginLoader tests" << endl;
166 p = pl->
load(
"test_plugin");
167 success = test_plugin(p);
171 cout <<
"Could not load plugin" << endl;
178 cout <<
"SUCCESSFULLY tested PluginLoader" << endl;
180 cout <<
"FAILED module manager tests, aborting further tests" << endl;
Fawkes library namespace.
This exception is thrown if the requested plugin could not be loaded.
virtual unsigned int get_ref_count()
Get the reference count of this module.
const char * name() const
Get the name of the plugin.
This class manages plugins.
void unload(Plugin *plugin)
Unload the given plugin This will unload the given plugin.
Dynamic module loader for Linux, FreeBSD, and MacOS X.
Base class for exceptions in Fawkes.
void print_trace()
Prints trace to stderr.
virtual void * get_symbol(const char *symbol_name)
Get a symbol from the module.
virtual bool has_symbol(const char *symbol_name)
Check if the module has the given symbol.
Plugin * load(const char *plugin_name)
Load a specific plugin The plugin loader is clever and guarantees that every plugin is only loaded on...