plugins_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 plugins_test.cpp
3 
4  plugins_test.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 
21 #include "unit.hpp"
22 
23 #include <boost/filesystem.hpp>
24 #include "TaskContext.hpp"
25 #include "plugin/Plugin.hpp"
26 #include "plugin/PluginLoader.hpp"
28 
29 /* For internal use only - check if extension contains a version. */
30 RTT_API bool isExtensionVersion(const std::string& ext);
31 /* For internal use only - check if library should be loaded */
32 RTT_API bool isLoadableLibrary(const boost::filesystem::path& filename);
33 
38 {
39 public:
41 public:
43  {
44  tc = new TaskContext( "root", TaskContext::Stopped );
45  }
46 
48  {
49  delete tc;
50  }
51 };
52 
53 using namespace plugin;
54 
55 // Registers the fixture into the 'registry'
57 
58 BOOST_AUTO_TEST_CASE( testExtensionVersion )
59 {
60  BOOST_CHECK( true == isExtensionVersion(".1") );
61  BOOST_CHECK( true == isExtensionVersion(".12") );
62  BOOST_CHECK( true == isExtensionVersion(".123") );
63 
64  BOOST_CHECK( false == isExtensionVersion("1") );
65  BOOST_CHECK( false == isExtensionVersion("12") );
66  BOOST_CHECK( false == isExtensionVersion("123") );
67  BOOST_CHECK( false == isExtensionVersion(".a") );
68  BOOST_CHECK( false == isExtensionVersion("a") );
69  BOOST_CHECK( false == isExtensionVersion(".123 ") );
70  BOOST_CHECK( false == isExtensionVersion(". 123") );
71 
72  // pathological
73  BOOST_CHECK( false == isExtensionVersion("") );
74  BOOST_CHECK( false == isExtensionVersion(".") );
75  BOOST_CHECK( false == isExtensionVersion(".1.a") );
76  BOOST_CHECK( false == isExtensionVersion("..1") );
77  BOOST_CHECK( false == isExtensionVersion(".1a2") );
78  BOOST_CHECK( false == isExtensionVersion(".1.2") );
79  BOOST_CHECK( false == isExtensionVersion(" .1") );
80 }
81 
82 BOOST_AUTO_TEST_CASE( testLoadableLibrary )
83 {
84 #if defined(__APPLE__)
85 
86  BOOST_CHECK( true == isLoadableLibrary("libfoo.dylib") );
87  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.dylib") );
88  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.2.dylib") );
89  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.2.3.dylib") );
90 
91  BOOST_CHECK( true == isLoadableLibrary("libfoo.bar.dylib") );
92  BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.dylib") );
93  BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.2.dylib") );
94  BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.2.3.dylib") );
95  BOOST_CHECK( true == isLoadableLibrary("libfoo.bar.1..dylib") );
96 
97  BOOST_CHECK( true == isLoadableLibrary("libfoo.1.bar.dylib") );
98  BOOST_CHECK( true == isLoadableLibrary("libfoo.1.2.bar.dylib") );
99  BOOST_CHECK( true == isLoadableLibrary("libfoo.1.2.3.bar.dylib") );
100  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.dylib") );
101  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.2.dylib") );
102  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.2.3.dylib") );
103 
104  BOOST_CHECK( true == isLoadableLibrary("libfoo-bar.dylib") );
105  BOOST_CHECK( true == isLoadableLibrary("libfoo-2.3.bar.dylib") );
106 
107  // acceptable to RTT as libraries
108  BOOST_CHECK( true == isLoadableLibrary("foo.dylib") );
109  BOOST_CHECK( false == isLoadableLibrary("foo.1.dylib") );
110  BOOST_CHECK( true == isLoadableLibrary("foo.1.b.dylib") );
111  BOOST_CHECK( true == isLoadableLibrary("1.dylib") );
112 
113  // not libraries
114  BOOST_CHECK( false == isLoadableLibrary("libfoo.a") );
115  BOOST_CHECK( false == isLoadableLibrary("foo") );
116  BOOST_CHECK( false == isLoadableLibrary("libfoo.so") );
117  BOOST_CHECK( false == isLoadableLibrary("foo.so") );
118  BOOST_CHECK( false == isLoadableLibrary("foo.dylib.x") );
119  BOOST_CHECK( false == isLoadableLibrary("foo.dll") );
120 
121  // pathological
122  BOOST_CHECK( false == isLoadableLibrary(".dylib") );
123 
124 #elif defined(WIN32)
125 
126  BOOST_CHECK( true == isLoadableLibrary("libfoo.dll") );
127  BOOST_CHECK( false == isLoadableLibrary("libfoo.dll.1") );
128 
129  // not libraries
130  BOOST_CHECK( false == isLoadableLibrary("foo") );
131  BOOST_CHECK( false == isLoadableLibrary("foo.so") );
132  BOOST_CHECK( false == isLoadableLibrary("foo.dylib") );
133  BOOST_CHECK( false == isLoadableLibrary("foo.1.dll") );
134 
135  // pathological
136  BOOST_CHECK( false == isLoadableLibrary(".dll") );
137  BOOST_CHECK( false == isLoadableLibrary("1.dll") );
138 
139 #else
140  // assume Linux
141 
142  BOOST_CHECK( true == isLoadableLibrary("libfoo.so") );
143  BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1") );
144  BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1.2") );
145  BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1.2.3") );
146 
147  BOOST_CHECK( true == isLoadableLibrary("libfoo.bar.so") );
148  BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1") );
149  BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1.2") );
150  BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1.2.3") );
151 
152  BOOST_CHECK( true == isLoadableLibrary("libfoo.1.bar.so") );
153  BOOST_CHECK( true == isLoadableLibrary("libfoo.1.2.bar.so") );
154  BOOST_CHECK( true == isLoadableLibrary("libfoo.1.2.3.bar.so") );
155  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1") );
156  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1.2") );
157  BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1.2.3") );
158 
159  BOOST_CHECK( true == isLoadableLibrary("libfoo-bar.so") );
160  BOOST_CHECK( true == isLoadableLibrary("libfoo-2.3.bar.so") );
161 
162  // acceptable to RTT as libraries
163  BOOST_CHECK( true == isLoadableLibrary("foo.so") );
164  BOOST_CHECK( true == isLoadableLibrary("foo.1.so") );
165 
166  // not libraries
167  BOOST_CHECK( false == isLoadableLibrary("libfoo.a") );
168  BOOST_CHECK( false == isLoadableLibrary("foo") );
169  BOOST_CHECK( false == isLoadableLibrary("libfoo.dylib") );
170  BOOST_CHECK( false == isLoadableLibrary("foo.dylib") );
171  BOOST_CHECK( false == isLoadableLibrary("foo.dll") );
172  BOOST_CHECK( false == isLoadableLibrary("foo.so.x") );
173 
174  // pathological
175  BOOST_CHECK( false == isLoadableLibrary(".so") );
176  BOOST_CHECK( false == isLoadableLibrary(".so.1") );
177 
178 #endif
179 
180  // pathological
181  BOOST_CHECK( false == isLoadableLibrary("") );
182  BOOST_CHECK( false == isLoadableLibrary(".") );
183  BOOST_CHECK( false == isLoadableLibrary("..") );
184  BOOST_CHECK( false == isLoadableLibrary("1.") );
185  BOOST_CHECK( false == isLoadableLibrary("1") );
186  BOOST_CHECK( false == isLoadableLibrary(".1") );
187  BOOST_CHECK( false == isLoadableLibrary("a.") );
188  BOOST_CHECK( false == isLoadableLibrary("a") );
189  BOOST_CHECK( false == isLoadableLibrary(".a") );
190 }
191 
194 BOOST_AUTO_TEST_CASE( testTypePlugins )
195 {
196  PluginLoader::shared_ptr pl = PluginLoader::Instance();
197 
198  BOOST_CHECK( pl->isLoaded("typekit_plugin") == false);
199  BOOST_CHECK( pl->isLoaded("TypesPluginTest") == false);
200  pl->loadTypekit("testproject",".;..");
201  BOOST_CHECK( pl->isLoaded("typekit_plugin") );
202  BOOST_CHECK( pl->isLoaded("TypesPluginTest") );
203 
204 }
205 
208 BOOST_AUTO_TEST_CASE( testTypePlugin )
209 {
210  PluginLoader::shared_ptr pl = PluginLoader::Instance();
211 
212  BOOST_REQUIRE( pl->loadTypekit("typekit_plugin", "testproject;../testproject") );
213  BOOST_CHECK( pl->isLoaded("typekit_plugin") );
214  BOOST_CHECK( pl->isLoaded("TypesPluginTest") );
215 }
216 
217 BOOST_AUTO_TEST_CASE( testServicePlugins )
218 {
219  PluginLoader::shared_ptr pl = PluginLoader::Instance();
220 
221  BOOST_CHECK( pl->isLoaded("service_plugin") == false);
222  BOOST_CHECK( pl->isLoaded("serviceplugin") == false);
223  BOOST_CHECK( pl->isLoaded("global_service_plugin") == false);
224  BOOST_CHECK( pl->isLoaded("globalserviceplugin") == false);
225  pl->loadPlugin("testproject",".;..");
226  BOOST_CHECK( pl->isLoaded("service_plugin") );
227  BOOST_CHECK( pl->isLoaded("serviceplugin") );
228  BOOST_CHECK( pl->isLoaded("global_service_plugin") );
229  BOOST_CHECK( pl->isLoaded("globalserviceplugin") );
230 
231  BOOST_CHECK( RTT::internal::GlobalService::Instance()->hasService("the_global_service") );
232 }
233 
234 BOOST_AUTO_TEST_CASE( testServicePlugin )
235 {
236  PluginLoader::shared_ptr pl = PluginLoader::Instance();
237 
238  BOOST_REQUIRE( pl->loadService("serviceplugin", tc) );
239  BOOST_CHECK( tc->provides()->hasService("the_service") );
240 
241 }
242 
244 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
Service::shared_ptr provides()
TaskContext * tc
BOOST_AUTO_TEST_CASE(testExtensionVersion)
#define BOOST_AUTO_TEST_SUITE_END()
RTT_API bool isLoadableLibrary(const boost::filesystem::path &filename)
RTT_API bool isExtensionVersion(const std::string &ext)
static RTT_API Service::shared_ptr Instance()
boost::shared_ptr< PluginLoader > shared_ptr


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:26