Phoenix
Object-oriented orthogonally persistent operating system
Classes | Namespaces | Defines | Functions | Variables
phoenix_ut.h File Reference

Main header file for unit tests source files inclusions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ut::TestDesc
 Test descriptor. More...
class  ut::TestValueBase
 Base class for TestValue. More...
class  ut::TestException
 Exceptions during a test (e.g. More...
class  ut::TestValue< T >
 Class for wrapping all values being tested in tests. More...

Namespaces

namespace  ut
 

Unit tests related definitions reside in this namespace.


Defines

#define __UT_CONCAT(x, y)   __UT_CONCAT2(x, y)
 Concatenate identifiers.
#define __UT_STR(x)   __UT_STR2(x)
 Stringify identifiers.
#define __UT_UID(str)   __UT_CONCAT(str, __COUNTER__)
 Get unique identifier.
#define UT_TEST(name)
 Macro for defining a test.
#define UT_TEST_END
 Macro for test definition termination.
#define UT(value)   ut::TestValue<decltype(value)>(value, __UT_STR(value), __FILE__, __LINE__)
 Wrapper for all values which are participating in asserts.
#define UT_BOOL(value)   ut::TestValue<bool>(static_cast<bool>(value), __UT_STR(value), __FILE__, __LINE__)
 Wrapper which interprets value as boolean.
#define UT_FALSE   UT(false)
 Predefined unit test value for boolean false.
#define UT_TRUE   UT(true)
 Predefined unit test value for boolean true.
#define UT_SIZE(value)   UT(static_cast<size_t>(value))
 Wrapper which interprets value as size type.
#define UT_NULL   ut::TestValue<void *>(nullptr, "NULL", __FILE__, __LINE__)
 Wrapper for null pointer value.
#define UT_CPTR(value)
 Wrapper which interprets value as pointer to constant data.
#define UT_PTR(value)
 Wrapper which interprets value as pointer to data.
#define UT_CSTR(value)
 Wrapper which interprets value as pointer to constant string.
#define UT_FAIL(desc,...)   ut::__ut_user_fault(__FILE__, __LINE__, desc, ## __VA_ARGS__)
 User requested failure.
#define UT_PASS()   ut::__ut_hit_assert()
 Indicate successful milestone passing.
#define UT_TRACE(msg,...)   ut::__ut_trace(__FILE__, __LINE__, msg, ## __VA_ARGS__)
 Output message to the test log.

Functions

bool ut::__ut_InitStubs ()
 Environment-specific stubs definition module must provide this function which is called by the framework before any test is executed.
void * ut::__ut_malloc (const char *file, int line, unsigned long size, unsigned long align=0)
 Allocate memory block.
void ut::__ut_mfree (void *ptr)
 Free memory block.
void ut::__ut_putc (char c)
 Output character to the test log.
void ut::__ut_trace (const char *file, int line, const char *msg,...)
 Output message to the test log.
void ut::__ut_vtrace (const char *file, int line, const char *msg, __ut_va_list args)
 Output message to the test log.
void ut::__ut_hit_value ()
 Increment tested values statistics.
void ut::__ut_hit_assert ()
 Increment assertions statistics.
void ut::__ut_user_fault (const char *file, int line, const char *desc,...)
 Throw user requested fault.

Variables

const char * ut::__ut_test_description
 Description provided in the test makefile.

Detailed Description

Main header file for unit tests source files inclusions.

This header should not include any third party header (e.g. standard library headers) to avoid conflicts with the code being tested.


Define Documentation

#define __UT_CONCAT (   x,
 
)    __UT_CONCAT2(x, y)

Concatenate identifiers.

#define __UT_STR (   x)    __UT_STR2(x)

Stringify identifiers.

#define __UT_UID (   str)    __UT_CONCAT(str, __COUNTER__)

Get unique identifier.

#define UT (   value)    ut::TestValue<decltype(value)>(value, __UT_STR(value), __FILE__, __LINE__)

Wrapper for all values which are participating in asserts.

Usage example:

 UT(someValue) == UT(anotherValue);
 UT(a) < UT(b);
 UT(someString) != UT("string content");
Parameters:
valueValue of any supported type to participate in assert condition.
#define UT_BOOL (   value)    ut::TestValue<bool>(static_cast<bool>(value), __UT_STR(value), __FILE__, __LINE__)

Wrapper which interprets value as boolean.

#define UT_CPTR (   value)
Value:
ut::TestValue<const void *>( \
    static_cast<const void *>(value), __UT_STR(value), __FILE__, __LINE__)

Wrapper which interprets value as pointer to constant data.

Can be useful to force comparing strings by pointers instead of comparing by content.

#define UT_CSTR (   value)
Value:
ut::TestValue<const char *>( \
    static_cast<const char *>(value), __UT_STR(value), __FILE__, __LINE__)

Wrapper which interprets value as pointer to constant string.

Example:

 UT(someString) == UT_CSTR("some string");
#define UT_FAIL (   desc,
  ... 
)    ut::__ut_user_fault(__FILE__, __LINE__, desc, ## __VA_ARGS__)

User requested failure.

Parameters:
descDescription of the fault.
#define UT_FALSE   UT(false)

Predefined unit test value for boolean false.

#define UT_NULL   ut::TestValue<void *>(nullptr, "NULL", __FILE__, __LINE__)

Wrapper for null pointer value.

#define UT_PASS ( )    ut::__ut_hit_assert()

Indicate successful milestone passing.

Can be used to affect assertions statistics while checking conditions manually.

#define UT_PTR (   value)
Value:
ut::TestValue<void *>( \
    static_cast<void *>(value), __UT_STR(value), __FILE__, __LINE__)

Wrapper which interprets value as pointer to data.

#define UT_SIZE (   value)    UT(static_cast<size_t>(value))

Wrapper which interprets value as size type.

#define UT_TEST (   name)
Value:
namespace { \
    class __UT_TEST_DESC : public ut::TestDesc { \
    public: \
        __UT_TEST_DESC() : TestDesc(__FILE__, __LINE__, name) { } \
        \
        virtual void TestBody()

Macro for defining a test.

Usage example:

 UT_TEST("My test of some functionality")
 {
      <test code here>
 }
 UT_TEST_END
Parameters:
nameArbitrary name of the test.
#define UT_TEST_END
Value:
} __UT_UID(utTestDesc_); \
    }

Macro for test definition termination.

See UT_TEST.

#define UT_TRACE (   msg,
  ... 
)    ut::__ut_trace(__FILE__, __LINE__, msg, ## __VA_ARGS__)

Output message to the test log.

#define UT_TRUE   UT(true)

Predefined unit test value for boolean true.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines