mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-07 21:10:46 +08:00
engine: add simple unit-testing (v3?)
This commit is contained in:
@@ -40,12 +40,16 @@ GNU General Public License for more details.
|
||||
#include "input.h"
|
||||
#include "enginefeatures.h"
|
||||
#include "render_api.h" // decallist_t
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
pfnChangeGame pChangeGame = NULL;
|
||||
host_parm_t host; // host parms
|
||||
sysinfo_t SI;
|
||||
|
||||
#ifdef XASH_ENGINE_TESTS
|
||||
struct tests_stats_s tests_stats;
|
||||
#endif
|
||||
|
||||
CVAR_DEFINE( host_developer, "developer", "0", 0, "engine is in development-mode" );
|
||||
CVAR_DEFINE_AUTO( sys_ticrate, "100", 0, "framerate in dedicated mode" );
|
||||
|
||||
@@ -771,6 +775,19 @@ void Host_Userconfigd_f( void )
|
||||
Mem_Free( t );
|
||||
}
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
static void Host_RunTests( void )
|
||||
{
|
||||
memset( &tests_stats, 0, sizeof( tests_stats ));
|
||||
|
||||
Test_RunLibCommon();
|
||||
|
||||
Msg( "Done! %d passed, %d failed\n", tests_stats.passed, tests_stats.failed );
|
||||
|
||||
Sys_Quit();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================
|
||||
Host_InitCommon
|
||||
@@ -827,6 +844,14 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
}
|
||||
}
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
if( Sys_CheckParm( "-runtests" ))
|
||||
{
|
||||
host.allow_console = true;
|
||||
developer = DEV_EXTENDED;
|
||||
}
|
||||
#endif
|
||||
|
||||
host.con_showalways = true;
|
||||
|
||||
#if XASH_DEDICATED
|
||||
@@ -896,6 +921,11 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
|
||||
Con_Init(); // early console running to catch all the messages
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
if( Sys_CheckParm( "-runtests" ))
|
||||
Host_RunTests();
|
||||
#endif
|
||||
|
||||
Platform_Init();
|
||||
|
||||
baseDir = getenv( "XASH3D_BASEDIR" );
|
||||
|
||||
28
engine/common/tests.h
Normal file
28
engine/common/tests.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef TESTS_H
|
||||
#define TESTS_H
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
|
||||
struct tests_stats_s
|
||||
{
|
||||
uint passed;
|
||||
uint failed;
|
||||
};
|
||||
|
||||
extern struct tests_stats_s tests_stats;
|
||||
|
||||
#define TRUN( x ) Msg( "Running " #x "\n" ); x
|
||||
|
||||
#define TASSERT( exp ) \
|
||||
if(!( exp )) \
|
||||
{ \
|
||||
tests_stats.failed++; \
|
||||
Msg( "assert failed at %s:%i\n", __FILE__, __LINE__ ) \
|
||||
} \
|
||||
else tests_stats.passed++;
|
||||
|
||||
void Test_RunLibCommon( void );
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* TESTS_H */
|
||||
Reference in New Issue
Block a user