myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2840] Replaced tabs by blanks in the LogManager relat


From: Francesco Pipita
Subject: [myserver-commit] [2840] Replaced tabs by blanks in the LogManager related classes and added new tests for them .
Date: Wed, 24 Sep 2008 17:21:35 +0000

Revision: 2840
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2840
Author:   francesco_pipita
Date:     2008-09-24 17:21:34 +0000 (Wed, 24 Sep 2008)

Log Message:
-----------
Replaced tabs by blanks in the LogManager related classes and added new tests 
for them.

Modified Paths:
--------------
    trunk/myserver/include/filter/filters_chain.h
    trunk/myserver/include/log/log_manager.h
    trunk/myserver/include/log/stream/console_stream.h
    trunk/myserver/include/log/stream/console_stream_creator.h
    trunk/myserver/include/log/stream/file_stream.h
    trunk/myserver/include/log/stream/file_stream_creator.h
    trunk/myserver/include/log/stream/log_stream.h
    trunk/myserver/include/log/stream/log_stream_creator.h
    trunk/myserver/include/log/stream/log_stream_factory.h
    trunk/myserver/include/log/stream/socket_stream.h
    trunk/myserver/include/log/stream/socket_stream_creator.h
    trunk/myserver/src/log/log_manager.cpp
    trunk/myserver/src/log/stream/console_stream.cpp
    trunk/myserver/src/log/stream/console_stream_creator.cpp
    trunk/myserver/src/log/stream/file_stream.cpp
    trunk/myserver/src/log/stream/file_stream_creator.cpp
    trunk/myserver/src/log/stream/log_stream.cpp
    trunk/myserver/src/log/stream/log_stream_factory.cpp
    trunk/myserver/src/log/stream/socket_stream.cpp
    trunk/myserver/src/log/stream/socket_stream_creator.cpp
    trunk/myserver/tests/Makefile.am
    trunk/myserver/tests/test_log_manager.cpp

Added Paths:
-----------
    trunk/myserver/tests/test_file_stream.cpp
    trunk/myserver/tests/test_file_stream_creator.cpp
    trunk/myserver/tests/test_log_stream_factory.cpp
    trunk/myserver/tests/test_socket_stream_creator.cpp

Modified: trunk/myserver/include/filter/filters_chain.h
===================================================================
--- trunk/myserver/include/filter/filters_chain.h       2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/include/filter/filters_chain.h       2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -62,7 +62,7 @@
   list<string> getFilters ();
   virtual int read(char* buffer, u_long len, u_long*);
   virtual int write(const char* buffer, u_long len, u_long*);
-       virtual int flush(u_long*);
+        virtual int flush(u_long*);
   FiltersChain();
   ~FiltersChain();
 protected:

Modified: trunk/myserver/include/log/log_manager.h
===================================================================
--- trunk/myserver/include/log/log_manager.h    2008-09-23 21:00:56 UTC (rev 
2839)
+++ trunk/myserver/include/log/log_manager.h    2008-09-24 17:21:34 UTC (rev 
2840)
@@ -55,14 +55,15 @@
   
 
   LogManager (FiltersFactory* filtersFactory,
-             LogStreamFactory* logStreamFactory,
-             LoggingLevel level = WARNING);
+              LogStreamFactory* logStreamFactory,
+              LoggingLevel level = WARNING);
 
 
   /*!
    * Deallocates all LogStream owned by the LogManager and
-   * other objects (like the Mutex and the LogStreamFactory)
-   * allocated by the LogManager.
+   * the objects (like the Mutex) allocated by the LogManager.
+   * Other objects, like the FiltersFactory and the 
+   * LogStreamFactory should be destroied from the outside.
    */
   ~LogManager ();
 
@@ -74,21 +75,23 @@
    * \param filters A list of filters used within the new LogStream.
    * \param cycleLog A non-zero value establishes the threshold for
    * the LogStream's growth before cycling it.
+   * \return 0 on success.
    */
-  void addLogStream (string& location, 
-                    list<string>& filters, 
-                    u_long cycleLog);
+  int addLogStream (string location, 
+                    list<string>& filters, 
+                    u_long cycleLog);
 
 
   /*!
    * Remove the LogStream that point to location if it exists.
    * \param location The location where the LogStream which has to
    * be removed points to.
+   * \return 0 on success.
    */
-  void removeLogStream (string& location);
+  int removeLogStream (string location);
 
 
-  LogStream* getLogStream (string& location);
+  LogStream* getLogStream (string location);
   
 
   /*!
@@ -101,9 +104,9 @@
    * \param location The location where `message' will be written.
    * \return 0 on success.
    */
-  int log (string& message, 
-          LoggingLevel level = WARNING,
-          string location = "all");
+  int log (string message, 
+           LoggingLevel level = WARNING,
+           string location = "all");
 
 
   /*!
@@ -118,7 +121,7 @@
    * \return The cycleLog value for the LogStream that points to
    * location.
    */
-  u_long getCycleLog (string& location);
+  u_long getCycleLog (string location);
 
 
   /*!
@@ -129,7 +132,7 @@
    * \param location The LogStream whose cycleLog will be changed.
    */
   void setCycleLog (u_long cycleLog, 
-                   string location);
+                    string location);
 
 
   /*!
@@ -161,7 +164,7 @@
   bool empty ();
 
 
-  bool contains (string& location);
+  bool contains (string location);
 
   
   /*!
@@ -177,8 +180,8 @@
   int storeFile ();
   int load (char const*);
   void setGzip (int);
-  int write (char const*, int len = 0);
-  int writeln (char const*);
+  int write (string message, int len = 0);
+  int writeln (string message);
   File* getFile ();
   u_long setMaxSize (u_long);
   u_long getMaxSize ();
@@ -207,8 +210,8 @@
    * \return 0 on success.
    */
   int notifyLogStreams (LogStreamEvent evt,
-                       void* message = 0,
-                       void* reply = 0);
+                        void* message = 0,
+                        void* reply = 0);
 private:
 
 

Modified: trunk/myserver/include/log/stream/console_stream.h
===================================================================
--- trunk/myserver/include/log/stream/console_stream.h  2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/include/log/stream/console_stream.h  2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -29,9 +29,9 @@
 {
  public:
   ConsoleStream (FiltersFactory* filtersFactory, 
-                u_long cycleLog,
-                Stream* outStream,
-                FiltersChain* filtersChain);
+                 u_long cycleLog,
+                 Stream* outStream,
+                 FiltersChain* filtersChain);
 };
 
 #endif

Modified: trunk/myserver/include/log/stream/console_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/console_stream_creator.h  2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/include/log/stream/console_stream_creator.h  2008-09-24 
17:21:34 UTC (rev 2840)
@@ -26,9 +26,9 @@
 {
  public:
   virtual LogStream* create (FiltersFactory* filtersFactory, 
-                            string& location, 
-                            list<string>& filters,
-                            u_long cycleLog);
+                             string location, 
+                             list<string>& filters,
+                             u_long cycleLog);
 };
 
 #endif

Modified: trunk/myserver/include/log/stream/file_stream.h
===================================================================
--- trunk/myserver/include/log/stream/file_stream.h     2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/include/log/stream/file_stream.h     2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -35,9 +35,9 @@
 
 
   FileStream (FiltersFactory* filtersFactory, 
-             u_long cycleLog,
-             Stream* outStream,
-             FiltersChain* filtersChain);
+              u_long cycleLog,
+              Stream* outStream,
+              FiltersChain* filtersChain);
 
 
   /*!
@@ -49,6 +49,9 @@
   virtual u_long streamSize ();
 
 
+  string makeNewFileName (string oldFileName);
+
+
  protected:
 
 

Modified: trunk/myserver/include/log/stream/file_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/file_stream_creator.h     2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/include/log/stream/file_stream_creator.h     2008-09-24 
17:21:34 UTC (rev 2840)
@@ -26,9 +26,9 @@
 {
  public:
   virtual LogStream* create (FiltersFactory* filtersFactory, 
-                            string& location, 
-                            list<string>& filters,
-                            u_long cycleLog);
+                             string location, 
+                             list<string>& filters,
+                             u_long cycleLog);
 };
 
 #endif

Modified: trunk/myserver/include/log/stream/log_stream.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream.h      2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/include/log/stream/log_stream.h      2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -57,9 +57,9 @@
    * FiltersChain before being written to the Stream.
    */
   LogStream (FiltersFactory* filtersFactory,
-            u_long cycleLog, 
-            Stream* outStream,
-            FiltersChain* filtersChain);
+             u_long cycleLog, 
+             Stream* outStream,
+             FiltersChain* filtersChain);
 
 
   /*!
@@ -123,11 +123,15 @@
   /*!
    * \return 0 on success.
    */
-  virtual int log (string& message);
+  virtual int log (string message);
 
 
   virtual ~LogStream ();
 
+
+  list<string>& getCycledStreams ();
+
+
  protected:
 
 
@@ -148,7 +152,7 @@
   /*!
    * \return 0 on success.
    */
-  int write (string& message);
+  int write (string message);
 
 
   /*!
@@ -184,6 +188,9 @@
 
 
   FiltersFactory* filtersFactory;
+
+
+  list<string> cycledStreams;
 };
 
 #endif

Modified: trunk/myserver/include/log/stream/log_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream_creator.h      2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/include/log/stream/log_stream_creator.h      2008-09-24 
17:21:34 UTC (rev 2840)
@@ -28,10 +28,16 @@
 class LogStreamCreator
 {
  public:
+  
+
+  /*!
+   * Create a new instance of a concrete LogStream. If something
+   * of wrong happens, it must return 0.
+   */
   virtual LogStream* create (FiltersFactory* filtersFactory, 
-                            string& location, 
-                            list<string>& filters,
-                            u_long cycleLog) = 0;
+                             string location, 
+                             list<string>& filters,
+                             u_long cycleLog) = 0;
 };
 
 #endif

Modified: trunk/myserver/include/log/stream/log_stream_factory.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream_factory.h      2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/include/log/stream/log_stream_factory.h      2008-09-24 
17:21:34 UTC (rev 2840)
@@ -63,31 +63,44 @@
    * the new LogStream.
    * \param cycleLog Whether the log should be cycled or not. 0 means never
    * cycle.
-   * \return A new instance of one of LogStream subclasses.
+   * \return A new instance of one of LogStream subclasses or 0 if 
+   * the location string does not contain a protocol known by the
+   * LogStreamFactory or if something of wrong happened during the LogStream
+   * creation.
    */
   LogStream* createLogStream (FiltersFactory* filtersFactory, 
-                             string& location, 
-                             list<string>& filters,
-                             u_long cycleLog);
+                              string location, 
+                              list<string>& filters,
+                              u_long cycleLog);
 
 
   /*!
-   * A helper method useful to get the protocol part of a location string.
+   * Get the protocol part of a location string.
    * \param location The string representing a valid location as explained
    * in createLogStream method description.
-   * \return A new string with the protocol part of the location.
+   * \return A new string with the protocol part of the location, an empty
+   * string if an invalid protocol was detected.
    */
-  string getProtocol (string& location);
+  string getProtocol (string location);
 
 
   /*!
-   * A helper method useful to get the path part of a location string.
+   * Get the path part of a location string.
    * \param location The string representing a valid location as explained
    * in createLogStream method description.
-   * \return A new string with the path part of the location.
+   * \return A new string with the path part of the location, an empty
+   * string is an invalid protocol was detected.
    */
-  string getPath (string& location);
+  string getPath (string location);
 
+  
+  /*!
+   * Checks wheter `protocol' is between those known by the LogStreamFactory.
+   * \return true If it is.
+   */
+   bool protocolCheck (string protocol);
+
+
 private:
 
 

Modified: trunk/myserver/include/log/stream/socket_stream.h
===================================================================
--- trunk/myserver/include/log/stream/socket_stream.h   2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/include/log/stream/socket_stream.h   2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -30,9 +30,9 @@
  public:
 
   SocketStream (FiltersFactory* filtersFactory, 
-               u_long cycleLog,
-               Stream* outStream,
-               FiltersChain* filtersChain);
+                u_long cycleLog,
+                Stream* outStream,
+                FiltersChain* filtersChain);
 };
 
 #endif

Modified: trunk/myserver/include/log/stream/socket_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/socket_stream_creator.h   2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/include/log/stream/socket_stream_creator.h   2008-09-24 
17:21:34 UTC (rev 2840)
@@ -28,21 +28,21 @@
 {
  public:
   virtual LogStream* create (FiltersFactory* filtersFactory, 
-                            string& location, 
-                            list<string>& filters,
-                            u_long cycleLog);
+                             string location, 
+                             list<string>& filters,
+                             u_long cycleLog);
 
 
   /*!
    * A helper method to get the port part of an URL.
    */
-  u_short getPort (string& location);
+  u_short getPort (string location);
 
 
   /*!
    * A helper method to get the host part of an URL.
    */
-  string getHost (string& location);
+  string getHost (string location);
 };
 
 #endif

Modified: trunk/myserver/src/log/log_manager.cpp
===================================================================
--- trunk/myserver/src/log/log_manager.cpp      2008-09-23 21:00:56 UTC (rev 
2839)
+++ trunk/myserver/src/log/log_manager.cpp      2008-09-24 17:21:34 UTC (rev 
2840)
@@ -1,18 +1,18 @@
 /*
-MyServer
-Copyright (C) 2006, 2008 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.
+  MyServer
+  Copyright (C) 2006, 2008 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.
+  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/>.
+  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 <include/log/log_manager.h>
@@ -21,8 +21,8 @@
 int const LogManager::TYPE_FILE = 2;
 
 LogManager::LogManager (FiltersFactory* filtersFactory,
-                       LogStreamFactory* logStreamFactory,
-                       LoggingLevel level) : level (level)
+                        LogStreamFactory* logStreamFactory,
+                        LoggingLevel level) : level (level)
 {
   this->filtersFactory = filtersFactory;
   this->logStreamFactory = logStreamFactory;
@@ -37,112 +37,136 @@
   delete mutex;
 }
 
-void
-LogManager::addLogStream (string& location, 
-                         list<string>& filters, 
-                         u_long cycleLog)
+int
+LogManager::addLogStream (string location, 
+                          list<string>& filters, 
+                          u_long cycleLog)
 {
   mutex->lock ();
+  int retVal = 1;
   if (!contains (location))
     {
-      logStreams[location] = 
-       logStreamFactory->createLogStream (filtersFactory,
-                                          location,
-                                          filters,
-                                          cycleLog);
+      LogStream* logStream = logStreamFactory->createLogStream (filtersFactory,
+                                                                location,
+                                                                filters,
+                                                                cycleLog);
+      if (logStream)
+        {
+          logStreams[location] = logStream;
+          retVal = 0;
+        }
     }
   mutex->unlock ();
+  return retVal;
 }
 
-void
-LogManager::removeLogStream (string& location)
+int
+LogManager::removeLogStream (string location)
 {
   mutex->lock ();
+  int retVal = 1;
   if (contains (location))
     {
       delete logStreams[location];
       logStreams.erase (location);
+      retVal = 0;
     }
   mutex->unlock ();
+  return retVal;
 }
 
 LogStream*
-LogManager::getLogStream (string& location)
+LogManager::getLogStream (string location)
 {
+  LogStream* retVal = 0;
   if (contains (location))
-    return logStreams[location];
-  return 0;
+    retVal = logStreams[location];
+  return retVal;
 }
 
 int
 LogManager::notifyLogStreams (LogStreamEvent evt, 
-                             void* message, 
-                             void* reply)
+                              void* message, 
+                              void* reply)
 {
-  mutex->lock ();
   map<string, LogStream*>::iterator it;
   int retVal = 0;
   for (it = logStreams.begin (); it != logStreams.end (); it++)
     {
       retVal |= it->second->update (evt, message, reply);
     }
-  mutex->unlock ();
   return retVal;
 }
 
 int
-LogManager::log (string& message, LoggingLevel level, string location)
+LogManager::log (string message, LoggingLevel level, string location)
 {
+  mutex->lock ();
+  int retVal = 1;
   if (level >= this->level)
     {
       if (contains (location))
-       {
-         return logStreams[location]->log (message);
-       }
-      else
-       {
-         return notifyLogStreams (EVT_LOG, static_cast<void*>(&message));
-       }
+        {
+          retVal = logStreams[location]->log (message);
+        }
+      else if (!location.compare ("all"))
+        {
+          retVal = notifyLogStreams (EVT_LOG, static_cast<void*>(&message));
+        }
     }
-  return 1;
+  mutex->unlock ();
+  return retVal;
 }
 
 int
 LogManager::close (string location)
 {
+  mutex->lock ();
+  int retVal = 1;
   if (contains (location))
     {
-      return logStreams[location]->close ();
+      retVal = logStreams[location]->close ();
     }
-  return notifyLogStreams (EVT_CLOSE);
+  else if (!location.compare ("all"))
+    {
+      retVal = notifyLogStreams (EVT_CLOSE);
+    }
+  mutex->unlock ();
+  return retVal;
 }
 
 void
 LogManager::setCycleLog (u_long cycleLog, string location)
 {
+  mutex->lock ();
   if (contains (location))
     {
       logStreams[location]->setCycleLog (cycleLog);
     }
-  else
+  else if (!location.compare ("all"))
     {
       notifyLogStreams (EVT_SET_CYCLE_LOG, static_cast<void*>(&cycleLog));
     }
+  mutex->unlock ();
 }
 
 LoggingLevel
 LogManager::setLoggingLevel (LoggingLevel level)
 {
+  mutex->lock ();
   LoggingLevel oldLevel = level;
   this->level = level;
+  mutex->unlock ();
   return oldLevel;
 }
 
 u_long
-LogManager::getCycleLog (string& location)
+LogManager::getCycleLog (string location)
 {
+  u_long retVal = -1;
   if (contains (location))
-    return logStreams[location]->getCycleLog ();
+    retVal = logStreams[location]->getCycleLog ();
+  return retVal;
 }
 
 LoggingLevel
@@ -154,7 +178,9 @@
 void
 LogManager::setLogStreamFactory (LogStreamFactory* logStreamFactory)
 {
+  mutex->lock ();
   this->logStreamFactory = logStreamFactory;
+  mutex->unlock ();
 }
 
 LogStreamFactory* 
@@ -166,7 +192,9 @@
 void
 LogManager::setFiltersFactory (FiltersFactory* filtersFactory)
 {
+  mutex->lock ();
   this->filtersFactory = filtersFactory;
+  mutex->unlock ();
 }
 
 FiltersFactory* 
@@ -184,10 +212,12 @@
 void
 LogManager::clear ()
 {
+  mutex->lock ();
   map<string, LogStream*>::iterator it;
   for (it = logStreams.begin (); it != logStreams.end (); it++)
     delete it->second;
   logStreams.clear ();
+  mutex->unlock ();
 }
 
 bool
@@ -197,7 +227,7 @@
 }
 
 bool
-LogManager::contains (string& location)
+LogManager::contains (string location)
 {
   return logStreams.count (location) > 0;
 }
@@ -221,9 +251,8 @@
   maxSize = 0;
   gzipLog = 1;
   cycleLog = 0;
-  string location ("console://");
   list<string> filters;
-  addLogStream (location, filters, maxSize);
+  addLogStream ("console://", filters, maxSize);
 }
 
 int
@@ -239,9 +268,8 @@
 }
 
 int
-LogManager::write (const char *str, int len)
+LogManager::write (string message, int len)
 {
-  string message (str);
   return notifyLogStreams (EVT_LOG, static_cast<void*>(&message));
 }
 
@@ -266,17 +294,17 @@
   for (it = logStreams.begin (); it != logStreams.end (); it++)
     {
       if (it->first.find ("file://") != string::npos)
-       {
-         return dynamic_cast<File*>(it->second->getOutStream ());
-       }
+        {
+          return dynamic_cast<File*>(it->second->getOutStream ());
+        }
     }
   return 0;
 }
 
 int 
-LogManager::writeln (const char *str)
+LogManager::writeln (string message)
 {
-  int ret = write (str);
+  int ret = write (message);
 #ifdef WIN32
   if (ret == 0)
     ret = write ("\r\n");

Modified: trunk/myserver/src/log/stream/console_stream.cpp
===================================================================
--- trunk/myserver/src/log/stream/console_stream.cpp    2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/src/log/stream/console_stream.cpp    2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -18,12 +18,12 @@
 #include <include/log/stream/console_stream.h>
 
 ConsoleStream::ConsoleStream (FiltersFactory* filtersFactory, 
-                             u_long cycleLog,
-                             Stream* outStream,
-                             FiltersChain* filtersChain) : 
+                              u_long cycleLog,
+                              Stream* outStream,
+                              FiltersChain* filtersChain) : 
 LogStream (filtersFactory,
-          cycleLog,
-          outStream,
-          filtersChain)
+           cycleLog,
+           outStream,
+           filtersChain)
 {
 }

Modified: trunk/myserver/src/log/stream/console_stream_creator.cpp
===================================================================
--- trunk/myserver/src/log/stream/console_stream_creator.cpp    2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/src/log/stream/console_stream_creator.cpp    2008-09-24 
17:21:34 UTC (rev 2840)
@@ -19,17 +19,17 @@
 
 LogStream*
 ConsoleStreamCreator::create (FiltersFactory* filtersFactory, 
-                             string& location, 
-                             list<string>& filters,
-                             u_long cycleLog)
+                              string location, 
+                              list<string>& filters,
+                              u_long cycleLog)
 {
   Console* outStream = new Console ();
   u_long nbw;
   FiltersChain* filtersChain = filtersFactory->chain (filters, 
-                                                     outStream, 
-                                                     &nbw);
+                                                      outStream, 
+                                                      &nbw);
   return new ConsoleStream (filtersFactory, 
-                           cycleLog,
-                           outStream,
-                           filtersChain);
+                            cycleLog,
+                            outStream,
+                            filtersChain);
 }

Modified: trunk/myserver/src/log/stream/file_stream.cpp
===================================================================
--- trunk/myserver/src/log/stream/file_stream.cpp       2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/src/log/stream/file_stream.cpp       2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -18,15 +18,15 @@
 #include <include/log/stream/file_stream.h>
 
 int const FileStream::defaultFileMask = File::MYSERVER_OPEN_APPEND | 
-                                      File::MYSERVER_OPEN_ALWAYS |
-                                      File::MYSERVER_OPEN_WRITE | 
-                                      File::MYSERVER_OPEN_READ | 
-                                      File::MYSERVER_NO_INHERIT;
+                                       File::MYSERVER_OPEN_ALWAYS |
+                                       File::MYSERVER_OPEN_WRITE | 
+                                       File::MYSERVER_OPEN_READ | 
+                                       File::MYSERVER_NO_INHERIT;
 
 FileStream::FileStream (FiltersFactory* filtersFactory,
-                       u_long cycleLog,
-                       Stream* outStream,
-                       FiltersChain* filtersChain) : 
+                        u_long cycleLog,
+                        Stream* outStream,
+                        FiltersChain* filtersChain) : 
   LogStream (filtersFactory, cycleLog, outStream, filtersChain)
 {
 }
@@ -45,91 +45,70 @@
   const u_long bufferSize = MYSERVER_KB (64);
   try
     {
-      string filepath;
-      string filedir;
-      string filename;
-      string ext;
-      ostringstream newfilename;
-      string time;
-
-      filepath.assign (dynamic_cast<File*>(outStream)->getFilename ());
-      FilesUtility::completePath (filepath);
-      FilesUtility::splitPath (filepath, filedir, filename);
-      
-      FilesUtility::getFileExt (ext, filename);
-      
-      getRFC822LocalTime (time, 32);
-      time = trim (time.substr (5, 32));
-    
-      for (int i = 0; i < static_cast<int>(time.length ()); i++)
-       if ((time[i] == ' ') || (time[i] == ':'))
-         time[i]= '.';
-      if (ext.size ())
-       {
-         filename = (filename.substr (0, filename.find (string (".") + ext)));
-       }
-      newfilename << filedir << "/" << filename << "." << time <<
-       (ext.size () ? "." : "") << ext;
-
       File newFile;
       File *currentFile = dynamic_cast<File*>(outStream);
-
+      string filepath (currentFile->getFilename ());
+      string newFileName (makeNewFileName (currentFile->getFilename ()));
+      cycledStreams.push_back (newFileName);
       buffer = new char[bufferSize];
       if (buffer == 0)
-       return 1;
+        {
+          return 1;
+        }
       buffer2 = new char[bufferSize];
       if (buffer == 0)
-       {
-         delete [] buffer;
-         return 1;
-       }
+        {
+          delete [] buffer;
+          return 1;
+        }
      
-      if (newFile.openFile (newfilename.str ().c_str (),
-                           File::MYSERVER_OPEN_WRITE |
-                           File::MYSERVER_NO_INHERIT |
-                           File::MYSERVER_CREATE_ALWAYS))
-       {
-         delete [] buffer;
-         delete [] buffer2;
-         return 1;
-       }
+      if (newFile.openFile (newFileName,
+                            File::MYSERVER_OPEN_WRITE |
+                            File::MYSERVER_NO_INHERIT |
+                            File::MYSERVER_CREATE_ALWAYS))
+        {
+          cerr << "could not open " << newFileName << endl;
+          delete [] buffer;
+          delete [] buffer2;
+          return 1;
+        }
       if (currentFile->setFilePointer (0))
-       {
-         delete [] buffer;
-         delete [] buffer2;
-         newFile.close ();
-         return 1;
-       }
+        {
+          delete [] buffer;
+          delete [] buffer2;
+          newFile.close ();
+          return 1;
+        }
       for (;;)
-       {
-         u_long nbr;
-         u_long nbw;
-         if(currentFile->readFromFile (buffer, bufferSize, &nbr))
-           {
-             delete [] buffer;
-             delete [] buffer2;
-             newFile.close ();
-             return 1;
-           }
-         if (nbr == 0)
-           break;
-         if (newFile.writeToFile (buffer, nbr, &nbw))
-           {
-             delete [] buffer;
-             delete [] buffer2;
-             newFile.close ();
-             return 1;
-           }
-       }
+        {
+          u_long nbr;
+          u_long nbw;
+          if(currentFile->readFromFile (buffer, bufferSize, &nbr))
+            {
+              delete [] buffer;
+              delete [] buffer2;
+              newFile.close ();
+              return 1;
+            }
+          if (nbr == 0)
+            break;
+          if (newFile.writeToFile (buffer, nbr, &nbw))
+            {
+              delete [] buffer;
+              delete [] buffer2;
+              newFile.close ();
+              return 1;
+            }
+        }
       newFile.close ();
       currentFile->close ();
       FilesUtility::deleteFile (filepath.c_str ());
       if (currentFile->openFile (filepath.c_str(), defaultFileMask))
-       {
-         delete [] buffer;
-         delete [] buffer2;
-         return 1;
-       }
+        {
+          delete [] buffer;
+          delete [] buffer2;
+          return 1;
+        }
       delete [] buffer;
       delete [] buffer2;
       return 0;
@@ -137,9 +116,37 @@
   catch (...)
     {
       if (buffer)
-       delete [] buffer;
+        delete [] buffer;
       if (buffer2)
-       delete [] buffer2;
+        delete [] buffer2;
       throw;
     };
 }
+
+string
+FileStream::makeNewFileName (string oldFileName)
+{
+  string filedir;
+  string filename;
+  string ext;
+  ostringstream newfilename;
+  string time;
+
+  FilesUtility::completePath (oldFileName);
+  FilesUtility::splitPath (oldFileName, filedir, filename);
+  FilesUtility::getFileExt (ext, oldFileName);
+      
+  getRFC822LocalTime (time, 32);
+  time = trim (time.substr (5, 32));
+    
+  for (int i = 0; i < static_cast<int>(time.length ()); i++)
+    if ((time[i] == ' ') || (time[i] == ':'))
+      time[i]= '.';
+  if (ext.size ())
+    {
+      filename = (filename.substr (0, filename.find (string (".") + ext)));
+    }
+  newfilename << filedir << filename << "." << time <<
+    (ext.size () ? "." : "") << ext;
+  return newfilename.str ();
+}

Modified: trunk/myserver/src/log/stream/file_stream_creator.cpp
===================================================================
--- trunk/myserver/src/log/stream/file_stream_creator.cpp       2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/src/log/stream/file_stream_creator.cpp       2008-09-24 
17:21:34 UTC (rev 2840)
@@ -19,18 +19,22 @@
 
 LogStream*
 FileStreamCreator::create (FiltersFactory* filtersFactory,
-                          string& location, 
-                          list<string>& filters,
-                          u_long cycleLog)
+                           string location, 
+                           list<string>& filters,
+                           u_long cycleLog)
 {
-  Stream* outStream = new File (const_cast<char*>(location.c_str ()),
-                               FileStream::defaultFileMask);
-  u_long nbw;
-  FiltersChain* filtersChain = filtersFactory->chain (filters,
-                                                     outStream,
-                                                     &nbw);
-  return new FileStream (filtersFactory,
-                        cycleLog,
-                        outStream,
-                        filtersChain);
+  File* outStream = new File ();
+  if (!outStream->openFile (const_cast<char*>(location.c_str ()),
+                            FileStream::defaultFileMask))
+    {
+      u_long nbw;
+      FiltersChain* filtersChain = filtersFactory->chain (filters,
+                                                          outStream,
+                                                          &nbw);
+      return new FileStream (filtersFactory,
+                             cycleLog,
+                             outStream,
+                             filtersChain);
+    }
+  return 0;
 }

Modified: trunk/myserver/src/log/stream/log_stream.cpp
===================================================================
--- trunk/myserver/src/log/stream/log_stream.cpp        2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/src/log/stream/log_stream.cpp        2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -18,9 +18,9 @@
 #include <include/log/stream/log_stream.h>
 
 LogStream::LogStream (FiltersFactory* filtersFactory, 
-                     u_long cycleLog,
-                     Stream* outStream,
-                     FiltersChain* filtersChain) :
+                      u_long cycleLog,
+                      Stream* outStream,
+                      FiltersChain* filtersChain) :
 cycleLog (cycleLog), isOpened (1)
 {
   this->filtersFactory = filtersFactory;
@@ -46,7 +46,7 @@
 }
 
 int
-LogStream::log (string& message)
+LogStream::log (string message)
 {
   if (needToCycle ())
     {
@@ -68,7 +68,7 @@
 }
 
 int
-LogStream::write (string& message)
+LogStream::write (string message)
 {
   return filtersChain->write (message.c_str (), message.size (), &nbw);
 }
@@ -100,7 +100,9 @@
 int
 LogStream::close ()
 {
-  return isOpened = (filtersChain->flush (&nbw) || outStream->close ());
+  if (isOpened)
+    return isOpened = (filtersChain->flush (&nbw) || outStream->close ());
+  return isOpened;
 }
 
 int
@@ -110,23 +112,23 @@
     {
     case EVT_SET_CYCLE_LOG:
       {
-       setCycleLog (*static_cast<u_long*>(message));
-       return 0;
+        setCycleLog (*static_cast<u_long*>(message));
+        return 0;
       }
       break;
     case EVT_LOG:
       {
-       return log (*static_cast<string*>(message));
+        return log (*static_cast<string*>(message));
       }
       break;
     case EVT_CLOSE:
       {
-       return close ();
+        return close ();
       }
       break;
     case EVT_ADD_FILTER:
       {
-       return addFilter (static_cast<Filter*>(message));
+        return addFilter (static_cast<Filter*>(message));
       }
       break;
     default:
@@ -175,3 +177,9 @@
 {
   return nbw;
 }
+
+list<string>&
+LogStream::getCycledStreams ()
+{
+  return cycledStreams;
+}

Modified: trunk/myserver/src/log/stream/log_stream_factory.cpp
===================================================================
--- trunk/myserver/src/log/stream/log_stream_factory.cpp        2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/src/log/stream/log_stream_factory.cpp        2008-09-24 
17:21:34 UTC (rev 2840)
@@ -36,26 +36,40 @@
 
 LogStream*
 LogStreamFactory::createLogStream (FiltersFactory* filtersFactory, 
-                                  string& location,
-                                  list<string>& filters,
-                                  u_long cycleLog)
+                                   string location,
+                                   list<string>& filters,
+                                   u_long cycleLog)
 {
   string protocol (getProtocol (location));
   string path (getPath (location));
-  return logStreamCreators[protocol]->create (filtersFactory,
-                                             path,
-                                             filters,
-                                             cycleLog);
+  if (protocolCheck (protocol))
+    {
+      return logStreamCreators[protocol]->create (filtersFactory,
+                                                  path,
+                                                  filters,
+                                                  cycleLog);
+    }
+  return 0;
 }
 
 string
-LogStreamFactory::getProtocol (string& location)
+LogStreamFactory::getProtocol (string location)
 {
-  return (location.substr (0, location.find("://"))).append ("://");
+  if (location.find ("://") != string::npos)
+    return (location.substr (0, location.find("://"))).append ("://");
+  return string ("");
 }
 
 string
-LogStreamFactory::getPath (string& location)
+LogStreamFactory::getPath (string location)
 {
-  return location.substr (getProtocol (location).size (), location.size ());
+  if (protocolCheck (getProtocol (location)))
+    return location.substr (getProtocol (location).size (), location.size ());
+  return string ("");
 }
+
+bool
+LogStreamFactory::protocolCheck (string protocol)
+{
+  return logStreamCreators.count (protocol) != 0;
+}

Modified: trunk/myserver/src/log/stream/socket_stream.cpp
===================================================================
--- trunk/myserver/src/log/stream/socket_stream.cpp     2008-09-23 21:00:56 UTC 
(rev 2839)
+++ trunk/myserver/src/log/stream/socket_stream.cpp     2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -18,12 +18,12 @@
 #include <include/log/stream/socket_stream.h>
 
 SocketStream::SocketStream (FiltersFactory* filtersFactory,
-                           u_long cycleLog,
-                           Stream* outStream,
-                           FiltersChain* filtersChain) : 
+                            u_long cycleLog,
+                            Stream* outStream,
+                            FiltersChain* filtersChain) : 
 LogStream (filtersFactory,
-          cycleLog,
-          outStream,
-          filtersChain)
+           cycleLog,
+           outStream,
+           filtersChain)
 {
 }

Modified: trunk/myserver/src/log/stream/socket_stream_creator.cpp
===================================================================
--- trunk/myserver/src/log/stream/socket_stream_creator.cpp     2008-09-23 
21:00:56 UTC (rev 2839)
+++ trunk/myserver/src/log/stream/socket_stream_creator.cpp     2008-09-24 
17:21:34 UTC (rev 2840)
@@ -19,31 +19,33 @@
 
 LogStream*
 SocketStreamCreator::create (FiltersFactory* filtersFactory,
-                            string& location, 
-                            list<string>& filters,
-                            u_long cycleLog)
+                             string location, 
+                             list<string>& filters,
+                             u_long cycleLog)
 {
-  Stream* outStream = new Socket ();
+  Socket* outStream = new Socket ();
   u_long nbw;
-  dynamic_cast<Socket*>(outStream)->connect (getHost (location).c_str (),
-                                            getPort (location));
-  FiltersChain* filtersChain = filtersFactory->chain (filters, 
-                                                     outStream,
-                                                     &nbw);
-  return new SocketStream (filtersFactory,
-                          cycleLog,
-                          outStream,
-                          filtersChain);
+  if (!outStream->connect (getHost (location).c_str (), getPort (location)))
+    {
+      FiltersChain* filtersChain = filtersFactory->chain (filters, 
+                                                          outStream,
+                                                          &nbw);
+      return new SocketStream (filtersFactory,
+                               cycleLog,
+                               outStream,
+                               filtersChain);
+    }
+  return 0;
 }
 
 u_short
-SocketStreamCreator::getPort (string& location)
+SocketStreamCreator::getPort (string location)
 {
   return static_cast<u_short>(atoi (location.substr (location.find (":") + 
1).c_str ()));
 }
 
 string
-SocketStreamCreator::getHost (string& location)
+SocketStreamCreator::getHost (string location)
 {
   return location.substr (0, location.find (":"));
 }

Modified: trunk/myserver/tests/Makefile.am
===================================================================
--- trunk/myserver/tests/Makefile.am    2008-09-23 21:00:56 UTC (rev 2839)
+++ trunk/myserver/tests/Makefile.am    2008-09-24 17:21:34 UTC (rev 2840)
@@ -2,5 +2,5 @@
 #
 
 bin_PROGRAMS = tests_suite
-tests_suite_SOURCES = main.cpp test_base64.cpp test_cached_file.cpp 
test_cached_file_buffer.cpp test_cached_file_factory.cpp test_connection.cpp 
test_connections_scheduler.cpp test_files_utility.cpp test_filter_chain.cpp 
test_ftp.cpp test_gzip.cpp test_hashmap.cpp test_homedir.cpp 
test_http_request.cpp test_http_response.cpp test_md5.cpp test_mem_buff.cpp 
test_mem_stream.cpp test_multicast.cpp test_mutex.cpp test_recursive_mutex.cpp 
test_regex.cpp test_pipe.cpp test_safetime.cpp test_semaphore.cpp 
test_thread.cpp test_utility.cpp test_log_manager.cpp
+tests_suite_SOURCES = main.cpp test_base64.cpp test_cached_file.cpp 
test_cached_file_buffer.cpp test_cached_file_factory.cpp test_connection.cpp 
test_connections_scheduler.cpp test_files_utility.cpp test_filter_chain.cpp 
test_ftp.cpp test_gzip.cpp test_hashmap.cpp test_homedir.cpp 
test_http_request.cpp test_http_response.cpp test_md5.cpp test_mem_buff.cpp 
test_mem_stream.cpp test_multicast.cpp test_mutex.cpp test_recursive_mutex.cpp 
test_regex.cpp test_pipe.cpp test_safetime.cpp test_semaphore.cpp 
test_thread.cpp test_utility.cpp test_log_manager.cpp 
test_log_stream_factory.cpp test_socket_stream_creator.cpp 
test_file_stream_creator.cpp test_file_stream.cpp
 tests_suite_LDADD = ../src/libmyserver.a $(CPPUNIT_LDFLAGS) $(PTHREAD_LIB) 
$(IDN_LIB) $(XNET_LIB) $(EVENT_LIB) $(DL_LIB) $(OPENSSL_LIB) $(ZLIB_LIB) 
$(XML_LIBS) $(LDFLAGS)

Added: trunk/myserver/tests/test_file_stream.cpp
===================================================================
--- trunk/myserver/tests/test_file_stream.cpp                           (rev 0)
+++ trunk/myserver/tests/test_file_stream.cpp   2008-09-24 17:21:34 UTC (rev 
2840)
@@ -0,0 +1,106 @@
+/*
+ MyServer
+ Copyright (C) 2008 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 <list>
+#include <string>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/filter/filters_factory.h>
+#include <include/log/stream/file_stream.h>
+#include <include/log/stream/file_stream_creator.h>
+#include <include/base/file/files_utility.h>
+#include <include/base/file/file.h>
+#include <include/base/utility.h>
+
+class TestFileStream : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestFileStream);
+  CPPUNIT_TEST (testCycleLog);
+  CPPUNIT_TEST (testMakeNewFileName);
+  CPPUNIT_TEST_SUITE_END ();
+public:
+  void setUp()
+  {
+    fsc = new FileStreamCreator ();
+    ff = new FiltersFactory ();
+    setcwdBuffer ();
+  }
+
+  void testMakeNewFileName ()
+  {
+    list<string> filters;
+    LogStream* ls = fsc->create (ff, "foo", filters, 0);
+    FileStream* fs = dynamic_cast<FileStream*>(ls);
+    File* outStream = dynamic_cast<File*>(fs->getOutStream ());
+    string newFileName = fs->makeNewFileName (outStream->getFilename ());
+    string wd;
+    getdefaultwd (wd);
+    wd.append ("/foo");
+    CPPUNIT_ASSERT (newFileName.find (wd) != string::npos);
+    delete fs;
+  }
+
+  void testCycleLog ()
+  {
+    list<string> filters;
+    string message ("thisisaverylongmessage\n");
+    string message2 ("thisisanothermessage\n");
+    LogStream* ls = fsc->create (ff, "foo", filters, 10);
+    File* outStream = dynamic_cast<File*>(ls->getOutStream ());
+    CPPUNIT_ASSERT (!ls->log (message));
+    CPPUNIT_ASSERT (!ls->log (message2));
+    ls->close ();
+    File f;
+    f.openFile ("foo", FileStream::defaultFileMask);
+    char buf[64];
+    u_long nbr;
+    f.read (buf, 64, &nbr);
+    buf[nbr] = '\0';
+    CPPUNIT_ASSERT (!message2.compare (buf));
+    f.close ();
+    list<string> cs = ls->getCycledStreams ();
+    CPPUNIT_ASSERT (cs.size ());
+    list<string>::iterator it;
+    for (it = cs.begin (); it != cs.end (); it++)
+      {
+        f.openFile (*it, FileStream::defaultFileMask);
+        f.read (buf, 64, &nbr);
+        buf[nbr] = '\0';
+        CPPUNIT_ASSERT (!message.compare (buf));
+        f.close ();
+        CPPUNIT_ASSERT (!FilesUtility::deleteFile (*it));
+      }
+    delete ls;
+  }
+
+  void tearDown()
+  {
+    delete ff;
+    delete fsc;
+    FilesUtility::deleteFile ("foo");
+  }
+
+private:
+  FiltersFactory* ff;
+  FileStreamCreator* fsc;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestFileStream);

Added: trunk/myserver/tests/test_file_stream_creator.cpp
===================================================================
--- trunk/myserver/tests/test_file_stream_creator.cpp                           
(rev 0)
+++ trunk/myserver/tests/test_file_stream_creator.cpp   2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -0,0 +1,65 @@
+/*
+ MyServer
+ Copyright (C) 2008 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 <list>
+#include <string>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/log/stream/file_stream_creator.h>
+#include <include/base/file/file.h>
+#include <include/base/file/files_utility.h>
+#include <include/filter/filters_factory.h>
+
+class TestFileStreamCreator : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestFileStreamCreator);
+  CPPUNIT_TEST (testCreation);
+  CPPUNIT_TEST_SUITE_END ();
+public:
+  void setUp ()
+  {
+    fsc = new FileStreamCreator ();
+    ff = new FiltersFactory ();
+  }
+  
+  void testCreation ()
+  {
+    list<string> filters;
+    LogStream* ls = fsc->create (ff, "foo", filters, 0);
+    CPPUNIT_ASSERT (ls);
+#ifdef NOT_WIN
+    ls = fsc->create (ff, "/dev/", filters, 0);
+    CPPUNIT_ASSERT (!ls);
+#endif
+  }
+  
+  void tearDown ()
+  {
+    delete fsc;
+    delete ff;
+    FilesUtility::deleteFile ("foo");
+  }
+private:
+  FileStreamCreator* fsc;
+  FiltersFactory* ff;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestFileStreamCreator);

Modified: trunk/myserver/tests/test_log_manager.cpp
===================================================================
--- trunk/myserver/tests/test_log_manager.cpp   2008-09-23 21:00:56 UTC (rev 
2839)
+++ trunk/myserver/tests/test_log_manager.cpp   2008-09-24 17:21:34 UTC (rev 
2840)
@@ -28,12 +28,184 @@
 #include <include/log/stream/log_stream_factory.h>
 #include <include/base/file/files_utility.h>
 #include <include/base/file/file.h>
+#include <include/base/utility.h>
+#include <include/filter/gzip/gzip.h>
+#include <include/filter/gzip/gzip_decompress.h>
 
 class TestLogManager : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE (TestLogManager);
+  CPPUNIT_TEST (testEmpty);
+  CPPUNIT_TEST (testSize);
+  CPPUNIT_TEST (testContains);
+  CPPUNIT_TEST (testAddLogStream);
+  CPPUNIT_TEST (testRemoveLogStream);
+  CPPUNIT_TEST (testLog);
+  CPPUNIT_TEST (testClose);
+  CPPUNIT_TEST (testCycleLog);
+  CPPUNIT_TEST (testLoggingLevel);
+  CPPUNIT_TEST (testClear);
+  CPPUNIT_TEST (testLogThroughGzip);
   CPPUNIT_TEST_SUITE_END ();
+public:
+  void setUp()
+  {
+    lsf = new LogStreamFactory ();
+    ff = new FiltersFactory ();
+    ff->insert ("gzip", Gzip::factory);
+    ff->insert ("gunzip", GzipDecompress::factory);
+    lm = new LogManager (ff, lsf);
+    setcwdBuffer ();
+  }
 
+  void testEmpty ()
+  {
+    CPPUNIT_ASSERT (lm->empty ());
+  }
+
+  void testSize ()
+  {
+    CPPUNIT_ASSERT (lm->size () == 0);
+  }
+
+  void testContains ()
+  {
+    CPPUNIT_ASSERT (!lm->contains ("foo"));
+  }
+
+  void testAddLogStream ()
+  {
+    list<string> filters;
+    CPPUNIT_ASSERT (lm->addLogStream ("foo", filters, 0));
+    CPPUNIT_ASSERT (lm->addLogStream ("file", filters, 0));
+    CPPUNIT_ASSERT (!lm->addLogStream ("file://foo", filters, 0));
+    CPPUNIT_ASSERT (lm->addLogStream ("file://foo", filters, 0));
+  }
+
+  void testRemoveLogStream ()
+  {
+    list<string> filters;
+    CPPUNIT_ASSERT (lm->removeLogStream ("foo"));
+    lm->addLogStream ("file://foo", filters, 0);
+    CPPUNIT_ASSERT (!lm->removeLogStream ("file://foo"));
+  }
+
+  void testLog ()
+  {
+    string message ("A message");
+    list<string> filters;
+    lm->addLogStream ("file://foo", filters, 0);
+    lm->log (message);
+    CPPUNIT_ASSERT (!lm->removeLogStream ("file://foo"));
+    File f;
+    f.openFile ("foo", 
+                File::MYSERVER_OPEN_APPEND | 
+                File::MYSERVER_OPEN_ALWAYS |
+                File::MYSERVER_OPEN_WRITE | 
+                File::MYSERVER_OPEN_READ | 
+                File::MYSERVER_NO_INHERIT);
+    f.setFilePointer (0);
+    char buf[message.size () + 1];
+    u_long nbr;
+    f.read (buf, message.size () + 1, &nbr);
+    buf[nbr] = '\0';
+    CPPUNIT_ASSERT (!message.compare (buf));
+    f.close ();
+  }
+  
+  void testClose ()
+  {
+    list<string> filters;
+    lm->addLogStream ("file://foo", filters, 0);
+    lm->close ();
+    CPPUNIT_ASSERT (!lm->getLogStream ("file://foo")->getIsOpened ());
+  }
+
+  void testCycleLog ()
+  {
+    string message ("A message\n");
+    string message1 ("Another message\n");
+    list<string> filters;
+    lm->addLogStream ("file://foo", filters, 10);
+    lm->log (message);
+    CPPUNIT_ASSERT (!lm->log (message1));
+    lm->close ();
+    File f;
+    f.openFile ("foo", FileStream::defaultFileMask);
+    char buf[64];
+    u_long nbr;
+    f.read (buf, 64, &nbr);
+    buf[nbr] = '\0';
+    f.close ();
+    CPPUNIT_ASSERT (!message1.compare (buf));
+    list<string> cs = lm->getLogStream ("file://foo")->getCycledStreams ();
+    list<string>::iterator it;
+    for (it = cs.begin (); it != cs.end (); it++)
+      {
+        f.openFile (*it, FileStream::defaultFileMask);
+        f.read (buf, 64, &nbr);
+        buf[nbr] = '\0';
+        f.close ();
+        CPPUNIT_ASSERT (!message.compare (buf));
+        CPPUNIT_ASSERT (!FilesUtility::deleteFile (*it));
+      }
+  }
+
+  void testLoggingLevel ()
+  {
+    list<string> filters;
+    lm->addLogStream ("file://foo", filters, 0);
+    CPPUNIT_ASSERT (lm->log ("a message", INFO));
+    CPPUNIT_ASSERT (!lm->log ("a message", ERROR));
+    CPPUNIT_ASSERT (!lm->log ("a message", WARNING));
+    lm->setLoggingLevel (INFO);
+    CPPUNIT_ASSERT (!lm->log ("a message", INFO));
+  }
+
+  void testClear ()
+  {
+    list<string> filters;
+    lm->addLogStream ("file://foo", filters, 0);
+    lm->addLogStream ("console://", filters, 0);
+    CPPUNIT_ASSERT (!lm->empty ());
+    lm->clear ();
+    CPPUNIT_ASSERT (lm->empty ());
+  }
+  
+  void testLogThroughGzip ()
+  {
+//     list<string> filters;
+//     string message ("a message");
+//     filters.push_back (string ("gzip"));
+//     lm->addLogStream ("file://foo", filters, 0);
+//     lm->log (message);
+//     lm->close ();
+//     File f;
+//     f.openFile ("foo", FileStream::defaultFileMask);
+//     char buf[64];
+//     char d_buf[64];
+//     u_long nbr;
+//     f.read (buf, 64, &nbr);
+//     cout << nbr << endl;
+//     f.close ();
+//     GzipDecompress gzdc;
+//     gzdc.decompress (buf, 64, d_buf, 64);
+//     d_buf[message.size ()] = '\0';
+//     CPPUNIT_ASSERT (!message.compare (d_buf));
+  }
+
+  void tearDown()
+  {
+    delete lm;
+    delete lsf;
+    delete ff;
+    FilesUtility::deleteFile ("foo");
+  }
+
+private:
+  LogManager* lm;
+  LogStreamFactory* lsf;
+  FiltersFactory* ff;
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION (TestLogManager);

Added: trunk/myserver/tests/test_log_stream_factory.cpp
===================================================================
--- trunk/myserver/tests/test_log_stream_factory.cpp                            
(rev 0)
+++ trunk/myserver/tests/test_log_stream_factory.cpp    2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -0,0 +1,78 @@
+/*
+ MyServer
+ Copyright (C) 2008 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 <list>
+#include <string>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/log/stream/log_stream_factory.h>
+#include <include/filter/filters_factory.h>
+
+class TestLogStreamFactory : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestLogStreamFactory);
+  CPPUNIT_TEST (testGetProtocol);
+  CPPUNIT_TEST (testGetPath);
+  CPPUNIT_TEST (testCreation);
+  CPPUNIT_TEST_SUITE_END ();
+public:
+  void setUp ()
+  {
+    lsf = new LogStreamFactory ();
+  }
+  
+  void testGetProtocol ()
+  {
+    CPPUNIT_ASSERT (!lsf->protocolCheck (lsf->getProtocol ("foo")));
+    CPPUNIT_ASSERT (!lsf->protocolCheck (lsf->getProtocol ("foo:bar")));
+    CPPUNIT_ASSERT (!lsf->protocolCheck (lsf->getProtocol ("foo://")));
+    CPPUNIT_ASSERT (!lsf->protocolCheck (lsf->getProtocol ("://")));
+    CPPUNIT_ASSERT (!lsf->protocolCheck (lsf->getProtocol ("://foo")));
+    CPPUNIT_ASSERT (lsf->protocolCheck (lsf->getProtocol ("file://")));
+  }
+
+  void testGetPath ()
+  {
+    CPPUNIT_ASSERT (!lsf->getPath ("foo:bla").size ());
+    CPPUNIT_ASSERT (!lsf->getPath ("foo://bar").size ());
+    CPPUNIT_ASSERT (lsf->getPath ("socket://foo").size ());
+  }
+
+  void testCreation ()
+  {
+    list<string> filters;
+    FiltersFactory ff;
+    CPPUNIT_ASSERT (!lsf->createLogStream (&ff, "foo", filters, 0));
+    LogStream* ls = lsf->createLogStream (&ff, "console://", filters, 0);
+    CPPUNIT_ASSERT (ls);
+    CPPUNIT_ASSERT (!lsf->createLogStream (&ff, "socket://foo_bar:-1", 
filters, 0));
+    delete ls;
+  }
+  
+  void tearDown ()
+  {
+    delete lsf;
+  }
+private:
+  LogStreamFactory* lsf;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestLogStreamFactory);

Added: trunk/myserver/tests/test_socket_stream_creator.cpp
===================================================================
--- trunk/myserver/tests/test_socket_stream_creator.cpp                         
(rev 0)
+++ trunk/myserver/tests/test_socket_stream_creator.cpp 2008-09-24 17:21:34 UTC 
(rev 2840)
@@ -0,0 +1,71 @@
+/*
+ MyServer
+ Copyright (C) 2008 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 <list>
+#include <string>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/log/stream/socket_stream_creator.h>
+#include <include/filter/filters_factory.h>
+#include <include/base/socket/socket.h>
+
+class TestSocketStreamCreator : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE (TestSocketStreamCreator);
+  CPPUNIT_TEST (testCreation);
+  CPPUNIT_TEST (testGetPort);
+  CPPUNIT_TEST (testGetHost);
+  CPPUNIT_TEST_SUITE_END ();
+public:
+  void setUp ()
+  {
+    ssc = new SocketStreamCreator ();
+    ff = new FiltersFactory ();
+  }
+  
+  void testCreation ()
+  {
+    list<string> filters;
+    LogStream* ls = ssc->create (ff, "foo:0", filters, 0);
+    CPPUNIT_ASSERT (!ls);
+  }
+
+  void testGetPort ()
+  {
+    CPPUNIT_ASSERT (ssc->getPort ("foohost:8081") == 8081);
+  }
+
+  void testGetHost ()
+  {
+    CPPUNIT_ASSERT (!ssc->getHost ("foohost:8081").compare (string 
("foohost")));
+  }
+
+  void tearDown ()
+  {
+    delete ssc;
+    delete ff;
+  }
+private:
+  SocketStreamCreator* ssc;
+  FiltersFactory* ff;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestSocketStreamCreator);






reply via email to

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