public: add basic test for our strcpy, strcmp and strcat functions
This commit is contained in:
parent
2db2375b4d
commit
339c08d89f
2 changed files with 56 additions and 0 deletions
42
public/tests/test_strings.c
Normal file
42
public/tests/test_strings.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "crtlib.h"
|
||||||
|
|
||||||
|
int Test_Strcpycatcmp( void )
|
||||||
|
{
|
||||||
|
char buf[] = "meowmeowmeow", buf2[] = "barkbark";
|
||||||
|
char dst[64];
|
||||||
|
|
||||||
|
if( Q_strncpy( dst, buf, sizeof( dst )) != sizeof( buf ) - 1 )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if( Q_strcmp( dst, buf ))
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
if( Q_strcpy( dst, buf ) != sizeof( buf ) - 1 )
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
if( Q_strcmp( dst, buf ))
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
if( !Q_strcmp( dst, buf2 ))
|
||||||
|
return 5;
|
||||||
|
|
||||||
|
if( Q_strncat( dst, buf2, sizeof( dst )) != sizeof( buf ) + sizeof( buf2 ) - 2 )
|
||||||
|
return 6;
|
||||||
|
|
||||||
|
if( Q_strcmp( dst, "meowmeowmeowbarkbark" ))
|
||||||
|
return 7;
|
||||||
|
|
||||||
|
if( Q_strncmp( dst, buf, sizeof( buf ) - 1 ))
|
||||||
|
return 8;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( void )
|
||||||
|
{
|
||||||
|
if( Test_Strcpycatcmp( ))
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
|
@ -22,3 +22,17 @@ def build(bld):
|
||||||
features = 'c',
|
features = 'c',
|
||||||
use = 'sdk_includes',
|
use = 'sdk_includes',
|
||||||
subsystem = bld.env.MSVC_SUBSYSTEM)
|
subsystem = bld.env.MSVC_SUBSYSTEM)
|
||||||
|
|
||||||
|
if bld.env.TESTS:
|
||||||
|
tests = {
|
||||||
|
'strings': 'tests/test_strings.c',
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in tests:
|
||||||
|
bld.program(features = 'test',
|
||||||
|
source = tests[i],
|
||||||
|
target = 'test_%s' % i,
|
||||||
|
use = 'public',
|
||||||
|
rpath = '$ORIGIN',
|
||||||
|
subsystem = bld.env.CONSOLE_SUBSYSTEM,
|
||||||
|
install_path = None)
|
||||||
|
|
Loading…
Add table
Reference in a new issue