tests: first draft with imagelib save/load testing. Breaks engine as we disable -fvisibility=hidden and singlebinary for dedicated mode

This commit is contained in:
Alibek Omarov 2020-11-22 19:04:56 +03:00
parent eb652d53ac
commit c103b7e345
8 changed files with 163 additions and 6 deletions

View File

@ -580,6 +580,7 @@ fs_offset_t FS_FileLength( file_t *f );
#include "com_image.h"
void Image_Init( void );
void Image_Setup( void ); // for unittesting
void Image_Shutdown( void );
void Image_AddCmdFlags( uint flags );
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size );
@ -679,6 +680,7 @@ typedef void( *pfnChangeGame )( const char *progname );
qboolean Host_IsQuakeCompatible( void );
void EXPORT Host_Shutdown( void );
int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGame, pfnChangeGame func );
void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bChangeGame );
int Host_CompareFileTime( int ft1, int ft2 );
void Host_NewInstance( const char *name, const char *finalmsg );
void Host_EndGame( qboolean abort, const char *message, ... ) _format( 2 );

View File

@ -2006,7 +2006,6 @@ void FS_LoadGameInfo( const char *rootfolder )
FS_Rescan(); // create new filesystem
Image_CheckPaletteQ1 ();
Host_InitDecals (); // reload decals
}
/*

View File

@ -998,6 +998,8 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa
Host_InitCommon( argc, argv, progname, bChangeGame );
Host_InitDecals (); // reload decals, was in filesystem init
// init commands and vars
if( host_developer.value >= DEV_EXTENDED )
{

View File

@ -148,9 +148,7 @@ void Image_Init( void )
switch( host.type )
{
case HOST_NORMAL:
image.cmd_flags = IL_USE_LERPING|IL_ALLOW_OVERWRITE;
image.loadformats = load_game;
image.saveformats = save_game;
Image_Setup();
break;
case HOST_DEDICATED:
image.cmd_flags = 0;
@ -167,6 +165,13 @@ void Image_Init( void )
image.tempbuffer = NULL;
}
void Image_Setup( void )
{
image.cmd_flags = IL_USE_LERPING|IL_ALLOW_OVERWRITE;
image.loadformats = load_game;
image.saveformats = save_game;
}
void Image_Shutdown( void )
{
Mem_Check(); // check for leaks

23
tests/gameinfo.txt Normal file
View File

@ -0,0 +1,23 @@
// generated by Xash3D FWGS 0.20-f60c398-dirty (linux-i386)
basedir "tests"
gamedir "tests"
title "New Game"
startmap "c0a0"
trainmap "t0a0"
version 1
dllpath "cl_dlls"
gamedll "dlls/hl.dll"
gamedll_linux "dlls/hl.so"
gamedll_osx "dlls/hl.dylib"
icon "game.ico"
sp_entity "info_player_start"
mp_entity "info_player_deathmatch"
max_edicts 900
max_tempents 500
max_beams 128
max_particles 4096

84
tests/test_imagelib.c Normal file
View File

@ -0,0 +1,84 @@
#include "common.h"
#include "eiface.h"
#include "imagelib.h"
#include "xash3d_mathlib.h"
#include "img_tga.h"
void GeneratePixel( byte *pix, int i, int j, int w, int h, qboolean genAlpha )
{
float x = (j/(float)w)-0.5f;
float y = (i/(float)h)-0.5f;
float d = sqrt(x*x+y*y);
pix[0] = (sin(d*30.0f)+1.0f)*126;
pix[1] = (sin(d*27.723f)+1.0f)*126;
pix[2] = (sin(d*42.41f)+1.0f)*126;
pix[3] = genAlpha ? (cos(d*2.0f)+1.0f)*126 : 255;
}
void Test_CheckImage( const char *name, rgbdata_t *rgb )
{
int i, j;
rgbdata_t *load;
byte *buf;
// test reading
load = FS_LoadImage( name, NULL, 0 );
ASSERT( load->width == rgb->width );
ASSERT( load->height == rgb->height );
ASSERT( load->type == rgb->type );
ASSERT( (load->flags & rgb->flags) != 0 );
ASSERT( load->size == rgb->size );
ASSERT( memcmp(load->buffer, rgb->buffer, rgb->size ) == 0 );
Con_Printf("Loaded %s -- OK\n", name );
Mem_Free( load );
}
int main( int argc, char **argv )
{
int i, j;
rgbdata_t rgb = { 0 };
byte *buf;
const char *extensions[] = { "tga", "png", "bmp" };
// 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 = 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;
}
}
// init engine
Host_InitCommon( argc, argv, "tests", false );
// initialize normal imagelib
Image_Setup();
for( i = 0; i < ARRAYSIZE(extensions); i++ )
{
const char *name = va( "test_gen.%s", extensions[i] );
// test saving
qboolean ret = FS_SaveImage( name, &rgb );
Con_Printf("Save %s -- %s\n", name, ret ? "OK" : "FAIL");
ASSERT(ret == true);
// test reading
Test_CheckImage( name, &rgb );
}
free( rgb.buffer );
Host_Shutdown();
return 0;
}

41
tests/wscript Normal file
View File

@ -0,0 +1,41 @@
#! /usr/bin/env python
# encoding: utf-8
# mittorn, 2018
from waflib import Logs
import os
top = '.'
def options(opt):
opt.load('waf_unit_test')
# stub
return
def configure(conf):
conf.load('waf_unit_test')
if conf.options.SUPPORT_BSP2_FORMAT:
conf.env.append_unique('DEFINES', 'SUPPORT_BSP2_FORMAT')
conf.env.append_unique('DEFINES', 'UNITTEST')
def build(bld):
libs = [ 'public', 'xash', 'M' ]
includes = ['.',
'../engine',
'../engine/common',
'../engine/common/imagelib',
'../engine/common/soundlib',
'../engine/server',
'../engine/client',
'../public',
'../common',
'../pm_shared' ]
bld.program(features='c',
includes = includes,
use = libs,
subsystem = bld.env.MSVC_SUBSYSTEM,
source = 'test_imagelib.c',
target = 'test_imagelib')

View File

@ -55,6 +55,7 @@ SUBDIRS = [
Subproject('stub/server', dedicated=False),
Subproject('stub/client'),
Subproject('dllemu'),
Subproject('tests', dedicated=False),
Subproject('engine', dedicated=False),
]
@ -219,7 +220,7 @@ def configure(conf):
# disable thread-safe local static initialization for C++11 code, as it cause crashes on Windows XP
'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS', '/Zc:threadSafeInit-', '/MT'],
'clang': ['-g', '-gdwarf-2', '-fvisibility=hidden'],
'gcc': ['-g', '-fvisibility=hidden'],
'gcc': ['-g'],
'owcc': ['-fno-short-enum', '-ffloat-store', '-g3']
},
'fast': {
@ -361,7 +362,7 @@ def configure(conf):
conf.define('STDINT_H', 'pstdint.h')
conf.env.DEDICATED = conf.options.DEDICATED
conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY or conf.env.DEDICATED
conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY # or conf.env.DEDICATED
if conf.env.DEST_OS == 'dos':
conf.env.SINGLE_BINARY = True