RTXI  2.4
The Real-Time eXperiment Interface Documentation
plugin_tests.cpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  */
19 
20 #include <plugin_tests.h>
21 #include <QString>
22 #include <typeinfo>
23 #include <filesystem>
24 #include <dlfcn.h>
25 #include <fakePlugin.h>
26 
28 {
29  manager = Plugin::Manager::getInstance();
30  ASSERT_EQ(manager, Plugin::Manager::getInstance());
31  ASSERT_EQ(manager, manager->getInstance());
32 }
33 
35 {
36  manager = Plugin::Manager::getInstance();
37  QString libraryPath(std::filesystem::current_path().string().c_str());
38  libraryPath += "/.libs/fakePlugin.so";
39  Plugin::Object *testobject = new Plugin::Object();
40  ASSERT_EQ(typeid(testobject).name(), typeid(manager->load(libraryPath)).name());
41  delete testobject;
42 }
43 
45 {
46  manager = Plugin::Manager::getInstance();
47  Plugin::Object *plugin;
48  QString libraryPath(std::filesystem::current_path().string().c_str());
49  libraryPath += "/.libs/fakePlugin.so";
50  plugin = manager->load(libraryPath);
51  manager->unload(plugin);
52  delete plugin;
53  // Plugin::Manager uses QEvents from QT to tell itself that it needs to unload plugins... why?
54  // TODO: eliminate the need to use QEvents in this instance
55  // TODO: How can I tell if a single plugin has been unloaded? answer: you can't *face palm*
56 }
57 
59 {
60  manager = Plugin::Manager::getInstance();
61  Plugin::Object **plugins = new Plugin::Object*[5];
62  QString libraryPath(std::filesystem::current_path().string().c_str());
63  libraryPath += "/.libs/fakePlugin.so";
64  for (int i = 0; i < 5; ++i)
65  {
66  plugins[i] = manager->load(libraryPath);
67  }
68  manager->unloadAll();
69  delete[] plugins;
70 }
71 
72 TEST_F(PluginManagerTest, foreachPlugin)
73 {
74  manager = Plugin::Manager::getInstance();
75  // TODO: create a test plugin for testing foreachPlugin function in Plugin::Manager
76 }
77 
79 {
80  // TODO: Decouple Plugin::Object from Plugin::Manager and test getLibrary function
82  QString libraryPath(std::filesystem::current_path().string().c_str());
83  libraryPath += "/.libs/fakePlugin.so";
84  object = manager->load(libraryPath);
85  EXPECT_EQ(libraryPath.toStdString(), object->getLibrary());
86  manager->unload(object);
87  delete object;
88 }
89 
91 {
92  // Its impossible to test this. No interface provided in order to check loading and unloading
93  // status. Mainly tied to the manager class.
94  // TODO: Decouple Plugin::Object from Plugin::Manager and test unload function
95 }
96 
97 
Plugin::Manager::unload
void unload(Object *object)
Definition: plugin.cpp:100
PluginManagerTest
Definition: plugin_tests.h:35
Plugin::Manager::load
Object * load(const QString &library)
Definition: plugin.cpp:46
Plugin::Object
Definition: plugin.h:145
Plugin::Manager
Definition: plugin.h:57
plugin_tests.h
PluginObjectTest
Definition: plugin_tests.h:26
TEST_F
TEST_F(PluginManagerTest, getInstance)
Definition: plugin_tests.cpp:27
fakePlugin.h
Plugin::Manager::getInstance
static Manager * getInstance(void)
Definition: plugin.cpp:188
Settings::Object::load
void load(const State &)
Definition: settings.cpp:195