/*!
     * @brief logfile出力のテスト
     * 
     * - ログレベルを ERROR にした場合のファイル出力が正しく行われるか?
     */
    void test_logfile_ERROR(void)
    {
//      std::cout << "test_logfile_ERROR() IN" << std::endl;
      coil::LogStreamBuffer logger;
      std::string logfile("rtcERROR.log");

      std::filebuf of;
      of.open(logfile.c_str(), std::ios::out);
      if (!of.is_open())
        {
          std::cerr << "Error: cannot open logfile: "
                    << logfile << std::endl;
        }
      logger.addStream(&of, true);

      RTC::Logger rtclog(&logger);
      rtclog.setName("Test");
      rtclog.setDateFormat("%b %d %H:%M:%S");
      rtclog.setLevel("ERROR");

      // 汎用ログ出力マクロ、各種ログ出力マクロで正しくファイル出力されるか?
      RTC_LOG(    ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
      RTC_PARANOID(   ("Macro RTL_PARANOID tests %s","fmt"));
      RTC_PARANOID_STR("Macro RTL_PARANOID tests str");

      RTC_LOG(    ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
      RTC_VERBOSE(   ("Macro RTL_VERBOSE tests %s","fmt"));
      RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");

      RTC_LOG(    ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
      RTC_TRACE(   ("Macro RTL_TRACE tests %s","fmt"));
      RTC_TRACE_STR("Macro RTL_TRACE tests str");

      RTC_LOG(    ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
      RTC_DEBUG(   ("Macro RTL_DEBUG tests %s","fmt"));
      RTC_DEBUG_STR("Macro RTL_DEBUG tests str");

      RTC_LOG(    ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
      RTC_INFO(   ("Macro RTL_INFO tests %s","fmt"));
      RTC_INFO_STR("Macro RTL_INFO tests str");

      RTC_LOG(    ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
      RTC_WARN(   ("Macro RTL_WARN tests %s","fmt"));
      RTC_WARN_STR("Macro RTL_WARN tests str");

      RTC_LOG(    ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
      RTC_ERROR(   ("Macro RTL_ERROR tests %s","fmt"));
      RTC_ERROR_STR("Macro RTL_ERROR tests str");

      RTC_LOG(    ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
      RTC_FATAL(   ("Macro RTL_FATAL tests %s","fmt"));
      RTC_FATAL_STR("Macro RTL_FATAL tests str");

      RTC_LOG(    ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");

      of.close();

      // ファイル出力があるか?
      std::string rstr;
      std::ifstream ifs(logfile.c_str());
      ifs >> rstr;
      CPPUNIT_ASSERT(rstr.size() > 0);
      ifs >> rstr;
      ifs >> rstr;
      ifs >> rstr;
      CPPUNIT_ASSERT_EQUAL(std::string("ERROR:"), rstr);
      ifs >> rstr;
      CPPUNIT_ASSERT_EQUAL(std::string("Test:"), rstr);
      ifs >> rstr;
      CPPUNIT_ASSERT_EQUAL(std::string("RTL_ERROR"), rstr);
      ifs >> rstr;
      CPPUNIT_ASSERT_EQUAL(std::string("tests"), rstr);
      ifs >> rstr;
      CPPUNIT_ASSERT_EQUAL(std::string("fmt"), rstr);

//      std::cout << "test_logfile_ERROR() OUT" << std::endl;
    }
예제 #2
0
//--------------------------------------------------
//**************** Public Functions ****************
//--------------------------------------------------
void DcpsFuncPubImpl::init(coil::Properties const& props,
                           std::string const portName)
{
    // Get the host and port of DCPSInfoRepo service
    std::string address = props.getProperty("dcpsir_ip_address");
    std::string port_num = props.getProperty("dcpsir_port_number");
    if (address.empty())
    {
        RTC_ERROR(("Invalid dcpsir_ip_address value"));
        return;
    }
    if (port_num.empty())
    {
        RTC_ERROR(("Invalid dcpsir_port_number value"));
        return;
    }

    std::vector<std::string> args;
    args.push_back("-DCPSInfoRepo");
    args.push_back(address + ":" + port_num);
    // args.push_back("-ORBDebugLevel");
    // args.push_back("10");
    // args.push_back("-DCPSDebugLevel");
    // args.push_back("10");
    // args.push_back("-ORBLogFile");
    // args.push_back(portName + ".log");
    char** argv = coil::toArgv(args);
    int argc(args.size());

    // Create DomainParticipantFactory
    fact_ = TheParticipantFactoryWithArgs(argc, argv);

    DDS::DomainParticipantFactoryQos qos;
    DDS::ReturnCode_t res = fact_->get_qos(qos);
    if (res != DDS::RETCODE_OK)
    {
        RTC_ERROR(("Failed to get factory QoS (%d); cannot "
                   "set QoS properties", res));
    }

    if (!participant_)
    {
        int domain(0);
        if (!coil::stringTo(domain, props.getProperty("domain",
                            "0").c_str()))
        {
            RTC_ERROR(("Invalid domain value"));
            return;
        }
        RTC_INFO(("DDSPubPort %s joining domain %d", portName.c_str(), domain));
        participant_ = fact_->create_participant(
                           domain,
                           PARTICIPANT_QOS_DEFAULT,
                           0,
                           ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (!participant_)
        {
            RTC_ERROR(("Failed to create domain participant"));
            return;
        }
    }

    // Register the Type
    dds_datatype::DdsDataTypeTypeSupport_var ddtTs
        = new dds_datatype::DdsDataTypeTypeSupportImpl();
    if (DDS::RETCODE_OK !=
            ddtTs->register_type(participant_, type_name_.c_str()))
    {
        RTC_ERROR(("Failed to register data type"));
        return;
    }
    RTC_PARANOID(("DDSPubPort %s initialised succesfully", portName.c_str()));
}
    /*!
     * @brief コンストラクタログレベルのテスト
     * 
     * - コンストラクタ(name)の場合、Managerの設定ログレベル(INFO)で動作するか?
     */
    void test_constract_name(void)
    {
//      std::cout << "test_constract_name() IN" << std::endl;
      RTC::Manager* m_mgr;
      m_mgr = RTC::Manager::init(0, NULL);
      CPPUNIT_ASSERT(m_mgr != NULL);

      RTC::Logger rtclog("TestName");
      std::string log_level = m_mgr->getLogLevel();
      CPPUNIT_ASSERT_EQUAL(std::string("INFO"), log_level);

      coil::Properties m_config = m_mgr->getConfig();
      std::vector<std::string> logouts = coil::split(m_config["logger.file_name"], ",");

      // 汎用ログ出力マクロ、各種ログ出力マクロでファイル出力
      RTC_LOG(    ::RTC::Logger::RTL_PARANOID,("RTL_PARANOID tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_PARANOID, "RTL_PARANOID tests str");
      RTC_PARANOID(   ("Macro RTL_PARANOID tests %s","fmt"));
      RTC_PARANOID_STR("Macro RTL_PARANOID tests str");

      RTC_LOG(    ::RTC::Logger::RTL_VERBOSE,("RTL_VERBOSE tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_VERBOSE, "RTL_VERBOSE tests str");
      RTC_VERBOSE(   ("Macro RTL_VERBOSE tests %s","fmt"));
      RTC_VERBOSE_STR("Macro RTL_VERBOSE tests str");

      RTC_LOG(    ::RTC::Logger::RTL_TRACE,("RTL_TRACE tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_TRACE, "RTL_TRACE tests str");
      RTC_TRACE(   ("Macro RTL_TRACE tests %s","fmt"));
      RTC_TRACE_STR("Macro RTL_TRACE tests str");

      RTC_LOG(    ::RTC::Logger::RTL_DEBUG,("RTL_DEBUG tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_DEBUG, "RTL_DEBUG tests str");
      RTC_DEBUG(   ("Macro RTL_DEBUG tests %s","fmt"));
      RTC_DEBUG_STR("Macro RTL_DEBUG tests str");

      RTC_LOG(    ::RTC::Logger::RTL_INFO,("RTL_INFO tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_INFO, "RTL_INFO tests str");
      RTC_INFO(   ("Macro RTL_INFO tests %s","fmt"));
      RTC_INFO_STR("Macro RTL_INFO tests str");

      RTC_LOG(    ::RTC::Logger::RTL_WARN,("RTL_WARN tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_WARN, "RTL_WARN tests str");
      RTC_WARN(   ("Macro RTL_WARN tests %s","fmt"));
      RTC_WARN_STR("Macro RTL_WARN tests str");

      RTC_LOG(    ::RTC::Logger::RTL_ERROR,("RTL_ERROR tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_ERROR, "RTL_ERROR tests str");
      RTC_ERROR(   ("Macro RTL_ERROR tests %s","fmt"));
      RTC_ERROR_STR("Macro RTL_ERROR tests str");

      RTC_LOG(    ::RTC::Logger::RTL_FATAL,("RTL_FATAL tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_FATAL, "RTL_FATAL tests str");
      RTC_FATAL(   ("Macro RTL_FATAL tests %s","fmt"));
      RTC_FATAL_STR("Macro RTL_FATAL tests str");

      RTC_LOG(    ::RTC::Logger::RTL_SILENT,("RTL_SILENT tests %s","fmt"));
      RTC_LOG_STR(::RTC::Logger::RTL_SILENT, "RTL_SILENT tests str");

      m_mgr->terminate();

      // rtc*.log ファイルが作成され、4列目のログレベルが INFO以下か?
      // INFO WARNING ERROR FATAL SILENT だけが記録されているか?
      // Aug 03 14:03:09 INFO: manager: OpenRTM-aist-1.0.0
      // [0] 1  2        3     4        5
      std::string rstr;
      std::vector<std::string> vstr;
      bool bret;
      std::ifstream ifs(logouts[0].c_str());
      while(getline(ifs, rstr))
        {
          if(rstr.size() == 0) break;
          vstr = coil::split(rstr, " ");
          // ログレベル判定
          bret = false;
          if( (vstr[3] == "INFO:") || (vstr[3] == "WARNING:") || (vstr[3] == "ERROR:") ||
              (vstr[3] == "FATAL:") || (vstr[3] == "SILENT:") )
              bret = true;
          CPPUNIT_ASSERT(bret);

          // name判定
          bret = false;
          if( (vstr[4] == "manager:") || (vstr[4] == "TestName:") ||
              (vstr[4] == "NamingOnCorba:") || (vstr[4] == "NamingManager:") ||
              (vstr[4] == "ManagerServant:") )
              bret = true;
          CPPUNIT_ASSERT(bret);
        }
//      std::cout << "test_constract_name() OUT" << std::endl;
    }