Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
unitTestCommon.cpp
Go to the documentation of this file.
1#include "unitTestCommon.h"
2
5
6#if defined( ENGINE_TESTS )
8#endif //ENGINE_TESTS
9
10#include <iostream>
11
12namespace
13{
14#if defined(PLATFORM_TESTS)
15 const char* TARGET_NAME_STR = "Platform";
16#elif defined(ENGINE_TESTS)
17 const char* TARGET_NAME_STR = "Engine";
18#else
19#error "Unknow UT build target!";
20#endif
21}
22
24
26{
27 using namespace Divide;
28
29 if ( !PLATFORM_INIT )
30 {
31 std::cout << Util::StringFormat( "[ {} ]: Init platform code for unit test run\n", TARGET_NAME_STR );
32 const char* data[] = { "--disableCopyright" };
33 ErrorCode err = Divide::PlatformInit( 1, const_cast<char**>(data) );
34
35 if ( err != ErrorCode::NO_ERR )
36 {
37 std::cout << Util::StringFormat( "[ {} ]: Platform init error! [ {} ]", TARGET_NAME_STR, TypeUtil::ErrorCodeToString( err ) );
38 }
39
40#if defined( ENGINE_TESTS )
41 Script::OnStartup();
42#endif //ENGINE_TESTS
43
44 PLATFORM_INIT = true;
45 }
46}
47
48void platformInitRunListener::testRunStarting( Catch::TestRunInfo const& )
49{
50 using namespace Divide;
51
52 if ( _testTimer == nullptr)
53 {
54 _testTimer = &Divide::Time::ADD_TIMER( "Unit Tests" );
55 }
56
57 std::cout << Util::StringFormat( "[ {} ]: Running unit tests.\n", TARGET_NAME_STR );
58
60
61}
62
63void platformInitRunListener::testRunEnded( Catch::TestRunStats const& )
64{
65 using namespace Divide;
66
68 std::cout << Util::StringFormat( "[ {} ]: Finished running UTs in [ {:5.2f} ] ms. \n", TARGET_NAME_STR, Divide::Time::MicrosecondsToMilliseconds<float>( Divide::Time::QUERY_TIMER( *_testTimer ) ) );
69 if ( _testTimer != nullptr )
70 {
72 }
73
74#if defined( ENGINE_TESTS )
75 Script::OnShutdown();
76#endif //ENGINE_TESTS
77
78 if ( PLATFORM_INIT && !PlatformClose() )
79 {
80 std::cout << Util::StringFormat( "[ {} ]: Platform close error!\n", TARGET_NAME_STR );
81 PLATFORM_INIT = false;
82 }
83
84 std::cout << Util::StringFormat( "[ {} ]: Shuting down ...\n", TARGET_NAME_STR );
85}
void testRunStarting(Catch::TestRunInfo const &) override
Divide::Time::ProfileTimer * _testTimer
void testRunEnded(Catch::TestRunStats const &) override
void REMOVE_TIMER(ProfileTimer *&timer)
U64 QUERY_TIMER(const ProfileTimer &timer) noexcept
void START_TIMER(ProfileTimer &timer) noexcept
ProfileTimer & ADD_TIMER(const char *timerName)
void STOP_TIMER(ProfileTimer &timer) noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
ErrorCode PlatformInit(int argc, char **argv)