TEST_F(TestLogger, LogToClosedLogger) { loggerEcho.close(); EXPECT_THROW( H_LOG(loggerEcho, Logger::SEVERE) << "This message should not show up" << std::endl, h_exception ); ASSERT_EQ(consoleTestBuff.str(), ""); }
TEST_F(TestLogger, PriorityHighEnough) { H_LOG(loggerEcho, Logger::SEVERE) << "This message should show up" << std::endl; // TODO: what to do about the non-deterministic logging message const std::string bufferValue = consoleTestBuff.str(); EXPECT_NE(bufferValue, ""); // TODO: create a more strict regular expression for what we are expecting. testing::internal::RE regex( ".*This message should show up" ); ASSERT_TRUE(testing::internal::RE::PartialMatch( bufferValue, regex ) ) << "The actual value was " << bufferValue; }
void CNetListener::addListener(const char *pszParser, const unsigned short &usType, const char *pszHost, const unsigned short &usPort) { CParser *pParser(m_pParserMgr->getParser(pszParser)); H_ASSERT(NULL != pParser, "get parser error."); CNetInfo *pNetInfo = new(std::nothrow) CNetInfo(this, pParser, usType, pszHost, usPort); if (NULL == pNetInfo) { H_LOG(LOGLV_ERROR, "%s", H_ERR_MEMORY); return; } CAddListenAdjure *pAdjure = new(std::nothrow) CAddListenAdjure(pNetInfo); if (NULL == pAdjure) { H_SafeDelete(pNetInfo); H_LOG(LOGLV_ERROR, "%s", H_ERR_MEMORY); return; } Adjure(pAdjure); }
void CNetListener::onAdjure(CAdjure *pAdjure) { CNETAddr objAddr; CNetInfo *pNetInfo(((CAddListenAdjure *)pAdjure)->getListenInfo()); if (H_RTN_OK != objAddr.setAddr(pNetInfo->getHost(), pNetInfo->getPort(), pNetInfo->isIpV6())) { H_SafeDelete(pNetInfo); H_LOG(LOGLV_ERROR, "parse host %s port %d error.", pNetInfo->getHost(), pNetInfo->getPort()); return; } struct evconnlistener *pListener(evconnlistener_new_bind((struct event_base *)getLoop(), acceptCB, pNetInfo, LEV_OPT_CLOSE_ON_FREE | LEV_OPT_CLOSE_ON_EXEC, -1, objAddr.getAddr(), (int)objAddr.getAddrSize())); if (NULL == pListener) { H_SafeDelete(pNetInfo); H_LOG(LOGLV_ERROR, "%s", "evconnlistener_new_bind error."); return; } H_LOG(LOGLV_SYS, "listen at host %s port %d", pNetInfo->getHost(), pNetInfo->getPort()); m_vcListener.push_back(pListener); m_vcNetInfo.push_back(pNetInfo); }
TEST_F(TestLogger, PriorityTooLow) { H_LOG(loggerEcho, Logger::DEBUG) << "This message should not show up" << std::endl; ASSERT_EQ(consoleTestBuff.str(), ""); }
TEST_F(TestLogger, UninitializedLog) { Logger unitialized; ASSERT_THROW(H_LOG(unitialized, Logger::SEVERE), h_exception); }
TEST_F(TestLogger, NoEchoDoesNotEcho) { H_LOG(loggerNoEcho, Logger::SEVERE) << "This message should not show up" << std::endl; ASSERT_EQ(consoleTestBuff.str(), ""); }
TEST_F(TestLogger, PrioritySameAsMin) { H_LOG(loggerEcho, Logger::WARNING) << "This message should show up" << std::endl; // TODO: what to do about the non-deterministic logging message ASSERT_NE(consoleTestBuff.str(), ""); }