⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tests.cpp

📁 日志类封装日志类封装日志类封装日志类封装日志类封装日志类封装
💻 CPP
字号:
/*============================================================================. | Copyright (C) 2006 Gareth Buxton                                           | |----------------------------------------------------------------------------| | LogPlusPlus is free software; you can redistribute it and/or               | | modify it under the terms of the GNU Lesser General Public                 | | License as published by the Free Software Foundation; either               | | version 2.1 of the License, or (at your option) any later version.         | |                                                                            | | LogPlusPlus 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          | | Lesser General Public License for more details.                            | |                                                                            | | You should have received a copy of the GNU Lesser General Public           | | License along with this library; if not, write to the Free Software        | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | '============================================================================*/#include "config.h"#include <string>#include <iostream>#include <iomanip>#include <fstream>#include <ctime>#include <liblpp/Log.h>#include <liblpp/LogForm.h>using namespace std;using namespace lpp;Log& narrate = Log::getLog("narative", std::cout);/*=============================================================================-	Access Test:		Ensure that every method of accessing the LogStream objects works in	each combination.-=============================================================================*/void accessTest(LogStream& infoStream){	narrate << "access(InfoStream(" << infoStream.getName() << ")):" << endl;	infoStream("(\"\")");	infoStream << "<<" << endl;	infoStream() << "()<<" << endl;	infoStream("\"\"") << "<<" << endl;}void accessTest(Log& log){	narrate << "access(Log(" << log.getName() << ")):" << endl;	accessTest(static_cast<LogStream&>(log));	accessTest(log.debug);	accessTest(log.info);	accessTest(log.warn);	accessTest(log.error);	accessTest(log.fatal);	accessTest(log.to("to"));}/*=============================================================================-	Builtin Test:		Ensure that each builtin LogStream object works-=============================================================================*/void builtinTest(Log& log){	narrate << "builtin(Log):" << endl;	log.debug("DEBUG") << endl;	log.info("INFO") << endl;	log.warn("WARN") << endl;	log.error("ERROR") << endl;	log.fatal("FATAL") << endl;	log("NATURAL") << endl;}void regressionTest(Log& log){	class TestLogForm	: public LogForm	{		virtual std::string operator()(const LogMessage& message)		{			std::ostringstream oss;			time_t logTime = 0x12345678;//message.time;			tm local;			//time(&curr); // get current time_t value			local = *(localtime(&logTime)); // dereference and assign			oss << (1900 + local.tm_year);			oss << "/" << std::setfill('0') << std::setw(2) << local.tm_mon;			oss << "/" << std::setfill('0') << std::setw(2) << local.tm_wday;			oss << " " << std::setfill('0') << std::setw(2) << local.tm_hour;			oss << ":" << std::setfill('0') << std::setw(2) << local.tm_min;			oss << ":" << std::setfill('0') << std::setw(2) << local.tm_sec;			oss << " [" << message.logName << "]";			oss << "\t(" << message.logStreamName << ")";			oss << "\t " << message.text;			return  oss.str();		}	};	TestLogForm testLogForm;	log.setLogForm(&testLogForm);	ostringstream oss;	log.attachOstream(oss);	narrate << "Beginning regression tests." << endl << endl;	narrate << "Access:" << endl;	accessTest(log);	narrate << endl;	narrate << "Beginning level tests." << endl;	narrate << endl;	for(unsigned int level = 0; level < 7; level++)	{		narrate << "Setting log mask to level " << level << endl;		log.setLogMask(LogMask::levelToMask(level));		//narate << "LogMask = " << log.getLogMask() << endl;		builtinTest(log);		narrate << endl;	}	narrate << "Beginning interleaved tests." << endl;	narrate << endl;	narrate << "Setting log mask to 01010 " << endl;	log.setLogMask(LogMask("01010"));	builtinTest(log);	narrate << "Setting log mask to 10101 " << endl;	log.setLogMask(LogMask("10101"));	builtinTest(log);	narrate << "Beginning format tests." << endl;	narrate << endl;//	log << "Beginning LogMask tests." << endl;//	log << endl;////	log << "setLogMaskLevel(level):" << endl;//	log << endl;//	for(unsigned int level = 0; level <= MAX_LEVEL; level++)//	{//		log << "Setting log mask to level " << level << endl;//		setLogMaskLevel(level);//		log << "LogMask = " << getLogMask() << endl;//	}////	log << endl;////	log << "setLogMaskLevel(level, Log::REPLACE):" << endl;//	log << endl;//	for(unsigned int level = 0; level <= MAX_LEVEL; level++)//	{//		log << "Setting log mask to level " << level << endl;//		setLogMaskLevel(level, REPLACE);//		log << "LogMask = " << getLogMask() << endl;//	}////	log << endl;////	log << "setLogMaskLevel(level, Log::SET):" << endl;//	log << endl;//	for(unsigned int level = 0; level <= MAX_LEVEL; level++)//	{//		log << "Setting log mask to level " << level << endl;//		setLogMaskLevel(level, SET);//		log << "LogMask = " << getLogMask() << endl;//	}////	log << endl;////	log << "setLogMaskLevel(level, Log::CLEAR):" << endl;//	log << endl;//	for(unsigned int level = 0; level <= MAX_LEVEL; level++)//	{//		log << "Setting log mask to level " << level << endl;//		setLogMaskLevel(level, CLEAR);//		log << "LogMask = " << getLogMask() << endl;//	}////	log << endl;////	log << "setLogMaskLevel(level, Log::TOGGLE):" << endl;//	log << endl;//	for(unsigned int level = 0; level <= MAX_LEVEL; level++)//	{//		log << "Setting log mask to level " << level << endl;//		setLogMaskLevel(level, TOGGLE);//		log << "LogMask = " << getLogMask() << endl;//	}	narrate << endl;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -