plugins_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:54:57 CEST 2010  plugins_test.cpp
00003 
00004                         plugins_test.cpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 
00020 
00021 #include "unit.hpp"
00022 
00023 #include <boost/filesystem.hpp>
00024 #include "TaskContext.hpp"
00025 #include "plugin/Plugin.hpp"
00026 #include "plugin/PluginLoader.hpp"
00027 
00028 /* For internal use only - check if extension contains a version. */
00029 RTT_API bool isExtensionVersion(const std::string& ext);
00030 /* For internal use only - check if library should be loaded */
00031 RTT_API bool isLoadableLibrary(const boost::filesystem::path& filename);
00032 
00036 class PluginsFixture
00037 {
00038 public:
00039     TaskContext* tc;
00040 public:
00041     PluginsFixture()
00042     {
00043         tc =  new TaskContext( "root", TaskContext::Stopped );
00044     }
00045 
00046     ~PluginsFixture()
00047     {
00048         delete tc;
00049     }
00050 };
00051 
00052 using namespace plugin;
00053 
00054 // Registers the fixture into the 'registry'
00055 BOOST_FIXTURE_TEST_SUITE(  PluginsSuite,  PluginsFixture )
00056 
00057 BOOST_AUTO_TEST_CASE( testExtensionVersion )
00058 {
00059     BOOST_CHECK( true  == isExtensionVersion(".1") );
00060     BOOST_CHECK( true  == isExtensionVersion(".12") );
00061     BOOST_CHECK( true  == isExtensionVersion(".123") );
00062 
00063     BOOST_CHECK( false == isExtensionVersion("1") );
00064     BOOST_CHECK( false == isExtensionVersion("12") );
00065     BOOST_CHECK( false == isExtensionVersion("123") );
00066     BOOST_CHECK( false == isExtensionVersion(".a") );
00067     BOOST_CHECK( false == isExtensionVersion("a") );
00068     BOOST_CHECK( false == isExtensionVersion(".123 ") );
00069     BOOST_CHECK( false == isExtensionVersion(". 123") );
00070 
00071     // pathological
00072     BOOST_CHECK( false == isExtensionVersion("") );
00073     BOOST_CHECK( false == isExtensionVersion(".") );
00074     BOOST_CHECK( false == isExtensionVersion(".1.a") );
00075     BOOST_CHECK( false == isExtensionVersion("..1") );
00076     BOOST_CHECK( false == isExtensionVersion(".1a2") );
00077     BOOST_CHECK( false == isExtensionVersion(".1.2") );
00078     BOOST_CHECK( false == isExtensionVersion(" .1") );
00079 }
00080 
00081 BOOST_AUTO_TEST_CASE( testLoadableLibrary )
00082 {
00083 #if     defined(__APPLE__)
00084 
00085     BOOST_CHECK( true  == isLoadableLibrary("libfoo.dylib") );
00086     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.dylib") );
00087     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.2.dylib") );
00088     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.2.3.dylib") );
00089 
00090     BOOST_CHECK( true  == isLoadableLibrary("libfoo.bar.dylib") );
00091     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.dylib") );
00092     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.2.dylib") );
00093     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.2.3.dylib") );
00094     BOOST_CHECK( true  == isLoadableLibrary("libfoo.bar.1..dylib") );
00095 
00096     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.bar.dylib") );
00097     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.bar.dylib") );
00098     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.3.bar.dylib") );
00099     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.dylib") );
00100     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.2.dylib") );
00101     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.2.3.dylib") );
00102 
00103     BOOST_CHECK( true  == isLoadableLibrary("libfoo-bar.dylib") );
00104     BOOST_CHECK( true  == isLoadableLibrary("libfoo-2.3.bar.dylib") );
00105 
00106     // acceptable to RTT as libraries
00107     BOOST_CHECK( true  == isLoadableLibrary("foo.dylib") );
00108     BOOST_CHECK( false == isLoadableLibrary("foo.1.dylib") );
00109     BOOST_CHECK( true  == isLoadableLibrary("foo.1.b.dylib") );
00110     BOOST_CHECK( true  == isLoadableLibrary("1.dylib") );
00111 
00112     // not libraries
00113     BOOST_CHECK( false == isLoadableLibrary("libfoo.a") );
00114     BOOST_CHECK( false == isLoadableLibrary("foo") );
00115     BOOST_CHECK( false == isLoadableLibrary("libfoo.so") );
00116     BOOST_CHECK( false == isLoadableLibrary("foo.so") );
00117     BOOST_CHECK( false == isLoadableLibrary("foo.dylib.x") );
00118     BOOST_CHECK( false == isLoadableLibrary("foo.dll") );
00119 
00120     // pathological
00121     BOOST_CHECK( false == isLoadableLibrary(".dylib") );
00122 
00123 #elif   defined(WIN32)
00124 
00125     BOOST_CHECK( true  == isLoadableLibrary("libfoo.dll") );
00126     BOOST_CHECK( false == isLoadableLibrary("libfoo.dll.1") );
00127 
00128     // not libraries
00129     BOOST_CHECK( false == isLoadableLibrary("foo") );
00130     BOOST_CHECK( false == isLoadableLibrary("foo.so") );
00131     BOOST_CHECK( false == isLoadableLibrary("foo.dylib") );
00132     BOOST_CHECK( false == isLoadableLibrary("foo.1.dll") );
00133 
00134     // pathological
00135     BOOST_CHECK( false == isLoadableLibrary(".dll") );
00136     BOOST_CHECK( false == isLoadableLibrary("1.dll") );
00137 
00138 #else
00139     // assume Linux
00140 
00141     BOOST_CHECK( true  == isLoadableLibrary("libfoo.so") );
00142     BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1") );
00143     BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1.2") );
00144     BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1.2.3") );
00145 
00146     BOOST_CHECK( true  == isLoadableLibrary("libfoo.bar.so") );
00147     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1") );
00148     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1.2") );
00149     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1.2.3") );
00150 
00151     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.bar.so") );
00152     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.bar.so") );
00153     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.3.bar.so") );
00154     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1") );
00155     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1.2") );
00156     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1.2.3") );
00157 
00158     BOOST_CHECK( true  == isLoadableLibrary("libfoo-bar.so") );
00159     BOOST_CHECK( true  == isLoadableLibrary("libfoo-2.3.bar.so") );
00160 
00161     // acceptable to RTT as libraries
00162     BOOST_CHECK( true  == isLoadableLibrary("foo.so") );
00163     BOOST_CHECK( true  == isLoadableLibrary("foo.1.so") );
00164 
00165     // not libraries
00166     BOOST_CHECK( false == isLoadableLibrary("libfoo.a") );
00167     BOOST_CHECK( false == isLoadableLibrary("foo") );
00168     BOOST_CHECK( false == isLoadableLibrary("libfoo.dylib") );
00169     BOOST_CHECK( false == isLoadableLibrary("foo.dylib") );
00170     BOOST_CHECK( false == isLoadableLibrary("foo.dll") );
00171     BOOST_CHECK( false == isLoadableLibrary("foo.so.x") );
00172 
00173     // pathological
00174     BOOST_CHECK( false == isLoadableLibrary(".so") );
00175     BOOST_CHECK( false == isLoadableLibrary(".so.1") );
00176 
00177 #endif
00178 
00179     // pathological
00180     BOOST_CHECK( false == isLoadableLibrary("") );
00181     BOOST_CHECK( false == isLoadableLibrary(".") );
00182     BOOST_CHECK( false == isLoadableLibrary("..") );
00183     BOOST_CHECK( false == isLoadableLibrary("1.") );
00184     BOOST_CHECK( false == isLoadableLibrary("1") );
00185     BOOST_CHECK( false == isLoadableLibrary(".1") );
00186     BOOST_CHECK( false == isLoadableLibrary("a.") );
00187     BOOST_CHECK( false == isLoadableLibrary("a") );
00188     BOOST_CHECK( false == isLoadableLibrary(".a") );
00189 }
00190 
00193 BOOST_AUTO_TEST_CASE( testTypePlugins )
00194 {
00195     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00196 
00197     BOOST_CHECK( pl->isLoaded("typekit_plugin") == false);
00198     BOOST_CHECK( pl->isLoaded("TypesPluginTest") == false);
00199     pl->loadTypekit("testproject",".;..");
00200     BOOST_CHECK( pl->isLoaded("typekit_plugin") );
00201     BOOST_CHECK( pl->isLoaded("TypesPluginTest") );
00202 
00203 }
00204 
00207 BOOST_AUTO_TEST_CASE( testTypePlugin )
00208 {
00209     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00210 
00211     BOOST_REQUIRE( pl->loadTypekit("typekit_plugin", "testproject;../testproject") );
00212     BOOST_CHECK( pl->isLoaded("typekit_plugin") );
00213     BOOST_CHECK( pl->isLoaded("TypesPluginTest") );
00214 }
00215 
00216 BOOST_AUTO_TEST_CASE( testServicePlugins )
00217 {
00218     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00219 
00220     BOOST_CHECK( pl->isLoaded("service_plugin") == false);
00221     BOOST_CHECK( pl->isLoaded("serviceplugin") == false);
00222     pl->loadPlugin("testproject",".;..");
00223     BOOST_CHECK( pl->isLoaded("service_plugin") );
00224     BOOST_CHECK( pl->isLoaded("serviceplugin") );
00225 
00226 }
00227 
00228 BOOST_AUTO_TEST_CASE( testServicePlugin )
00229 {
00230     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00231 
00232     BOOST_REQUIRE( pl->loadService("serviceplugin", tc) );
00233     BOOST_CHECK( tc->provides()->hasService("the_service") );
00234 
00235 }
00236 
00237 BOOST_AUTO_TEST_SUITE_END()
00238 


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:51