This repository was archived by the owner on Mar 24, 2025. It is now read-only.
forked from fastbuild/fastbuild
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUnitTestManager.h
65 lines (52 loc) · 2.04 KB
/
UnitTestManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// UnitTestManager
//------------------------------------------------------------------------------
#pragma once
// Includes
//------------------------------------------------------------------------------
#include "Core/Env/Assert.h"
#include "Core/Env/Types.h"
#include "Core/Time/Timer.h"
// Forward Declarations
//------------------------------------------------------------------------------
class UnitTest;
// UnitTestManager
//------------------------------------------------------------------------------
class UnitTestManager
{
public:
UnitTestManager();
~UnitTestManager();
// run all tests, or tests from a group
bool RunTests( const char * testGroup = nullptr );
// singleton behaviour
#ifdef RELEASE
static inline UnitTestManager & Get() { return *s_Instance; }
#else
static UnitTestManager & Get();
#endif
static inline bool IsValid() { return ( s_Instance != 0 ); }
// tests register (using the test declaration macros) via this interface
static void RegisterTestGroup( UnitTest * testGroup );
// When tests are being executed, they are wrapped with these
void TestBegin( UnitTest * testGroup, const char * testName );
void TestEnd();
// TEST_ASSERT uses this interface to notify of assertion failures
static bool AssertFailure( const char * message, const char * file, uint32_t line );
private:
Timer m_Timer;
enum : uint32_t { MAX_TESTS = 1024 };
struct TestInfo
{
TestInfo() :m_TestGroup( nullptr ), m_TestName( nullptr ), m_Passed( false ), m_MemoryLeaks( false ), m_TimeTaken( 0.0f ) {}
UnitTest * m_TestGroup;
const char * m_TestName;
bool m_Passed;
bool m_MemoryLeaks;
float m_TimeTaken;
};
static uint32_t s_NumTests;
static TestInfo s_TestInfos[ MAX_TESTS ];
static UnitTestManager * s_Instance;
static UnitTest * s_FirstTest;
};
//------------------------------------------------------------------------------