diff --git a/castor/log/Constants.hpp b/castor/log/Constants.hpp index 0d468c77e3b21931c804a1885fafbe2dd3cef57d..ed7c09949ae3f925c30c42364e6d2f6244470334 100644 --- a/castor/log/Constants.hpp +++ b/castor/log/Constants.hpp @@ -36,66 +36,6 @@ namespace log { */ const size_t LOG_MAX_PROGNAMELEN = 20; -/** - * Parameter type: Double precision floating point value. - */ -const int LOG_MSG_PARAM_DOUBLE = 1; - -/** - * Parameter type: 64 bit integer. - */ -const int LOG_MSG_PARAM_INT64 = 2; - -/** - * Parameter type: General purpose string. - */ -const int LOG_MSG_PARAM_STR = 3; - -/** - * Parameter type: Tape volume identifier string. - */ -const int LOG_MSG_PARAM_TPVID = 4; - -/** - * Parameter type: Subrequest identifier. - */ -const int LOG_MSG_PARAM_UUID = 5; - -/** - * Parameter type: Single precision floating point value. - */ -const int LOG_MSG_PARAM_FLOAT = 6; - -/** - * Parameter type: Integer. - */ -const int LOG_MSG_PARAM_INT = 7; - -/** - * Parameter type: User identifier as in getuid(). - */ -const int LOG_MSG_PARAM_UID = 8; - -/** - * Parameter type: Group identifier as in getgid(). - */ -const int LOG_MSG_PARAM_GID = 9; - -/** - * Parameter type: STYPE? - */ -const int LOG_MSG_PARAM_STYPE = 10; - -/** - * Parameter type: SNAME? - */ -const int LOG_MSG_PARAM_SNAME = 11; - -/** - * Parameter type: Raw (set of) parameters, in key=value format. - */ -const int LOG_MSG_PARAM_RAW = 12; - } // namespace log } // namespace castor diff --git a/castor/log/LoggerImplementation.cpp b/castor/log/LoggerImplementation.cpp index a6b1578a3f99dc44611f135c44418cf342d70d36..b47ada10bd3fdd186fd61b46c107a6977ea6b676 100644 --- a/castor/log/LoggerImplementation.cpp +++ b/castor/log/LoggerImplementation.cpp @@ -289,69 +289,13 @@ void castor::log::LoggerImplementation::logMsg( const std::string name = param.getName() == "" ? "Undefined" : cleanString(param.getName(), true); - // Process the data type associated with the parameter - switch(params[i].getType()) { - // Strings - case LOG_MSG_PARAM_TPVID: - case LOG_MSG_PARAM_STR: - { - const std::string value = cleanString(param.getStrValue(), false); - if(LOG_MSG_PARAM_TPVID == param.getType()) { - len += snprintf(buffer + len, m_maxMsgLen - len, "TPVID=%.*s ", - CA_MAXVIDLEN, value.c_str()); - } else { - len += snprintf(buffer + len, m_maxMsgLen - len, "%.*s=\"%.*s\" ", - (int)LOG_MAX_PARAMNAMELEN, name.c_str(), - (int)LOG_MAX_PARAMSTRLEN, value.c_str()); - } - } - break; - // Numerical values - case LOG_MSG_PARAM_INT: - len += snprintf(buffer + len, m_maxMsgLen - len, "%.*s=%d ", - (int)LOG_MAX_PARAMNAMELEN, name.c_str(), - param.getIntValue()); - break; - case LOG_MSG_PARAM_INT64: - len += snprintf(buffer + len, m_maxMsgLen - len, "%.*s=%lld ", - (int)LOG_MAX_PARAMNAMELEN, name.c_str(), - param.getUint64Value()); - break; - case LOG_MSG_PARAM_DOUBLE: - len += snprintf(buffer + len, m_maxMsgLen - len, "%.*s=%f ", - (int)LOG_MAX_PARAMNAMELEN, name.c_str(), - param.getDoubleValue()); - break; - - // Subrequest uuid - case LOG_MSG_PARAM_UUID: - { - char uuidstr[CUUID_STRING_LEN + 1]; - if(Cuuid2string(uuidstr, CUUID_STRING_LEN + 1, - ¶m.getUuidValue())) { - return; - } - - len += snprintf(buffer + len, m_maxMsgLen - len, "SUBREQID=%.*s ", - CUUID_STRING_LEN, uuidstr); - } - break; + // Process the parameter value + const std::string value = cleanString(param.getValue(), false); - case LOG_MSG_PARAM_RAW: - len += snprintf(buffer + len, m_maxMsgLen - len, "%s ", - param.getStrValue().c_str()); - break; - - default: - // Please note that this case is used for normal program execution - // for the following parameter types: - // - // LOG_MSG_PARAM_UID - // LOG_MSG_PARAM_GID - // LOG_MSG_PARAM_STYPE - // LOG_MSG_PARAM_SNAME - break; // Nothing - } + // Write the name and value to the buffer + len += snprintf(buffer + len, m_maxMsgLen - len, "%.*s=\"%.*s\" ", + (int)LOG_MAX_PARAMNAMELEN, name.c_str(), + (int)LOG_MAX_PARAMSTRLEN, value.c_str()); // Check if there is enough space in the buffer if(len >= m_maxMsgLen) { diff --git a/castor/log/Param.cpp b/castor/log/Param.cpp index f4cac890c3c1b3fc119c813d88f6acd7f6e93408..ec8a3c76a74c8e655b8d7098ae57cff64edf48e9 100644 --- a/castor/log/Param.cpp +++ b/castor/log/Param.cpp @@ -19,192 +19,10 @@ * * A parameter for the CASTOR logging system * - * @author castor dev team + * @author steve.murray@cern.ch *****************************************************************************/ -// Include Files -#include <time.h> -#include <sstream> -#include <string.h> -#include <iomanip> - -#include "castor/log/Constants.hpp" #include "castor/log/Param.hpp" -#include "castor/ObjectSet.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const std::string &value) - throw(): - m_name(name), - m_type(name == "TPVID" ? LOG_MSG_PARAM_TPVID : LOG_MSG_PARAM_STR), - m_strValue(value), m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const Cuuid_t value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_UUID), - m_strValue(), m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(value) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const Cuuid_t &value) throw() : - m_name(""), m_type(LOG_MSG_PARAM_UUID), - m_strValue(), m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(value) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -#if defined __x86_64__ -castor::log::Param::Param(const std::string &name, const long int value) - throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT64), - m_strValue(), m_intValue(0), m_uint64Value(value), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} -#else -castor::log::Param::Param(const std::string &name, const long int value) - throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT), - m_strValue(), m_intValue(value), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} -#endif - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -#if defined __x86_64__ -castor::log::Param::Param(const std::string &name, - const long unsigned int value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT64), - m_strValue(), m_intValue(0), m_uint64Value(value), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} -#else -castor::log::Param::Param(const std::string &name, - const long unsigned int value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT), - m_strValue(), m_intValue(value), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} -#endif - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const int value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT), - m_strValue(), m_intValue(value), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const unsigned int value) - throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT), - m_strValue(), m_intValue(value), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const u_signed64 value) - throw(): - m_name(name), m_type(LOG_MSG_PARAM_INT64), - m_strValue(), m_intValue(0), m_uint64Value(value), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const float value) - throw(): - m_name(name), m_type(LOG_MSG_PARAM_DOUBLE), - m_strValue(), m_intValue(0), m_uint64Value(0), m_doubleValue(value), - m_uuidValue(nullCuuid) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &name, const double value) - throw(): - m_name(name), m_type(LOG_MSG_PARAM_DOUBLE), - m_strValue(), m_intValue(0), m_uint64Value(0), m_doubleValue(value), - m_uuidValue(nullCuuid) { -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::log::Param::Param(const std::string &rawParams) throw(): - m_name(""), m_type(LOG_MSG_PARAM_RAW), - m_strValue(rawParams), m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), - m_uuidValue(nullCuuid) { -} - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -castor::log::Param::Param(const std::string &name, - const castor::IObject *const value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_STR), - m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), m_uuidValue(nullCuuid) { - std::ostringstream oss; - castor::ObjectSet set; - value->print(oss, "", set); - m_strValue = oss.str(); -} - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -castor::log::Param::Param(const std::string &name, - const castor::log::IPAddress &value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_STR), - m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), m_uuidValue(nullCuuid) { - std::ostringstream oss; - oss << ((value.ip() & 0xFF000000) >> 24) << "." - << ((value.ip() & 0x00FF0000) >> 16) << "." - << ((value.ip() & 0x0000FF00) >> 8) << "." - << ((value.ip() & 0x000000FF)); - m_strValue = oss.str(); -} - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -castor::log::Param::Param(const std::string &name, - const castor::log::TimeStamp &value) throw(): - m_name(name), m_type(LOG_MSG_PARAM_STR), - m_intValue(0), m_uint64Value(0), m_doubleValue(0.0), m_uuidValue(nullCuuid) { - time_t time = value.time(); - // There is NO localtime_r() on Windows, - // so we will use non-reentrant version localtime(). - struct tm tmstruc; - localtime_r (&time, &tmstruc); - std::ostringstream oss; - oss << std::setw(2) << tmstruc.tm_mon+1 - << "/" << tmstruc.tm_mday - << " " << tmstruc.tm_hour - << ":" << tmstruc.tm_min - << ":" << tmstruc.tm_sec; - m_strValue = oss.str(); -} //------------------------------------------------------------------------------ // getName @@ -214,63 +32,8 @@ const std::string &castor::log::Param::getName() const throw() { } //------------------------------------------------------------------------------ -// getType -//------------------------------------------------------------------------------ -int castor::log::Param::getType() const throw() { - return m_type; -} - -//------------------------------------------------------------------------------ -// getStrValue -//------------------------------------------------------------------------------ -const std::string &castor::log::Param::getStrValue() const throw() { - if(LOG_MSG_PARAM_STR == m_type || LOG_MSG_PARAM_RAW == m_type) { - return m_strValue; - } else { - return m_emptyStr; - } -} - -//------------------------------------------------------------------------------ -// getIntValue -//------------------------------------------------------------------------------ -int castor::log::Param::getIntValue() const throw() { - if(LOG_MSG_PARAM_INT == m_type) { - return m_intValue; - } else { - return 0; - } -} - -//------------------------------------------------------------------------------ -// getUint64Value -//------------------------------------------------------------------------------ -u_signed64 castor::log::Param::getUint64Value() const throw() { - if(LOG_MSG_PARAM_INT64 == m_type) { - return m_uint64Value; - } else { - return (u_signed64)0; - } -} - -//------------------------------------------------------------------------------ -// getDoubleValue -//------------------------------------------------------------------------------ -double castor::log::Param::getDoubleValue() const throw() { - if(LOG_MSG_PARAM_DOUBLE == m_type) { - return m_doubleValue; - } else { - return (double)0.0; - } -} - -//------------------------------------------------------------------------------ -// getUuidValue +// getValue //------------------------------------------------------------------------------ -const Cuuid_t &castor::log::Param::getUuidValue() const throw() { - if(LOG_MSG_PARAM_UUID == m_type) { - return m_uuidValue; - } else { - return nullCuuid; - } +const std::string &castor::log::Param::getValue() const throw() { + return m_value; } diff --git a/castor/log/Param.hpp b/castor/log/Param.hpp index 61b088a8c00f6172c3751ad5f484725d19d0b89e..9df67a8cd7483d2cef03735b055365afb8e48b3a 100644 --- a/castor/log/Param.hpp +++ b/castor/log/Param.hpp @@ -26,93 +26,32 @@ #ifndef CASTOR_LOG_PARAM_HPP #define CASTOR_LOG_PARAM_HPP 1 -#include "castor/IObject.hpp" -#include "castor/log/IPAddress.hpp" -#include "castor/log/TimeStamp.hpp" -#include "h/Cuuid.h" - +#include <sstream> #include <string.h> -#include <stdlib.h> namespace castor { namespace log { /** - * A parameter for the CASTOR logging system. + * A name/value parameter for the CASTOR logging system. */ class Param { public: /** - * Constructor for strings. - */ - Param(const std::string &name, const std::string &value) throw(); - - /** - * Constructor for uuids. - */ - Param(const std::string &name, const Cuuid_t value) throw(); - - /** - * Constructor for SubRequest uuids. - */ - Param(const Cuuid_t &value) throw(); - - /** - * Constructor for long int. - */ - Param(const std::string &name, const long int value) throw(); - - /** - * Constructor for long unsigned int. - */ - Param(const std::string &name, const long unsigned int value) throw(); - - /** - * Constructor for int. - */ - Param(const std::string &name, const int value) throw(); - - /** - * Constructor for unsigned int. - */ - Param(const std::string &name, const unsigned int value) throw(); - - /** - * Constructor for u_signed64. - */ - Param(const std::string &name, const u_signed64 value) throw(); - - /** - * Constructor for floats. - */ - Param(const std::string &name, const float value) throw(); - - /** - * Constructor for doubles. - */ - Param(const std::string &name, const double value) throw(); - - /** - * Constructor for Raw parameters. - */ - Param(const std::string &rawParams) throw(); - - /** - * Constructor for IPAddress. - */ - Param(const std::string &name, const castor::log::IPAddress &value) throw(); - - /** - * Constructor for TimeStamp. + * Constructor. + * + * @param name The name of the parameter. + * @param value The value of the parameter that will be converted to a string + * using std::ostringstream. */ - Param(const std::string &name, const castor::log::TimeStamp &value) throw(); - - /** - * Constructor for objects. - */ - Param(const std::string &name, const castor::IObject *const value) throw(); + template <typename T> Param(const std::string &name, const T &value) throw(): + m_name(name) { + std::stringstream oss; + oss << value; + m_value = oss.str(); + } /** * Returns a const reference to the name of the parameter. @@ -120,36 +59,9 @@ public: const std::string &getName() const throw(); /** - * Returns the type of the parameter. - */ - int getType() const throw(); - - /** - * Returns a const refverence to the string value if there is one, else an - * empty string. - */ - const std::string &getStrValue() const throw(); - - /** - * Returns the int value if there is one, else 0. - */ - int getIntValue() const throw(); - - /** - * Returns the unsigned 64-bit int value if there is one, else 0. - */ - u_signed64 getUint64Value() const throw(); - - /** - * Returns the double value if there is one, else 0.0; - */ - double getDoubleValue() const throw(); - - /** - * Returns a const reference to the UUID value if there is one, else - * nullCuuid. + * Returns a const reference to the value of the parameter. */ - const Cuuid_t &getUuidValue() const throw(); + const std::string &getValue() const throw(); private: @@ -159,40 +71,9 @@ private: std::string m_name; /** - * Parameter type, one of LOG_MSG_PARAM_*. - */ - int m_type; - - /** - * The string value of the parameter. - */ - std::string m_strValue; - - /** - * The int value of the parameter. - */ - int m_intValue; - - /** - * The unsigned 64-bit int value of the parameter. - */ - u_signed64 m_uint64Value; - - /** - * The double value of the parameter. - */ - double m_doubleValue; - - /** - * The UUID value of the parameter. - */ - Cuuid_t m_uuidValue; - - /** - * Empty string constant used by the getStrValue() method in the case where - * m_type does not equal LOG_MSG_PARAM_STR. + * The value of the parameter. */ - const std::string m_emptyStr; + std::string m_value; }; // class Param diff --git a/test/unittest/castor/log/ParamTest.cpp b/test/unittest/castor/log/ParamTest.cpp index 8a63e5326b9d247e3593561a0f4d0b2d54da7975..e5b608c50e4bd818ae02f43d6b119f11582d7c79 100644 --- a/test/unittest/castor/log/ParamTest.cpp +++ b/test/unittest/castor/log/ParamTest.cpp @@ -40,250 +40,26 @@ public: void tearDown() { } - void testConstructorForString() { + void testConstructorWithAString() { 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()); + CPPUNIT_ASSERT_EQUAL(std::string("Name"), param->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Value"), param->getValue()); } - void testConstructorForUuid() { - const Cuuid_t &value = nullCuuid; + void testConstructorWithAnInt() { 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_ASSERT_NO_THROW(param.reset(new Param("Name", 1234))); + CPPUNIT_ASSERT_EQUAL(std::string("Name"), param->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("1234"), param->getValue()); } 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(testConstructorWithAString); + CPPUNIT_TEST(testConstructorWithAnInt); CPPUNIT_TEST_SUITE_END(); };