Public Member Functions | Private Attributes

ut_Group Class Reference
[Classes for unit tests]

Class that hold identification of particular unit tests, it's used by ut_Basic class. More...

#include <ut.h>

Collaboration diagram for ut_Group:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ut_Group (string a_libName, bool a_headerSwitch=true)
 Main constructor.
 ut_Group (string a_libName, string a_modulName, bool a_headerSwitch, string a_title=string(""))
 ~ut_Group ()
void Init ()
 Is used by constructor to set members.
string Header ()
 return all header information as string prepared to push into stream.
void Tail ()
 It's invoke by destructor and use ut_Basic instance to write status of overall group tests.
void Failed ()
 To notice group that test was failed.
bool GetStatus ()
 Get current status of group tests.
string GetLibName ()
 Get library name.
string GetModulName ()
 Get module name.

Private Attributes

const string m_libName
const string m_modulName
const string m_title
ut_Groupm_OwnerUnitTest_p
bool m_status
 ut_Basic::Result method set this member to false using global pointer ut_CurrentTest_p if failed any of basic tests It is used by destructor to write OK or FAIL.
bool m_headerSwitch
 log_CLASSID_m
 Macro for class name member.

Detailed Description

Class that hold identification of particular unit tests, it's used by ut_Basic class.

It's major function is to write header to "ut_result" file.

See also:
ut_Basic

Definition at line 382 of file ut.h.


Constructor & Destructor Documentation

ut_Group::ut_Group ( string  a_libName,
bool  a_headerSwitch = true 
)

Main constructor.

It is possible to pass only library name to test group in case there is only one module (class) to check.

Example of possible constructors:

    ut_Group fileioTest("fileio");

instantiate unit test with library name fileio without mode name and enabled writes header.

    ut_Group fileioTest("fileio", false);

instantiate unit test with library name fileio without mode name and disabled writes header.

    ut_Group fileioTest("fileio", "RelFile", true);

instantiate unit test with library name fileio, mode name RelFile, and enabled writes header. Third parameter can't be exclude at overwritten method. It's mandatory.

Global ut_currentUnitTest_p pointer is evaluate when ut_Group is instantiate. This is used by ut_Basic class to write out library and module name and set group test to false if any of basic test fail.

Parameters:
a_headerSwitch enable header written. It's true by default.

Definition at line 81 of file ut_Group.cpp.

References Init().

                   : m_libName(a_libName),
                     m_modulName(""),
                     m_title(""),
                     m_headerSwitch(a_headerSwitch) {
    Init();
}

Here is the call graph for this function:

ut_Group::ut_Group ( string  a_libName,
string  a_modulName,
bool  a_headerSwitch,
string  a_title = string("") 
)

Definition at line 90 of file ut_Group.cpp.

References Init().

                   : m_libName(a_libName),
                     m_modulName(a_modulName),
                     m_title(" " + a_title + " "),
                     m_headerSwitch(a_headerSwitch) {
    Init();
}

Here is the call graph for this function:

ut_Group::~ut_Group (  ) 

Definition at line 101 of file ut_Group.cpp.

References stx_Stream::Close(), m_OwnerUnitTest_p, Tail(), and ut_resultStream_g.

Here is the call graph for this function:


Member Function Documentation

void ut_Group::Failed (  ) 

To notice group that test was failed.

It is invoked by ut_Basic::SetStatus when test fail.

Definition at line 181 of file ut_Group.cpp.

References Failed(), m_OwnerUnitTest_p, m_status, and NULL.

Referenced by Failed(), ut_Basic::SetStatus(), and ut_Basic::~ut_Basic().

                      {
    m_status = false;
    if (m_OwnerUnitTest_p != NULL) {
        m_OwnerUnitTest_p->Failed();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string ut_Group::GetLibName (  )  [inline]

Get library name.

Used by ut_Basic to write proper test ID.

Definition at line 471 of file ut.h.

Referenced by ut_Basic::Header(), and ut_Basic::ut_Basic().

{return m_libName;}

Here is the caller graph for this function:

string ut_Group::GetModulName (  )  [inline]

Get module name.

Used by ut_Basic to write proper test ID.

Definition at line 477 of file ut.h.

Referenced by ut_Basic::Header(), and ut_Basic::ut_Basic().

{return m_modulName;}

Here is the caller graph for this function:

bool ut_Group::GetStatus (  )  [inline]

Get current status of group tests.

Definition at line 465 of file ut.h.

Referenced by ut_Basic::~ut_Basic().

{return m_status;}

Here is the caller graph for this function:

string ut_Group::Header (  ) 

return all header information as string prepared to push into stream.

Definition at line 127 of file ut_Group.cpp.

References g_cmn, ivd_Versions::GetVersionString(), m_headerSwitch, cmn_SysInfo::m_hostName, cmn_SysInfo::m_ip, m_libName, cmn_SysInfo::m_machine, m_modulName, cmn_SysInfo::m_osName, cmn_SysInfo::m_osRelease, cmn_SysInfo::m_osVersion, m_title, cmn_SysInfo::m_userName, cmn_Global::si, cmn_Time::Time2YMDhmsm(), ut_DESCRIPTION_LEN_c, and ut_TESTID_LEN_c.

Referenced by Init().

                        {

    if (!m_headerSwitch) {
        return "";
    }

    cmn_Time currTime;

    const int lineLen = 103;
    string headerLine(lineLen, '=');
    string bootomLine(lineLen, '=');
    if (!m_title.empty()) {
        int tlen = m_title.length();
        int start = (lineLen / 2) - (tlen / 2);
        bootomLine.replace(start, tlen, m_title);
    }

    ostringstream buf;

    buf                                                              << endl
                                                                     << endl
        <<  headerLine                                               << endl
        <<  setiosflags(std::ios::left)
        << "Unit Test For :\""  << m_modulName << "\" Modul in \""
                                << m_libName << "\" Library"         << endl
        << "Username      : "   << g_cmn.si.m_userName               << endl
        << "Hostname      : "   << g_cmn.si.m_hostName               << endl
        << "IP            : "   << g_cmn.si.m_ip                     << endl
        << "Hardware      : "   << g_cmn.si.m_machine                << endl
        << "OS            : "   << g_cmn.si.m_osName                 << endl
        << "OS release    : "   << g_cmn.si.m_osRelease              << endl
        << "OS version    : "   << g_cmn.si.m_osVersion              << endl
        << "Build         : "                                        << endl
        << ivd_Versions::GetVersionString()                          << endl
        << "Time          : "   << currTime.Time2YMDhmsm()           << endl
                                                                     << endl
        <<  setw(23) << "Time" << " "
        <<  setw(ut_TESTID_LEN_c)      << "Lib_Modul_Test ID"
        <<  setw(ut_DESCRIPTION_LEN_c) << "Description" << " "
        <<  setw( 8) << "Status"                                     << endl
        <<  bootomLine                                               << endl;

    return buf.str();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ut_Group::Init (  ) 

Is used by constructor to set members.

Definition at line 107 of file ut_Group.cpp.

References dbg_LOW, Header(), log_DBG_m, log_FUNCTAG_m, m_OwnerUnitTest_p, m_status, NULL, stx_Stream::Open(), and ut_resultStream_g.

Referenced by ut_Group().

                    {
    log_FUNCTAG_m(Init);

    if (ut_currentUnitTest_p == NULL) {  // first group test set random seed
      srand( (unsigned)time( NULL ) );
    }

    m_OwnerUnitTest_p   = ut_currentUnitTest_p;
    ut_currentUnitTest_p = this;
    m_status = true;    // true at init, set to false if some of basic test failed

    string hdr = Header();

    ut_resultStream_g.Open();
    ut_resultStream_g << hdr;
    cout << hdr;

    log_DBG_m(dbg_LOW, hdr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ut_Group::Tail (  ) 

It's invoke by destructor and use ut_Basic instance to write status of overall group tests.

Definition at line 172 of file ut_Group.cpp.

References m_status, and ut_Basic::SetStatus().

Referenced by ~ut_Group().

                    {
    ut_Basic basict("END", "*** End Of Unit Test ***");
    basict.SetStatus(m_status);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Macro for class name member.

Definition at line 436 of file ut.h.

bool ut_Group::m_headerSwitch [private]

Definition at line 433 of file ut.h.

Referenced by Header().

const string ut_Group::m_libName [private]

Definition at line 420 of file ut.h.

Referenced by Header().

const string ut_Group::m_modulName [private]

Definition at line 421 of file ut.h.

Referenced by Header().

Definition at line 423 of file ut.h.

Referenced by Failed(), Init(), and ~ut_Group().

bool ut_Group::m_status [private]

ut_Basic::Result method set this member to false using global pointer ut_CurrentTest_p if failed any of basic tests It is used by destructor to write OK or FAIL.

See also:
ut_CurrentTest_p

Definition at line 432 of file ut.h.

Referenced by Failed(), Init(), and Tail().

const string ut_Group::m_title [private]

Definition at line 422 of file ut.h.

Referenced by Header().


The documentation for this class was generated from the following files: