OpenBarnyard
 
Loading...
Searching...
No Matches
T2TestingFramework Class Reference

#include <T2TestingFramework.h>

Classes

struct  Category
 
struct  Check
 
struct  Test
 
class  TestAutoReg
 

Public Types

using TestMethod_t = void ( * )()
 
using FailCallback_t = void ( * )( Test* a_pTest, Check* a_pCheck )
 
using SuccessCallback_t = void ( * )( Test* a_pTest, Check* a_pCheck )
 

Public Member Functions

 T2TestingFramework ()=default
 
 ~T2TestingFramework ()=default
 
CategoryFindCategory (const TCHAR *a_pchName)
 
CategoryRegisterCategory (const TCHAR *a_pchName)
 
TestRegisterTest (const TCHAR *a_pchTestName, Category *a_pCategory, TestMethod_t a_fnMethod)
 
TINT RunTests (FailCallback_t a_fnFailCallback=TNULL, SuccessCallback_t a_fnSuccessCallback=TNULL)
 
void SignalRequirementResult (Test *a_pTest, const TCHAR *a_pchFileName, TINT a_iLineNum, const TCHAR *a_pchStatement, TBOOL a_bFailed)
 
TestGetCurrentTest () const
 

Detailed Description

Definition at line 20 of file T2TestingFramework.h.

Member Typedef Documentation

◆ FailCallback_t

using T2TestingFramework::FailCallback_t = void ( * )( Test* a_pTest, Check* a_pCheck )

Definition at line 61 of file T2TestingFramework.h.

◆ SuccessCallback_t

using T2TestingFramework::SuccessCallback_t = void ( * )( Test* a_pTest, Check* a_pCheck )

Definition at line 62 of file T2TestingFramework.h.

◆ TestMethod_t

using T2TestingFramework::TestMethod_t = void ( * )()

Definition at line 23 of file T2TestingFramework.h.

Constructor & Destructor Documentation

◆ T2TestingFramework()

T2TestingFramework::T2TestingFramework ( )
default

◆ ~T2TestingFramework()

T2TestingFramework::~T2TestingFramework ( )
default

Member Function Documentation

◆ FindCategory()

T2TestingFramework::Category * T2TestingFramework::FindCategory ( const TCHAR * a_pchName)

Definition at line 45 of file T2TestingFramework.cpp.

46{
47 Category* pCategory = m_pHeadCategory;
48
49 while ( pCategory )
50 {
51 if ( !strcmp( pCategory->pchName, a_pchName ) )
52 return pCategory;
53
54 pCategory = pCategory->pNext;
55 }
56
57 return TNULL;
58}
#define TNULL
Definition Typedefs.h:23

◆ GetCurrentTest()

Test * T2TestingFramework::GetCurrentTest ( ) const
inline

Definition at line 85 of file T2TestingFramework.h.

85{ return m_pCurrentTest; }

◆ RegisterCategory()

T2TestingFramework::Category * T2TestingFramework::RegisterCategory ( const TCHAR * a_pchName)

Definition at line 60 of file T2TestingFramework.cpp.

61{
62 Category* pCategory = FindCategory( a_pchName );
63
64 if ( !pCategory )
65 {
66 pCategory = New<Category>();
67 pCategory->pchName = a_pchName;
68 pCategory->pNext = m_pHeadCategory;
69
70 m_pHeadCategory = pCategory;
71 }
72
73 return pCategory;
74}
Category * FindCategory(const TCHAR *a_pchName)

◆ RegisterTest()

T2TestingFramework::Test * T2TestingFramework::RegisterTest ( const TCHAR * a_pchTestName,
Category * a_pCategory,
TestMethod_t a_fnMethod )

Definition at line 76 of file T2TestingFramework.cpp.

77{
78 if ( !a_pCategory )
79 return TNULL;
80
81 Test* pTest = New<Test>();
82 pTest->pchName = a_pchTestName;
83 pTest->pCategory = a_pCategory;
84 pTest->fnMethod = a_fnMethod;
85 pTest->pNext = a_pCategory->pHeadTest;
86
87 a_pCategory->pHeadTest = pTest;
88
89 return pTest;
90}

◆ RunTests()

TINT T2TestingFramework::RunTests ( FailCallback_t a_fnFailCallback = TNULL,
SuccessCallback_t a_fnSuccessCallback = TNULL )

Definition at line 122 of file T2TestingFramework.cpp.

123{
124 TINT iNumFails = 0;
125 Category* pCategory = m_pHeadCategory;
126
127 // Update callbacks
128 g_fnFailCallback = a_fnFailCallback;
129 g_fnSuccessCallback = a_fnSuccessCallback;
130
131 while ( pCategory )
132 {
133 Test* pTest = pCategory->pHeadTest;
134
135 while ( pTest )
136 {
137 if ( !pTest->bWasExecuted )
138 {
139 // Run the actual test
140 m_pCurrentTest = pTest;
141
142 pTest->fnMethod();
143 pTest->bWasExecuted = TTRUE;
144
145 // Count number of fails
146 iNumFails += pTest->iNumFails;
147 pCategory->iNumTotalFails += pTest->iNumFails;
148 }
149
150 m_pCurrentTest = TNULL;
151 pTest = pTest->pNext;
152 }
153
154 pCategory = pCategory->pNext;
155 }
156
157 // Reset callbacks
160
161 return iNumFails;
162}
int TINT
Definition Typedefs.h:7
#define TTRUE
Definition Typedefs.h:25
T2TestingFramework::SuccessCallback_t g_fnSuccessCallback
T2TestingFramework::FailCallback_t g_fnFailCallback

◆ SignalRequirementResult()

void T2TestingFramework::SignalRequirementResult ( Test * a_pTest,
const TCHAR * a_pchFileName,
TINT a_iLineNum,
const TCHAR * a_pchStatement,
TBOOL a_bFailed )

Definition at line 95 of file T2TestingFramework.cpp.

96{
97 if ( !a_pTest )
98 return;
99
100 Check* pCheck = New<Check>();
101 pCheck->pchFileName = a_pchFileName;
102 pCheck->pchStatement = a_pchStatement;
103 pCheck->iLineNum = a_iLineNum;
104 pCheck->bFailed = a_bFailed;
105 pCheck->pNext = a_pTest->pHeadCheck;
106
107 a_pTest->pHeadCheck = pCheck;
108
109 if ( a_bFailed )
110 {
111 a_pTest->iNumFails += 1;
112
113 if ( g_fnFailCallback )
114 g_fnFailCallback( a_pTest, pCheck );
115 }
116 else if ( g_fnSuccessCallback )
117 {
118 g_fnSuccessCallback( a_pTest, pCheck );
119 }
120}

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