Output the Unit Test Log Files

xiaoxiao2021-03-06  39

// ******************************************************** ****** // filename: unittestlog.h //: // described: // Author: auding (spiritauding@msn.com) // Date: 2005-2-4 13:03:04 //// CopyRight Auding (SpiritAuding@msn.com) //// Permission to use, copy, modify, and distribute this software for any // purpose is hereby granted without fee, provided that this copyright and // permissions notice appear in all copies and DeriVatives.//////////////83939-201GesNido WITHOUT Express or Implied Warranty.///***************** **************************** # ifndef __Unittestlog_header __ # define __Unittestlog_header__

#pragma Message ("UnitTestLog Class Copyright Auding (Spiritauding@msn.com) 2005-02-14! / N")

#include #include #include #include #include

#include #include

class UnitTestLog {private: UnitTestLog (UnitTestLog & rth); UnitTestLog & operator = (UnitTestLog & rth); public: UnitTestLog (): m_strTitle ( ""), m_strUnitTestName ( ""), m_strWorkDirectory ( " "), M_file_ext (". Log "), m_bStarted (false), m_bxmlformat (false) {}; unittestlog (" "), m_strunittestname (UnitTestName) ), M_file_ext (". Log"), m_bstarted (false), m_bxmlformat (false) {}; ~ unitTestLog () {stop_log ();

void set_name (const std :: string & strname) {m_strUnitTestName = strname;} std :: string get_name () const {return m_strUnitTestName;} void start_log () {char file_name [MAX_PATH]; CreateFileName (file_name, MAX_PATH); std :: string str_log_file_name (file_name); clear_file_name (str_log_file_name, m_file_ext); m_fstream.open (str_log_file_name.c_str (), std :: ios_base :: out); if (m_fstream.is_open ()) {m_bXmlFormat = (m_file_ext == ".xml "); If (m_bxmlformat) m_fstream << m_strtitle <<" / n / n "; m_bstarted = true;}}}} void stop_log () {if (m_fstream.is_open ()) {if (m_bxmlformat) m_fstream << ""; m_fstream.close ();} m_bStarted = false;} void set_work_dir (const std :: string & strWork) {m_strWorkDirectory = strWork; std :: string :: iterator it = m_strWorkDirectory.end (); if ("//"! = IT) m_strWorkdirectory = "//";} std :: string get_work_dir () const {return m_strWorkdirectory;}

Void set_log_ext (const st: string & strets) {m_file_ext = strext;} std :: string get_log_ext () const {return m_file_ext;}

Template std :: ostream & operator << (const t & logcontent) {m_fstream << logcontent; return m_fstream;}

Private: std :: string createfilename (Char * buf, const Int "{std :: ostrstream OS (BUF, N); SystemTime Systm; GetLocalTime (& Systm);

IF (m_strWorkdirectory.Length () == 0) usesysdir ();

// filename is looks like: "e: //UnitTestName_Year_Month_Day_Hour_Minute_Second.FileExt" os << m_strWorkDirectory << m_strUnitTestName << "_" << systm.wYear << "_" << systm.wMonth << "_" << SYSTM.WDAY << "_" << systm.wHOUR << "_" << system.wminute << "_" << system.wsecond << m_file_ext; return os.str ();

Void clear_file_name (std :: string & strsub) {int npos = strname.find (strsub, 0); if (npos> -1 && npos strsub.length () <= strname.length () ) {Strname = strname.substr (0, NPOS strsub.length ());}}

void usesysdir () {char tmpbuf [MAX_PATH]; GetTempPath (MAX_PATH, tmpbuf); m_strWorkDirectory = tmpbuf;} private: std :: fstream m_fstream; std :: string m_strUnitTestName; std :: string m_strTitle; std :: string m_strWorkDirectory; std :: string m_file_ext; bool m_bstarted; bool m_bxmlformat;};

#ENDIF / / __ETTESTLOG_HEADER__

转载请注明原文地址:https://www.9cbs.com/read-58515.html

New Post(0)