public virtual bool runTest()
{
int iCountErrors = 0;
int iCountTestcases = 0;
Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
ArrayList arrList = null;
String [] strHeroes =
{
"Aquaman",
"Atom",
"Batman",
"Black Canary",
"Captain America",
"Captain Atom",
"Catwoman",
"Cyborg",
"Flash",
"Green Arrow",
"Green Lantern",
"Hawkman",
"Huntress",
"Ironman",
"Nightwing",
"Robin",
"SpiderMan",
"Steel",
"Superman",
"Thor",
"Wildcat",
"Wonder Woman",
};
do
{
++iCountTestcases;
Console.Error.WriteLine( "[] Construct ArrayList" );
try
{
arrList = new ArrayList( (ICollection)strHeroes );
if ( arrList == null )
{
Console.WriteLine( strTest+ "E_101: Failed to construct new ArrayList" );
++iCountErrors;
break;
}
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
++iCountTestcases;
Console.Error.WriteLine( "[] Set and verify list capacity" );
try
{
int nCapacity = 2*arrList.Capacity;
arrList.Capacity = nCapacity ;
if ( arrList.Capacity != nCapacity )
{
String strInfo = strTest + " error: ";
strInfo = strInfo + "Expected capacity <"+ nCapacity + "> ";
strInfo = strInfo + "Returned capacity <"+ arrList.Capacity + "> ";
Console.WriteLine( strTest+ "E_202: " + strInfo );
++iCountErrors;
break;
}
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
++iCountTestcases;
Console.Error.WriteLine( "[] Bogus negative argument" );
try
{
arrList.Capacity = -1000 ;
Console.WriteLine( strTest+ "E_404: Expected ArgumentException" );
++iCountErrors;
break;
}
catch (ArgumentException)
{
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10004: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
++iCountTestcases;
Console.Error.WriteLine( "[] Bogus super large capacity, expecting OutOfMemoryException" );
try
{
arrList.Capacity = Int32.MaxValue ;
Console.WriteLine( strTest+ "E_505: Expected OutOfMemoryException" );
++iCountErrors;
break;
}
catch (OutOfMemoryException)
{
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10005: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
iCountTestcases++;
arrList = new ArrayList();
for(int i=0; i<10; i++)
arrList.Add(i);
try
{
arrList.Capacity = arrList.Count-1;
++iCountErrors;
Console.WriteLine("Err_7842f! Excepiton not thrown");
}
catch(ArgumentOutOfRangeException)
{
}
catch(Exception ex)
{
++iCountErrors;
Console.WriteLine("Err_7842f! Unexpected exception thrown, " + ex);
}
}
while ( false );
Console.Error.Write( strName );
Console.Error.Write( ": " );
if ( iCountErrors == 0 )
{
Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
return true;
}
else
{
Console.WriteLine( strTest+ strPath );
Console.WriteLine( strTest+ "FAiL" );
Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
return false;
}
}
public static void Main( String[] args )