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 #include "internal/GlobalService.hpp"
00028 
00029 /* For internal use only - check if extension contains a version. */
00030 RTT_API bool isExtensionVersion(const std::string& ext);
00031 /* For internal use only - check if library should be loaded */
00032 RTT_API bool isLoadableLibrary(const boost::filesystem::path& filename);
00033 
00037 class PluginsFixture
00038 {
00039 public:
00040     TaskContext* tc;
00041 public:
00042     PluginsFixture()
00043     {
00044         tc =  new TaskContext( "root", TaskContext::Stopped );
00045     }
00046 
00047     ~PluginsFixture()
00048     {
00049         delete tc;
00050     }
00051 };
00052 
00053 using namespace plugin;
00054 
00055 // Registers the fixture into the 'registry'
00056 BOOST_FIXTURE_TEST_SUITE(  PluginsSuite,  PluginsFixture )
00057 
00058 BOOST_AUTO_TEST_CASE( testExtensionVersion )
00059 {
00060     BOOST_CHECK( true  == isExtensionVersion(".1") );
00061     BOOST_CHECK( true  == isExtensionVersion(".12") );
00062     BOOST_CHECK( true  == isExtensionVersion(".123") );
00063 
00064     BOOST_CHECK( false == isExtensionVersion("1") );
00065     BOOST_CHECK( false == isExtensionVersion("12") );
00066     BOOST_CHECK( false == isExtensionVersion("123") );
00067     BOOST_CHECK( false == isExtensionVersion(".a") );
00068     BOOST_CHECK( false == isExtensionVersion("a") );
00069     BOOST_CHECK( false == isExtensionVersion(".123 ") );
00070     BOOST_CHECK( false == isExtensionVersion(". 123") );
00071 
00072     // pathological
00073     BOOST_CHECK( false == isExtensionVersion("") );
00074     BOOST_CHECK( false == isExtensionVersion(".") );
00075     BOOST_CHECK( false == isExtensionVersion(".1.a") );
00076     BOOST_CHECK( false == isExtensionVersion("..1") );
00077     BOOST_CHECK( false == isExtensionVersion(".1a2") );
00078     BOOST_CHECK( false == isExtensionVersion(".1.2") );
00079     BOOST_CHECK( false == isExtensionVersion(" .1") );
00080 }
00081 
00082 BOOST_AUTO_TEST_CASE( testLoadableLibrary )
00083 {
00084 #if     defined(__APPLE__)
00085 
00086     BOOST_CHECK( true  == isLoadableLibrary("libfoo.dylib") );
00087     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.dylib") );
00088     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.2.dylib") );
00089     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.2.3.dylib") );
00090 
00091     BOOST_CHECK( true  == isLoadableLibrary("libfoo.bar.dylib") );
00092     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.dylib") );
00093     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.2.dylib") );
00094     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.1.2.3.dylib") );
00095     BOOST_CHECK( true  == isLoadableLibrary("libfoo.bar.1..dylib") );
00096 
00097     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.bar.dylib") );
00098     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.bar.dylib") );
00099     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.3.bar.dylib") );
00100     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.dylib") );
00101     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.2.dylib") );
00102     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.1.2.3.dylib") );
00103 
00104     BOOST_CHECK( true  == isLoadableLibrary("libfoo-bar.dylib") );
00105     BOOST_CHECK( true  == isLoadableLibrary("libfoo-2.3.bar.dylib") );
00106 
00107     // acceptable to RTT as libraries
00108     BOOST_CHECK( true  == isLoadableLibrary("foo.dylib") );
00109     BOOST_CHECK( false == isLoadableLibrary("foo.1.dylib") );
00110     BOOST_CHECK( true  == isLoadableLibrary("foo.1.b.dylib") );
00111     BOOST_CHECK( true  == isLoadableLibrary("1.dylib") );
00112 
00113     // not libraries
00114     BOOST_CHECK( false == isLoadableLibrary("libfoo.a") );
00115     BOOST_CHECK( false == isLoadableLibrary("foo") );
00116     BOOST_CHECK( false == isLoadableLibrary("libfoo.so") );
00117     BOOST_CHECK( false == isLoadableLibrary("foo.so") );
00118     BOOST_CHECK( false == isLoadableLibrary("foo.dylib.x") );
00119     BOOST_CHECK( false == isLoadableLibrary("foo.dll") );
00120 
00121     // pathological
00122     BOOST_CHECK( false == isLoadableLibrary(".dylib") );
00123 
00124 #elif   defined(WIN32)
00125 
00126     BOOST_CHECK( true  == isLoadableLibrary("libfoo.dll") );
00127     BOOST_CHECK( false == isLoadableLibrary("libfoo.dll.1") );
00128 
00129     // not libraries
00130     BOOST_CHECK( false == isLoadableLibrary("foo") );
00131     BOOST_CHECK( false == isLoadableLibrary("foo.so") );
00132     BOOST_CHECK( false == isLoadableLibrary("foo.dylib") );
00133     BOOST_CHECK( false == isLoadableLibrary("foo.1.dll") );
00134 
00135     // pathological
00136     BOOST_CHECK( false == isLoadableLibrary(".dll") );
00137     BOOST_CHECK( false == isLoadableLibrary("1.dll") );
00138 
00139 #else
00140     // assume Linux
00141 
00142     BOOST_CHECK( true  == isLoadableLibrary("libfoo.so") );
00143     BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1") );
00144     BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1.2") );
00145     BOOST_CHECK( false == isLoadableLibrary("libfoo.so.1.2.3") );
00146 
00147     BOOST_CHECK( true  == isLoadableLibrary("libfoo.bar.so") );
00148     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1") );
00149     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1.2") );
00150     BOOST_CHECK( false == isLoadableLibrary("libfoo.bar.so.1.2.3") );
00151 
00152     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.bar.so") );
00153     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.bar.so") );
00154     BOOST_CHECK( true  == isLoadableLibrary("libfoo.1.2.3.bar.so") );
00155     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1") );
00156     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1.2") );
00157     BOOST_CHECK( false == isLoadableLibrary("libfoo.1.bar.so.1.2.3") );
00158 
00159     BOOST_CHECK( true  == isLoadableLibrary("libfoo-bar.so") );
00160     BOOST_CHECK( true  == isLoadableLibrary("libfoo-2.3.bar.so") );
00161 
00162     // acceptable to RTT as libraries
00163     BOOST_CHECK( true  == isLoadableLibrary("foo.so") );
00164     BOOST_CHECK( true  == isLoadableLibrary("foo.1.so") );
00165 
00166     // not libraries
00167     BOOST_CHECK( false == isLoadableLibrary("libfoo.a") );
00168     BOOST_CHECK( false == isLoadableLibrary("foo") );
00169     BOOST_CHECK( false == isLoadableLibrary("libfoo.dylib") );
00170     BOOST_CHECK( false == isLoadableLibrary("foo.dylib") );
00171     BOOST_CHECK( false == isLoadableLibrary("foo.dll") );
00172     BOOST_CHECK( false == isLoadableLibrary("foo.so.x") );
00173 
00174     // pathological
00175     BOOST_CHECK( false == isLoadableLibrary(".so") );
00176     BOOST_CHECK( false == isLoadableLibrary(".so.1") );
00177 
00178 #endif
00179 
00180     // pathological
00181     BOOST_CHECK( false == isLoadableLibrary("") );
00182     BOOST_CHECK( false == isLoadableLibrary(".") );
00183     BOOST_CHECK( false == isLoadableLibrary("..") );
00184     BOOST_CHECK( false == isLoadableLibrary("1.") );
00185     BOOST_CHECK( false == isLoadableLibrary("1") );
00186     BOOST_CHECK( false == isLoadableLibrary(".1") );
00187     BOOST_CHECK( false == isLoadableLibrary("a.") );
00188     BOOST_CHECK( false == isLoadableLibrary("a") );
00189     BOOST_CHECK( false == isLoadableLibrary(".a") );
00190 }
00191 
00194 BOOST_AUTO_TEST_CASE( testTypePlugins )
00195 {
00196     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00197 
00198     BOOST_CHECK( pl->isLoaded("typekit_plugin") == false);
00199     BOOST_CHECK( pl->isLoaded("TypesPluginTest") == false);
00200     pl->loadTypekit("testproject",".;..");
00201     BOOST_CHECK( pl->isLoaded("typekit_plugin") );
00202     BOOST_CHECK( pl->isLoaded("TypesPluginTest") );
00203 
00204 }
00205 
00208 BOOST_AUTO_TEST_CASE( testTypePlugin )
00209 {
00210     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00211 
00212     BOOST_REQUIRE( pl->loadTypekit("typekit_plugin", "testproject;../testproject") );
00213     BOOST_CHECK( pl->isLoaded("typekit_plugin") );
00214     BOOST_CHECK( pl->isLoaded("TypesPluginTest") );
00215 }
00216 
00217 BOOST_AUTO_TEST_CASE( testServicePlugins )
00218 {
00219     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00220 
00221     BOOST_CHECK( pl->isLoaded("service_plugin") == false);
00222     BOOST_CHECK( pl->isLoaded("serviceplugin") == false);
00223     BOOST_CHECK( pl->isLoaded("global_service_plugin") == false);
00224     BOOST_CHECK( pl->isLoaded("globalserviceplugin") == false);
00225     pl->loadPlugin("testproject",".;..");
00226     BOOST_CHECK( pl->isLoaded("service_plugin") );
00227     BOOST_CHECK( pl->isLoaded("serviceplugin") );
00228     BOOST_CHECK( pl->isLoaded("global_service_plugin") );
00229     BOOST_CHECK( pl->isLoaded("globalserviceplugin") );
00230 
00231     BOOST_CHECK( RTT::internal::GlobalService::Instance()->hasService("the_global_service") );
00232 }
00233 
00234 BOOST_AUTO_TEST_CASE( testServicePlugin )
00235 {
00236     PluginLoader::shared_ptr pl = PluginLoader::Instance();
00237 
00238     BOOST_REQUIRE( pl->loadService("serviceplugin", tc) );
00239     BOOST_CHECK( tc->provides()->hasService("the_service") );
00240 
00241 }
00242 
00243 BOOST_AUTO_TEST_SUITE_END()
00244 


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:16