summaryrefslogtreecommitdiff
path: root/unittests/tier1test/processtest.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /unittests/tier1test/processtest.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'unittests/tier1test/processtest.cpp')
-rw-r--r--unittests/tier1test/processtest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/unittests/tier1test/processtest.cpp b/unittests/tier1test/processtest.cpp
new file mode 100644
index 0000000..e83d7dc
--- /dev/null
+++ b/unittests/tier1test/processtest.cpp
@@ -0,0 +1,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;
+ }
+}
+