Classes | Defines | Functions | Variables

Classes for unit tests
[Common modules]

Collaboration diagram for Classes for unit tests:

Classes

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

Defines

#define ivd_UT_MATCH_X_m(A, B)
 Different macroes for unit test classes.
#define ivd_UT_NOTMATCH_X_m(A, B, COMMENT)
#define ivd_UT_MATCH_A_m(A, B)
#define ivd_UT_MATCH_m(A, B)
#define ivd_UT_MATCH_COMM_m(A, B, COMMENT)
#define ivd_UT_COMPARE_m(MEM)
#define ivd_UT_COMPARE_S_m(MEM)
#define ivd_UT_COMPARE_AB_m(A, B)
#define ivd_UT_COMPARE_BC_m(BASE_CLASS)
#define ivd_UT_COMPARE_PTR_VAL_m(TYPE, MEM)
#define ivd_UT_COMPARE_VAL_m(UT_TYPE, MEM)
#define ivd_UT_COMPARE_PTR_m(UT_TYPE, MEM)
#define ivd_UT_COMPARE_ARR_m(TYPE, SIZEO, SIZES, MEM)
#define ivd_UT_COMPARE_VEC_m(TYPE, MEM)
#define ivd_UT_COMPARE_VEC_OF_PTR_m(UT_TYPE, VEC_TYPE, MEM)
#define ut_GROUP_m(_libName, _modName, _header, _text)
#define ut_BELAP_m(_testID, _text, _elapsedTime)
 Class that hold information about basic (elementary) unit test.
#define ut_BASIC_m(_testID, _text)

Functions

IVD_UT_DECL_d Int64_t Rand (Int64_t to=RAND_MAX, Int64_t from=0)
void ut_CompareHeaderOutput_On ()
void ut_CompareHeaderOutput_Off ()
void ut_ClassNameComment (const string &a_className)

Variables

stx_Stream ut_resultStream_g
 Stream that store unit result to file "ut_result" on current directory.
ut_Grouput_currentUnitTest_p
 Pointer to current unit test group.
const unsigned int ut_DESCRIPTION_LEN_c
 Maximum length of basic test description.
const unsigned int ut_TESTID_LEN_c
 Maximum length of basic test identification (testID) concatenate with library name, module name, and test ID.
bool ut_compareHeaderOutput_g

Define Documentation

#define ivd_UT_COMPARE_AB_m (   A,
  B 
)
Value:
if ((A) != (B)) {                           \
        ret = false;                            \
        cout << "    " << #A << " != " #B  << " "         \
             << (A) << " != " << (B) << endl;   \
    }

Definition at line 100 of file ut.h.

#define ivd_UT_COMPARE_ARR_m (   TYPE,
  SIZEO,
  SIZES,
  MEM 
)

Definition at line 169 of file ut.h.

#define ivd_UT_COMPARE_BC_m (   BASE_CLASS  ) 
Value:
const BASE_CLASS &obj = *static_cast<const BASE_CLASS*>(&tObj);    \
    const ut_##BASE_CLASS &sam = *static_cast<const ut_##BASE_CLASS*>( \
            static_cast<const BASE_CLASS*>(this)); \
    if (sam != obj) {   \
        ret = false;    \
    }

Definition at line 107 of file ut.h.

#define ivd_UT_COMPARE_m (   MEM  ) 
Value:
if (MEM != tObj.MEM) {             \
            cout << "    " << s_className << "::" << #MEM  \
                 << " " << tObj.MEM            \
                 << " != " << MEM << endl;      \
            ret = false;                                \
    };

Definition at line 82 of file ut.h.

#define ivd_UT_COMPARE_PTR_m (   UT_TYPE,
  MEM 
)
Value:
{ \
    if (ut_compareHeaderOutput_g) \
        cout << "  Compare prt of type " << #UT_TYPE  \
             << " " << s_className << "::" << #MEM  << endl;\
    void *a(MEM);                               \
    void *b(tObj.MEM);                          \
    if (   a == NULL && b != NULL               \
        || a != NULL && b == NULL) {            \
        cout << "    " << s_className << "::" << #MEM     \
            << " " << tObj.MEM                       \
            << " != " << MEM << endl;      \
        ret = false;                            \
    }                                           \
    else if (a != NULL) {                       \
        if (!(*static_cast<UT_TYPE*>(MEM) == *tObj.MEM)) {      \
            ret = false;                                        \
        }                                                       \
    } \
}

Definition at line 148 of file ut.h.

#define ivd_UT_COMPARE_PTR_VAL_m (   TYPE,
  MEM 
)
Value:
{ \
    if (ut_compareHeaderOutput_g) \
        cout << "  Compare prt val " << s_className << "::" << #MEM  << endl;\
    const TYPE *a = MEM;                              \
    const TYPE *b = tObj.MEM;                         \
    if (   a == NULL && b != NULL               \
        || a != NULL && b == NULL) {            \
        cout << "    " << s_className << "::" << #MEM     \
            << " " << tObj.MEM                       \
            << " != " << MEM << endl;      \
        ret = false;                            \
    }                                           \
    else if (a != NULL) {                       \
        if ((*MEM) != *tObj.MEM) {      \
            cout << "    *" << s_className << "::" << #MEM  \
                 << " " << *tObj.MEM            \
                 << " != " << *MEM << endl;      \
            ret = false;                                        \
        }                                                       \
    }   \
}

Definition at line 115 of file ut.h.

#define ivd_UT_COMPARE_S_m (   MEM  ) 
Value:
if (MEM != tObj.MEM) {             \
            cout << "    " << s_className << "::" << #MEM  \
                 << " '" << tObj.MEM            \
                 << "' != '" << MEM << "'" << endl;      \
            ret = false;                                \
    };

Definition at line 91 of file ut.h.

#define ivd_UT_COMPARE_VAL_m (   UT_TYPE,
  MEM 
)
Value:
{ \
    const UT_TYPE &sam = *static_cast<const UT_TYPE*>(&MEM); \
    if (sam != tObj.MEM) {      \
        cout << "  Member(s) of " << s_className << "::" << #MEM  \
             << " doesn't match" << endl;              \
        ret = false;                                   \
    }                                                  \
}

Definition at line 138 of file ut.h.

#define ivd_UT_COMPARE_VEC_m (   TYPE,
  MEM 
)

Definition at line 252 of file ut.h.

#define ivd_UT_COMPARE_VEC_OF_PTR_m (   UT_TYPE,
  VEC_TYPE,
  MEM 
)

Definition at line 327 of file ut.h.

#define ivd_UT_MATCH_A_m (   A,
  B 
)
Value:
if ((A) != (B)) {                           \
        match = false;                          \
        cout << #A <<  "; "                     \
             << (A) << " != " << (B) << endl;   \
    }

Definition at line 58 of file ut.h.

#define ivd_UT_MATCH_COMM_m (   A,
  B,
  COMMENT 
)
Value:
if ((A) != (B)) {                           \
        match = false;                          \
        cout << #A << " != " #B  << "; "        \
             << (A) << " != " << (B)            \
             << "; " << COMMENT << endl;         \
    }

Definition at line 74 of file ut.h.

#define ivd_UT_MATCH_m (   A,
  B 
)
Value:
if ((A) != (B)) {                           \
        match = false;                          \
        cout << #A << " != " #B  << "; "        \
             << (A) << " != " << (B) << endl;   \
    }

Definition at line 66 of file ut.h.

#define ivd_UT_MATCH_X_m (   A,
  B 
)
Value:
if ((A) != (B)) {                           \
        match = false;                          \
    }

Different macroes for unit test classes.

Definition at line 44 of file ut.h.

#define ivd_UT_NOTMATCH_X_m (   A,
  B,
  COMMENT 
)
Value:
if ((A) == (B)) {                           \
        match = false;                          \
    }                                           \
    else {                                      \
        cout << "OK! " << COMMENT << endl;      \
    }

Definition at line 49 of file ut.h.

#define ut_BASIC_m (   _testID,
  _text 
)
Value:
ostringstream sStr; \
        sStr << _text; \
        ut_Basic basict(_testID, sStr.str());

Definition at line 502 of file ut.h.

#define ut_BELAP_m (   _testID,
  _text,
  _elapsedTime 
)
Value:
ostringstream sStr; \
        sStr << _text; \
        ut_Basic basict(_testID, sStr.str(), _elapsedTime);

Class that hold information about basic (elementary) unit test.

It use functionality of ut_Group class that is singleton and is instantiate in ut_Group.cpp file as ut_Group_g.

Example:

    ut_Group fileioTest("fileio");
    {   ut_Basic basict("0002", "Seek end of file");
        ...
        succeed  = <some expresion>;
        basict.SetStatus(succeed);
    }

Definition at line 497 of file ut.h.

#define ut_GROUP_m (   _libName,
  _modName,
  _header,
  _text 
)
Value:
ostringstream sStr; \
        sStr << _text; \
        ut_Group groupTest(_libName, _modName, _header, sStr.str());

Definition at line 372 of file ut.h.


Function Documentation

IVD_UT_DECL_d Int64_t Rand ( Int64_t  to = RAND_MAX,
Int64_t  from = 0 
)

Definition at line 52 of file ut_Group.cpp.

                                       {
    Int64_t diff = to - from + 1; // number of different numbers
    return ((Int64_t)rand() * diff) / (RAND_MAX + 1LL) + from;
}

void ut_ClassNameComment ( const string &  a_className  ) 

Definition at line 61 of file ut_Group.cpp.

                                                    {
    string s(string("Test of class ") + a_className);
    cout
        << s << endl
         << string(s.length(), '=') << endl;
}

void ut_CompareHeaderOutput_Off (  ) 

Definition at line 60 of file ut_Group.cpp.

References ut_compareHeaderOutput_g.

void ut_CompareHeaderOutput_On (  ) 

Definition at line 59 of file ut_Group.cpp.

References ut_compareHeaderOutput_g.


Variable Documentation

Definition at line 57 of file ut_Group.cpp.

Referenced by ut_CompareHeaderOutput_Off(), and ut_CompareHeaderOutput_On().

Pointer to current unit test group.

Pointer to current unit test group.

It is used by ut_Basic::Result method to set

Definition at line 74 of file ut_Group.cpp.

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

const unsigned int ut_DESCRIPTION_LEN_c

Maximum length of basic test description.

Definition at line 57 of file ut_Basic.cpp.

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

Stream that store unit result to file "ut_result" on current directory.

Referenced by ut_Basic::Begin(), ut_Group::Init(), ut_Basic::~ut_Basic(), and ut_Group::~ut_Group().

const unsigned int ut_TESTID_LEN_c

Maximum length of basic test identification (testID) concatenate with library name, module name, and test ID.

See also:
ut_Basic::m_testID
ut_Group::m_libName
ut_Group::m_modulName

Definition at line 58 of file ut_Basic.cpp.

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