blob: e83d7dc8a3c111e3fe714f041933baf08d2c01bc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
//========= 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;
}
}
|