Xrasher/public/tests/test_parsefile.c
Alibek Omarov afaf5bf3ea engine: improve security a little bit by properly checking customization files starting with \!MD5
Implement basic test for COM_IsSafeFileToDownload

Move COM_ParseFileSafe test to libpublic
2024-10-08 03:22:53 +03:00

34 lines
964 B
C

#include "crtlib.h"
int main( void )
{
char *file = (char *)"q asdf \"qwerty\" \"f \\\"f\" meowmeow\n// comment \"stuff ignored\"\nbark";
int len;
char buf[5];
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
if( !( !Q_strcmp( buf, "q" ) && len == 1 ))
return 1;
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
if( !( !Q_strcmp( buf, "asdf" ) && len == 4 ))
return 2;
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
if( !( !Q_strcmp( buf, "qwer" ) && len == -1 ))
return 3;
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
if( !( !Q_strcmp( buf, "f \"f" ) && len == 4 ))
return 4;
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
if( !( !Q_strcmp( buf, "meow" ) && len == -1 ))
return 5;
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
if( !( !Q_strcmp( buf, "bark" ) && len == 4 ))
return 6;
return 0;
}