Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cUnitTests Class Reference

#include <cUnitTest.h>

Inheritance diagram for Gray::cUnitTests:
Gray::cSingleton< cUnitTests > Gray::cUnitTestCur Gray::cSingletonStatic< TYPE > Gray::cSingletonRegister Gray::CObject Gray::cHeapObject Gray::IHeapObject

Public Member Functions

 cUnitTests ()
 
HRESULT InitTestOutDir ()
 
bool RegisterUnitTest (cUnitTestRegister *pTest)
 
void SetTestLevel (UNITTEST_LEVEL_TYPE nTestLevel)
 
bool TestActive (const cUnitTestRegister *pUnitTest, bool remove)
 
cUnitTestRegisterFindUnitTest (const char *pszName) const
 
bool IsTestInteractive () const noexcept
 
bool TestInteractivePrompt (const char *pszMsg) noexcept
 
const FILECHAR_tget_TestInpDir () const
 
const FILECHAR_tget_TestOutDir () const
 
void RunInitialize ()
 
void RunCleanup ()
 
HRESULT RunUnitTests (UNITTEST_LEVEL_TYPE nTestLevel=UNITTEST_LEVEL_Common, const LOGCHAR_t *pszTestNameMatch=nullptr)
 Run all tests <= this UNITTEST_LEVEL_TYPE. More...
 
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from Gray::cHeapObject
 cHeapObject ()
 
virtual ~cHeapObject ()
 
bool IsValidInsideN (INT_PTR index) const
 
bool IsValidInsidePtr (void const *pTest) const
 
virtual size_t GetHeapStatsThis (OUT ITERATE_t &iAllocCount) const
 
virtual bool isValidCheck () const noexcept
 

Public Attributes

cArrayPtr< cUnitTestRegisterm_aUnitTests
 list of all registered unit tests. Register as they get instantiate by C runtime static loader. More...
 
AssertCallback_t * m_pAssertOrig
 
UNITTEST_LEVEL_TYPE m_nTestLevel
 restore the original assert. More...
 
cArrayString< LOGCHAR_tm_aTestNames
 
cStringF m_sTestInpDir
 root for source of test input files. might change based on cOSModImpl? More...
 
cStringF m_sTestOutDir
 global config for input files. More...
 
cLogProcessorm_pLog
 cLogMgr::I() for output of tests. Why not just use DEBUG_MSG ?? More...
 
bool m_bRunning
 We are actively running in the Gray test framework. Not in M$ framework. More...
 
int m_iFailures
 Count total unit test failures. More...
 

Static Public Attributes

static AssertCallback_t UnitTest_AssertCallback
 redirect assert here for test failure. requires _DEBUG or _DEBUG_FAST. More...
 
- Static Public Attributes inherited from Gray::cSingletonRegister
static cThreadLockFast sm_LockSingle
 common lock for all cSingleton. More...
 
- Static Public Attributes inherited from Gray::cUnitTestCur
static int sm_nCreatedUnitTests = 0
 Count the cUnitTest objects I have created. NOT just m_aUnitTests. More...
 
static const FILECHAR_tk_TestFiles = _FN("TestFiles")
 
static const StrLen_t k_TEXTBLOB_LEN = 566
 StrT::Len(k_sTextBlob) = 0x236. More...
 
static const cStrConst k_sTextBlob
 a single allocated k_TEXTBLOB_LEN+1 More...
 
static const StrLen_t k_TEXTLINES_QTY = 18
 STRMAX= _countof(k_asTextLines)-1. More...
 
static const cStrConst k_asTextLines [k_TEXTLINES_QTY+1]
 nullptr terminated array of lines of text. More...
 

Friends

class cUnitTestRegister
 

Additional Inherited Members

- Static Public Member Functions inherited from Gray::cSingleton< cUnitTests >
static cUnitTests *__stdcall get_Single ()
 
static TYPE2 *__stdcall get_SingleT ()
 
static cUnitTests &__stdcall I ()
 
- Static Public Member Functions inherited from Gray::cSingletonStatic< TYPE >
static bool isSingleCreated () noexcept
 
static TYPEget_SingleU () noexcept
 
static TYPEget_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleCast ()
 
static TYPEI () noexcept
 
- Static Public Member Functions inherited from Gray::cSingletonRegister
static void __stdcall ReleaseModule (HMODULE hMod)
 
- Static Public Member Functions inherited from Gray::cUnitTestCur
static bool __stdcall TestTypes ()
 
- Protected Member Functions inherited from Gray::cSingleton< cUnitTests >
 cSingleton (cUnitTests *pObject, const TYPEINFO_t &rAddrCode=typeid(cUnitTests)) noexcept
 
virtual ~cSingleton ()
 
- Protected Member Functions inherited from Gray::cSingletonStatic< TYPE >
 cSingletonStatic (TYPE *pObject) noexcept
 
virtual ~cSingletonStatic () noexcept
 
- Protected Member Functions inherited from Gray::cSingletonRegister
 cSingletonRegister (const TYPEINFO_t &rAddrCode) noexcept
 
virtual ~cSingletonRegister ()
 
void RegisterSingleton ()
 
- Protected Attributes inherited from Gray::cSingletonRegister
HMODULE m_hModuleLoaded
 What modules loaded this ? So singletons can be destroyed if DLL/SO unloads. More...
 
- Static Protected Attributes inherited from Gray::cSingletonStatic< TYPE >
static TYPEsm_pThe = nullptr
 pointer to the one and only object of this TYPE. ASSUME automatically init to = nullptr. More...
 

Detailed Description

Singleton class to hold the list of all unit tests registered. MUST use cSingleton and not cSingletonStatic to prevent C runtime load order problems.

Constructor & Destructor Documentation

◆ cUnitTests()

Gray::cUnitTests::cUnitTests ( )

Member Function Documentation

◆ FindUnitTest()

cUnitTestRegister * Gray::cUnitTests::FindUnitTest ( const char *  pszName) const

Find a single test by name.

◆ get_HeapPtr()

const void* Gray::cUnitTests::get_HeapPtr ( ) const
inlineoverridevirtualnoexcept

Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr().

Reimplemented from Gray::cHeapObject.

◆ get_TestInpDir()

const FILECHAR_t * Gray::cUnitTests::get_TestInpDir ( ) const

Get source of input files for tests. e.g. "C:\Dennis\Source\Gray\" or "C:\Dennis\Source\bin\x64v142"

◆ get_TestOutDir()

const FILECHAR_t * Gray::cUnitTests::get_TestOutDir ( ) const

Get a temporary directory for use by UnitTests

◆ InitTestOutDir()

HRESULT Gray::cUnitTests::InitTestOutDir ( )

◆ IsTestInteractive()

bool Gray::cUnitTests::IsTestInteractive ( ) const
noexcept

is a user expected to interact with or verify the output of the tests ?

◆ RegisterUnitTest()

bool Gray::cUnitTests::RegisterUnitTest ( cUnitTestRegister pTest)

◆ RunCleanup()

void Gray::cUnitTests::RunCleanup ( )

◆ RunInitialize()

void Gray::cUnitTests::RunInitialize ( )

◆ RunUnitTests()

HRESULT Gray::cUnitTests::RunUnitTests ( UNITTEST_LEVEL_TYPE  nTestLevel = UNITTEST_LEVEL_Common,
const LOGCHAR_t pszTestNameMatch = nullptr 
)

Run all tests <= this UNITTEST_LEVEL_TYPE.

Execute all the registered unit tests at the selected nTestLevel.

Note
assume each test is responsible for its own resources.
  • pszTestNameMatch = a name wildcard. possibly in a comma separated list. (or nullptr)

◆ SetTestLevel()

void Gray::cUnitTests::SetTestLevel ( UNITTEST_LEVEL_TYPE  nTestLevel)

◆ TestActive()

bool Gray::cUnitTests::TestActive ( const cUnitTestRegister pUnitTest,
bool  remove 
)

◆ TestInteractivePrompt()

bool Gray::cUnitTests::TestInteractivePrompt ( const char *  pszMsg)
noexcept

prompt the user to manually check some output from the test. require user to press key or button.

Returns
true = continue.

Friends And Related Function Documentation

◆ cUnitTestRegister

friend class cUnitTestRegister
friend

Member Data Documentation

◆ m_aTestNames

cArrayString<LOGCHAR_t> Gray::cUnitTests::m_aTestNames

◆ m_aUnitTests

cArrayPtr<cUnitTestRegister> Gray::cUnitTests::m_aUnitTests

list of all registered unit tests. Register as they get instantiate by C runtime static loader.

◆ m_bRunning

bool Gray::cUnitTests::m_bRunning

We are actively running in the Gray test framework. Not in M$ framework.

◆ m_iFailures

int Gray::cUnitTests::m_iFailures

Count total unit test failures.

◆ m_nTestLevel

UNITTEST_LEVEL_TYPE Gray::cUnitTests::m_nTestLevel

restore the original assert.

The current global test level for UnitTests(). throttle tests at run time.

◆ m_pAssertOrig

AssertCallback_t* Gray::cUnitTests::m_pAssertOrig

◆ m_pLog

cLogProcessor* Gray::cUnitTests::m_pLog

cLogMgr::I() for output of tests. Why not just use DEBUG_MSG ??

◆ m_sTestInpDir

cStringF Gray::cUnitTests::m_sTestInpDir

root for source of test input files. might change based on cOSModImpl?

◆ m_sTestOutDir

cStringF Gray::cUnitTests::m_sTestOutDir

global config for input files.

◆ UnitTest_AssertCallback

bool CALLBACK Gray::cUnitTests::UnitTest_AssertCallback
static

redirect assert here for test failure. requires _DEBUG or _DEBUG_FAST.

Assert was called during a unit test. This is a failure! Assume assert will log this. AssertCallback_t sm_pAssertCallback = cDebugAssert::Assert_Fail was called in UnitTest. GRAYCALL


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