diff --git a/castor/log/Param.cpp b/castor/log/Param.cpp index bb9cffc82a822e3ec40480de1a510f1a14ad12e6..f4cac890c3c1b3fc119c813d88f6acd7f6e93408 100644 --- a/castor/log/Param.cpp +++ b/castor/log/Param.cpp @@ -148,15 +148,6 @@ castor::log::Param::Param(const std::string &name, const double value) m_uuidValue(nullCuuid) { } -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const castor::stager::TapeVid &value) throw(): - m_name("TPVID"), m_type(LOG_MSG_PARAM_TPVID), - m_strValue(0 != value.vid() ? value.vid() : ""), m_intValue(0), - m_uint64Value(0), m_doubleValue(0.0), m_uuidValue(nullCuuid) { -} - //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ @@ -233,7 +224,7 @@ int castor::log::Param::getType() const throw() { // getStrValue //------------------------------------------------------------------------------ const std::string &castor::log::Param::getStrValue() const throw() { - if(LOG_MSG_PARAM_STR == m_type) { + if(LOG_MSG_PARAM_STR == m_type || LOG_MSG_PARAM_RAW == m_type) { return m_strValue; } else { return m_emptyStr; diff --git a/castor/log/Param.hpp b/castor/log/Param.hpp index 454adb56173f9bb179d8012824df74d0c84859c0..61b088a8c00f6172c3751ad5f484725d19d0b89e 100644 --- a/castor/log/Param.hpp +++ b/castor/log/Param.hpp @@ -27,7 +27,6 @@ #define CASTOR_LOG_PARAM_HPP 1 #include "castor/IObject.hpp" -#include "castor/stager/TapeVid.hpp" #include "castor/log/IPAddress.hpp" #include "castor/log/TimeStamp.hpp" #include "h/Cuuid.h" @@ -95,11 +94,6 @@ public: */ Param(const std::string &name, const double value) throw(); - /** - * Constructor for Tape VIDS. - */ - Param(const castor::stager::TapeVid &value) throw(); - /** * Constructor for Raw parameters. */ diff --git a/test/unittest/Makefile b/test/unittest/Makefile index f4a411c25b4f3441c188012571d878601c8ce6e8..0ac53dcde2d671a10a7d08dc8af2ef505f04b52c 100644 --- a/test/unittest/Makefile +++ b/test/unittest/Makefile @@ -370,6 +370,7 @@ rununittests: $(RMC_OBJECTS) \ unittest_TapeFlushConfigParamsTest.o \ unittest_LegacyTxRxTest.o \ unittest_LoggerImplementationTest.o \ + unittest_ParamTest.o \ unittest_GetMoreWorkConnectionTest.o \ unittest_ClientAddressTcpIpTest.o \ unittest_PendingMigrationsStoreTest.o \ @@ -1663,6 +1664,9 @@ unittest_LegacyTxRxTest.o: $(ROOT_DIR)/test/unittest/castor/tape/tapebridge/Lega unittest_LoggerImplementationTest.o: \ $(ROOT_DIR)/test/unittest/castor/log/LoggerImplementationTest.cpp g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ + +unittest_ParamTest.o: $(ROOT_DIR)/test/unittest/castor/log/ParamTest.cpp + g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ unittest_GetMoreWorkConnectionTest.o: $(ROOT_DIR)/test/unittest/castor/tape/tapebridge/GetMoreWorkConnectionTest.cpp g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ diff --git a/test/unittest/castor/log/ParamTest.cpp b/test/unittest/castor/log/ParamTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a63e5326b9d247e3593561a0f4d0b2d54da7975 --- /dev/null +++ b/test/unittest/castor/log/ParamTest.cpp @@ -0,0 +1,293 @@ +/****************************************************************************** + * test/unittest/castor/log/ParamTest.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/Constants.hpp" +#include "castor/log/Param.hpp" + +#include <cppunit/extensions/HelperMacros.h> +#include <memory> + +namespace castor { +namespace log { + +class ParamTest: public CppUnit::TestFixture { +public: + + void setUp() { + } + + void tearDown() { + } + + void testConstructorForString() { + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", "Value"))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + std::string("Value"), + param->getStrValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_STR, + param->getType()); + } + + void testConstructorForUuid() { + const Cuuid_t &value = nullCuuid; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_UUID, + param->getType()); + } + + void testConstructorForSubRequestUuid() { + const Cuuid_t &value = nullCuuid; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param(value))); + CPPUNIT_ASSERT_EQUAL( + std::string(""), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_UUID, + param->getType()); + } + + void testConstructorForLongInt() { + const long int value = 1234; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); +#if defined __x86_64__ + CPPUNIT_ASSERT_EQUAL( + (u_signed64)value, + param->getUint64Value()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT64, + param->getType()); +#else + CPPUNIT_ASSERT_EQUAL( + value, + param->getIntValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT, + param->getType()); +#endif + } + + void testConstructorForUnsignedLongInt() { + const long unsigned int value = 1234; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); +#if defined __x86_64__ + CPPUNIT_ASSERT_EQUAL( + (u_signed64)value, + param->getUint64Value()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT64, + param->getType()); +#else + CPPUNIT_ASSERT_EQUAL( + value, + param->getIntValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT, + param->getType()); +#endif + } + + void testConstructorForInt() { + const int value = 1234; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + value, + param->getIntValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT, + param->getType()); + } + + void testConstructorForUnsignedInt() { + const unsigned int value = 1234; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + (int)value, + param->getIntValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT, + param->getType()); + } + + void testConstructorForU_signed64() { + const u_signed64 value = 1234; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + value, + param->getUint64Value()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_INT64, + param->getType()); + } + + void testConstructorForFloat() { + const float value = 1234.5678; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + (double)value, + param->getDoubleValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_DOUBLE, + param->getType()); + } + + void testConstructorForDouble() { + const double value = 1234.5678; + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + value, + param->getDoubleValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_DOUBLE, + param->getType()); + } + + void testConstructorForRawParams() { + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name1=Value1,Name2=Value2"))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name1=Value1,Name2=Value2"), + param->getStrValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_RAW, + param->getType()); + } + + void testConstructorForIPAddress() { + IPAddress value(0x01020304); + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + std::string("1.2.3.4"), + param->getStrValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_STR, + param->getType()); + } + + void testConstructorForTimeStamp() { + const TimeStamp value(0); + std::auto_ptr<Param> param; + + CPPUNIT_ASSERT_NO_THROW( + param.reset(new Param("Name", value))); + CPPUNIT_ASSERT_EQUAL( + std::string("Name"), + param->getName()); + CPPUNIT_ASSERT_EQUAL( + std::string(" 1/1 1:0:0"), + param->getStrValue()); + CPPUNIT_ASSERT_EQUAL( + LOG_MSG_PARAM_STR, + param->getType()); + } + + CPPUNIT_TEST_SUITE(ParamTest); + CPPUNIT_TEST(testConstructorForString); + CPPUNIT_TEST(testConstructorForUuid); + CPPUNIT_TEST(testConstructorForSubRequestUuid); + CPPUNIT_TEST(testConstructorForLongInt); + CPPUNIT_TEST(testConstructorForUnsignedLongInt); + CPPUNIT_TEST(testConstructorForInt); + CPPUNIT_TEST(testConstructorForUnsignedInt); + CPPUNIT_TEST(testConstructorForU_signed64); + CPPUNIT_TEST(testConstructorForFloat); + CPPUNIT_TEST(testConstructorForDouble); + CPPUNIT_TEST(testConstructorForRawParams); + CPPUNIT_TEST(testConstructorForIPAddress); + CPPUNIT_TEST(testConstructorForTimeStamp); + //CPPUNIT_TEST(testConstructorForIObject); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ParamTest); + +} // namespace log +} // namespace castor