myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2875] Added more tests for the LogManager.


From: Francesco Pipita
Subject: [myserver-commit] [2875] Added more tests for the LogManager.
Date: Thu, 09 Oct 2008 15:41:05 +0000

Revision: 2875
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2875
Author:   francesco_pipita
Date:     2008-10-09 15:41:04 +0000 (Thu, 09 Oct 2008)

Log Message:
-----------
Added more tests for the LogManager.

Modified Paths:
--------------
    trunk/myserver/tests/test_file_stream.cpp
    trunk/myserver/tests/test_file_stream_creator.cpp
    trunk/myserver/tests/test_log_manager.cpp

Modified: trunk/myserver/tests/test_file_stream.cpp
===================================================================
--- trunk/myserver/tests/test_file_stream.cpp   2008-10-08 22:21:10 UTC (rev 
2874)
+++ trunk/myserver/tests/test_file_stream.cpp   2008-10-09 15:41:04 UTC (rev 
2875)
@@ -1,19 +1,19 @@
 /*
- 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.
+  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.
+  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 <list>
 #include <string>
@@ -29,27 +29,41 @@
 #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 TestFileStream : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE (TestFileStream);
   CPPUNIT_TEST (testCycleLog);
+  CPPUNIT_TEST (testReOpen);
   CPPUNIT_TEST_SUITE_END ();
 public:
   void setUp ()
   {
     fsc = new FileStreamCreator ();
     ff = new FiltersFactory ();
+    ff->insert ("gzip", Gzip::factory);
     setcwdBuffer ();
   }
 
   void testCycleLog ()
   {
     list<string> filters;
-    string message ("thisisaverylongmessage\n");
-    string message2 ("thisisanothermessage\n");
-    LogStream* ls = fsc->create (ff, "foo", filters, 10);
+    string message;
+    string message2;
+    LogStream* ls;
 
+#ifdef WIN32
+    message.assign ("thisisaverylongmessage\r\n");
+    message2.assign ("thisisanothermessage\r\n");
+#endif
+#ifdef NOT_WIN
+    message.assign ("thisisaverylongmessage\n");
+    message2.assign ("thisisanothermessage\n");
+#endif
+    ls = fsc->create (ff, "foo", filters, 10);
+    CPPUNIT_ASSERT (ls);
     CPPUNIT_ASSERT (!ls->log (message));
     CPPUNIT_ASSERT (!ls->log (message2));
     ls->close ();
@@ -76,6 +90,39 @@
     delete ls;
   }
 
+  void testReOpen ()
+  {
+    list<string> filters;
+    LogStream* ls;
+    File f;
+    char buf[128];
+    u_long nbr;
+    string message1;
+    string message2;
+    
+    ls = fsc->create (ff, "foo", filters, 0);
+    CPPUNIT_ASSERT (ls);
+#ifdef WIN32
+    message1.assign ("message1\r\n");
+    message2.assign ("message2\r\n");
+#endif
+#ifdef NOT_WIN
+    message1.assign ("message1\n");
+    message2.assign ("message2\n");
+#endif
+    ls->log (message1);
+    delete ls;
+    ls = fsc->create (ff, "foo", filters, 0);
+    CPPUNIT_ASSERT (ls);
+    ls->log (message2);
+    delete ls;
+    f.openFile ("foo", FileStream::defaultFileMask);
+    f.read (buf, 128, &nbr);
+    f.close ();
+    buf[nbr] = '\0';
+    CPPUNIT_ASSERT (!string (buf).compare (message1.append (message2)));
+  }
+  
   void tearDown ()
   {
     delete ff;

Modified: trunk/myserver/tests/test_file_stream_creator.cpp
===================================================================
--- trunk/myserver/tests/test_file_stream_creator.cpp   2008-10-08 22:21:10 UTC 
(rev 2874)
+++ trunk/myserver/tests/test_file_stream_creator.cpp   2008-10-09 15:41:04 UTC 
(rev 2875)
@@ -45,10 +45,6 @@
     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 ()

Modified: trunk/myserver/tests/test_log_manager.cpp
===================================================================
--- trunk/myserver/tests/test_log_manager.cpp   2008-10-08 22:21:10 UTC (rev 
2874)
+++ trunk/myserver/tests/test_log_manager.cpp   2008-10-09 15:41:04 UTC (rev 
2875)
@@ -47,6 +47,7 @@
   CPPUNIT_TEST (testCycleWithGzipChain);
   CPPUNIT_TEST (testCount);
   CPPUNIT_TEST (testGet);
+  CPPUNIT_TEST (testReOpen);
   CPPUNIT_TEST_SUITE_END ();
 public:
   void setUp ()
@@ -275,6 +276,37 @@
     CPPUNIT_ASSERT (!lm->get (this, "test", "console://stdout", &ls));
   }
 
+  void testReOpen ()
+  {
+    list<string> filters;
+    File f;
+    string message1;
+    string message2;
+    char buf[128];
+    u_long nbr;
+
+#ifdef WIN32
+    message1.assign ("message1\r\n");
+    message2.assign ("message2\r\n");
+#endif
+#ifdef NOT_WIN
+    message1.assign ("message1\n");
+    message2.assign ("message2\n");
+#endif
+
+    lm->add (this, "test", "file://foo", filters, 0);
+    lm->log (this, "test", "file://foo", message1);
+    lm->clear ();
+    CPPUNIT_ASSERT (!lm->add (this, "test", "file://foo", filters, 0));
+    CPPUNIT_ASSERT (!lm->log (this, "test", "file://foo", message2));
+    lm->clear ();
+    f.openFile ("foo", FileStream::defaultFileMask);
+    f.read (buf, 128, &nbr);
+    f.close ();
+    buf[nbr] = '\0';
+    CPPUNIT_ASSERT (!string (buf).compare (message1.append (message2)));
+  }
+
   void tearDown ()
   {
     delete lm;






reply via email to

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