[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2842] Added more tests for the LogManager class.
From: |
Francesco Pipita |
Subject: |
[myserver-commit] [2842] Added more tests for the LogManager class. |
Date: |
Fri, 26 Sep 2008 22:36:02 +0000 |
Revision: 2842
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2842
Author: francesco_pipita
Date: 2008-09-26 22:36:01 +0000 (Fri, 26 Sep 2008)
Log Message:
-----------
Added more tests for the LogManager class. Fixed a bug and removed an useless
test for the FileStream class.
Modified Paths:
--------------
trunk/myserver/include/log/stream/log_stream_factory.h
trunk/myserver/src/log/log_manager.cpp
trunk/myserver/src/log/stream/file_stream.cpp
trunk/myserver/tests/test_file_stream.cpp
trunk/myserver/tests/test_log_manager.cpp
trunk/myserver/tests/test_socket_stream_creator.cpp
Modified: trunk/myserver/include/log/stream/log_stream_factory.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream_factory.h 2008-09-24
19:43:55 UTC (rev 2841)
+++ trunk/myserver/include/log/stream/log_stream_factory.h 2008-09-26
22:36:01 UTC (rev 2842)
@@ -95,7 +95,7 @@
/*!
- * Checks wheter `protocol' is between those known by the LogStreamFactory.
+ * Checks whether `protocol' is between those known by the LogStreamFactory.
* \return true If it is.
*/
bool protocolCheck (string protocol);
Modified: trunk/myserver/src/log/log_manager.cpp
===================================================================
--- trunk/myserver/src/log/log_manager.cpp 2008-09-24 19:43:55 UTC (rev
2841)
+++ trunk/myserver/src/log/log_manager.cpp 2008-09-26 22:36:01 UTC (rev
2842)
@@ -259,10 +259,15 @@
LogManager::load (const char *filename)
{
setType (TYPE_FILE);
- clear ();
+ removeLogStream ("console://");
string location ("file://");
location.append (filename);
+ location.append (".gz");
list<string> filters;
+ /*
+ we use the gzip compression by default, for now.
+ */
+ filters.push_back ("gzip");
addLogStream (location, filters, maxSize);
return 0;
}
@@ -270,34 +275,24 @@
int
LogManager::write (string message, int len)
{
- return notifyLogStreams (EVT_LOG, static_cast<void*>(&message));
+ return log (message);
}
int LogManager::getLogSize ()
{
- if (getFile ())
- return getFile ()->getFileSize ();
return 0;
}
void
-LogManager::setCycleLog (u_long cycleLog)
+LogManager::setCycleLog (u_long l)
{
- cycleLog = 1;
- notifyLogStreams (EVT_SET_CYCLE_LOG, static_cast<void*>(&maxSize));
+ cycleLog = l;
+ setCycleLog (maxSize, "all");
}
File*
LogManager::getFile ()
{
- map<string, LogStream*>::iterator it;
- for (it = logStreams.begin (); it != logStreams.end (); it++)
- {
- if (it->first.find ("file://") != string::npos)
- {
- return dynamic_cast<File*>(it->second->getOutStream ());
- }
- }
return 0;
}
@@ -332,9 +327,7 @@
void
LogManager::setGzip (int useGzip)
{
- gzipLog = useGzip;
- if (gzipLog)
- notifyLogStreams (EVT_ADD_FILTER, new Gzip ());
+
}
int
Modified: trunk/myserver/src/log/stream/file_stream.cpp
===================================================================
--- trunk/myserver/src/log/stream/file_stream.cpp 2008-09-24 19:43:55 UTC
(rev 2841)
+++ trunk/myserver/src/log/stream/file_stream.cpp 2008-09-26 22:36:01 UTC
(rev 2842)
@@ -146,7 +146,7 @@
{
filename = (filename.substr (0, filename.find (string (".") + ext)));
}
- newfilename << filedir << filename << "." << time <<
+ newfilename << filedir << "/" << filename << "." << time <<
(ext.size () ? "." : "") << ext;
return newfilename.str ();
}
Modified: trunk/myserver/tests/test_file_stream.cpp
===================================================================
--- trunk/myserver/tests/test_file_stream.cpp 2008-09-24 19:43:55 UTC (rev
2841)
+++ trunk/myserver/tests/test_file_stream.cpp 2008-09-26 22:36:01 UTC (rev
2842)
@@ -34,30 +34,15 @@
{
CPPUNIT_TEST_SUITE (TestFileStream);
CPPUNIT_TEST (testCycleLog);
- CPPUNIT_TEST (testMakeNewFileName);
CPPUNIT_TEST_SUITE_END ();
public:
- void setUp()
+ 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;
@@ -91,7 +76,7 @@
delete ls;
}
- void tearDown()
+ void tearDown ()
{
delete ff;
delete fsc;
Modified: trunk/myserver/tests/test_log_manager.cpp
===================================================================
--- trunk/myserver/tests/test_log_manager.cpp 2008-09-24 19:43:55 UTC (rev
2841)
+++ trunk/myserver/tests/test_log_manager.cpp 2008-09-26 22:36:01 UTC (rev
2842)
@@ -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>
@@ -46,9 +46,10 @@
CPPUNIT_TEST (testLoggingLevel);
CPPUNIT_TEST (testClear);
CPPUNIT_TEST (testLogThroughGzip);
+ CPPUNIT_TEST (testCycleLogWithGzipChain);
CPPUNIT_TEST_SUITE_END ();
public:
- void setUp()
+ void setUp ()
{
lsf = new LogStreamFactory ();
ff = new FiltersFactory ();
@@ -96,15 +97,9 @@
list<string> filters;
lm->addLogStream ("file://foo", filters, 0);
lm->log (message);
- CPPUNIT_ASSERT (!lm->removeLogStream ("file://foo"));
+ lm->close ();
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);
+ f.openFile ("foo", FileStream::defaultFileMask);
char buf[message.size () + 1];
u_long nbr;
f.read (buf, message.size () + 1, &nbr);
@@ -174,28 +169,70 @@
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));
+ list<string> filters;
+ string message ("a message");
+ filters.push_back ("gzip");
+ lm->addLogStream ("file://foo", filters, 0);
+ lm->log (message);
+ lm->close ();
+ File f;
+ f.openFile ("foo", FileStream::defaultFileMask);
+ char gzipChainComp[64];
+ char gzipChainDecomp[64];
+ u_long nbr;
+ f.read (gzipChainComp, 64, &nbr);
+ f.close ();
+ GzipDecompress gzdc;
+ gzdc.decompress (&gzipChainComp[gzdc.headerSize ()],
+ nbr - gzdc.headerSize (),
+ gzipChainDecomp, 64);
+ gzipChainDecomp[message.size ()] = '\0';
+ CPPUNIT_ASSERT (!message.compare (gzipChainDecomp));
}
- void tearDown()
+ void testCycleLogWithGzipChain ()
{
+ u_long cycleLog = 40;
+ list<string> filters;
+ string message ("The quick brown fox jumped over the lazy dog.");
+ string message1 ("Yet another short log message.");
+ File f;
+ char gzipComp[128];
+ char gzipDecomp[128];
+ GzipDecompress gzdc;
+ u_long nbr = 0;
+ list<string> cs;
+ list<string>::iterator it;
+
+ filters.push_back ("gzip");
+ lm->addLogStream ("file://foo", filters, cycleLog);
+ lm->log (message);
+ CPPUNIT_ASSERT (!lm->log (message1));
+ f.openFile ("foo", FileStream::defaultFileMask);
+ f.read (gzipComp, 128, &nbr);
+ f.close ();
+ gzdc.decompress (&gzipComp[gzdc.headerSize ()],
+ nbr - gzdc.headerSize (),
+ gzipDecomp, 128);
+ gzipDecomp[message1.size ()] = '\0';
+ CPPUNIT_ASSERT (!message1.compare (gzipDecomp));
+ cs = lm->getLogStream ("file://foo")->getCycledStreams ();
+ for (it = cs.begin (); it != cs.end (); it++)
+ {
+ f.openFile (*it, FileStream::defaultFileMask);
+ f.read (gzipComp, 128, &nbr);
+ f.close ();
+ gzdc.decompress (&gzipComp[gzdc.headerSize ()],
+ nbr - gzdc.headerSize (),
+ gzipDecomp, 128);
+ gzipDecomp[message.size ()] = '\0';
+ CPPUNIT_ASSERT (!message.compare (gzipDecomp));
+ CPPUNIT_ASSERT (!FilesUtility::deleteFile (*it));
+ }
+ }
+
+ void tearDown ()
+ {
delete lm;
delete lsf;
delete ff;
Modified: trunk/myserver/tests/test_socket_stream_creator.cpp
===================================================================
--- trunk/myserver/tests/test_socket_stream_creator.cpp 2008-09-24 19:43:55 UTC
(rev 2841)
+++ trunk/myserver/tests/test_socket_stream_creator.cpp 2008-09-26 22:36:01 UTC
(rev 2842)
@@ -55,7 +55,7 @@
void testGetHost ()
{
- CPPUNIT_ASSERT (!ssc->getHost ("foohost:8081").compare (string
("foohost")));
+ CPPUNIT_ASSERT (!ssc->getHost ("foohost:8081").compare ("foohost"));
}
void tearDown ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2842] Added more tests for the LogManager class.,
Francesco Pipita <=