Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Unit test program for processes
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "unitlib/unitlib.h"
  8. #include "vstdlib/iprocessutils.h"
  9. #include "tier1/strtools.h"
  10. #include "tier1/tier1.h"
  11. #include "tier0/dbg.h"
  12. DEFINE_TESTSUITE( ProcessTestSuite )
  13. DEFINE_TESTCASE( ProcessTestSimple, ProcessTestSuite )
  14. {
  15. Msg( "Simple process test...\n" );
  16. ProcessHandle_t hProcess = g_pProcessUtils->StartProcess( "unittests\\testprocess.exe -delay 1.0", true );
  17. g_pProcessUtils->WaitUntilProcessCompletes( hProcess );
  18. int nLen = g_pProcessUtils->GetProcessOutputSize( hProcess );
  19. char *pBuf = (char*)_alloca( nLen );
  20. g_pProcessUtils->GetProcessOutput( hProcess, pBuf, nLen );
  21. g_pProcessUtils->CloseProcess( hProcess );
  22. Shipping_Assert( !Q_stricmp( pBuf, "Test Finished!\n" ) );
  23. }
  24. DEFINE_TESTCASE( ProcessTestBufferOverflow, ProcessTestSuite )
  25. {
  26. Msg( "Buffer overflow process test...\n" );
  27. ProcessHandle_t hProcess = g_pProcessUtils->StartProcess( "unittests\\testprocess.exe -delay 1.0 -extrabytes 32768", true );
  28. g_pProcessUtils->WaitUntilProcessCompletes( hProcess );
  29. int nLen = g_pProcessUtils->GetProcessOutputSize( hProcess );
  30. Shipping_Assert( nLen == 32768 + 16 );
  31. char *pBuf = (char*)_alloca( nLen );
  32. g_pProcessUtils->GetProcessOutput( hProcess, pBuf, nLen );
  33. g_pProcessUtils->CloseProcess( hProcess );
  34. Shipping_Assert( !Q_strnicmp( pBuf, "Test Finished!\n", 15 ) );
  35. int nEndExtraBytes = 32768;
  36. char *pTest = pBuf + 15;
  37. while( --nEndExtraBytes >= 0 )
  38. {
  39. Shipping_Assert( *pTest == (( nEndExtraBytes % 10 ) + '0') );
  40. ++pTest;
  41. }
  42. }