Skip to content
Snippets Groups Projects
Commit 329a398d authored by Steven Murray's avatar Steven Murray
Browse files

Added the first CppUnit test for castor::log.

parent d065f4a8
No related branches found
No related tags found
No related merge requests found
......@@ -60,11 +60,6 @@ const size_t LOG_MAX_PARAMNAMELEN = 20;
*/
const size_t LOG_MAX_PARAMSTRLEN = 1024;
/**
* Maximum length of the program name to be prepended to every log message.
*/
const size_t LOG_MAX_PROGNAMELEN = 20;
/**
* Maximum length of a log message.
*/
......
......@@ -50,11 +50,17 @@
namespace castor {
namespace log {
/**
* Maximum length of the program name to be prepended to every log message.
*/
const size_t LOG_MAX_PROGNAMELEN = 20;
/**
* Initialize the CASTOR logging interface.
*
* @param progname The name of the program to be prepended to every log
* message.
* @param progname The name of the program to be prepended to every log message.
* The name should not be longer than castor::log::LOG_MAX_PROGNAMELEN
* characters.
*/
void initLog (const std::string &progname)
throw(castor::exception::AlreadyInitialized, castor::exception::Internal,
......
/******************************************************************************
* test/unittest/castor/log/LogTest.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/log/Log.hpp"
#include <cppunit/extensions/HelperMacros.h>
namespace castor {
namespace log {
class LogTest: public CppUnit::TestFixture {
public:
void setUp() {
}
void tearDown() {
}
void testInitLog() {
// Create a program name that is 1 character too long
std::string tooLongProgname;
for(size_t i = 0; i <= LOG_MAX_PROGNAMELEN; i++) {
tooLongProgname += 'X';
}
CPPUNIT_ASSERT_THROW_MESSAGE(
"Checking a program name that is too long throws InvalidArgument",
initLog(tooLongProgname),
castor::exception::InvalidArgument);
CPPUNIT_ASSERT_NO_THROW_MESSAGE(
"Checking the first call to initLog() does not fail",
initLog("LogTest"));
CPPUNIT_ASSERT_THROW_MESSAGE(
"Checking the second call to initLog() throws AlreadyInitialized",
initLog("LogTest"),
castor::exception::AlreadyInitialized);
}
CPPUNIT_TEST_SUITE(LogTest);
CPPUNIT_TEST(testInitLog);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(LogTest);
} // namespace log
} // namespace castor
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment