Esempio n. 1
0
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     String str1, str2;
     StringBuilder sb1;
     strLoc = "Loc_299nu";
     try {
     String.IsInterned (null);
     }
     catch (ArgumentNullException ) {
     }
     strLoc = "Loc_230ema.2";
     iCountTestcases++;
     if(String.IsInterned (new StringBuilder (String.Empty).ToString ()) == null)	
       {
       iCountErrors++;
       printerr( "Error_230a.2! String.Empty should be already interned!");
       }
     strLoc = "Loc_231loa";
     sb1 = new StringBuilder().Append("a").Append("b").Append("c").Append("d").Append("e").Append("f").Append("g").Append("h").Append("i").Append("j").Append("k").Append("l").Append("m").Append("n").Append("o").Append("p").Append("q").Append("r").Append("s").Append("t").Append("u").Append("v").Append("w").Append("x").Append("y").Append("z").Append("aa").Append("bb").Append("cc").Append("dd").Append("ee").Append("ff").Append("gg").Append("hh").Append("ii").Append("jj").Append("kk").Append("ll").Append("mm").Append("nn").Append("oo").Append("pp").Append("qq").Append("rr").Append("ss").Append("tt").Append("uu").Append("vv").Append("ww").Append("xx").Append("yy").Append("zz");
     str1 = sb1.ToString();
     strLoc = "Loc_231loa.2";
     iCountTestcases++;
     if(String.IsInterned (sb1.ToString()) != null)
       {
       iCountErrors++;
       printerr( "Error_231a.2! References of a built string can't be already interned!");
       }
     IntlStrings intl = new IntlStrings();
     sb1 = new StringBuilder().Append(intl.GetString(4, true, true)).Append(intl.GetString(8, false, true));
     str1 = sb1.ToString();
     if(String.IsInterned (sb1.ToString()) != null)
       {
       iCountErrors++;
       printerr( "Error_234949 References of a built string can't be already interned!");
       }
     strLoc = "Loc_232syma";
     sb1 = new StringBuilder().Append("abc").Append("`").Append("-").Append("=").Append("[").Append("]").Append(";").Append("'").Append(",").Append(".").Append("/").Append("~").Append("!").Append("@").Append("#").Append("$").Append("%").Append("^").Append("&").Append("*").Append("(").Append(")").Append("_").Append("+").Append("{").Append("}").Append("|").Append(":").Append("<").Append(">").Append("?");
     str1 = sb1.ToString();
     str2 = "abc`-=[];',./~!@#$%^&*()_+{}|:<>?";
     strLoc = "Loc_232syma.2";
     iCountTestcases++;
     if(String.IsInterned (sb1.ToString()) == null)
       {
       iCountErrors++;
       printerr( "Error_231yma.2! even though built this string should 've been interned at JIT time!");
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     String str1;
     Object obj1;
     strLoc = "Loc_299cu";
     obj1 = null;
     iCountTestcases++;
     if(String.Concat(obj1) != String.Empty)
       {
       iCountErrors++;
       printerr( "Error_2029s! String.Empty not returned as expected");
       }
     IntlStrings intl = new IntlStrings();
     str1 = intl.GetString(20, false, true);
     iCountTestcases++;
     if(!String.Concat(str1).Equals((object)str1))
       {
       iCountErrors++;
       printerr( "Error_209sj! got value=="+String.Concat(str1));
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 public virtual bool runTest
   ()
   {
   int nErrorBits = 0; 
   System.String swrString2 = null;
   System.String swrString4 = null;
   IntlStrings intl = new IntlStrings();
   swrString2 = intl.GetString(50, false, true);
   swrString4 = swrString2.ToLower();
   Console.WriteLine(swrString4);
   foreach(Char c in swrString4) {
   if(Char.GetUnicodeCategory( c ) == UnicodeCategory.UppercaseLetter) {
   nErrorBits = nErrorBits | 0x1;
   }
   }
   System.Console.Error.WriteLine(nErrorBits );
   if (nErrorBits == 0)
     {
     return true; 
     }
   else
     {
     return false; 
     }
   }
 public virtual bool runTest
   ()
   {
   System.Console.Error.WriteLine( "String.EndsWith: Co1150EW runTest starting..." );
   int nErrorBits = 0; 
   System.String swrString2 = null;
   swrString2 = "nOpqRs";
   if ( swrString2.EndsWith( "qRs" ) != true ) 
     nErrorBits = nErrorBits | 0x1;
   if ( swrString2.EndsWith( "qrs" ) != false )
     nErrorBits = nErrorBits | 0x2;
   if ( swrString2.EndsWith( "nOp" ) != false )
     nErrorBits = nErrorBits | 0x4;
   Char[] swrString3 = new Char[8];
   IntlStrings intl = new IntlStrings();
   swrString2 = intl.GetString(10, true, true);
   swrString2.CopyTo(2, swrString3, 0, swrString2.Length - 2);
   String swrString4 = new String(swrString3);
   if(swrString2.EndsWith(swrString4) != true) {
   nErrorBits = nErrorBits | 0x1;
   }
   System.Console.Error.WriteLine( nErrorBits  );
   if (nErrorBits == 0)
     {
     return true; 
     }
   else
     {
     return false; 
     }
   }
Esempio n. 5
0
File: a.cs Progetto: ArildF/masters
 public static void Main()
   {
   IntlStrings intl = new IntlStrings( 0x41F );
   Console.WriteLine(intl.GetRandomDirectoryName( 5 ));
   for(int iLoop = 0 ; iLoop < 5 ; iLoop++)
     Console.WriteLine( intl.GetTop20String( 20, true, true ));
   for(int iLoop = 0 ; iLoop < 5 ; iLoop++)
     Console.WriteLine( intl.GetProbCharString( 20, true, true ));
   }
Esempio n. 6
0
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     strLoc = "Loc_299cu";
     iCountTestcases++;
     if(!String.Concat(null,null,null).Equals(String.Empty))
       {
       iCountErrors++;
       printerr( "Error_2029s! String.Empty not returned as expected");
       }
     strLoc = "Loc_109xh";
     iCountTestcases++;
     if(!String.Concat("Hello","World","End").Equals("HelloWorldEnd"))
       {
       iCountErrors++;
       printerr( "Error_209sj! Expected==HelloWorldEnd");
       }
     iCountTestcases++;
     if(!String.Concat("Hi", null, "There").Equals("HiThere"))
       {
       iCountErrors++;
       printerr( "Error_2091x! Expected==HiThere");
       }
     iCountTestcases++;
     if(!String.Concat(null, "Hi", "There").Equals("HiThere"))
       {
       iCountErrors++;
       printerr( "Error_099xj! Expected==HiThere");
       }
     iCountTestcases++;
     if(!String.Concat("Hi", "There", null).Equals("HiThere"))
       {
       iCountErrors++;
       printerr( "Error_1909x! Expected==HiThere");
       }
     IntlStrings intl = new IntlStrings();
     String str1 = intl.GetString(3, true, true);
     String str2 = intl.GetString(5, true, true);
     if(!String.Concat(str1,str2).Equals(String.Concat(str1, str2, null)))
       {
       iCountErrors++;
       printerr( "Error_209sj! Expected==HelloWorld");
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 public virtual bool runTest()
   {
   Console.Error.WriteLine( "Co1454ctor_Strings.  runTest started." );
   int iCountErrors = 0;
   StringBuilder sbl2 = null;
   String str2b = null;
   String str2c = null;
   String str2d = null;
   String str2e = null;
   String str2_All = null;
   String str2_Some = null;
   String str9 = null;
   IntlStrings intl = new IntlStrings();
   str9 = intl.GetString(6, true, true);
   str2_All = str9;
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_6555im! (Co1454ctor_Strings)"  );
     }
   str2b = "Bb";
   str2c = "Cc";
   str2d = "Dd";
   str2e = "Ee";
   str2_All = "BbCcDdEe";
   str9 =  "BbCcDdEe" ;
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_638im! (Co1454ctor_Strings)"  );
     }
   sbl2 = new StringBuilder( "BbCcDd" );
   sbl2.Append( str2e );
   str9 = sbl2.ToString();
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_517cw! (Co1454ctor_Strings)"  );
     }
   str9 =  "Bb" + "Cc" +"Dd" ;
   str2_Some = "BbCcDd";
   if ( ! str9.Equals( str2_Some ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_460is! (Co1454ctor_Strings)"  );
     }
   str9 =  str2b + str2c + str2d ;
   str9 = new StringBuilder( str9 ).Append( str2e ).ToString();
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_253xi! (Co1454ctor_Strings)"  );
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 8
0
 public virtual bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   Console.Out.Write( strName );
   Console.Out.Write( ": " );
   Console.Out.Write( strTest );
   Console.Out.WriteLine( " runTest started..." );
   String strFromStrStr = null;
   String strAlphabets = "abcdefghijklmnopqrstuvwxyz";
   String strDigits = "0123456789";
   do
     {
     IntlStrings intl = new IntlStrings();
     String testString = intl.GetString(12, true, true);
     String testString2 = intl.GetString(3, true, true);
     Console.Out.WriteLine( "[] Construct a string from two strings" );
     try
       {
       strFromStrStr =  testString + testString2 ;
       if ( strFromStrStr == null )
	 {
	 Console.WriteLine( strTest+ "E_101" );
	 Console.WriteLine( strTest+ "Failed to construct valid string" );
	 ++iCountErrors;
	 break;
	 }
       if ( strFromStrStr.Equals( testString + testString2 ) != true )
	 {
	 String strInfo = strTest + " error: ";
	 strInfo = strInfo + "Expected string<" + strAlphabets + strDigits + ">\n";
	 strInfo = strInfo + "Returned character <" + strFromStrStr + ">";
	 Console.WriteLine( strTest+ "E_202" );
	 Console.WriteLine( strTest+ strInfo );
	 ++iCountErrors;
	 break;
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_303" );
       Console.WriteLine( strTest+ "Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     strFromStrStr =  strAlphabets+ strDigits ;
     }
   while ( false );
   Console.Error.Write( strName );
   Console.Error.Write( ": " );
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 private Boolean runTest(double timeInterval, int repetitions)
   {
   try
     {
     String emptyString="";
     emptyString=emptyString.Replace ('r', 't');
     IntlStrings intl = new IntlStrings();
     String testingString = intl.GetString(7, true, true);
     String copyTestString = testingString;
     Char charVar = testingString[4];
     testingString = testingString.Replace(testingString[4], 'h');
     testString(copyTestString, testingString, copyTestString[4], 'h', "Rep_cc-1");
     testString ("Yehia", "Ye7ia", 'h', '7', "Rep_cc00");	
     iCountTestcases++;
     testString ("Redmond", "Redmond", 'x', 'd', "Rep_cc01");      
     testString ("Redmond", "Redmond", 'd', 'd', "Rep_cc02");      
     iCountTestcases++;
     iCountTestcases++;
     testString ("Redmond", "redmond", 'R', 'r', "Rep_cc03");     
     testString ("Redmond", "Redmond", 'r', 'c', "Rep_cc04");     
     testString ("Redmond", "Re mon ", 'd', ' ', "Rep_cc05");     
     iCountTestcases++;
     testString ("Reddod", "Rexxox", 'd', 'x', "Rep_cc06");     
     testString ("Redmo", "Rexmo", 'd', 'x', "Rep_cc07");     
     iCountTestcases++;
     testString ("Null", "N"+'\u0000'+"ll", 'u', '\u0000', "Rep_cc08");	
     testString ("In", "I"+'\uFFFF', 'n', '\uFFFF', "Rep_cc09");		
     testString (" ", " ", ' ', ' ', "Rep_cc10");	
     testString ("  ", "aa", ' ', 'a', "Rep_cc11");	
     testString ("Seattle", "Sea"+'\n'+'\n'+"le", 't', '\n', "Rep_cc12");	
     testString ("Seattle", "Sea"+'\r'+'\r'+"le", 't', '\r', "Rep_cc13");			
     testString ("Seattle", "Sea"+'\t'+'\t'+"le", 't', '\t', "Rep_cc14");
     testString ("Seattle", "Sea"+'\\'+'\\'+"le", 't', '\\', "Rep_cc15");			
     testString ("Seattle", "Sea"+'\a'+'\a'+"le", 't', '\a', "Rep_cc16");
     testString ("Seattle", "Sea"+'\0'+'\0'+"le", 't', '\0', "Rep_cc17");
     for (int index=0; index<repetitions; index++) {
     Console.WriteLine ("Finished "+index+" repetition(s)");
     randomTest (timeInterval);	
     }
     }
   catch (Exception ex)
     {
     ++iCountErrors;
     String strInfo =  "Unexpected Exception: (runTest)" ;
     strInfo = strInfo + ex.ToString() ;
     Console.Error.WriteLine (strName+" "+strTest+" "+strPath);
     Console.Error.WriteLine (strInfo);
     }
   Console.WriteLine ("FINAL TEST RESULT:" + strName+" "+strTest+" "+strPath);
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 10
0
 public virtual bool runTest
   ()
   {
   Console.Error.WriteLine( "String.Equals: Cb1100E runTest running:" );
   int nErrorBits = 0; 
   String swrString1 = null;
   String swrString2 = null;
   String swrString3 = null;
   String swrString4 = null;
   String swrString5 = null;
   String swrString6 = null;
   swrString2 = "nOpqrs"; 
   swrString3 = "nopqrs"; 
   swrString4 = "Dill Guv Dill Guv Dill"; 
   swrString5 = "Dill Guv Dill Guv Dill Guv Dill"; 
   swrString6 = "Y2"; 
   swrString1 = swrString2; 
   if ( String.Equals( swrString1, swrString2 ) != true ) 
     nErrorBits = nErrorBits | 0x1;
   if ( String.Equals( swrString1, swrString3 ) != false ) 
     nErrorBits = nErrorBits | 0x2;
   IntlStrings intl = new IntlStrings();
   String str1 = intl.GetString(3, true, true);
   String str2 =  str1;
   if(!str1.Equals(str2))
     {
     nErrorBits = nErrorBits | 0x20;
     }
   swrString1 = swrString4; 
   if ( String.Equals( swrString1, swrString5 ) != false ) 
     nErrorBits = nErrorBits | 0x4; 
   if ( String.Equals( swrString1, swrString6 ) != false ) 
     nErrorBits = nErrorBits | 0x8;
   swrString1 = swrString5; 
   if ( String.Equals( swrString1, swrString4 ) != false ) 
     nErrorBits = nErrorBits | 0x10;
   Console.Error.Write( "String.Equals: Cb1100E nErrorBits==" );
   Console.Error.WriteLine( nErrorBits  );
   if (nErrorBits == 0)
     {
     return true; 
     }
   else
     {
     return false; 
     }
   }
Esempio n. 11
0
 public virtual bool runTest
   ()
   {
   System.Console.Error.WriteLine( "String.Equals: Co1100E runTest running:" );
   int nErrorBits = 0; 
   System.String swrString1 = null;
   System.String swrString2 = null;
   System.String swrString3 = null;
   System.String swrString4 = null;
   System.String swrString5 = null;
   System.String swrString6 = null;
   System.String swrString7 = null;
   System.String swrString8 = null;
   swrString2 = "nOpqrs"; 
   swrString3 = "nopqrs"; 
   swrString4 = "Dill Guv Dill Guv Dill"; 
   swrString5 = "Dill Guv Dill Guv Dill Guv Dill"; 
   swrString6 = "Y2"; 
   swrString1 = swrString2; 
   IntlStrings intl = new IntlStrings();
   swrString7 = intl.GetString(10, false, true);
   swrString8 = swrString7;
   if ( swrString7.Equals( swrString8 ) != true ) 
     nErrorBits = nErrorBits | 0x1;
   if ( swrString1.Equals( swrString3 ) != false ) 
     nErrorBits = nErrorBits | 0x2;
   swrString1 = swrString4; 
   if ( swrString1.Equals( swrString5 ) != false ) 
     nErrorBits = nErrorBits | 0x4; 
   if ( swrString1.Equals( swrString6 ) != false ) 
     nErrorBits = nErrorBits | 0x8;
   swrString1 = swrString5; 
   if ( swrString1.Equals( swrString4 ) != false ) 
     nErrorBits = nErrorBits | 0x10;
   System.Console.Error.Write( "String.Equals: Co1100E nErrorBits==" );
   System.Console.Error.WriteLine( nErrorBits  );
   if (nErrorBits == 0)
     {
     return true; 
     }
   else
     {
     return false; 
     }
   }
 public virtual bool runTest()
   {
   Console.Out.WriteLine( "String\\Co3041ToString. runTest() started." );
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String str1 = null;
   iCountTestcases++;
   IntlStrings intl = new IntlStrings();
   str1 = intl.GetString(17, false, true);
   if(!(str1.ToString().Equals(str1)))
     {
     iCountErrors++;
     Console.Error.WriteLine("POINTTOBREAK: find E_498o (Co3041ToString.)");
     }
   iCountTestcases++;
   str1 = "4874378828457y34";
   if(!(str1.ToString().Equals(str1)))
     {
     iCountErrors++;
     Console.Error.WriteLine("POINTTOBREAK: find E_433r (Co3041ToString.)");
     }
   iCountTestcases++;
   str1 = "#$%@#$%@*#_@_!__!_!($#%JWE(@JA)(*#@$";
   if(!(str1.ToString().Equals(str1)))
     {
     iCountErrors++;
     Console.Error.WriteLine("POINTTOBREAK: find E_879u (Co3041ToString.)");
     }
   iCountTestcases++;
   str1 = "\0";
   if(!(str1.ToString().Equals(str1)))
     {
     iCountErrors++;
     Console.Error.WriteLine("POINTTOBREAK: find E_899 (Co3041ToString.)");
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 public virtual bool runTest
   ()
   {
   int nErrorBits = 0; 
   int n2 = 0;
   System.String swrString2 = null;
   IntlStrings intl = new IntlStrings();
   swrString2 =  "" ;
   if ( swrString2.Length != 0x0)
     nErrorBits = nErrorBits | 0x1;
   swrString2 =  intl.GetString(6 , true, true);
   if ( swrString2.Length != 6)
     nErrorBits = nErrorBits | 0x2;
   if ( swrString2.Length != 6)
     nErrorBits = nErrorBits | 0x4;
   System.Console.Error.WriteLine( nErrorBits);
   if (nErrorBits == 0){
   return true; 
   }
   else {
   return false; 
   }
   }
 public Boolean runTest()
   {
   int iCountErrors = 0;
   int iTestCases = 0;
   Console.Out.Write( strName );
   Console.Out.Write( ": " );
   Console.Out.Write( strTest );
   Console.Out.WriteLine( " runTest started..." );
   int ii = 0;
   String strAlphabets = "abcdefghijklmnopqrstuvwxyz";
   String strDigits = "0123456789";
   char[] charArray = null; 
   char[] charAlphabets = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 
			    'h', 'i', 'j', 'k', 'l', 'm', 'n',
			    'o', 'p', 'q', 'r', 's', 't', 'u',
			    'v', 'w', 'x', 'y', 'z' };
   char[] charDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 
   char[] charBuffer = new char[256]; 
   IntlStrings intl = new IntlStrings();
   char[] MyCharArr = new char[2];
   char[] CopyArr = new char[2];
   MyCharArr[0] = (intl.GetString(1, true, true))[0];
   MyCharArr[1] = (intl.GetString(1, true, true))[0];
   String intlString = new String(MyCharArr);
   CopyArr = intlString.ToCharArray();
   if((CopyArr[0] != MyCharArr[0]) || (CopyArr[1] != MyCharArr[1]) ) {
   iCountErrors++;
   }
   do
     {
     ++iTestCases;
     Console.Out.WriteLine( "[] Obtain char array for entire string" ); 
     try
       {
       strAlphabets.CopyTo( 0, charBuffer, 0, strAlphabets.Length );
       if ( charBuffer == null )
	 {
	 Console.WriteLine( strTest+ "E_101" );
	 Console.WriteLine( strTest+ "Failed to return valid buffer" );
	 ++iCountErrors;
	 break;
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_202" );
       Console.WriteLine( strTest+ "Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     for ( ii = 0; ii < charAlphabets.Length; ++ii )
       {
       if ( charAlphabets[ii] != charBuffer[ii] )
	 {
	 String strInfo = strTest + " error: ";
	 strInfo = strInfo + "On character item " + ii + " ";
	 strInfo = strInfo + "Expected character <" + (charAlphabets[ii]).ToString() + ">\n";
	 Console.WriteLine( strTest+ "E_303" );
	 Console.WriteLine( strTest+ strInfo );
	 ++iCountErrors;
	 break;
	 }
       }
     ++iTestCases;
     Console.Out.WriteLine( "[] Obtain char array for substring" ); 
     try
       {
       strAlphabets.CopyTo(12, charBuffer,  20, 5 );
       if ( charBuffer == null )
	 {
	 Console.WriteLine( strTest+ "E_404" );
	 Console.WriteLine( strTest+ "Failed to return valid buffer" );
	 ++iCountErrors;
	 break;
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_505" );
       Console.WriteLine( strTest+ "Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     for ( ii = 0; ii < 5; ++ii )
       {
       if ( charAlphabets[ii+12] != charBuffer[ii+20] )
	 {
	 String strInfo = strTest + " error: ";
	 strInfo = strInfo + "On character item " + ii + " ";
	 strInfo = strInfo + "Expected character <" + (charAlphabets[ii+12]).ToString() + ">\n";
	 strInfo = strInfo + "Returned character <" + (charBuffer[ii+20]).ToString() + ">";
	 Console.WriteLine( strTest+ "E_606" );
	 Console.WriteLine( strTest+ strInfo );
	 ++iCountErrors;
	 break;
	 }
       }
     ++iTestCases;
     Console.Out.WriteLine( "[] Index out of range" ); 
     try
       {
       strAlphabets.CopyTo( 12, charBuffer,  1000, 5 );
       Console.WriteLine( strTest+ "E_707" );
       Console.WriteLine( strTest+ "Failed to throw IndexOutOfRangeException" );
       ++iCountErrors;
       break;
       }
     catch (ArgumentException ex)
       {
       Console.Error.WriteLine( "IndexOutOfRangeException caught" );
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_808" );
       Console.WriteLine( strTest+ "Generic Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     ++iTestCases;
     ++iTestCases;
     Console.Out.WriteLine( "[] Null buffer expection" ); 
     try
       {
       strAlphabets.CopyTo( 12, null,  20, 5 );
       Console.WriteLine( strTest+ "E_909" );
       Console.WriteLine( strTest+ "Failed to throw ArgumentException" );
       ++iCountErrors;
       break;
       }
     catch (ArgumentException ex)
       {
       Console.Error.WriteLine( "ArgumentException caught" );
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_1010" );
       Console.WriteLine( strTest+ "Generic Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     }
   while ( false );
   Console.Error.Write( strName );
   Console.Error.Write( ": " );
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 15
0
        public void Test01()
        {
            IntlStrings intl;
            StringCollection sc;

            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aa",
                "text",
                "     spaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            int cnt = 0;            // Count

            // initialize IntStrings
            intl = new IntlStrings();


            // [] StringCollection is constructed as expected
            //-----------------------------------------------------------------

            sc = new StringCollection();

            // [] on empty collection
            //
            for (int i = 0; i < values.Length; i++)
            {
                if (sc.Contains(values[i]))
                {
                    Assert.False(true, string.Format("Error, returned true for empty collection", i));
                }
            }


            // [] add simple strings and verify Contains()
            //

            cnt = sc.Count;
            sc.AddRange(values);
            if (sc.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length));
            }

            for (int i = 0; i < values.Length; i++)
            {
                // verify that collection contains all added items
                //
                if (!sc.Contains(values[i]))
                {
                    Assert.False(true, string.Format("Error, collection doesn't contain item \"{1}\"", i, values[i]));
                }
            }

            //
            // Intl strings
            // [] add Intl strings and verify Contains()
            //

            string[] intlValues = new string[values.Length];

            // fill array with unique strings
            //
            for (int i = 0; i < values.Length; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }

            int len = values.Length;
            Boolean caseInsensitive = false;
            for (int i = 0; i < len; i++)
            {
                if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper())
                    caseInsensitive = true;
            }

            cnt = sc.Count;
            sc.AddRange(intlValues);
            if (sc.Count != (cnt + intlValues.Length))
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, cnt + intlValues.Length));
            }

            for (int i = 0; i < intlValues.Length; i++)
            {
                // verify that collection contains all added items
                //
                if (!sc.Contains(intlValues[i]))
                {
                    Assert.False(true, string.Format("Error, collection doesn't contain item \"{1}\"", i, intlValues[i]));
                }
            }

            //
            // add very long string
            // [] add very long string and verify Contains()
            //
            cnt = sc.Count;
            string intlStr = intlValues[0];
            while (intlStr.Length < 10000)
                intlStr += intlStr;

            sc.Add(intlStr);
            if (sc.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, count is {1} instead of {2}", sc.Count, cnt + 1));
            }

            // verify that collection contains newly added item
            //
            if (!sc.Contains(intlStr))
            {
                Assert.False(true, string.Format("Error, collection doesn't contain new item"));
            }

            //
            //  [] Case sensitivity: search should be case-sensitive
            //

            sc.Clear();
            if (sc.Count != 0)
            {
                Assert.False(true, string.Format("Error, count is {1} instead of {2} after Clear()", sc.Count, 0));
            }

            // add uppercase item
            //
            intlStr = intlValues[0].ToUpper();
            sc.Add(intlStr);
            if (sc.Count != 1)
            {
                Assert.False(true, string.Format("Error, count is {1} instead of {2}", sc.Count, 1));
            }

            // verify that Contains returns true for newly added uppercase item
            //
            if (!sc.Contains(intlStr))
            {
                Assert.False(true, string.Format("Error, Contains() returned false "));
            }
            // verify that Contains returns false for lowercase version
            //
            intlStr = intlValues[0].ToLower();
            if (!caseInsensitive && sc.Contains(intlStr))
            {
                Assert.False(true, string.Format("Error, Contains() returned true for lowercase version"));
            }
        }
Esempio n. 16
0
 public virtual bool runTest()
   {
   Console.Out.WriteLine( "String\\Co3148ctor_CharArrIntInt. runTest() started." );
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strError = null;
   char[] cArr2 = null;
   int startIndex = 0;
   int length = 0;
   String str8 = null;
   String str9 = null;
   int[] iArrInvalidValues = new Int32[]{ -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue};
   int[] iArrLargeValues = new Int32[]{ Int32.MaxValue, Int32.MaxValue-1, Int32.MaxValue/2 , Int32.MaxValue/10 , Int32.MaxValue/100 };                      
   iCountTestcases++;
   String strNewString = String.Empty ;
   char[] cArr = new char[256];
   for (int i = 0; i < 256; i++) cArr[i] = (char)i;
   for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ ){
   try
     {                                                                                                              
     strNewString = new String(cArr , iArrInvalidValues[iLoop], 1);
     iCountErrors++;
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_0000!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   if ( strNewString != String.Empty )
     {
     iCountErrors++;
     Console.Error.WriteLine( "Error_1111!!!! Incorrect string content.... Expected...{0},  Actual...{1}", String.Empty, strNewString );
     }
   }
   iCountTestcases++;
   for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ ){
   try
     {
     strNewString = new String(cArr , 1, iArrInvalidValues[iLoop]);
     iCountErrors++;
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_2222!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   if ( strNewString != String.Empty )
     {
     iCountErrors++;
     Console.Error.WriteLine( "Error_3333!!!! Incorrect string content.... Expected...{0},  Actual...{1}", String.Empty, strNewString );
     }
   }
   iCountTestcases++;
   for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ ){
   try
     {
     strNewString = new String(cArr , iArrLargeValues[iLoop] , 1);
     if ( strNewString.Length != iArrLargeValues[iLoop] )
       {
       iCountErrors++;
       Console.Error.WriteLine( "Error_5555!!!! Incorrect string length.... Expected...{0},  Actual...{1}", iArrLargeValues[iLoop], strNewString.Length );
       }
     Console.WriteLine("String content..." + strNewString );
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_4444!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   }
   iCountTestcases++;
   for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ ){
   try
     {
     strNewString = new String(cArr , 1 , iArrLargeValues[iLoop] );
     if ( strNewString.Length != iArrLargeValues[iLoop] )
       {
       iCountErrors++;
       Console.Error.WriteLine( "Error_6666!!!! Incorrect string length.... Expected...{0},  Actual...{1}", iArrLargeValues[iLoop], strNewString.Length );
       }
     } catch ( ArgumentOutOfRangeException ){                            
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_7777!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   }
   iCountTestcases++;
   int iString_Length = 10000;
   char[] p2 = new char[ iString_Length];
   for (int i = 0; i < iString_Length; i++) p2[i] = (char)(i%65000);
   int[] iArrLengths = new int[]{ 1 , iString_Length , iString_Length -1 , iString_Length/2 , iString_Length/10 }; 
   for(int iLoop = 0 ; iLoop < iArrLengths.Length ; iLoop++ ){
   try
     {                            
     strNewString = new String(p2 , iString_Length, iArrLengths[iLoop]);
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_9999!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   if ( strNewString.Length != 0 )
     {
     iCountErrors++;
     Console.Error.WriteLine( "Error_8888!!!! Incorrect string Length.... Expected...{0},  Actual...{1}", String.Empty.Length, strNewString.Length );
     }
   }
   iCountTestcases++;
   try {
   str9 = new String(cArr2, startIndex, length);
   iCountErrors++;
   print("E_31kk");
   } catch (ArgumentException ) {}
   catch (Exception exc2)
     {
     iCountErrors++;
     print("E_39mz");
     strError = "EXTENDEDINFO: "+exc2.ToString();
     Console.Error.WriteLine(strError);
     }
   cArr2 = new char[10];
   startIndex = -1;
   length = 0;
   iCountTestcases++;
   try {
   str9 = new String(cArr2, startIndex, length);
   iCountErrors++;
   print("E_328i");
   } catch (ArgumentException ) {}
   catch (Exception exc2)
     {
     iCountErrors++;
     print("E_7auo");
     strError = "EXTENDEDINFO: ";
     strError = strError + exc2.ToString();
     Console.Error.WriteLine(strError);
     }
   startIndex = 11;
   length = 3;
   iCountTestcases++;
   try {
   str9 = new String(cArr2, startIndex, length);
   iCountErrors++;
   print("E_489a");
   } catch (ArgumentException ) {}
   catch (Exception exc2)
     {
     iCountErrors++;
     print("E_34zm");
     Console.Error.WriteLine(exc2.ToString());
     }
   cArr2 = new char[10];
   startIndex = 0;
   length = -4;
   iCountTestcases++;
   try {
   str9 = new String(cArr2, startIndex, length);
   iCountErrors++;
   print("E_329w");
   } catch (ArgumentException ) {}
   catch (Exception exc2)
     {
     iCountErrors++;
     print("E_38sn");
     Console.Error.WriteLine(exc2.ToString());
     }
   cArr2 = new char[10];
   startIndex = 0;
   length = 15;
   iCountTestcases++;
   try {
   str9 = new String(cArr2, startIndex, length);
   iCountErrors++;
   print("E_12xj");
   } catch (ArgumentException ) {}
   catch (Exception exc2)
     {
     iCountErrors++;
     print("E_39ds");
     Console.Error.WriteLine(exc2.ToString());
     }
   cArr2 = new char[10];
   for(int i=0;i<10;i++)
     cArr2[i] = '\0';
   StringBuilder strb = new StringBuilder("\0\0\0\0\0\0\0\0\0\0");
   str9 = new String(cArr2, 0, cArr2.Length);
   str8 = strb.ToString();
   iCountTestcases++;
   if(!str9.Equals(str8)) 
     {
     iCountErrors++;
     print("E_57ai");
     }
   cArr2 = new char[10];
   cArr2[0] = 'a';
   cArr2[1] = 'b';
   cArr2[2] = 'c';
   cArr2[3] = 'd';
   cArr2[4] = 'e';
   cArr2[5] = 'f';
   cArr2[6] = 'g';
   cArr2[7] = 'h';
   cArr2[8] = 'i';
   cArr2[9] = 'j';
   str9 =  new String(cArr2, 0, cArr2.Length) ;
   str8 = "abcdefghij";
   iCountTestcases++;
   if ( ! str9.Equals( str8 ) )
     {
     iCountErrors ++;
     print("E_89is");
     }
   cArr2 = new char[10];
   cArr2[0] = 'a';
   cArr2[1] = 'b';
   cArr2[2] = 'c';
   cArr2[3] = 'd';
   cArr2[4] = 'e';
   cArr2[5] = 'f';
   cArr2[6] = 'g';
   cArr2[7] = 'h';
   cArr2[8] = 'i';
   cArr2[9] = 'j';
   str9 = new String(cArr2, 0, 5);
   str8 = "abcde";
   iCountTestcases++;
   if(!str9.Equals(str8))
     {
     iCountErrors++;
     print("E_47nd");
     }
   cArr2 = new char[10];
   cArr2[0] = 'a';
   cArr2[1] = 'b';
   cArr2[2] = 'c';
   cArr2[3] = 'd';
   cArr2[4] = 'e';
   cArr2[5] = 'f';
   cArr2[6] = 'g';
   cArr2[7] = 'h';
   cArr2[8] = 'i';
   cArr2[9] = 'j';
   str9 = new String(cArr2, 5, 5);
   str8 = "fghij";
   iCountTestcases++;
   if(!str9.Equals(str8))
     {
     iCountErrors++;
     print("E_31sj");
     }
   IntlStrings intl = new IntlStrings();
   String testString = intl.GetString(8, true, true);
   cArr2 = testString.ToCharArray();
   str9 = new String(cArr2, 0, 8);
   if(! str9.Equals(testString)) {
   ++iCountErrors;
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 17
0
 public virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strBaseLoc = "";
   String strToSearch;
   String strValue;
   try {
   LABEL_860_GENERAL:
   do
     {
     strLoc = "Loc_30894";
     strToSearch = " ";
     strValue = null;
     iCountTestcases++;
     try {
     strToSearch.LastIndexOf(strValue);
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_234us");
     } catch (ArgumentException aExc) {}
     catch ( Exception exc) {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_417as");
     }
     strLoc = "Loc_3804u";
     strToSearch = "This is a \tstring";
     strValue = "  ";
     iCountTestcases++;
     if(strToSearch.LastIndexOf(strValue) != -1)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_0952u! , return=="+strToSearch.LastIndexOf(strValue));
       }
     strLoc = "Loc_842ey";
     strToSearch = "This is a \n\n\n small \t\t\t string \r\r\r";
     strValue = "\n\n";
     iCountTestcases++;
     if(strToSearch.LastIndexOf(strValue) != 11)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_348yu! , index=="+strToSearch.LastIndexOf(strValue));
       }
     strToSearch = "This is a \t\t\n small \t\t\t string \r\r\r";
     strValue = "\t";
     iCountTestcases++;
     if(strToSearch.LastIndexOf(strValue) != 22)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_473yf! , index=="+strToSearch.LastIndexOf(strValue));
       }
     strToSearch = "This is a \n\n\n \r\r\r\r small \t\t\t string \r\r\r\r";
     strValue = "\r\r\r";
     iCountTestcases++;
     if(strToSearch.LastIndexOf(strValue) != 37)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_9837u! , index=="+strToSearch.LastIndexOf(strValue));
       }
     IntlStrings intl = new IntlStrings();
     strToSearch = intl.GetString(5, true, true);
     strValue = intl.GetString(18, true, true);
     strToSearch = String.Concat(strToSearch, strValue);
     if(strToSearch.LastIndexOf(strValue) < 5) {
     ++iCountErrors;
     }
     strValue = " ";
     strToSearch = "This is \t a String";
     iCountTestcases++;
     if(strToSearch.LastIndexOf(strValue) != 11)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_3489d! , index=="+strToSearch.LastIndexOf(strValue));
       }
     strToSearch = "this is a string";
     iCountTestcases++;
     if(strToSearch.LastIndexOf(String.Empty) != strToSearch.Length-1)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_3247s! , index=="+strToSearch.LastIndexOf(String.Empty));
       }
     } while (false);
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 18
0
        public void Test01()
        {
            IntlStrings intl;
            StringDictionary sd;
            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aa",
                "tExt",
                "     spAces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "one",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };

            Array arr;
            ICollection ks;         // Keys collection
            int ind;

            // initialize IntStrings
            intl = new IntlStrings();


            // [] StringDictionary is constructed as expected
            //-----------------------------------------------------------------

            sd = new StringDictionary();

            // [] get Keys on empty dictionary
            //
            if (sd.Count > 0)
                sd.Clear();

            if (sd.Keys.Count != 0)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", sd.Keys.Count));
            }

            //
            // [] get Keys on filled dictionary
            //
            int len = values.Length;
            sd.Clear();
            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len));
            }

            ks = sd.Keys;
            if (ks.Count != len)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", ks.Count));
            }
            arr = Array.CreateInstance(typeof(string), len);
            ks.CopyTo(arr, 0);
            for (int i = 0; i < len; i++)
            {
                ind = Array.IndexOf(arr, keys[i].ToLowerInvariant());
                if (ind < 0)
                {
                    Assert.False(true, string.Format("Error, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keys[i], ind));
                }
            }



            //
            // [] get Keys on dictionary with identical values
            //

            sd.Clear();
            string intlStr = intl.GetRandomString(MAX_LEN);

            sd.Add("keykey1", intlStr);        // 1st duplicate
            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            sd.Add("keykey2", intlStr);        // 2nd duplicate
            if (sd.Count != len + 2)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len + 2));
            }

            // get Keys
            //

            ks = sd.Keys;
            if (ks.Count != sd.Count)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", ks.Count));
            }
            arr = Array.CreateInstance(typeof(string), len + 2);
            ks.CopyTo(arr, 0);
            for (int i = 0; i < len; i++)
            {
                ind = Array.IndexOf(arr, keys[i].ToLowerInvariant());
                if (ind < 0)
                {
                    Assert.False(true, string.Format("Error, Keys doesn't contain \"{1}\" key", i, keys[i]));
                }
            }
            ind = Array.IndexOf(arr, "keykey1");
            if (ind < 0)
            {
                Assert.False(true, string.Format("Error, Keys doesn't contain {0} key", "keykey1"));
            }

            ind = Array.IndexOf(arr, "keykey2");
            if (ind < 0)
            {
                Assert.False(true, string.Format("Error, Keys doesn't contain \"{0}\" key", "keykey2"));
            }

            //
            // Intl strings
            // [] get Keys on dictionary filled with Intl strings
            //

            string[] intlValues = new string[len * 2];
            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }

            //
            // will use first half of array as values and second half as keys
            //
            sd.Clear();
            for (int i = 0; i < len; i++)
            {
                sd.Add(intlValues[i + len], intlValues[i]);
            }
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len));
            }

            ks = sd.Keys;
            if (ks.Count != len)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", ks.Count));
            }
            arr = Array.CreateInstance(typeof(string), len);
            ks.CopyTo(arr, 0);
            for (int i = 0; i < arr.Length; i++)
            {
                ind = Array.IndexOf(arr, intlValues[i + len].ToLowerInvariant());
                if (ind < 0)
                {
                    Assert.False(true, string.Format("Error, Keys doesn't contain \"{1}\" key", i, intlValues[i + len]));
                }
            }

            //
            //  Case sensitivity: keys are always lowercased - not doing it
            // [] Change dictionary and check Keys
            //

            sd.Clear();
            for (int i = 0; i < len; i++)
            {
                sd.Add(keys[i], values[i]);
            }
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len));
            }

            ks = sd.Keys;
            if (ks.Count != len)
            {
                Assert.False(true, string.Format("Error, returned Keys.Count = {0}", ks.Count));
            }

            sd.Remove(keys[0]);
            if (sd.Count != len - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove element"));
            }
            if (ks.Count != len - 1)
            {
                Assert.False(true, string.Format("Error, Keys were not updated after removal"));
            }
            arr = Array.CreateInstance(typeof(string), sd.Count);
            ks.CopyTo(arr, 0);
            ind = Array.IndexOf(arr, keys[0].ToLowerInvariant());
            if (ind >= 0)
            {
                Assert.False(true, string.Format("Error, Keys still contains removed key " + ind));
            }

            sd.Add(keys[0], "new item");
            if (sd.Count != len)
            {
                Assert.False(true, string.Format("Error, didn't add element"));
            }
            if (ks.Count != len)
            {
                Assert.False(true, string.Format("Error, Keys were not updated after addition"));
            }
            arr = Array.CreateInstance(typeof(string), sd.Count);
            ks.CopyTo(arr, 0);
            ind = Array.IndexOf(arr, keys[0].ToLowerInvariant());
            if (ind < 0)
            {
                Assert.False(true, string.Format("Error, Keys doesn't contain added key "));
            }
        }
Esempio n. 19
0
        public void Test01()
        {
            IntlStrings intl;
            StringCollection sc;
            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aa",
                "text",
                "     spaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // initialize IntStrings
            intl = new IntlStrings();


            // [] StringCollection is constructed as expected
            //-----------------------------------------------------------------

            sc = new StringCollection();

            // [] Insert into empty collection
            //
            for (int i = 0; i < values.Length; i++)
            {
                if (sc.Count > 0)
                    sc.Clear();
                sc.Insert(0, values[i]);
                if (sc.Count != 1)
                {
                    Assert.False(true, string.Format("Error, Count {1} instead of 1", i, sc.Count));
                }
                if (!sc.Contains(values[i]))
                {
                    Assert.False(true, string.Format("Error, doesn't contain just inserted item", i));
                }
            }

            //
            // [] Insert into filled collection



            sc.Clear();
            sc.AddRange(values);
            if (sc.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length));
            }

            // string to insert
            string val = intl.GetRandomString(MAX_LEN);

            sc.Insert(0, val);

            if (sc.Count != values.Length + 1)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", sc.Count, values.Length + 1));
            }

            if (sc.IndexOf(val) != 0)
            {
                Assert.False(true, string.Format("Error, IndexOf returned {0} instead of {1}", sc.IndexOf(val), 0));
            }

            // check that all init items were moved
            for (int i = 0; i < values.Length; i++)
            {
                if (sc.IndexOf(values[i]) != i + 1)
                {
                    Assert.False(true, string.Format("Error, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i + 1));
                }
            }

            sc.Clear();
            sc.AddRange(values);
            if (sc.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length));
            }

            sc.Insert(values.Length, val);

            if (sc.Count != values.Length + 1)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", sc.Count, values.Length + 1));
            }

            if (sc.IndexOf(val) != values.Length)
            {
                Assert.False(true, string.Format("Error, IndexOf returned {0} instead of {1}", sc.IndexOf(val), values.Length));
            }

            // check that all init items were moved
            for (int i = 0; i < values.Length; i++)
            {
                if (sc.IndexOf(values[i]) != i)
                {
                    Assert.False(true, string.Format("Error, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i));
                }
            }


            sc.Clear();
            sc.AddRange(values);
            if (sc.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", sc.Count, values.Length));
            }

            sc.Insert(values.Length / 2, val);

            if (sc.Count != values.Length + 1)
            {
                Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", sc.Count, values.Length + 1));
            }

            if (sc.IndexOf(val) != values.Length / 2)
            {
                Assert.False(true, string.Format("Error, IndexOf returned {0} instead of {1}", sc.IndexOf(val), values.Length / 2));
            }

            // check that all init items were moved
            for (int i = 0; i < values.Length; i++)
            {
                int expected = i;
                if (i >= values.Length / 2)
                    expected = i + 1;
                if (sc.IndexOf(values[i]) != expected)
                {
                    Assert.False(true, string.Format("Error, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), expected));
                }
            }

            //
            // [] Invalid parameter
            //
            Assert.Throws<ArgumentOutOfRangeException>(() => { sc.Insert(-1, val); });
            Assert.Throws<ArgumentOutOfRangeException>(() => { sc.Insert(sc.Count + 1, val); });
            Assert.Throws<ArgumentOutOfRangeException>(() => { sc.Insert(sc.Count + 2, val); });
        }
 public virtual bool runTest()
   {
   Console.Out.WriteLine( "Co4000ctor_StrArr.  runTest() started." );
   StringBuilder sblMsg = null;
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String[] strArr1 = null;
   String strConstructed = null;
   String strExpectedResult = null;
   char[] chArr2 = new char[1];
   String str3 = null;
   int inw1 = -2;
   do
     {
     chArr2[0] = '\0';
     str3 = new String( chArr2 );
     inw1 = str3.Length;
     ++iCountTestcases;
     if ( inw1 != 1 )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: Error E_831gm (Co4000ctor_StrArr)  inw1==" + inw1  );
       }
     IntlStrings intl = new IntlStrings();
     strArr1 = new String[2];
     strArr1[0] = intl.GetString(4, true, true);
     strArr1[1] = intl.GetString(6, true, true);
     strExpectedResult = String.Concat(strArr1[0], strArr1[1]);
     String testString = strExpectedResult;
     if(testString.Equals(strExpectedResult) == false) {
     ++iCountErrors;
     }
     ++iCountTestcases;
     strArr1 = new String[5];
     strArr1[0] = "bc";
     strArr1[1] = "cd";
     strArr1[2] = "de";
     strArr1[3] = "ef";
     strArr1[4] = "fg";
     strExpectedResult = "bccddeeffg";
     strConstructed = String.Concat( strArr1 );
     if ( strConstructed == null )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_3b62 (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_3b62 ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     if ( strConstructed.Equals( strExpectedResult ) == false )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_09pv (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_09pv ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     ++iCountTestcases;
     strArr1 = new String[5];
     strArr1[0] = "bc";
     strArr1[1] = "cd";
     strArr1[2] = "\0";     
     strArr1[3] = "ef";
     strArr1[4] = "fg";
     strExpectedResult = "bccd\0effg";
     strConstructed = String.Concat( strArr1 );
     if ( strConstructed == null )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_g4v87 (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_g4v87 ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     if ( strConstructed.Equals( strExpectedResult ) == false )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_89fr (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_89fr ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     ++iCountTestcases;
     strArr1 = new String[5];
     strArr1[0] = "bc";
     strArr1[1] = "cd";
     strArr1[2] = null;      
     strArr1[3] = "ef";
     strArr1[4] = "fg";
     strExpectedResult = "bccdeffg";  
     strConstructed = String.Concat( strArr1 );
     if ( strConstructed == null )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_f3d6 (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_f3d6 ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     if ( strConstructed.Equals( strExpectedResult ) == false )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_173fn (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_173fn ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     ++iCountTestcases;
     strArr1 = new String[5];
     strArr1[0] = "bc";
     strArr1[1] = "cd";
     strArr1[2] = "";
     strArr1[3] = "ef";
     strArr1[4] = "fg";
     strExpectedResult = "bccdeffg";
     strConstructed = String.Concat( strArr1 );
     if ( strConstructed == null )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_f4j2 (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_f4j2 ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     if ( strConstructed.Equals( strExpectedResult ) == false )
       {
       ++iCountErrors;
       Console.Error.WriteLine(  "POINTTOBREAK: find error E_290kp (Co4000ctor_StrArr)"  );
       sblMsg = new StringBuilder( "EXTENDEDINFO: (E_290kp ,Co4000ctor_StrArr).  strConstructed==" );
       sblMsg.Append( strConstructed );
       Console.Error.WriteLine(  sblMsg.ToString()  );
       }
     }
   while ( false );
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 public unsafe bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     sbyte* chptr = null, baseptr = null;
     String str1 = String.Empty, str2 = String.Empty;
     strLoc = "Loc_498hv";
     try {
     iCountTestcases++;
     str2 = new String(chptr);
     if(!str2.Equals(String.Empty))
       {
       iCountErrors++;
       printerr( "Error_498ch! incorrect string returned for null argument=="+str2);
       } 
     } catch(Exception e) {Console.WriteLine(e.ToString());};
     strLoc = "Loc_982hc";
     iCountTestcases++;
     try {
     iCountTestcases++;
     IntlStrings intl = new IntlStrings();
     String testString = intl.GetString(1, true, true);
     fixed (char *charptr = testString) {
     str2 =new  String(charptr);
     }
     if(str2 != testString)
       {
       iCountErrors++;
       printerr( "Error_49hcx! incorrect string constructed=="+str2);
       }
     } catch(Exception e) {Console.WriteLine("WRONG");}
     try {
     strLoc = "Loc_9fhc1";
     *chptr = (sbyte)'\t';
     str2 = new String(chptr);
     iCountTestcases++;
     if(str2[0]!='\t')
       {
       iCountErrors++;
       printerr( "Error_89hfd! incorrect string constructed=="+str2);
       }
     } catch(Exception e) {Console.WriteLine(e.ToString());}
     try {
     strLoc = "Loc_9fh56";
     iCountTestcases++;
     sbyte* p = stackalloc sbyte[10];
     for (int i = 0; i < 10; i++) {
     p[i] = (sbyte)(i + (int)'0');
     str1 += ((sbyte) i);
     }
     strLoc = "Loc_93286";
     iCountTestcases++;
     str2 = new String (p);
     strLoc = "Loc_93287";
     if(!str2.Equals(str1))
       { 
       iCountErrors++;
       printerr( "Error_209xu! Expected=="+str1+"\nIncorrect string=="+str2);
       printinfo ("str2.Length == " + str2.Length);
       } }
     catch(Exception e) {Console.WriteLine(e.ToString());}
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
 public virtual bool runTest
   ()
   {
   System.Console.Error.WriteLine( "String.LastIndexOf: Co1160LIO runTest starting..." );
   int iCountTestcases = 0 ;
   int nErrorBits = 0; 
   int n2 = -2;
   String strLoc="Loc_000oo";
   System.String swrString2 = null;
   System.String swrString3 = null;
   System.String swrString4 = null;
   int iResult = 0;
   int[] iArrInvalidValues = new Int32[]{ -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue};
   int[] iArrLargeValues = new Int32[]{ Int32.MaxValue, Int32.MaxValue-1, Int32.MaxValue/2 , Int32.MaxValue/10 , Int32.MaxValue/100, 100000, 10000, 1000, 100, 21 };
   int[] iArrValidValues = new Int32[]{ 100000, 99999 , 10000 , 1000, 100, 10, 1, 0 };
   IntlStrings intl = new IntlStrings();
   String intlString = intl.GetString(20, true, true);    
   iCountTestcases++;
   for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ ){
   try
     {
     iResult = intlString.LastIndexOf( intlString[5] , iArrInvalidValues[iLoop] );
     nErrorBits++;
     Console.WriteLine("Error_0000!!! Expected exception not occured...");
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.WriteLine( "Error_2222!!! Unexpected exception " + ex.ToString() );
       nErrorBits++ ;
       }
   }
   iCountTestcases++;
   for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ ){
   try
     {
     iResult = intlString.LastIndexOf( intlString[5] , iArrLargeValues[iLoop] );
     nErrorBits++;
     Console.WriteLine("Error_1111!!! Expected exception not occured...");                
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.WriteLine( "Error_3333!!! Unexpected exception " + ex.ToString() );
       nErrorBits++ ;
       }
   }
   iCountTestcases++;
   intlString = intl.GetString(100002, true, true);        
   for(int iLoop = 0 ; iLoop < iArrValidValues.Length ; iLoop++ ){
   try
     {                            
     iResult = intlString.LastIndexOf( intlString[iArrValidValues[iLoop]] , intlString.Length - 1 );
     if ( iResult == -1 ){
     nErrorBits++;
     Console.WriteLine( "Error_6666!!!! Incorrect LastIndexOf value.... Actual...{0}", iResult );
     }
     } catch ( Exception ex ){
     Console.WriteLine( "Error_7777!!! Unexpected exception " + ex.ToString() );
     nErrorBits++ ;
     }
   }
   try
     {
     iCountTestcases++ ;
     swrString2 = "abc X def X ghi";
     n2 = swrString2.LastIndexOf( 'i' ,13 );
     if (n2 != -1)
       nErrorBits = nErrorBits | 0x1;
     strLoc="Loc_304sd";
     try
       {
       swrString2 = "abc X def X ghi";
       n2 = swrString2.LastIndexOf( 'i' ,-1  );
       nErrorBits = nErrorBits | 0x2;
       }
     catch (ArgumentException)
       {
       }
     catch (Exception)
       {
       nErrorBits = nErrorBits | 0x40;
       }
     iCountTestcases++ ;
     strLoc="Loc_204_os";
     try
       {
       n2 = swrString2.LastIndexOf( 'I' ,-1  );
       nErrorBits = nErrorBits | 0x10;
       }
     catch (ArgumentException)
       {
       }
     catch (Exception)
       {
       nErrorBits = nErrorBits | 0x80;
       }
     iCountTestcases++ ;
     strLoc="Loc_038_ai";
     swrString2 = "abc X def X ghi";
     n2 = swrString2.LastIndexOf( 'c' ,2 );
     if (n2 != 2)
       nErrorBits = nErrorBits | 0x4;
     iCountTestcases++ ;
     strLoc="Loc_543_lw";
     swrString2 = "abc X def X ghi";
     n2 = swrString2.LastIndexOf( 'X' ,7  );
     if (n2 != 4)
       nErrorBits = nErrorBits | 0x8;
     intl = new IntlStrings();
     swrString2 = intl.GetString(4, true, true);
     swrString3 = intl.GetString(1, true, true);
     swrString4 = String.Concat(swrString2, swrString3);
     swrString4 = String.Concat(swrString4, swrString2);
     swrString4 = String.Concat(swrString4, swrString3);
     swrString4 = String.Concat(swrString4, swrString2);
     n2 = swrString4.LastIndexOf(swrString3[0], 7);
     if(n2 < 4) 
       nErrorBits = nErrorBits | 0x8;
     }
   catch (Exception ex)
     {
     Console.Error.WriteLine(  "POINTTOBREAK: Error Err_343un! (Co1160LastIndexOf_CharInt) ex==" + ex  );
     Console.Error.WriteLine(  "EXTENDEDINFO: (Err_343un) strLoc==" + strLoc  );
     nErrorBits = nErrorBits | 0x20;
     }
   System.Console.Error.Write( "String.LastIndexOf: Co1160LIO nErrorBits==" );
   System.Console.Error.WriteLine( nErrorBits  );
   if (nErrorBits == 0) {
   return true; 
   }
   else {
   return false; 
   }
   }
Esempio n. 23
0
        public void Test01()
        {
            IntlStrings intl;
            NameValueCollection nvc;

            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aA",
                "text",
                "     SPaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "oNe",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };

            int cnt = 0;            // Count

            // initialize IntStrings
            intl = new IntlStrings();


            // [] NameValueCollection is constructed as expected
            //-----------------------------------------------------------------

            nvc = new NameValueCollection();

            // [] add simple strings
            //
            for (int i = 0; i < values.Length; i++)
            {
                cnt = nvc.Count;
                nvc.Add(keys[i], values[i]);
                if (nvc.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, nvc.Count, cnt + 1));
                }

                // verify that collection contains newly added item
                //
                if (Array.IndexOf(nvc.AllKeys, keys[i]) < 0)
                {
                    Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i));
                }

                //  access the item
                //
                if (String.Compare(nvc[keys[i]], values[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, nvc[keys[i]], values[i]));
                }
            }

            //
            // Intl strings
            // [] add Intl strings
            //
            int len = values.Length;
            string[] intlValues = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }

            Boolean caseInsensitive = false;
            for (int i = 0; i < len * 2; i++)
            {
                if (intlValues[i].Length != 0 && intlValues[i].ToLowerInvariant() == intlValues[i].ToUpperInvariant())
                    caseInsensitive = true;
            }


            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                cnt = nvc.Count;

                nvc.Add(intlValues[i + len], intlValues[i]);
                if (nvc.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, nvc.Count, cnt + 1));
                }

                // verify that collection contains newly added item
                //
                if (Array.IndexOf(nvc.AllKeys, intlValues[i + len]) < 0)
                {
                    Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i));
                }

                //  access the item
                //
                if (String.Compare(nvc[intlValues[i + len]], intlValues[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, nvc[intlValues[i + len]], intlValues[i]));
                }
            }

            //
            // [] Case sensitivity
            // Casing doesn't change ( keya are not converted to lower!)
            //
            string[] intlValuesLower = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                intlValues[i] = intlValues[i].ToUpperInvariant();
            }

            for (int i = 0; i < len * 2; i++)
            {
                intlValuesLower[i] = intlValues[i].ToLowerInvariant();
            }

            nvc.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                cnt = nvc.Count;

                nvc.Add(intlValues[i + len], intlValues[i]);
                if (nvc.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, nvc.Count, cnt + 1));
                }

                // verify that collection contains newly added uppercase item
                //
                if (Array.IndexOf(nvc.AllKeys, intlValues[i + len]) < 0)
                {
                    Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i));
                }

                //  access the item
                //
                if (String.Compare(nvc[intlValues[i + len]], intlValues[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, nvc[intlValues[i + len]], intlValues[i]));
                }

                // verify that collection doesn't contains lowercase item
                //
                if (!caseInsensitive && String.Compare(nvc[intlValuesLower[i + len]], intlValuesLower[i]) == 0)
                {
                    Assert.False(true, string.Format("Error, returned item \"{1}\" is lowercase after adding uppercase", i, nvc[intlValuesLower[i + len]]));
                }

                // key is not converted to lower
                if (!caseInsensitive && Array.IndexOf(nvc.AllKeys, intlValuesLower[i + len]) >= 0)
                {
                    Assert.False(true, string.Format("Error, key was converted to lower", i));
                }

                // but search among keys is case-insensitive
                if (String.Compare(nvc[intlValuesLower[i + len]], intlValues[i]) != 0)
                {
                    Assert.False(true, string.Format("Error, could not find item using differently cased key", i));
                }
            }

            //
            //  [] Add multiple values with the same key
            //

            nvc.Clear();
            len = values.Length;
            string k = "keykey";

            for (int i = 0; i < len; i++)
            {
                nvc.Add(k, "Value" + i);
            }
            if (nvc.Count != 1)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of 1}", nvc.Count));
            }

            if (nvc.AllKeys.Length != 1)
            {
                Assert.False(true, "Error, should contain only 1 key");
            }

            // verify that collection contains newly added item
            //
            if (Array.IndexOf(nvc.AllKeys, k) < 0)
            {
                Assert.False(true, "Error, collection doesn't contain key of new item");
            }

            //  access the item
            //
            string[] vals = nvc.GetValues(k);
            if (vals.Length != len)
            {
                Assert.False(true, string.Format("Error, number of values at given key is {0} instead of {1}", vals.Length, len));
            }

            for (int i = 0; i < len; i++)
            {
                if (Array.IndexOf(vals, "Value" + i) < 0)
                {
                    Assert.False(true, string.Format("Error, doesn't contain {1}", i, "Value" + i));
                }
            }

            //
            // [] Add null value
            //

            cnt = nvc.Count;
            k = "kk";
            nvc.Add(k, null);

            if (nvc.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, cnt + 1));
            }

            if (Array.IndexOf(nvc.AllKeys, k) < 0)
            {
                Assert.False(true, "Error, collection doesn't contain key of new item");
            }

            // verify that collection contains null
            //
            if (nvc[k] != null)
            {
                Assert.False(true, "Error, returned non-null on place of null");
            }

            //
            // [] Add item with null key
            // Add item with null key - NullReferenceException expected
            //

            cnt = nvc.Count;

            nvc.Add(null, "item");

            if (nvc.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, cnt + 1));
            }

            if (Array.IndexOf(nvc.AllKeys, null) < 0)
            {
                Assert.False(true, "Error, collection doesn't contain null key ");
            }

            // verify that collection contains null
            //
            if (nvc[null] != "item")
            {
                Assert.False(true, "Error, returned wrong value at null key");
            }
        }
 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     StringDictionary sd; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aa",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "one",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     string itm;         
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create dictionary ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sd = new StringDictionary();
         Console.WriteLine("1. set Item on empty dictionary");
         iCountTestcases++;
         for (int i = 0; i < keys.Length; i++) 
         {
             if (sd.Count > 0)
                 sd.Clear();
             sd[keys[i]] = values[i];
             if (sd.Count != 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001a_{0}, didn't add item with {0} key", i);
             }
             if (String.Compare(sd[keys[i]], values[i], false) != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001b_{0}, added wrong value", i);
             }
         }
         Console.WriteLine("2. set Item on filled dictionary");  
         strLoc = "Loc_002oo"; 
         int len = values.Length;
         iCountTestcases++;
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, len);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             itm = "item" + i;
             sd[keys[i]] = itm;
             if (String.Compare(sd[keys[i]], itm, false) != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, returned {1} instead of {2}", i, sd[keys[i]], itm);
             } 
         }
         Console.WriteLine("3. set Item on dictionary with duplicate values ");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         sd.Clear();
         string intlStr = intl.GetString(MAX_LEN, true, true, true);
         string intlStr1 = intl.GetString(MAX_LEN, true, true, true);
         sd.Add("keykey1", intlStr);        
         for (int i = 0; i < len; i++) 
         {
             sd.Add(keys[i], values[i]);
         }
         sd.Add("keykey2", intlStr);        
         if (sd.Count != len+2) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", sd.Count, len+2);
         } 
         iCountTestcases++;
         sd["keykey1"] = intlStr1;
         if (String.Compare(sd["keykey1"], intlStr1, false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, returned {1} instead of {2}", sd["keykey1"],intlStr1);
         } 
         iCountTestcases++;
         sd["keykey2"] = intlStr1;
         if (String.Compare(sd["keykey2"], intlStr1, false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003c, returned {1} instead of {2}", sd["keykey2"],intlStr1);
         } 
         Console.WriteLine("4. set Item on dictionary with intl strings");
         strLoc = "Loc_004oo"; 
         string [] intlValues = new string [len*2];
         string [] intlSets = new string [len];
         for (int i = 0; i < len*2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         for (int i = 0; i < len; i++) 
         {
             intlSets[i] = intl.GetString(MAX_LEN, true, true, true);
         } 
         sd.Clear();
         for (int i = 0; i < len; i++) 
         {
             sd.Add(intlValues[i+len], intlValues[i]);
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, count is {0} instead of {1}", sd.Count, len);
         }
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             sd[intlValues[i+len]] = intlSets[i];
             if (String.Compare(sd[intlValues[i+len]], intlSets[i], false) != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, returned {1} instead of {2}", i, sd[intlValues[i+len]], intlSets[i]);
             } 
         }
         Console.WriteLine("5. Case sensitivity");
         strLoc = "Loc_005oo"; 
         iCountTestcases++;
         sd.Clear();
         string [] intlValuesUpper = new string [len];
         for (int i = 0; i < len * 2; i++) 
         {
             intlValues[i] = intlValues[i].ToLower();
         }
         for (int i = 0; i < len; i++) 
         {
             intlValuesUpper[i] = intlValues[i].ToUpper();
         } 
         sd.Clear();
         Console.WriteLine(" ... add Lowercased ...");
         for (int i = 0; i < len; i++) 
         {
             sd.Add(intlValues[i+len], intlValues[i]);     
         }
         if (sd.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005a, count is {0} instead of {1}", sd.Count, len);
         } 
         Console.WriteLine(" ... set to Uppercased ..."); 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             sd[intlValues[i+len]] = intlValuesUpper[i];
             if (String.Compare(sd[intlValues[i+len]], intlValuesUpper[i], false) != 0) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0005b_{0}, returned {1} instead of {2}", i, sd[intlValues[i+len]], intlValuesUpper[i]);
             } 
         }
         Console.WriteLine("6. set Item(null)");
         strLoc = "Loc_006oo"; 
         iCountTestcases++;
         try 
         {
             sd[null] = intlStr;
             iCountErrors++;
             Console.WriteLine("Err_0006a, no exception");
         }
         catch (ArgumentNullException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0006b, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("7. set Item to null");
         strLoc = "Loc_007oo"; 
         iCountTestcases++;
         if (!sd.ContainsKey(keys[0]) ) 
         {
             sd.Add(keys[0], values[0]);
         }
         sd[keys[0]] = null;
         if ( sd[keys[0]] != null )
         {
             iCountErrors++;
             Console.WriteLine("Err_0007, returned non-null");
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
Esempio n. 25
0
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     String str1 = String.Empty, str2 = String.Empty, str3 = String.Empty;
     String str = null;
     strLoc = "Loc_498hv";
     iCountTestcases++;
     str = String.Concat (str1, str2);
     if(!str.Equals (String.Empty))
       {
       iCountErrors++;
       printerr( "Error_498ch! incorrect string returned for null argument=="+str);
       } 
     strLoc = "Loc_982hc.2";			
     iCountTestcases++;
     try {
     str = String.Concat (null, str2);
     if(!str.Equals (String.Empty))
       {
       iCountErrors++;
       printerr( "Error_687ch.2! incorrect string returned for null argument=="+str);
       } 
     }
     catch (ArgumentException aexc) {
     iCountErrors++;
     printerr( "Error_498ch.2! Unexpcted! " + aexc);
     }
     strLoc = "Loc_982hc.3";			
     iCountTestcases++;
     try {
     str = String.Concat (str1, null);
     if(!str.Equals (String.Empty))
       {
       iCountErrors++;
       printerr( "Error_687ch.3! incorrect string returned for null argument=="+str);
       } 
     }
     catch (ArgumentException aexc) {
     iCountErrors++;
     printerr( "Error_498ch.3! Unexpcted! " + aexc);
     }
     strLoc = "Loc_982hc.4";			
     iCountTestcases++;
     try {
     str = String.Concat (null, null);
     if(str != String.Empty)
       {
       iCountErrors++;
       printerr( "Error_687ch.4! incorrect string returned for null argument=="+str);
       Console.WriteLine (str == String.Empty);
       } 
     }
     catch (ArgumentException aexc) {
     iCountErrors++;
     printerr( "Error_498ch.4! Unexpcted! " + aexc);
     }
     strLoc = "Loc_498hv";
     iCountTestcases++;
     str1 = "abc";
     str2 = "123";
     str = String.Concat (str1, str2);
     if(!str.Equals ("abc123"))
       {
       iCountErrors++;
       printerr( "Error_498ch! incorrect string returned for null argument=="+str);
       } 
     IntlStrings intl = new IntlStrings();
     str1 = intl.GetString(5, true, true);
     str2 = intl.GetString(4, true, true);
     str3 = intl.GetString(9, true, true);
     String testString = String.Concat(str1, str2, null);
     str = String.Concat (str1, str2);
     if(! str.Equals(testString)) {
     ++iCountErrors;
     }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 26
0
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     String str1 = String.Empty, str2 = String.Empty;
     strLoc = "Loc_498hv";
     iCountTestcases++;
     str1 = String.Concat (String.Empty);
     str2 = String.Copy (str1);
     if(!str2.Equals(String.Empty))
       {
       iCountErrors++;
       printerr( "Error_498ch! incorrect string returned for null argument=="+str2);
       } 
     strLoc = "Loc_498hv.2";
     iCountTestcases++;
     if(str1 != str2)
       {
       iCountErrors++;
       printerr( "Error_498ch.2! str1 != str2; str2 == "+ str2);
       } 
     strLoc = "Loc_498hv.3";
     str1 = "Hi There";
     str2 = String.Copy (str1);
     iCountTestcases++;
     if(!str2.Equals ("Hi There"))
       {
       iCountErrors++;
       printerr( "Error_498ch.3! incorrect string returned for null argument=="+str2);
       } 
     IntlStrings intl = new IntlStrings();
     str1 = intl.GetString(12, false, true);
     str2 = String.Copy (str1);
     String str3 = str1;
     iCountTestcases++;
     if(!str2.Equals (str3))
       {
       iCountErrors++;
       printerr( "Error_498ch.3! incorrect string returned for null argument=="+str2);
       }
     strLoc = "Loc_498hv.4";
     iCountTestcases++;
     if(str1 != str2)
       {
       iCountErrors++;
       printerr( "Error_498ch.4! str1 != str2; str2 == "+ str2);
       } 
     strLoc = "Loc_498hv.5";
     iCountTestcases++;
     try {
     str2 = String.Copy (null);
     iCountErrors++;
     printerr( "Error_498ch.5! expected argnullexc; instead resturned "+str2);
     }
     catch (ArgumentNullException ) {
     }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Esempio n. 27
0
 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     NameValueCollection nvc; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aA",
         "text",
         "     SPaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "oNe",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001_oo"; 
         iCountTestcases++;
         nvc = new NameValueCollection();
         cnt = nvc.Count;
         if ( cnt != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, count is {0} instead of {1} after default ctor", nvc.Count, 0);
         }
         Console.WriteLine("1. call HasKeys() on empty collection");
         strLoc = "Loc_001oa"; 
         iCountTestcases++;
         if ( nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, HasKeys returned true after default ctor");
         }
         Console.WriteLine("2. add simple strings and call HasKeys()");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = nvc.Count;
         for (int i = 0; i < values.Length; i++) 
         {    
             nvc.Add(keys[i], values[i]);
         }
         if (nvc.Count != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length);
         }
         iCountTestcases++;
         if ( !nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002b, returned false for collection with {0} items", nvc.Count);
         }
         Console.WriteLine("3. add intl strings and call HasKeys()");
         strLoc = "Loc_003oo"; 
         int len = values.Length;
         string [] intlValues = new string [len * 2];
         for (int i = 0; i < len * 2; i++) 
         {
             string val = intl.GetString(MAX_LEN, true, true, true);
             while (Array.IndexOf(intlValues, val) != -1 )
                 val = intl.GetString(MAX_LEN, true, true, true);
             intlValues[i] = val;
         } 
         cnt = nvc.Count;
         iCountTestcases++;
         for (int i = 0; i < len; i++) 
         {    
             nvc.Add(intlValues[i+len], intlValues[i]);
         }
         if (nvc.Count != (cnt + len)) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003a, count is {0} instead of {1}", nvc.Count, cnt + len);
         }
         iCountTestcases++;
         if ( !nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, returned false for collection with {0} items", nvc.Count);
         }
         Console.WriteLine("4. add item with null-key and call HasKeys()");
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         nvc.Clear();
         cnt = nvc.Count;
         for (int i = 0; i < values.Length; i++) 
         {    
             nvc.Add(null, values[i]);
         }
         if (nvc.Count != 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, count is {0} instead of {1}", nvc.Count, 1);
         }
         iCountTestcases++;
         Console.WriteLine(" HasKeys() returns: " + nvc.HasKeys());
         if ( nvc.HasKeys() ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004b, returned true for collection null-key");
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
Esempio n. 28
0
        public void Test01()
        {
            IntlStrings intl;


            HybridDictionary hd;

            const int BIG_LENGTH = 100;

            // simple string values
            string[] valuesShort =
            {
                "",
                " ",
                "$%^#",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keysShort =
            {
                Int32.MaxValue.ToString(),
                " ",
                System.DateTime.Today.ToString(),
                "",
                "$%^#"
            };

            string[] valuesLong = new string[BIG_LENGTH];
            string[] keysLong = new string[BIG_LENGTH];

            int cnt = 0;            // Count
            Object itm;         // Item

            // initialize IntStrings
            intl = new IntlStrings();

            for (int i = 0; i < BIG_LENGTH; i++)
            {
                valuesLong[i] = "Item" + i;
                keysLong[i] = "keY" + i;
            }

            // [] HybridDictionary is constructed as expected
            //-----------------------------------------------------------------

            hd = new HybridDictionary();

            // [] set Item() on empty dictionary
            //
            cnt = hd.Count;
            try
            {
                hd[null] = valuesShort[0];
                Assert.False(true, string.Format("Error, no exception"));
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
                Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString()));
            }

            cnt = hd.Count;
            hd["some_string"] = valuesShort[0];
            if (hd.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, failed to add Item(some_string)"));
            }
            itm = hd["some_string"];
            if (String.Compare(itm.ToString(), valuesShort[0]) != 0)
            {
                Assert.False(true, string.Format("Error, added wrong Item(some_string)"));
            }

            cnt = hd.Count;
            Hashtable l = new Hashtable();
            ArrayList bb = new ArrayList();
            hd[l] = bb;
            if (hd.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, failed to add Item(some_object)"));
            }
            itm = hd[l];
            if (!itm.Equals(bb))
            {
                Assert.False(true, string.Format("Error, returned wrong Item(some_object)"));
            }

            // [] set Item() on short dictionary with simple strings
            //

            hd.Clear();
            cnt = hd.Count;
            int len = valuesShort.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
            }
            //

            for (int i = 0; i < len; i++)
            {
                cnt = hd.Count;
                hd[keysShort[i]] = valuesLong[0];
                if (hd.Count != cnt)
                {
                    Assert.False(true, string.Format("Error, added item instead of setting", i));
                }
                itm = hd[keysShort[i]];
                if (String.Compare(itm.ToString(), valuesLong[0]) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set item", i));
                }
            }
            // should add non-existing item
            cnt = hd.Count;
            hd[keysLong[0]] = valuesLong[0];
            if (hd.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, didn't add non-existing item"));
            }
            itm = hd[keysLong[0]];
            if (String.Compare(itm.ToString(), valuesLong[0]) != 0)
            {
                Assert.False(true, string.Format("Error, failed to set item"));
            }

            // [] set Item() on long dictionary with simple strings
            //
            hd.Clear();
            cnt = hd.Count;
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }
            //

            for (int i = 0; i < len; i++)
            {
                cnt = hd.Count;
                hd[keysLong[i]] = valuesShort[0];
                if (hd.Count != cnt)
                {
                    Assert.False(true, string.Format("Error, added item instead of setting", i));
                }
                itm = hd[keysLong[i]];
                if (String.Compare(itm.ToString(), valuesShort[0]) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set item", i));
                }
            }
            // should add non-existing item
            cnt = hd.Count;
            hd[keysShort[0]] = valuesShort[0];
            if (hd.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, didn't add non-existing item"));
            }
            itm = hd[keysShort[0]];
            if (String.Compare(itm.ToString(), valuesShort[0]) != 0)
            {
                Assert.False(true, string.Format("Error, failed to set item"));
            }


            //
            // [] set Item() on long dictionary with Intl strings
            // Intl strings
            //

            len = valuesLong.Length;
            string[] intlValues = new string[len * 2 + 1];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2 + 1; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }
            string toSet = intlValues[len * 2];      // string to set

            cnt = hd.Count;
            for (int i = 0; i < len; i++)
            {
                hd.Add(intlValues[i + len], intlValues[i]);
            }
            if (hd.Count != (cnt + len))
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len));
            }

            for (int i = 0; i < len; i++)
            {
                //
                cnt = hd.Count;
                hd[intlValues[i + len]] = toSet;
                if (hd.Count != cnt)
                {
                    Assert.False(true, string.Format("Error, added item instead of setting", i));
                }
                itm = hd[intlValues[i + len]];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set item", i));
                }
            }

            // [] set Item() on short dictionary with Intl strings
            //

            len = valuesShort.Length;

            hd.Clear();
            cnt = hd.Count;
            for (int i = 0; i < len; i++)
            {
                hd.Add(intlValues[i + len], intlValues[i]);
            }
            if (hd.Count != (cnt + len))
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, cnt + len));
            }

            for (int i = 0; i < len; i++)
            {
                //
                cnt = hd.Count;
                hd[intlValues[i + len]] = toSet;
                if (hd.Count != cnt)
                {
                    Assert.False(true, string.Format("Error, added item instead of setting", i));
                }
                itm = hd[intlValues[i + len]];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, returned wrong item", i));
                }
            }


            //
            // Case sensitivity
            // [] Case sensitivity - hashtable
            //

            len = valuesLong.Length;

            hd.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper());     // adding uppercase strings
            }

            //
            for (int i = 0; i < len; i++)
            {
                // uppercase key
                hd[keysLong[i].ToUpper()] = toSet;
                itm = hd[keysLong[i].ToUpper()];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set", i));
                }
            }

            hd.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper());     // adding uppercase strings
            }

            //  LD is case-sensitive by default   - should add lowercase key
            for (int i = 0; i < len; i++)
            {
                // lowercase key
                cnt = hd.Count;
                hd[keysLong[i].ToLower()] = toSet;
                if (hd.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, failed to add when setting", i));
                }
                itm = hd[keysLong[i].ToLower()];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set item", i));
                }
                itm = hd[keysLong[i].ToUpper()];
                if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to preserve item", i));
                }
            }

            //
            // [] Case sensitivity - list


            len = valuesShort.Length;

            hd.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper());     // adding uppercase strings
            }

            //
            for (int i = 0; i < len; i++)
            {
                // uppercase key
                hd[keysLong[i].ToUpper()] = toSet;
                itm = hd[keysLong[i].ToUpper()];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set", i));
                }
            }

            hd.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i].ToUpper(), valuesLong[i].ToUpper());     // adding uppercase strings
            }

            //  LD is case-sensitive by default   - should add lowercase key
            for (int i = 0; i < len; i++)
            {
                // lowercase key
                cnt = hd.Count;
                hd[keysLong[i].ToLower()] = toSet;
                if (hd.Count != cnt + 1)
                {
                    Assert.False(true, string.Format("Error, failed to add when setting", i));
                }
                itm = hd[keysLong[i].ToLower()];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set item", i));
                }
                itm = hd[keysLong[i].ToUpper()];
                if (String.Compare(itm.ToString(), valuesLong[i].ToUpper()) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to preserve item", i));
                }
            }

            // [] set Item() on case-insensitive HD - list
            //

            hd = new HybridDictionary(true);

            len = valuesShort.Length;
            hd.Clear();
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower());
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            for (int i = 0; i < len; i++)
            {
                hd[keysLong[i].ToUpper()] = toSet;
                itm = hd[keysLong[i].ToUpper()];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set via uppercase key", i));
                }
                hd[keysLong[i].ToLower()] = valuesLong[0];
                itm = hd[keysLong[i].ToLower()];
                if (String.Compare(itm.ToString(), valuesLong[0]) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set via lowercase key", i));
                }
            }

            // [] set Item() on case-insensitive HD - hashtable
            //
            hd = new HybridDictionary(true);

            len = valuesLong.Length;
            hd.Clear();
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i].ToLower(), valuesLong[i].ToLower());
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            for (int i = 0; i < len; i++)
            {
                hd[keysLong[i].ToUpper()] = toSet;
                itm = hd[keysLong[i].ToUpper()];
                if (String.Compare(itm.ToString(), toSet) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set via uppercase key", i));
                }
                hd[keysLong[i].ToLower()] = valuesLong[0];
                itm = hd[keysLong[i].ToLower()];
                if (String.Compare(itm.ToString(), valuesLong[0]) != 0)
                {
                    Assert.False(true, string.Format("Error, failed to set via lowercase key", i));
                }
            }


            //
            //  [] set Item(null) on filled HD - list
            //
            hd = new HybridDictionary();
            len = valuesShort.Length;
            hd.Clear();
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }

            try
            {
                hd[null] = toSet;
                Assert.False(true, string.Format("Error, no exception"));
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
                Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString()));
            }

            //  [] set Item(null) on filled HD - hashtable
            //
            hd = new HybridDictionary();
            len = valuesLong.Length;
            hd.Clear();
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }

            try
            {
                hd[null] = toSet;
                Assert.False(true, string.Format("Error, no exception"));
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
                Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString()));
            }

            //  [] set Item(special_object) on filled HD - list
            //
            hd = new HybridDictionary();

            hd.Clear();
            len = 2;
            ArrayList[] b = new ArrayList[len];
            Hashtable[] lbl = new Hashtable[len];
            SortedList cb = new SortedList();
            for (int i = 0; i < len; i++)
            {
                lbl[i] = new Hashtable();
                b[i] = new ArrayList();
                hd.Add(lbl[i], b[i]);
            }

            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            for (int i = 0; i < len; i++)
            {
                cnt = hd.Count;
                hd[lbl[i]] = cb;
                if (hd.Count != cnt)
                {
                    Assert.False(true, string.Format("Error, added special object instead of setting"));
                }
                itm = hd[lbl[i]];
                if (!itm.Equals(cb))
                {
                    Assert.False(true, string.Format("Error, failed to set special object"));
                }
            }

            cnt = hd.Count;
            hd[cb] = lbl[0];
            if (hd.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, failed to add non-existing special object"));
            }
            itm = hd[cb];
            if (!itm.Equals(lbl[0]))
            {
                Assert.False(true, string.Format("Error, failed to set special object"));
            }

            //  [] set Item(special_object) on filled HD - hashtable
            //
            hd = new HybridDictionary();

            hd.Clear();
            len = 40;
            b = new ArrayList[len];
            lbl = new Hashtable[len];
            for (int i = 0; i < len; i++)
            {
                lbl[i] = new Hashtable();
                b[i] = new ArrayList();
                hd.Add(lbl[i], b[i]);
            }

            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            for (int i = 0; i < len; i++)
            {
                cnt = hd.Count;
                hd[lbl[i]] = cb;
                if (hd.Count != cnt)
                {
                    Assert.False(true, string.Format("Error, added special object instead of setting"));
                }
                itm = hd[lbl[i]];
                if (!itm.Equals(cb))
                {
                    Assert.False(true, string.Format("Error, failed to set special object"));
                }
            }
            cnt = hd.Count;
            hd[cb] = lbl[0];
            if (hd.Count != cnt + 1)
            {
                Assert.False(true, string.Format("Error, failed to add non-existing special object"));
            }
            itm = hd[cb];
            if (!itm.Equals(lbl[0]))
            {
                Assert.False(true, string.Format("Error, failed to set special object"));
            }

            //  [] set Item() to null on filled HD - list
            //
            hd = new HybridDictionary();

            hd.Clear();
            len = valuesShort.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }

            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            cnt = hd.Count;
            hd[keysShort[0]] = null;
            if (hd.Count != cnt)
            {
                Assert.False(true, string.Format("Error, added entry instead of setting"));
            }
            itm = hd[keysShort[0]];
            if (itm != null)
            {
                Assert.False(true, string.Format("Error, failed to set to null"));
            }

            //  [] set Item() to null on filled HD - hashtable
            //
            hd.Clear();

            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }

            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            cnt = hd.Count;
            hd[keysLong[0]] = null;
            if (hd.Count != cnt)
            {
                Assert.False(true, string.Format("Error, added entry instead of setting"));
            }
            itm = hd[keysLong[0]];
            if (itm != null)
            {
                Assert.False(true, string.Format("Error, failed to set to null"));
            }
        }
Esempio n. 29
0
 public unsafe bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   try
     {
     char* chptr = null;
     String str2 = null;
     strLoc = "Loc_498hv";
     iCountTestcases++;
     str2 = new String(chptr);
     if(!str2.Equals(String.Empty))
       {
       iCountErrors++;
       printerr( "Error_498ch! incorrect string returned for null argument=="+str2);
       } 
     strLoc = "Loc_982hc";
     iCountTestcases++;
     char c = 'k';
     chptr = &c;
     str2 = new String(chptr);
     if(!str2.Equals("k"))
       {
       iCountErrors++;
       printerr( "Error_49hcx! incorrect string constructed=="+str2);
       }
     strLoc = "Loc_9fhc1";
     *chptr = '\t';
     str2 = new String(chptr);
     iCountTestcases++;
     if(!str2.Equals("\t"))
       {
       iCountErrors++;
       printerr( "Error_89hfd! incorrect string constructed=="+str2);
       }
     for(int i = 30 ; i < 150 ; i++)
       {
       c = (char) i;
       chptr = &c;
       str2 = new String(chptr);
       iCountTestcases++;
       if(!str2.Equals(c.ToString()))
	 { 
	 iCountErrors++;
	 printerr( "Error_209xu! Expected=="+c+" , Incorrect string=="+str2);
	 }
       }
     iCountTestcases++;
     IntlStrings intl = new IntlStrings();
     String testString = intl.GetString(1, true, true);
     c = testString[0];
     chptr = &c;
     str2 = new String(chptr);
     if(!str2.Equals(testString))
       {
       iCountErrors++;
       printerr( "Error_49hcx! incorrect string constructed=="+str2 + "should be==" + testString);
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,inCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
Esempio n. 30
0
 public virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String str1;
   String strInsert;
   int iStartIndex;
   try {
   int[] iArrInvalidValues = new Int32[]{ -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue};
   int[] iArrLargeValues = new Int32[]{ Int32.MaxValue, Int32.MaxValue-1, Int32.MaxValue/2 , Int32.MaxValue/10 , Int32.MaxValue/100 };
   int[] iArrValidValues = new Int32[]{ 10000, 100000 , Int32.MaxValue/200 , Int32.MaxValue/1000 };
   iCountTestcases++;
   String strNewString = "This is a tesing string" ;
   String strTemp = new String( 'a', 10000);
   for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ ){
   try
     {
     strNewString = strNewString.Insert(iArrInvalidValues[iLoop], strTemp);
     iCountErrors++;                        
     Console.Error.WriteLine( "Error_0000!! Expected exception not occured");
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_2222!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   }
   iCountTestcases++;
   for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ ){
   try
     {
     strNewString = strNewString.Insert(iArrLargeValues[iLoop], strTemp);
     iCountErrors++;                        
     Console.Error.WriteLine( "Error_1111!! Expected exception not occured");
     } catch ( ArgumentOutOfRangeException ){
     } catch ( Exception ex )
       {
       Console.Error.WriteLine( "Error_3333!!! Unexpected exception " + ex.ToString() );
       iCountErrors++ ;
       }
   }
   iCountTestcases++;
   strTemp =  new String( 'a' , Int32.MaxValue/200 );
   strNewString = strTemp ;
   for(int iLoop = 0 ; iLoop < iArrValidValues.Length ; iLoop++ ){
   try
     {                            
     strNewString = strNewString.Insert(iArrValidValues[iLoop], strTemp);
     if ( strNewString.Length != (Int32.MaxValue/200 ) * ( 2+iLoop) ){
     iCountErrors++;
     Console.Error.WriteLine( "Error_6666!!!! Incorrect string length.... Expected...{0},  Actual...{1}", (Int32.MaxValue/200 ) * ( 1+iLoop), strNewString.Length );
     }
     } catch ( Exception ex ){
     Console.Error.WriteLine( "Error_7777!!! Unexpected exception " + ex.ToString() );
     iCountErrors++ ;
     }
   }
   strLoc = "Loc_38947";
   str1 = "\t\t";
   strInsert = "  ";
   iStartIndex = -1;
   iCountTestcases++;
   try {
   str1.Insert(iStartIndex, strInsert);
   iCountErrors++;
   Console.WriteLine( s_strTFAbbrev+ "Err_4982u");
   } catch (ArgumentException ) {}
   catch ( Exception exc) {
   iCountErrors++;
   Console.WriteLine( s_strTFAbbrev+ "Err_9083u! , exc=="+exc);
   }
   strLoc = "Loc_129ew";
   str1 = "\t\t";
   strInsert = "  ";
   iStartIndex = 3;
   iCountTestcases++;
   try {
   str1.Insert(iStartIndex, strInsert);
   iCountErrors++;
   Console.WriteLine( s_strTFAbbrev+ "Err_983uq");
   } catch ( ArgumentException) {}
   catch ( Exception exc) {
   iCountErrors++;
   Console.WriteLine( s_strTFAbbrev+ "Err_5388g! , exc=="+exc);
   }
   strLoc = "Loc_538wi";
   str1 = "\t\t";
   strInsert = null;
   iStartIndex = 0;
   iCountTestcases++;
   try {
   str1.Insert(iStartIndex, strInsert);
   iCountErrors++;
   Console.WriteLine( s_strTFAbbrev+ "Err_128qu");
   } catch ( ArgumentException) {}
   catch ( Exception exc) {
   iCountErrors++;
   Console.WriteLine( s_strTFAbbrev+ "Err_3948u! , exc=="+exc);
   }
   strLoc = "Loc_3894u";
   str1 = "";
   strInsert = "This is a string";
   iStartIndex = 0;
   iCountTestcases++;
   if (!str1.Insert(iStartIndex, strInsert).Equals(strInsert))
     {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_438du");
     }
   IntlStrings intl = new IntlStrings();
   str1 = intl.GetString(19, true, true);
   strInsert = intl.GetString(12, false, true);
   iStartIndex = 0;
   iCountTestcases++;
   if (!str1.Insert(iStartIndex, strInsert).Equals(String.Concat(strInsert, str1)))
     {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_299138du");
     }
   strLoc = "Loc_3948r";
   str1 = "This is a string";
   strInsert = "\t\t\t\t";
   iStartIndex = 0;
   iCountTestcases++;
   if(!str1.Insert(iStartIndex, strInsert).Equals("\t\t\t\tThis is a string"))
     {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_8904e");
     }
   strLoc = "Loc_3498j";
   str1 = "This is a \n\n";
   strInsert = "string";
   iStartIndex = str1.ToCharArray().Length;
   iCountTestcases++;
   if(!str1.Insert(iStartIndex, strInsert).Equals(str1+strInsert))
     {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_1289m");
     }
   strLoc = "Loc_3487y";
   str1 = "\t is a string";
   strInsert = "This\t";
   iStartIndex = 1;
   iCountTestcases++;
   if(!str1.Insert(iStartIndex, strInsert).Equals("\tThis\t is a string"))
     {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_3739c");
     }
   strLoc = "Loc_238us";
   str1 = "This is a string";
   strInsert = "!@#$%^&*()";
   iStartIndex = str1.ToCharArray().Length-1;
   iCountTestcases++;
   if(!str1.Insert(iStartIndex, strInsert).Equals("This is a strin!@#$%^&*()g"))
     {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_34fdy");
     }
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }