Skip to content

Instantly share code, notes, and snippets.

@TheByKotik
Created July 7, 2020 06:09
Show Gist options
  • Save TheByKotik/d84d2fbe80581df600def7d2e1b4477d to your computer and use it in GitHub Desktop.
Save TheByKotik/d84d2fbe80581df600def7d2e1b4477d to your computer and use it in GitHub Desktop.
#pragma newdecls required
#pragma semicolon 1
#define f_value 1
#define f_array { 2, 3, 4 }
#define f_string "567890"
#define s_string "098765"
#define s_array { 4, 3, 2 }
#define s_value 1
public void OnPluginStart ()
{
int array[3];
char string[7];
ArrayStack stack, clone;
stack = new ArrayStack( 6 );
stack.Push( f_value );
stack.PushArray( f_array );
stack.PushString( f_string );
stack.PushString( s_string );
stack.PushArray( s_array );
stack.Push( s_value );
for ( int i; i < 1000000; ++i ) // check memory leak
{
clone = stack.Clone();
if ( clone.Pop() != s_value ) { PrintToServer( "Clone: Second value wrong!" ); }
if ( clone.PopArray( array, sizeof array ), !arrcmp( array, s_array, sizeof array ) ) { PrintToServer( "Clone: Second array wrong!" ); }
if ( clone.PopString( string, sizeof string ), strcmp( string, s_string ) ) { PrintToServer( "Clone: Second string wrong!" ); }
if ( clone.PopString( string, sizeof string ), strcmp( string, f_string ) ) { PrintToServer( "Clone: First string wrong!" ); }
if ( clone.PopArray( array, sizeof array ), !arrcmp( array, f_array, sizeof array ) ) { PrintToServer( "Clone: First array wrong!" ); }
if ( clone.Pop() != f_value ) { PrintToServer( "Clone: First value wrong!" ); }
CloseHandle( clone );
}
if ( stack.Pop() != s_value ) { PrintToServer( "Stack: Second value wrong!" ); }
if ( stack.PopArray( array, sizeof array ), !arrcmp( array, s_array, sizeof array ) ) { PrintToServer( "Stack: Second array wrong!" ); }
if ( stack.PopString( string, sizeof string ), strcmp( string, s_string ) ) { PrintToServer( "Stack: Second string wrong!" ); }
if ( stack.PopString( string, sizeof string ), strcmp( string, f_string ) ) { PrintToServer( "Stack: First string wrong!" ); }
if ( stack.PopArray( array, sizeof array ), !arrcmp( array, f_array, sizeof array ) ) { PrintToServer( "Stack: First array wrong!" ); }
if ( stack.Pop() != f_value ) { PrintToServer( "Stack: First value wrong!" ); }
CloseHandle( stack );
PrintToServer( "Assert ended." );
}
bool arrcmp (const int[] i, const int[] j, const int iLength)
{
for ( int k; k < iLength; ++k ) { if ( i[k] != j[k] ) { return false; } }
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment