mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-25 14:24:45 +00:00
engine: merge tests for imagelib
This commit is contained in:
parent
6ea25b8194
commit
91ee9bd32a
@ -581,6 +581,7 @@ fs_offset_t FS_FileLength( file_t *f );
|
|||||||
//
|
//
|
||||||
#include "com_image.h"
|
#include "com_image.h"
|
||||||
|
|
||||||
|
void Image_Setup( void );
|
||||||
void Image_Init( void );
|
void Image_Init( void );
|
||||||
void Image_Shutdown( void );
|
void Image_Shutdown( void );
|
||||||
void Image_AddCmdFlags( uint flags );
|
void Image_AddCmdFlags( uint flags );
|
||||||
|
@ -776,15 +776,19 @@ void Host_Userconfigd_f( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if XASH_ENGINE_TESTS
|
#if XASH_ENGINE_TESTS
|
||||||
static void Host_RunTests( void )
|
static void Host_RunTests( int stage )
|
||||||
{
|
{
|
||||||
memset( &tests_stats, 0, sizeof( tests_stats ));
|
switch( stage )
|
||||||
|
{
|
||||||
Test_RunLibCommon();
|
case 0: // early engine load
|
||||||
|
memset( &tests_stats, 0, sizeof( tests_stats ));
|
||||||
Msg( "Done! %d passed, %d failed\n", tests_stats.passed, tests_stats.failed );
|
Test_RunLibCommon();
|
||||||
|
break;
|
||||||
Sys_Quit();
|
case 1: // after FS load
|
||||||
|
Test_RunImagelib();
|
||||||
|
Msg( "Done! %d passed, %d failed\n", tests_stats.passed, tests_stats.failed );
|
||||||
|
Sys_Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -923,7 +927,7 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
|||||||
|
|
||||||
#if XASH_ENGINE_TESTS
|
#if XASH_ENGINE_TESTS
|
||||||
if( Sys_CheckParm( "-runtests" ))
|
if( Sys_CheckParm( "-runtests" ))
|
||||||
Host_RunTests();
|
Host_RunTests( 0 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Platform_Init();
|
Platform_Init();
|
||||||
@ -991,6 +995,11 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
|||||||
Image_Init();
|
Image_Init();
|
||||||
Sound_Init();
|
Sound_Init();
|
||||||
|
|
||||||
|
#if XASH_ENGINE_TESTS
|
||||||
|
if( Sys_CheckParm( "-runtests" ))
|
||||||
|
Host_RunTests( 1 );
|
||||||
|
#endif
|
||||||
|
|
||||||
FS_LoadGameInfo( NULL );
|
FS_LoadGameInfo( NULL );
|
||||||
Q_strncpy( host.gamefolder, GI->gamefolder, sizeof( host.gamefolder ));
|
Q_strncpy( host.gamefolder, GI->gamefolder, sizeof( host.gamefolder ));
|
||||||
|
|
||||||
|
@ -491,3 +491,78 @@ rgbdata_t *FS_CopyImage( rgbdata_t *in )
|
|||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if XASH_ENGINE_TESTS
|
||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
static void GeneratePixel( byte *pix, uint i, uint j, uint w, uint h, qboolean genAlpha )
|
||||||
|
{
|
||||||
|
double x = ( j / (double)w ) - 0.5;
|
||||||
|
double y = ( i / (double)h ) - 0.5;
|
||||||
|
double d = sqrt( x * x + y * y );
|
||||||
|
pix[0] = (byte)(( sin( d * 30.0 ) + 1.0 ) * 126 );
|
||||||
|
pix[1] = (byte)(( sin( d * 27.723 ) + 1.0 ) * 126 );
|
||||||
|
pix[2] = (byte)(( sin( d * 42.41 ) + 1.0 ) * 126 );
|
||||||
|
pix[3] = genAlpha ? (byte)(( cos( d * 2.0 ) + 1.0 ) * 126 ) : 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test_CheckImage( const char *name, rgbdata_t *rgb )
|
||||||
|
{
|
||||||
|
rgbdata_t *load;
|
||||||
|
|
||||||
|
// test reading
|
||||||
|
load = FS_LoadImage( name, NULL, 0 );
|
||||||
|
TASSERT( load->width == rgb->width )
|
||||||
|
TASSERT( load->height == rgb->height )
|
||||||
|
TASSERT( load->type == rgb->type )
|
||||||
|
TASSERT( ( load->flags & rgb->flags ) != 0 )
|
||||||
|
TASSERT( load->size == rgb->size )
|
||||||
|
TASSERT( memcmp(load->buffer, rgb->buffer, rgb->size ) == 0 )
|
||||||
|
|
||||||
|
Mem_Free( load );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test_RunImagelib( void )
|
||||||
|
{
|
||||||
|
rgbdata_t rgb = { 0 };
|
||||||
|
byte *buf;
|
||||||
|
const char *extensions[] = { "tga", "png", "bmp" };
|
||||||
|
uint i, j;
|
||||||
|
|
||||||
|
Image_Setup();
|
||||||
|
|
||||||
|
// generate image
|
||||||
|
rgb.width = 256;
|
||||||
|
rgb.height = 512;
|
||||||
|
rgb.type = PF_RGBA_32;
|
||||||
|
rgb.flags = IMAGE_HAS_ALPHA;
|
||||||
|
rgb.size = rgb.width * rgb.height * 4;
|
||||||
|
buf = rgb.buffer = Z_Malloc( rgb.size );
|
||||||
|
|
||||||
|
for( i = 0; i < rgb.height; i++ )
|
||||||
|
{
|
||||||
|
for( j = 0; j < rgb.width; j++ )
|
||||||
|
{
|
||||||
|
GeneratePixel( buf, i, j, rgb.width, rgb.height, true );
|
||||||
|
buf += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( i = 0; i < sizeof(extensions) / sizeof(extensions[0]); i++ )
|
||||||
|
{
|
||||||
|
const char *name = va( "test_gen.%s", extensions[i] );
|
||||||
|
|
||||||
|
// test saving
|
||||||
|
qboolean ret = FS_SaveImage( name, &rgb );
|
||||||
|
Con_Printf( "Checking if we can save images in '%s' format...\n", extensions[i] );
|
||||||
|
ASSERT(ret == true);
|
||||||
|
|
||||||
|
// test reading
|
||||||
|
Con_Printf( "Checking if we can read images in '%s' format...\n", extensions[i] );
|
||||||
|
Test_CheckImage( name, &rgb );
|
||||||
|
}
|
||||||
|
|
||||||
|
Z_Free( rgb.buffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* XASH_ENGINE_TESTS */
|
||||||
|
@ -139,6 +139,13 @@ static const savepixformat_t save_game[] =
|
|||||||
{ NULL, NULL, NULL }
|
{ NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void Image_Setup( void )
|
||||||
|
{
|
||||||
|
image.cmd_flags = IL_USE_LERPING|IL_ALLOW_OVERWRITE;
|
||||||
|
image.loadformats = load_game;
|
||||||
|
image.saveformats = save_game;
|
||||||
|
}
|
||||||
|
|
||||||
void Image_Init( void )
|
void Image_Init( void )
|
||||||
{
|
{
|
||||||
// init pools
|
// init pools
|
||||||
@ -148,9 +155,7 @@ void Image_Init( void )
|
|||||||
switch( host.type )
|
switch( host.type )
|
||||||
{
|
{
|
||||||
case HOST_NORMAL:
|
case HOST_NORMAL:
|
||||||
image.cmd_flags = IL_USE_LERPING|IL_ALLOW_OVERWRITE;
|
Image_Setup( );
|
||||||
image.loadformats = load_game;
|
|
||||||
image.saveformats = save_game;
|
|
||||||
break;
|
break;
|
||||||
case HOST_DEDICATED:
|
case HOST_DEDICATED:
|
||||||
image.cmd_flags = 0;
|
image.cmd_flags = 0;
|
||||||
|
@ -17,10 +17,11 @@ extern struct tests_stats_s tests_stats;
|
|||||||
if(!( exp )) \
|
if(!( exp )) \
|
||||||
{ \
|
{ \
|
||||||
tests_stats.failed++; \
|
tests_stats.failed++; \
|
||||||
Msg( "assert failed at %s:%i\n", __FILE__, __LINE__ ) \
|
Msg( "assert failed at %s:%i\n", __FILE__, __LINE__ ); \
|
||||||
} \
|
} \
|
||||||
else tests_stats.passed++;
|
else tests_stats.passed++;
|
||||||
|
|
||||||
|
void Test_RunImagelib( void );
|
||||||
void Test_RunLibCommon( void );
|
void Test_RunLibCommon( void );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
#include "unittest.h"
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
TEST_FIRST(helloworld)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST3(hw2, helloworld, "Hello, World")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(nonsense, hw2)
|
|
||||||
{
|
|
||||||
if( !( sin( 0 ) != 0.0 ))
|
|
||||||
_self->status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(sense, nonsense)
|
|
||||||
{
|
|
||||||
if( !( sin( 0 ) == 0.0 ) )
|
|
||||||
_self->status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
IMPLEMENT_MAIN(sense, "self-testing")
|
|
Loading…
x
Reference in New Issue
Block a user