myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-27-g


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-27-ged65943
Date: Tue, 23 Feb 2010 12:06:28 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  ed65943af58579a421e31d6645e3a33d08031d20 (commit)
      from  6d146ec8613b6c9c847fb14bab0687d65862e943 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit ed65943af58579a421e31d6645e3a33d08031d20
Author: Giuseppe Scrivano <address@hidden>
Date:   Tue Feb 23 13:06:10 2010 +0100

    The plugins manager can load plugins before the server startup.

diff --git a/myserver/include/plugin/plugin_info.h 
b/myserver/include/plugin/plugin_info.h
index 56991f2..79eefb7 100644
--- a/myserver/include/plugin/plugin_info.h
+++ b/myserver/include/plugin/plugin_info.h
@@ -61,7 +61,7 @@ public:
   void setEnabled (bool enabled);
   pair<int,int>* getDependence (string name);
 
-  static int convertVersion (string* s);
+  static int convertVersion (const string& s);
 
 private:
   string name;
diff --git a/myserver/include/plugin/plugins_manager.h 
b/myserver/include/plugin/plugins_manager.h
index 67ad458..c74569d 100644
--- a/myserver/include/plugin/plugins_manager.h
+++ b/myserver/include/plugin/plugins_manager.h
@@ -46,14 +46,16 @@ public:
     return pluginsInfos.end ();
   }
 
-  Plugin* getPlugin (string& name);
+  Plugin* getPlugin (string &name);
 
-  int preLoad (Server *server, string& resource);
+  int preLoad (Server *server, string &resource);
   int load (Server *server);
   int postLoad (Server *server);
   int unLoad ();
 
-  virtual void removePlugin (string& name);
+  int quickLoad (Server *server, const string &plugins);
+
+  virtual void removePlugin (string &name);
 
   virtual int addPluginInfo (string&, PluginInfo*);
   virtual PluginInfo* getPluginInfo (string&);
@@ -63,13 +65,16 @@ public:
   PluginsManager ();
   ~PluginsManager ();
 
-private:
+protected:
+  virtual int loadFile (Server* server, string &name, string &file, 
PluginInfo* pinfo);
   HashMap<string, PluginInfo*> pluginsInfos;
   int loadOptions (Server *server);
-  void recursiveDependencesFallDown (Server* server, string &name, 
HashMap<string, bool> &remove, HashMap<string, list<string>*> &dependsOn);
-  Plugin* preLoadPlugin (string& file, Server* server, bool global);
+  void recursiveDependencesFallDown (Server* server, string &name,
+                                     HashMap<string, bool> &remove,
+                                     HashMap<string, list<string>*> 
&dependsOn);
+  virtual Plugin* preLoadPlugin (string &file, Server* server, bool global);
 
-  PluginInfo* loadInfo (Server* server, string& name, string& path);
+  virtual PluginInfo* loadInfo (Server* server, string &name, string &path);
 };
 
 #endif
diff --git a/myserver/src/plugin/plugin_info.cpp 
b/myserver/src/plugin/plugin_info.cpp
index 53ee7e4..fd7a6b1 100644
--- a/myserver/src/plugin/plugin_info.cpp
+++ b/myserver/src/plugin/plugin_info.cpp
@@ -39,9 +39,6 @@ PluginInfo::PluginInfo (string& name, bool enabled, bool 
global)
   this->plugin = NULL;
 }
 
-
-
-
 /*!
  *Destroy the object.
  */
@@ -75,7 +72,7 @@ bool PluginInfo::isGlobal ()
  */
 void PluginInfo::addDependence (string name, int minVersion, int maxVersion)
 {
-  dependences.put (name, new pair<int,int>(minVersion,maxVersion));
+  dependences.put (name, new pair<int, int> (minVersion, maxVersion));
 }
 
 /*!
@@ -188,9 +185,9 @@ Plugin* PluginInfo::removePlugin ()
 
 /*!
  * Converts a string in the format "a.b.c.d" in an int in the format abcd where
- * each number takes 8 bit.
+ * each number takes 8 bits.
  */
-int PluginInfo::convertVersion (string* s)
+int PluginInfo::convertVersion (const string & s)
 {
   int ret;
 
@@ -198,54 +195,51 @@ int PluginInfo::convertVersion (string* s)
     regex = new Regex 
("^[1-2]?[1-9]?[0-9](\\.[1-2]?[0-9]?[0-9](\\.[1-2]?[0-9]?[0-9](\\.[1-2]?[0-9]?[0-9])?)?)?$",
                        REG_EXTENDED | REG_NOSUB);
 
-  ret = regex->exec (s->c_str (), 0, NULL, 0);
+  ret = regex->exec (s.c_str (), 0, NULL, 0);
 
   if (ret)
     return -1;
 
-  string::size_type pos = s->find (".",0);
+  string::size_type pos = s.find (".", 0);
   if (pos == string::npos)
-    return atoi (s->c_str ())  <<  24;
+    return atoi (s.c_str ())  <<  24;
 
   int n1 = 0;
   int n2 = 0;
   int n3 = 0;
   int n4 = 0;
 
-  string sa = s->substr (0, pos);
+  string sa = s.substr (0, pos);
   n1 = atoi (sa.c_str ());
   if (n1>255)
     return -1;
 
   string::size_type oldpos = pos;
 
-
-  if (oldpos!=string::npos)
+  if (oldpos != string::npos)
     {
-      pos = s->find (".",oldpos + 1);
-      string sa = s->substr (oldpos + 1, pos - oldpos);
+      pos = s.find (".", oldpos + 1);
+      string sa = s.substr (oldpos + 1, pos - oldpos);
       n2 = atoi (sa.c_str ());
-      if (n2>255)
+      if (n2 > 255)
         return -1;
     }
 
-
   oldpos = pos;
-  if (oldpos!=string::npos)
+  if (oldpos != string::npos)
     {
-      pos = s->find (".",oldpos + 1);
-      string sa = s->substr (oldpos + 1, pos - oldpos);
+      pos = s.find (".",oldpos + 1);
+      string sa = s.substr (oldpos + 1, pos - oldpos);
       n3 = atoi (sa.c_str ());
-      if (n3>255)
+      if (n3 > 255)
         return -1;
     }
 
-
   oldpos = pos;
   if (oldpos != string::npos)
     {
-      pos = s->find (".",oldpos + 1);
-      string sa = s->substr (oldpos + 1, pos - oldpos);
+      pos = s.find (".",oldpos + 1);
+      string sa = s.substr (oldpos + 1, pos - oldpos);
       n4 = atoi (sa.c_str ());
       if (n4 > 255)
         return -1;
diff --git a/myserver/src/plugin/plugins_manager.cpp 
b/myserver/src/plugin/plugins_manager.cpp
index 6988c41..9cdd8e5 100644
--- a/myserver/src/plugin/plugins_manager.cpp
+++ b/myserver/src/plugin/plugins_manager.cpp
@@ -51,7 +51,7 @@ PluginsManager::~PluginsManager () { }
  * \param name The plugin name.
  */
 Plugin*
-PluginsManager::getPlugin (string& name)
+PluginsManager::getPlugin (string &name)
 {
   PluginInfo* info = pluginsInfos.get (name);
   if (info)
@@ -126,7 +126,7 @@ PluginsManager::loadOptions (Server *server)
  * implementation it is a directory name.
  */
 int
-PluginsManager::preLoad (Server* server, string& resource)
+PluginsManager::preLoad (Server* server, string &resource)
 {
   ReadDirectory fdir;
   ReadDirectory flib;
@@ -168,7 +168,6 @@ PluginsManager::preLoad (Server* server, string& resource)
           if (flib.name[0] == '.')
             continue;
 
-
           if (!strstr (flib.name.c_str (), "plugin.xml"))
             continue;
           completeFileName.assign (filename);
@@ -203,31 +202,50 @@ PluginsManager::preLoad (Server* server, string& resource)
 #else
           libname.append (".so");
 #endif
-          if (pinfo->isEnabled ())
-            {
-              Plugin* plugin = preLoadPlugin (libname, server,
-                                              pinfo->isGlobal ());
-              if (plugin)
-                pinfo->setPlugin (plugin);
-              else
-                {
-                  ret |= 1;
-                  server->log (MYSERVER_LOG_MSG_ERROR,
-                              _("Error loading plugin `%s'"), libname.c_str 
());
-                }
-            }
-          addPluginInfo (pname, pinfo);
+
+          ret |= loadFile (server, pname, libname, pinfo);
         }
-      while (!flib.findnext ());
+      while (! flib.findnext ());
     }
-  while (!fdir.findnext ());
+  while (! fdir.findnext ());
+
   fdir.findclose ();
   flib.findclose ();
   return ret;
 }
 
 /*!
- *Create the appropriate object to keep a plugin.
+ * Load the specified plugin file.
+ * \param server The server object to use.
+ * \param name Plugin name.
+ * \param file Plugin file.
+ * \param pinfo Plugin information.
+ */
+int
+PluginsManager::loadFile (Server* server, string &name, string &file,
+                          PluginInfo* pinfo)
+{
+  int ret = 0;
+  if (pinfo->isEnabled ())
+    {
+      Plugin* plugin = preLoadPlugin (file, server,
+                                      pinfo->isGlobal ());
+      if (plugin)
+        pinfo->setPlugin (plugin);
+      else
+        {
+          ret = 1;
+          server->log (MYSERVER_LOG_MSG_ERROR,
+                       _("Error loading plugin `%s'"), file.c_str ());
+        }
+    }
+
+  addPluginInfo (name, pinfo);
+  return ret;
+}
+
+/*!
+ * Create the appropriate object to keep a plugin.
  */
 Plugin*
 PluginsManager::createPluginObject ()
@@ -236,12 +254,70 @@ PluginsManager::createPluginObject ()
 }
 
 /*!
+ * Quick load a plugin, doing all phases {pre,,post}Load.
+ * \param server The server object to use.
+ * \param plugins comma separed list of plugins to load as:
+ * "name1:pluginfile1.so,name2:pluginfile2.so"
+*/
+int
+PluginsManager::quickLoad (Server *server, const string &plugins)
+{
+  size_t start = 0;
+  int ret = 0;
+  while (1)
+    {
+      size_t commaPos = plugins.find (",", start);
+
+      size_t sep = plugins.find (":", start);
+      if (sep > commaPos || sep == string::npos)
+        {
+          server->log (MYSERVER_LOG_MSG_ERROR,
+                       _("Invalid plugins data specified"));
+          return -1;
+        }
+
+      string name = plugins.substr (start, sep - start);
+      string file = plugins.substr (sep + 1, commaPos == string::npos
+                                    ? string::npos
+                                    : commaPos - sep - 1);
+
+      PluginInfo *pinfo = new PluginInfo (name);
+      auto_ptr<PluginInfo> pinfoAutoPtr (pinfo);
+
+      ret |= loadFile (server, name, file, pinfo);
+
+      pinfoAutoPtr.release ();
+
+      Plugin *plugin = preLoadPlugin (file, server, true);
+      if (! plugin)
+        {
+          server->log (MYSERVER_LOG_MSG_ERROR,
+                       _("Cannot load plugin %s"), file.c_str ());
+          return -1;
+        }
+
+      pinfo->setPlugin (plugin);
+      addPluginInfo (name, pinfo);
+
+      ret |= plugin->load (server);
+      ret |= plugin->postLoad (server);
+
+      if (commaPos == string::npos)
+        break;
+
+      start = commaPos + 1;
+    }
+
+  return ret;
+}
+
+/*!
  *Loads the plugin info.
  *\param name The plugin name.
  *\param path the plugin xml descriptor path.
  */
 PluginInfo*
-PluginsManager::loadInfo (Server* server, string& name, string& path)
+PluginsManager::loadInfo (Server* server, string &name, string &path)
 {
   PluginInfo* pinfo = getPluginInfo (name);
   auto_ptr<PluginInfo> pinfoAutoPtr (NULL);
@@ -277,8 +353,8 @@ PluginsManager::loadInfo (Server* server, string& name, 
string& path)
       xmlChar *minVersion = xmlGetProp (nodes->nodeTab[0],
                                         (const xmlChar*) "min-version");
 
-      string sMinVer ((char*)minVersion);
-      pinfo->setMyServerMinVersion (PluginInfo::convertVersion (&sMinVer));
+      string sMinVer ((char*) minVersion);
+      pinfo->setMyServerMinVersion (PluginInfo::convertVersion (sMinVer));
     }
   else
     {
@@ -294,7 +370,7 @@ PluginsManager::loadInfo (Server* server, string& name, 
string& path)
                                         (const xmlChar*) "max-version");
 
       string sMaxVer ((char*)maxVersion);
-      pinfo->setMyServerMaxVersion (PluginInfo::convertVersion (&sMaxVer));
+      pinfo->setMyServerMaxVersion (PluginInfo::convertVersion (sMaxVer));
     }
   else
     {
@@ -335,7 +411,7 @@ PluginsManager::loadInfo (Server* server, string& name, 
string& path)
     }
 
   string verStr ((char*) nodes->nodeTab[0]->content);
-  int version = PluginInfo::convertVersion (&verStr);
+  int version = PluginInfo::convertVersion (verStr);
 
   if (version != -1)
     pinfo->setVersion (version);
@@ -372,8 +448,8 @@ PluginsManager::loadInfo (Server* server, string& name, 
string& path)
       string maxVerStr = ((char*) xmlGetProp (nodes->nodeTab[i],
                                               (const xmlChar*) "max-version"));
 
-      int minVersion = PluginInfo::convertVersion (&minVerStr);
-      int maxVersion = PluginInfo::convertVersion (&maxVerStr);
+      int minVersion = PluginInfo::convertVersion (minVerStr);
+      int maxVersion = PluginInfo::convertVersion (maxVerStr);
 
       if (minVersion == -1 || maxVersion == -1)
         {
@@ -398,7 +474,7 @@ PluginsManager::loadInfo (Server* server, string& name, 
string& path)
  * \param global Specify if the library should be loaded globally.
  */
 Plugin*
-PluginsManager::preLoadPlugin (string& file, Server* server, bool global)
+PluginsManager::preLoadPlugin (string &file, Server* server, bool global)
 {
   Plugin *plugin = createPluginObject ();
 
@@ -459,8 +535,6 @@ PluginsManager::recursiveDependencesFallDown (Server* 
server, string &name,
 int
 PluginsManager::load (Server *server)
 {
-
-
   list<string*> toRemove;
   HashMap<string, list<string>*> dependsOn;
   HashMap<string, PluginInfo*>::Iterator it = pluginsInfos.begin ();
@@ -476,7 +550,7 @@ PluginsManager::load (Server *server)
       if (i != string::npos)
         msversion = msversion.substr (0, i);
 
-      int msVersion = PluginInfo::convertVersion (&msversion);
+      int msVersion = PluginInfo::convertVersion (msversion);
       if (msVersion < pinfo->getMyServerMinVersion ()
           || msVersion > pinfo->getMyServerMaxVersion ())
         server->log (MYSERVER_LOG_MSG_WARNING,
@@ -499,7 +573,6 @@ PluginsManager::load (Server *server)
           deps->push_front (name);
         }
 
-
       it++;
     }
 
@@ -508,8 +581,6 @@ PluginsManager::load (Server *server)
     removePlugin (**tRIt);
   toRemove.clear ();
 
-
-
   HashMap<string, list<string>*>::Iterator dIt = dependsOn.begin ();
   for (; dIt != dependsOn.end (); dIt++)
     {
@@ -621,7 +692,7 @@ PluginsManager::unLoad ()
  * \param name The plugin to remove.
  */
 void
-PluginsManager::removePlugin (string& name)
+PluginsManager::removePlugin (string &name)
 {
   PluginInfo* info = pluginsInfos.remove (name);
 
@@ -634,7 +705,7 @@ PluginsManager::removePlugin (string& name)
  * \param pi The options for the plugin.
  */
 int
-PluginsManager::addPluginInfo (string& plugin, PluginInfo* pi)
+PluginsManager::addPluginInfo (string &plugin, PluginInfo* pi)
 {
   PluginInfo* oldPi = pluginsInfos.put (plugin, pi);
 
@@ -649,7 +720,7 @@ PluginsManager::addPluginInfo (string& plugin, PluginInfo* 
pi)
  * \param plugin The plugin name.
  */
 PluginInfo*
-PluginsManager::getPluginInfo (string& plugin)
+PluginsManager::getPluginInfo (string &plugin)
 {
   return pluginsInfos.get (plugin);
 }
diff --git a/myserver/tests/Makefile.am b/myserver/tests/Makefile.am
index 3503dcb..069bd32 100644
--- a/myserver/tests/Makefile.am
+++ b/myserver/tests/Makefile.am
@@ -56,6 +56,7 @@ test_suite_SOURCES =          main.cpp                        
        \
                        test_nodetree.cpp                       \
                        test_pipe.cpp                           \
                        test_plugin_info.cpp                    \
+                       test_plugins_manager.cpp                \
                        test_read_directory.cpp                 \
                        test_recursive_mutex.cpp                \
                        test_regex.cpp                          \
diff --git a/myserver/tests/test_plugin_info.cpp 
b/myserver/tests/test_plugin_info.cpp
index 203d4ae..b3334a5 100644
--- a/myserver/tests/test_plugin_info.cpp
+++ b/myserver/tests/test_plugin_info.cpp
@@ -1,19 +1,19 @@
 /*
- MyServer
- Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
+  MyServer
+  Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 #include "myserver.h"
 #include <ctype.h>
@@ -49,121 +49,119 @@ private:
 public:
   void setUp ()
   {
-       string name ("test");
-       pluginfo = new PluginInfo (name,false,false);
+    string name ("test");
+    pluginfo = new PluginInfo (name, false, false);
   }
 
   void tearDown ()
   {
-       delete (pluginfo);
+    delete (pluginfo);
   }
 
   void testIsNotEnabled ()
   {
-       CPPUNIT_ASSERT (!pluginfo->isEnabled ());
+    CPPUNIT_ASSERT (! pluginfo->isEnabled ());
   }
 
   void testIsEnabled ()
   {
-       delete (pluginfo);
-       string name ("test");
-       pluginfo = new PluginInfo (name,true,false);
-       CPPUNIT_ASSERT (pluginfo->isEnabled ());
+    delete (pluginfo);
+    string name ("test");
+    pluginfo = new PluginInfo (name, true, false);
+    CPPUNIT_ASSERT (pluginfo->isEnabled ());
   }
 
   void testIsNotGlobal ()
   {
-       CPPUNIT_ASSERT (!pluginfo->isGlobal ());
+    CPPUNIT_ASSERT (! pluginfo->isGlobal ());
   }
 
   void testIsGlobal ()
   {
-       delete (pluginfo);
-       string name ("test");
-       pluginfo = new PluginInfo (name,false,true);
-       CPPUNIT_ASSERT (pluginfo->isGlobal ());
+    delete (pluginfo);
+    string name ("test");
+    pluginfo = new PluginInfo (name, false, true);
+    CPPUNIT_ASSERT (pluginfo->isGlobal ());
   }
 
   void testGetVersion ()
   {
-       CPPUNIT_ASSERT_EQUAL (pluginfo->getVersion (),0);
+    CPPUNIT_ASSERT_EQUAL (pluginfo->getVersion (), 0);
   }
 
   void testGetMyServerMinVersion ()
   {
-       CPPUNIT_ASSERT_EQUAL (pluginfo->getMyServerMinVersion (),0);
+    CPPUNIT_ASSERT_EQUAL (pluginfo->getMyServerMinVersion (), 0);
   }
 
   void testGetMyServerMaxVersion ()
   {
-       CPPUNIT_ASSERT_EQUAL (pluginfo->getMyServerMaxVersion (),0);
+    CPPUNIT_ASSERT_EQUAL (pluginfo->getMyServerMaxVersion (), 0);
   }
 
   void testGetName ()
   {
-       CPPUNIT_ASSERT_EQUAL (pluginfo->getName ().compare ("test"),0);
+    CPPUNIT_ASSERT_EQUAL (pluginfo->getName ().compare ("test"), 0);
   }
 
   void testDependencies ()
   {
-       string test ("test-dep");
-       pluginfo->addDependence (test ,0,1);
-       CPPUNIT_ASSERT_EQUAL ( (*(pluginfo->begin ()))->first , 0);
-       CPPUNIT_ASSERT_EQUAL ( (*(pluginfo->begin ()))->second , 1);
-       CPPUNIT_ASSERT_EQUAL ( pluginfo->begin ().getKey ().compare 
("test-dep"),0);
+    string test ("test-dep");
+    pluginfo->addDependence (test ,0,1);
+    CPPUNIT_ASSERT_EQUAL ((*(pluginfo->begin ()))->first , 0);
+    CPPUNIT_ASSERT_EQUAL ((*(pluginfo->begin ()))->second , 1);
+    CPPUNIT_ASSERT_EQUAL (pluginfo->begin ().getKey ().compare ("test-dep"), 
0);
   }
 
-
-
   void testVersionConversionStringInt ()
   {
-       int v = PluginInfo::convertVersion (new string ("1"));
-       CPPUNIT_ASSERT_EQUAL (1<<24,v);
+    int v = PluginInfo::convertVersion ("1");
+    CPPUNIT_ASSERT_EQUAL (1 << 24,v);
 
-       v = PluginInfo::convertVersion (new string ("255"));
-       CPPUNIT_ASSERT_EQUAL (255<<24,v);
+    v = PluginInfo::convertVersion ("255");
+    CPPUNIT_ASSERT_EQUAL (255 << 24,v);
 
-       v = PluginInfo::convertVersion (new string ("1.2"));
-       CPPUNIT_ASSERT_EQUAL ((1<<24) + (2<<16),v);
+    v = PluginInfo::convertVersion ("1.2");
+    CPPUNIT_ASSERT_EQUAL ((1 << 24) + (2 << 16),v);
 
-       v = PluginInfo::convertVersion (new string ("1.2.3"));
-       CPPUNIT_ASSERT_EQUAL ((1<<24) + (2<<16) + (3<<8),v);
+    v = PluginInfo::convertVersion ("1.2.3");
+    CPPUNIT_ASSERT_EQUAL ((1 << 24) + (2 << 16) + (3 << 8),v);
 
-       v = PluginInfo::convertVersion (new string ("1.2.3.4"));
-       CPPUNIT_ASSERT_EQUAL ((1<<24) + (2<<16) + (3<<8) + 4,v);
+    v = PluginInfo::convertVersion ("1.2.3.4");
+    CPPUNIT_ASSERT_EQUAL ((1 << 24) + (2 << 16) + (3 << 8) + 4, v);
 
-       v = PluginInfo::convertVersion (new string ("1."));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.2."));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.2.");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.2.3."));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.2.3.");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.2.3.4."));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.2.3.4.");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.2.3.4...."));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.2.3.4....");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("......1.2.3.4"));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("......1.2.3.4");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1..2.3.4"));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1..2.3.4");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.2...3.4"));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.2...3.4");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.2.3....4"));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.2.3....4");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.300.3.4"));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.300.3.4");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
 
-       v = PluginInfo::convertVersion (new string ("1.3.299.4"));
-       CPPUNIT_ASSERT_EQUAL (-1,v);
+    v = PluginInfo::convertVersion ("1.3.299.4");
+    CPPUNIT_ASSERT_EQUAL (-1, v);
   }
 };
 
diff --git a/myserver/tests/test_plugins_manager.cpp 
b/myserver/tests/test_plugins_manager.cpp
new file mode 100644
index 0000000..c2bb5d8
--- /dev/null
+++ b/myserver/tests/test_plugins_manager.cpp
@@ -0,0 +1,139 @@
+/*
+  MyServer
+  Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "myserver.h"
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/plugin/plugins_manager.h>
+#include <include/server/server.h>
+#include <include/plugin/plugin_info.h>
+
+#include <string.h>
+
+#include <list>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+class MockPlugin : public Plugin
+{
+public:
+  virtual int load (Server* server)
+  {
+    return 0;
+  }
+
+  virtual int preLoad (string& file, bool global)
+  {
+    return 0;
+  }
+
+  virtual int postLoad (Server* server)
+  {
+    return 0;
+  }
+
+  virtual int unLoad ()
+  {
+    return 0;
+  }
+
+  virtual const char* getName (char* buffer, u_long len)
+  {
+    return 0;
+  }
+
+  virtual void* getDirectMethod (char* name)
+  {
+    return 0;
+  }
+
+};
+
+class MockPluginsManager : public PluginsManager
+{
+public:
+  vector<string> names;
+  vector<string> files;
+  vector<PluginInfo*> pinfos;
+  void clear ()
+  {
+    names.clear ();
+    files.clear ();
+    pinfos.clear ();
+  }
+
+protected:
+  virtual int loadFile (Server* server, string &name, string &file,
+                        PluginInfo* pinfo)
+  {
+    names.push_back (name);
+    files.push_back (file);
+    pinfos.push_back (pinfo);
+    return 0;
+  }
+
+  virtual Plugin* preLoadPlugin (string &file, Server* server, bool global)
+  {
+    new MockPlugin ();
+  }
+};
+
+class TestPluginsManager : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestPluginsManager );
+  CPPUNIT_TEST ( testQuickLoad );
+  CPPUNIT_TEST_SUITE_END ();
+private:
+  static int addPlugin (Server* server, string &name,
+                        string &file, PluginInfo* pinfo)
+  {
+
+  }
+
+public:
+  void setUp ()
+  {
+  }
+
+  void tearDown ()
+  {
+  }
+
+  void testQuickLoad ()
+  {
+    MockPluginsManager manager;
+    int ret = manager.quickLoad (Server::getInstance (),
+                                 "name1:plugin1.so,name2:plugin2.so");
+
+    CPPUNIT_ASSERT_EQUAL (ret, 0);
+    CPPUNIT_ASSERT_EQUAL (manager.names[0].compare ("name1"), 0);
+    CPPUNIT_ASSERT_EQUAL (manager.names[1].compare ("name2"), 0);
+
+    CPPUNIT_ASSERT_EQUAL (manager.files[0].compare ("plugin1.so"), 0);
+    CPPUNIT_ASSERT_EQUAL (manager.files[1].compare ("plugin2.so"), 0);
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestPluginsManager);

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/plugin/plugin_info.h     |    2 +-
 myserver/include/plugin/plugins_manager.h |   19 +++--
 myserver/src/plugin/plugin_info.cpp       |   40 ++++-----
 myserver/src/plugin/plugins_manager.cpp   |  145 +++++++++++++++++++++--------
 myserver/tests/Makefile.am                |    1 +
 myserver/tests/test_plugin_info.cpp       |  140 ++++++++++++++--------------
 myserver/tests/test_plugins_manager.cpp   |  139 +++++++++++++++++++++++++++
 7 files changed, 347 insertions(+), 139 deletions(-)
 create mode 100644 myserver/tests/test_plugins_manager.cpp


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]