add wscripts for unittests

This commit is contained in:
nillerusr
2022-08-17 11:12:27 +03:00
parent 08e3444409
commit 9aa0ecab6a
12 changed files with 331 additions and 75 deletions

View File

@@ -0,0 +1,37 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for testing of tier0 libraries
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "appframework/IAppSystem.h"
//-----------------------------------------------------------------------------
// Used to connect/disconnect the DLL
//-----------------------------------------------------------------------------
class CTier0TestAppSystem : public CTier0AppSystem< IAppSystem >
{
typedef CTier0AppSystem< IAppSystem > BaseClass;
public:
virtual bool Connect( CreateInterfaceFn factory )
{
if ( !BaseClass::Connect( factory ) )
return false;
return true;
}
virtual InitReturnVal_t Init()
{
return INIT_OK;
}
virtual void Shutdown()
{
BaseClass::Shutdown();
}
};
USE_UNITTEST_APPSYSTEM( CTier0TestAppSystem )

39
unittests/tier0test/wscript Executable file
View File

@@ -0,0 +1,39 @@
#! /usr/bin/env python
# encoding: utf-8
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'tier0test'
def options(opt):
return
def configure(conf):
conf.define('TIER1TEST_EXPORTS', 1)
def build(bld):
source = ['tier0test.cpp']
includes = ['../../public', '../../public/tier0']
defines = []
libs = ['tier0','tier1','unitlib']
if bld.env.DEST_OS != 'win32':
libs += [ 'DL', 'LOG' ]
else:
libs += ['USER32', 'SHELL32']
install_path = bld.env.TESTDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@@ -6,7 +6,7 @@
//=============================================================================//
#include "unitlib/unitlib.h"
#include "tier1/commandbuffer.h"
#include "tier1/CommandBuffer.h"
#include "tier1/strtools.h"
@@ -139,20 +139,24 @@ DEFINE_TESTCASE( CommandBufferTestTiming, CommandBufferTestSuite )
buffer.BeginProcessingCommands( 1 );
argc = buffer.DequeueNextCommand( argv );
Shipping_Assert( argc == 3 );
Shipping_Assert( !Q_stricmp( argv[0], "test_command" ) );
Shipping_Assert( !Q_stricmp( argv[1], "test_arg1" ) );
Shipping_Assert( !Q_stricmp( argv[2], "test_arg2" ) );
argc = buffer.DequeueNextCommand( argv );
Shipping_Assert( argc == 1 );
Shipping_Assert( !Q_stricmp( argv[0], "test_command3" ) );
argc = buffer.DequeueNextCommand( argv );
Shipping_Assert( argc == 0 );
buffer.EndProcessingCommands( );
}
{
buffer.BeginProcessingCommands( 1 );

View File

@@ -1,52 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for processes
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "vstdlib/iprocessutils.h"
#include "tier1/strtools.h"
#include "tier1/tier1.h"
#include "tier0/dbg.h"
DEFINE_TESTSUITE( ProcessTestSuite )
DEFINE_TESTCASE( ProcessTestSimple, ProcessTestSuite )
{
Msg( "Simple process test...\n" );
ProcessHandle_t hProcess = g_pProcessUtils->StartProcess( "unittests\\testprocess.exe -delay 1.0", true );
g_pProcessUtils->WaitUntilProcessCompletes( hProcess );
int nLen = g_pProcessUtils->GetProcessOutputSize( hProcess );
char *pBuf = (char*)_alloca( nLen );
g_pProcessUtils->GetProcessOutput( hProcess, pBuf, nLen );
g_pProcessUtils->CloseProcess( hProcess );
Shipping_Assert( !Q_stricmp( pBuf, "Test Finished!\n" ) );
}
DEFINE_TESTCASE( ProcessTestBufferOverflow, ProcessTestSuite )
{
Msg( "Buffer overflow process test...\n" );
ProcessHandle_t hProcess = g_pProcessUtils->StartProcess( "unittests\\testprocess.exe -delay 1.0 -extrabytes 32768", true );
g_pProcessUtils->WaitUntilProcessCompletes( hProcess );
int nLen = g_pProcessUtils->GetProcessOutputSize( hProcess );
Shipping_Assert( nLen == 32768 + 16 );
char *pBuf = (char*)_alloca( nLen );
g_pProcessUtils->GetProcessOutput( hProcess, pBuf, nLen );
g_pProcessUtils->CloseProcess( hProcess );
Shipping_Assert( !Q_strnicmp( pBuf, "Test Finished!\n", 15 ) );
int nEndExtraBytes = 32768;
char *pTest = pBuf + 15;
while( --nEndExtraBytes >= 0 )
{
Shipping_Assert( *pTest == (( nEndExtraBytes % 10 ) + '0') );
++pTest;
}
}

View File

@@ -180,20 +180,20 @@ static void FormatTests()
static void FileNameAPITests()
{
CUtlString path( "c:\\source2\\game\\source2\\somefile.ext" );
CUtlString path( "/source2/game/source2/somefile.ext" );
CUtlString absPath = path.AbsPath();
Shipping_Assert( absPath == path );
CUtlString file = path.UnqualifiedFilename();
Shipping_Assert( !V_stricmp( file.Get(), "somefile.ext" ) );
CUtlString dir = path.DirName();
Shipping_Assert( !V_stricmp( dir.Get(), "c:\\source2\\game\\source2" ) );
Shipping_Assert( !V_stricmp( dir.Get(), "/source2/game/source2" ) );
dir = dir.DirName();
Shipping_Assert( !V_stricmp( dir.Get(), "c:\\source2\\game" ) );
Shipping_Assert( !V_stricmp( dir.Get(), "/source2/game" ) );
CUtlString baseName = path.StripExtension();
Shipping_Assert( !V_stricmp( baseName.Get(), "c:\\source2\\game\\source2\\somefile" ) );
Shipping_Assert( !V_stricmp( baseName.Get(), "/source2/game/source2/somefile" ) );
dir = path.StripFilename();
Shipping_Assert( !V_stricmp( dir.Get(), "c:\\source2\\game\\source2" ) );
Shipping_Assert( !V_stricmp( dir.Get(), "/source2/game/source2" ) );
file = path.GetBaseFilename();
Shipping_Assert( !V_stricmp( file.Get(), "somefile" ) );
@@ -201,7 +201,7 @@ static void FileNameAPITests()
Shipping_Assert( !V_stricmp( ext.Get(), "ext" ) );
absPath = path.PathJoin( dir.Get(), file.Get() );
Shipping_Assert( !V_stricmp( absPath.Get(), "c:\\source2\\game\\source2\\somefile" ) );
Shipping_Assert( !V_stricmp( absPath.Get(), "/source2/game/source2/somefile" ) );
}
DEFINE_TESTCASE( UtlStringTest, UtlStringTestSuite )
@@ -221,4 +221,4 @@ DEFINE_TESTCASE( UtlStringTest, UtlStringTestSuite )
FormatTests();
FileNameAPITests();
}
}

39
unittests/tier1test/wscript Executable file
View File

@@ -0,0 +1,39 @@
#! /usr/bin/env python
# encoding: utf-8
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'tier1test'
def options(opt):
return
def configure(conf):
conf.define('TIER1TEST_EXPORTS', 1)
def build(bld):
source = ['commandbuffertest.cpp', 'utlstringtest.cpp', 'tier1test.cpp']
includes = ['../../public', '../../public/tier0']
defines = []
libs = ['tier0', 'tier1', 'mathlib', 'unitlib']
if bld.env.DEST_OS != 'win32':
libs += [ 'DL', 'LOG' ]
else:
libs += ['USER32', 'SHELL32']
install_path = bld.env.TESTDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

39
unittests/tier2test/wscript Executable file
View File

@@ -0,0 +1,39 @@
#! /usr/bin/env python
# encoding: utf-8
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'tier2test'
def options(opt):
return
def configure(conf):
conf.define('TIER2TEST_EXPORTS', 1)
def build(bld):
source = ['tier2test.cpp']
includes = ['../../public', '../../public/tier0']
defines = []
libs = ['tier0', 'tier1','tier2', 'mathlib', 'unitlib']
if bld.env.DEST_OS != 'win32':
libs += [ 'DL', 'LOG' ]
else:
libs += ['USER32', 'SHELL32']
install_path = bld.env.TESTDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

39
unittests/tier3test/wscript Executable file
View File

@@ -0,0 +1,39 @@
#! /usr/bin/env python
# encoding: utf-8
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'tier3test'
def options(opt):
return
def configure(conf):
conf.define('TIER3TEST_EXPORTS', 1)
def build(bld):
source = ['tier3test.cpp']
includes = ['../../public', '../../public/tier0']
defines = []
libs = ['tier0', 'tier1','tier2', 'tier3', 'mathlib', 'unitlib']
if bld.env.DEST_OS != 'win32':
libs += [ 'DL', 'LOG' ]
else:
libs += ['USER32', 'SHELL32']
install_path = bld.env.TESTDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)