IsControl_str_i.runTest C# (CSharp) Method

runTest() public method

public runTest ( ) : bool
return bool
 public virtual bool runTest()
   {
   int iNumStrings , iMaxLength ;        
   int iCountErrors = 0;
   int iCountTestcases = 1;
   string[] testStrs;   
   IList charData;      
   Console.WriteLine( "IsControl_str_i runTest started." );
   Random rand = new Random(unchecked((int)(DateTime.Now.Ticks)));
   do
     {
     iNumStrings = rand.Next( 0, NUM_RANDOM_STRINGS);
     iMaxLength  = rand.Next( 0, MAX_RANDOM_STR_LENGTH);
     } while ( iNumStrings < 1 && iMaxLength < 1 );
   charData = m_CharData.GetValueList();
   testStrs = new String[iNumStrings];
   for (int iCurStr = 0; iCurStr < testStrs.Length; iCurStr++)
     {
     int iRdmStrLen = 0;           
     StringBuilder strbRdmString;  
     iRdmStrLen = rand.Next(1,iMaxLength + 1);
     strbRdmString = new StringBuilder(iRdmStrLen);
     for (int iCurChar = 0; iCurChar < iRdmStrLen; iCurChar++)
       {
       int iRdmCharIdx = -1;    
       CharInfo rdmCharInfo;    
       iRdmCharIdx = rand.Next(0,(int)m_CharData.Count);
       rdmCharInfo = (CharInfo) charData[iRdmCharIdx];
       strbRdmString.Append(rdmCharInfo.chChar);
       }
     testStrs[iCurStr] = strbRdmString.ToString();
     }
   foreach (string strCurTest in testStrs)
     {
     for (int iCurChar = 0; iCurChar < strCurTest.Length; iCurChar++)
       {
       CharInfo curCharInfo;    
       curCharInfo = (CharInfo) m_CharData[strCurTest[iCurChar]];
       if ( curCharInfo.eCategory == UnicodeCategory.Control )
	 {
	 if ( Char.IsControl(strCurTest,iCurChar) )
	   {                    
	   iCountTestcases++ ;
	   Console.WriteLine("Passed :: " + 
			     "Categories match for char '" + 
			     ((int)(curCharInfo.chChar)).ToString("x4") + 
			     "' at position " + iCurChar.ToString("d3") + " Category :: " + 
			     curCharInfo.eCategory);
	   }
	 else
	   {
	   iCountErrors++ ;
	   Console.WriteLine("Failed :: " +
			     "Category mismatch for char '0x" + 
			     ((int)(curCharInfo.chChar)).ToString("x4") + 
			     "' at position " + iCurChar.ToString("d3") + 
			     " UCD  Category : " + curCharInfo.eCategory + 
			     " NLS+ Category : " + 
			     Char.IsControl(strCurTest,iCurChar) );
	   }
	 }                                
       }
     }
   if ( iCountErrors == 0 ){
   Console.Error.Write( "Char_IsControl_str_i: paSs. iCountTestcases== " + iCountTestcases.ToString("d3"));
   return true;
   }
   else{
   Console.Error.Write( "Char_IsControl_str_i: Fail. iCountErrors== " + iCountErrors.ToString("d3"));
   return false;
   }
   }
 protected UnicodeCategory TranslateUnicodeCategory(string strCatAbbrev) 

Usage Example

    public static void Main(String[] strArgList)
    {
        bool bResult = false;
        bool bDataOK;

        try
        {
            IsControl_str_i ObjIsControl_str_i = new IsControl_str_i();
            bDataOK = ObjIsControl_str_i.ReadUnicodeData();
            if (!bDataOK)
            {
                Console.WriteLine("Not able to read the UniCode data from the file");
                return;
            }
            bResult = ObjIsControl_str_i.runTest();
        }
        catch (Exception exc)
        {
            bResult = false;
            Console.Error.WriteLine("IsControl_str_i main caught an Exception!" + exc.ToString());
            Console.Error.WriteLine(exc.ToString());
        }
        if (bResult == true)
        {
            Environment.ExitCode = 0;
        }
        else
        {
            Environment.ExitCode = 1;
        }
    }
All Usage Examples Of IsControl_str_i::runTest