HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TestUnit Class Reference

Status maintainer used to run a test. More...

#include <UT_TestManager.h>

Public Types

enum  InitEnum { OK, FAIL }
 

Public Member Functions

 UT_TestUnit (const char *format,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
 UT_TestUnit (InitEnum init_enum, const char *format,...) SYS_PRINTF_CHECK_ATTRIBUTE(3
 
 ~UT_TestUnit ()
 
bool fail (const char *format=NULL,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
bool bool ok (const char *format=NULL,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
bool bool void restartTimer (const char *format=NULL,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
 
bool bool void void setAlwaysPrint (bool f)
 Enable printing of success/failure when this unit test is destroyed. More...
 
bool status () const
 Query the status of the test. More...
 
bool getStatus () const
 
bool setStatus (bool b)
 

Detailed Description

Status maintainer used to run a test.

This class simplifies the book-keeping when running a test. The unit test will automatically log information (i.e. performance, memory) if the UT_TestManager is so configured.

Example 1:

static bool
unitTest(int argument)
{
UT_TestUnit status("UnitTest: %d", argument);
if (!doTest(...))
return status.fail("Test failed: %s", some_string);
return status.ok();
}

Example 2:

static bool
unitTest(int argument)
{
UT_TestUnit unit(UT_TestUnit::OK, "UnitTest: %d", argument);
if (!doTest1(...))
unit.fail("Test 1 failed: %s", some_string);
if (!doTest2(...))
unit.fail("Test 2 failed: %s", some_string);
return unit.status();
}

Definition at line 107 of file UT_TestManager.h.

Member Enumeration Documentation

Enumerator
OK 
FAIL 

Definition at line 110 of file UT_TestManager.h.

Constructor & Destructor Documentation

UT_TestUnit::UT_TestUnit ( const char *  format,
  ... 
)
UT_TestUnit::UT_TestUnit ( InitEnum  init_enum,
const char *  format,
  ... 
)
UT_TestUnit::~UT_TestUnit ( )

Member Function Documentation

bool UT_TestUnit::fail ( const char *  format = NULL,
  ... 
)

Print out the message given by a format. This includes the test name, and other information. No newline should be included in the format.

The function always returns false.

bool UT_TestUnit::getStatus ( ) const
inline

Definition at line 142 of file UT_TestManager.h.

bool bool UT_TestUnit::ok ( const char *  format = NULL,
  ... 
)

Print out the message given by a format. This includes the test name, and other information. No newline should be included in the format.

The function always returns true.

bool bool void UT_TestUnit::restartTimer ( const char *  format = NULL,
  ... 
)

Restart the timer. If format is non-NULL, then it will print the time as well from when the timer last started. Note that the timer is automatically started in the constructor.

bool bool void void UT_TestUnit::setAlwaysPrint ( bool  f)
inline

Enable printing of success/failure when this unit test is destroyed.

Definition at line 138 of file UT_TestManager.h.

bool UT_TestUnit::setStatus ( bool  b)
inline

Definition at line 143 of file UT_TestManager.h.

bool UT_TestUnit::status ( ) const
inline

Query the status of the test.

Definition at line 141 of file UT_TestManager.h.


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