mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-11-22 01:45:19 +01:00
filesystem: add caseinsensitive emulation test
This commit is contained in:
parent
c454e37064
commit
2febe632c5
122
filesystem/tests/caseinsensitive.c
Normal file
122
filesystem/tests/caseinsensitive.c
Normal file
@ -0,0 +1,122 @@
|
||||
#include "port.h"
|
||||
#include "build.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "filesystem.h"
|
||||
#if XASH_POSIX
|
||||
#include <dlfcn.h>
|
||||
#define LoadLibrary( x ) dlopen( x, RTLD_NOW )
|
||||
#define GetProcAddress( x, y ) dlsym( x, y )
|
||||
#define FreeLibrary( x ) dlclose( x )
|
||||
#elif XASH_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void *g_hModule;
|
||||
FSAPI g_pfnGetFSAPI;
|
||||
fs_api_t g_fs;
|
||||
fs_globals_t *g_nullglobals;
|
||||
|
||||
|
||||
static qboolean LoadFilesystem( void )
|
||||
{
|
||||
g_hModule = LoadLibrary( "filesystem_stdio." OS_LIB_EXT );
|
||||
if( !g_hModule )
|
||||
return false;
|
||||
|
||||
g_pfnGetFSAPI = (void*)GetProcAddress( g_hModule, GET_FS_API );
|
||||
if( !g_pfnGetFSAPI )
|
||||
return false;
|
||||
|
||||
if( !g_pfnGetFSAPI( FS_API_VERSION, &g_fs, &g_nullglobals, NULL ))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static qboolean CheckFileContents( const char *path, const void *buf, fs_offset_t size )
|
||||
{
|
||||
fs_offset_t len;
|
||||
byte *data;
|
||||
|
||||
data = g_fs.LoadFile( path, &len, true );
|
||||
if( !data )
|
||||
{
|
||||
printf( "LoadFile fail\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( len != size )
|
||||
{
|
||||
printf( "LoadFile sizeof fail\n" );
|
||||
free( data );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( memcmp( data, buf, size ))
|
||||
{
|
||||
printf( "LoadFile magic fail\n" );
|
||||
free( data );
|
||||
return false;
|
||||
}
|
||||
|
||||
free( data );
|
||||
return true;
|
||||
}
|
||||
|
||||
static qboolean TestCaseinsensitive( void )
|
||||
{
|
||||
file_t *f1;
|
||||
FILE *f2;
|
||||
int magic = rand();
|
||||
|
||||
// create game dir for us
|
||||
g_fs.AddGameDirectory( "./", FS_GAMEDIR_PATH );
|
||||
|
||||
// create some files first and write data
|
||||
f1 = g_fs.Open( "FOO/Bar.bin", "wb", true );
|
||||
g_fs.Write( f1, &magic, sizeof( magic ));
|
||||
g_fs.Close( f1 );
|
||||
|
||||
// try to search it with different file name
|
||||
if( !g_fs.FileExists( "fOO/baR.bin", true ))
|
||||
{
|
||||
printf( "FileExists fail\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// create a file directly, to check if cache can re-read
|
||||
f2 = fopen( "FOO/Baz.bin", "wb" );
|
||||
fwrite( &magic, sizeof( magic ), 1, f2 );
|
||||
fclose( f2 );
|
||||
|
||||
// try to open first file back but with different file name case
|
||||
if( !CheckFileContents( "foo/bar.BIN", &magic, sizeof( magic )))
|
||||
return false;
|
||||
|
||||
// try to open second file that we created directly
|
||||
if( !CheckFileContents( "Foo/BaZ.Bin", &magic, sizeof( magic )))
|
||||
return false;
|
||||
|
||||
g_fs.Delete( "foo/Baz.biN" );
|
||||
g_fs.Delete( "foo/bar.bin" );
|
||||
g_fs.Delete( "Foo" );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main( void )
|
||||
{
|
||||
if( !LoadFilesystem() )
|
||||
return EXIT_FAILURE;
|
||||
|
||||
srand( time( NULL ));
|
||||
|
||||
if( !TestCaseinsensitive())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
printf( "success\n" );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from waflib.Tools import waf_unit_test
|
||||
|
||||
def options(opt):
|
||||
pass
|
||||
grp = opt.add_option_group('filesystem_stdio options')
|
||||
|
||||
grp.add_option('--enable-fs-tests', action='store_true', dest = 'FS_TESTS', default = False,
|
||||
help = 'enable filesystem_stdio tests')
|
||||
|
||||
def configure(conf):
|
||||
nortti = {
|
||||
@ -10,6 +15,8 @@ def configure(conf):
|
||||
}
|
||||
conf.env.append_unique('CXXFLAGS', conf.get_flags_by_compiler(nortti, conf.env.COMPILER_CC))
|
||||
|
||||
conf.env.FS_TESTS = conf.options.FS_TESTS
|
||||
|
||||
if conf.env.DEST_OS != 'android':
|
||||
if conf.env.cxxshlib_PATTERN.startswith('lib'):
|
||||
conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:]
|
||||
@ -22,3 +29,16 @@ def build(bld):
|
||||
use = 'filesystem_includes public',
|
||||
install_path = bld.env.LIBDIR,
|
||||
subsystem = bld.env.MSVC_SUBSYSTEM)
|
||||
|
||||
if bld.env.FS_TESTS:
|
||||
# build in same module, so dynamic linking will work
|
||||
# for now (until we turn libpublic to shared module lol)
|
||||
bld.program(features = 'test',
|
||||
source = 'tests/caseinsensitive.c',
|
||||
target = 'test_caseinsensitive',
|
||||
use = 'filesystem_includes public DL',
|
||||
rpath = '$ORIGIN',
|
||||
subsystem = bld.env.CONSOLE_SUBSYSTEM,
|
||||
install_path = None)
|
||||
bld.add_post_fun(waf_unit_test.summary)
|
||||
bld.add_post_fun(waf_unit_test.set_exit_code)
|
||||
|
Loading…
Reference in New Issue
Block a user