OpenBarnyard
 
Loading...
Searching...
No Matches
T2TestingFramework.h
Go to the documentation of this file.
1#pragma once
2
3#define T2_TEST1( TEST_NAME, CATEGORY_NAME, TEST_ID ) \
4 namespace JustMakingSureTheMacroIsCalledOutsideOfAnyMethod \
5 {} \
6 void CONCATTOKEN( s_T2TestingFrameworkTest_, TEST_ID )(); \
7 static Toshi::T2TestingFramework::TestAutoReg CONCATTOKEN( s_T2TestingFrameworkAutoReg_, TEST_ID )( TEST_NAME, CATEGORY_NAME, CONCATTOKEN( s_T2TestingFrameworkTest_, TEST_ID ) ); \
8 void CONCATTOKEN( s_T2TestingFrameworkTest_, TEST_ID )()
9
10#define T2_TEST( TEST_NAME, CATEGORY_NAME ) T2_TEST1( TEST_NAME, CATEGORY_NAME, __COUNTER__ )
11
12#define T2_TEST_REQUIRE( STATEMENT ) \
13 { \
14 volatile TBOOL __bCheckResult = ( STATEMENT ); \
15 g_pTestingFramework->SignalRequirementResult( g_pTestingFramework->GetCurrentTest(), __FILE__, __LINE__, #STATEMENT, !__bCheckResult ); \
16 }
17
19
21{
22public:
23 using TestMethod_t = void ( * )();
24
26 {
27 public:
28 TestAutoReg( const TCHAR* a_pchTestName, const TCHAR* a_pchCategoryName, TestMethod_t a_fnMethod );
29 };
30
31 struct Test;
32
40
41 struct Check
42 {
46 TINT iLineNum : 31 = -1;
48 };
49
60
61 using FailCallback_t = void ( * )( Test* a_pTest, Check* a_pCheck );
62 using SuccessCallback_t = void ( * )( Test* a_pTest, Check* a_pCheck );
63
64public:
65 // constructors/destructor
66 T2TestingFramework() = default;
68
69 // Returns pointer to a category if it exists or TNULL if it doesn't
70 Category* FindCategory( const TCHAR* a_pchName );
71
72 // Registers a category if it doesn't exist and returns it
73 Category* RegisterCategory( const TCHAR* a_pchName );
74
75 // Registers a test in a category and returns it
76 Test* RegisterTest( const TCHAR* a_pchTestName, Category* a_pCategory, TestMethod_t a_fnMethod );
77
78 // Runs all incomplete tests and returns total number of fails
79 TINT RunTests( FailCallback_t a_fnFailCallback = TNULL, SuccessCallback_t a_fnSuccessCallback = TNULL );
80
81 // Saves info about results of a T2_TEST_REQUIRE call
82 void SignalRequirementResult( Test* a_pTest, const TCHAR* a_pchFileName, TINT a_iLineNum, const TCHAR* a_pchStatement, TBOOL a_bFailed );
83
84 // Returns the currently running test or TNULL if no test is run
85 Test* GetCurrentTest() const { return m_pCurrentTest; }
86
87private:
88 Category* m_pHeadCategory = TNULL;
89 Test* m_pCurrentTest = TNULL;
90};
91
93
#define TOSHI_API
Definition Defines.h:41
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
bool TBOOL
Definition Typedefs.h:6
T2TestingFramework * g_pTestingFramework
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)
void(*)(Test *a_pTest, Check *a_pCheck) SuccessCallback_t
Category * FindCategory(const TCHAR *a_pchName)
Test * GetCurrentTest() const
Test * RegisterTest(const TCHAR *a_pchTestName, Category *a_pCategory, TestMethod_t a_fnMethod)
void(*)(Test *a_pTest, Check *a_pCheck) FailCallback_t
T2TestingFramework()=default
Category * RegisterCategory(const TCHAR *a_pchName)
~T2TestingFramework()=default
TestAutoReg(const TCHAR *a_pchTestName, const TCHAR *a_pchCategoryName, TestMethod_t a_fnMethod)