Пример #1
0
        /*
         *   Starts all the BlackBox tests
         */
        public static void StartTests()
        {
            if (File.Exists("output.dbg"))
            {
                Console.WriteLine("WARNING: output.dbg already exists; output of this session will be appended.\r\n");
            }
            FileStream fs = File.Open("output.dbg", FileMode.Append, FileAccess.Write, FileShare.Read);

            BlackBox[] tests = new BlackBox[] { new CertificateExceptionBox(fs), new CertificateStoreBox(fs), new CertificateBox(fs), new CertificateChainBox(fs),
                                                new RijndaelUnmanagedTransformBox(fs), new ARCFourManagedBox(fs), new RC4CryptoServiceProviderBox(fs),
                                                new RIPEMD160ManagedBox(fs), new MD2CryptoServiceProviderBox(fs), new HMACBox(fs),
                                                new DataProtectionCryptoServiceProviderBox(fs) };
            StopWatch sw       = new StopWatch();
            int       errors   = 0;
            int       warnings = 0;
            int       testcnt  = 0;
            string    name;
            long      time;

            fs.Write(Encoding.ASCII.GetBytes("CertificateServices BlackBox tests\r\n"), 0, 36);
            fs.Write(Encoding.ASCII.GetBytes(Environment.OSVersion.ToString() + "\r\n"), 0, Environment.OSVersion.ToString().Length + 2);
            fs.Write(Encoding.ASCII.GetBytes(".NET CLR " + Environment.Version.ToString() + "\r\n"), 0, Environment.Version.ToString().Length + 11);
            ConsoleAttributes.ForeColor = ConsoleColor.Gray;
            Console.WriteLine("CertificateServices BlackBox tests");
                        #if (DEBUG)
            Console.WriteLine("   running in DEBUG mode");
                        #else
            Console.WriteLine("   running in RELEASE mode");
                        #endif
            Console.WriteLine("   on " + Environment.OSVersion.ToString());
            Console.WriteLine("   and .NET CLR " + Environment.Version.ToString() + "\r\n");
            for (int i = 0; i < tests.Length; i++)
            {
                HasSubItems = false;
                name        = tests[i].Name;
                if (name.Length > 27)
                {
                    name = name.Substring(0, 27) + "...";
                }
                else
                {
                    name = name + "..." + new String(' ', 27 - name.Length);
                }
                Console.Write(name + "  ");
                sw.Reset();
                testcnt += tests[i].Start();
                time     = sw.Peek();
                if (!HasSubItems)
                {
                    if (tests[i].Errors + tests[i].Warnings > 0)
                    {
                        WriteResult(false, time);

/*						if (tests[i].Errors > 0)
 *                                                      Console.WriteLine("  " + tests[i].ErrorLog);
 *                                              if (tests[i].Warnings > 0)
 *                                                      Console.WriteLine("  " + tests[i].WarningLog); */
                    }
                    else
                    {
                        WriteResult(true, time);
                    }
                }
                errors   += tests[i].Errors;
                warnings += tests[i].Warnings;
            }
            string result = String.Format("\r\n\r\nAll tests complete\r\n  {0} error(s), {1} warning(s)\r\n  {2} tests performed\r\n\r\n", errors, warnings, testcnt);
            fs.Write(Encoding.ASCII.GetBytes(result), 0, result.Length);
            Console.WriteLine(result + "\r\n");
            fs.Close();
            Console.WriteLine("Output saved to " + Environment.CurrentDirectory.TrimEnd('\\') + @"\output.dbg");
            Console.WriteLine("\r\nPress ENTER to continue...");
            Console.ReadLine();
        }
Пример #2
0
 /*
  *   Starts all the BlackBox tests
  */
 public static void StartTests()
 {
     if (File.Exists("output.dbg"))
         Console.WriteLine("WARNING: output.dbg already exists; output of this session will be appended.\r\n");
     FileStream fs = File.Open("output.dbg", FileMode.Append, FileAccess.Write, FileShare.Read);
     BlackBox[] tests = new BlackBox[] { new CertificateExceptionBox(fs), new CertificateStoreBox(fs), new CertificateBox(fs), new CertificateChainBox(fs),
                                         new RijndaelUnmanagedTransformBox(fs), new ARCFourManagedBox(fs), new RC4CryptoServiceProviderBox(fs),
                                         new RIPEMD160ManagedBox(fs), new MD2CryptoServiceProviderBox(fs), new HMACBox(fs),
                                         new DataProtectionCryptoServiceProviderBox(fs) };
     StopWatch sw = new StopWatch();
     int errors = 0;
     int warnings = 0;
     int testcnt = 0;
     string name;
     long time;
     fs.Write(Encoding.ASCII.GetBytes("CertificateServices BlackBox tests\r\n"), 0, 36);
     fs.Write(Encoding.ASCII.GetBytes(Environment.OSVersion.ToString() + "\r\n"), 0, Environment.OSVersion.ToString().Length + 2);
     fs.Write(Encoding.ASCII.GetBytes(".NET CLR " + Environment.Version.ToString() + "\r\n"), 0, Environment.Version.ToString().Length + 11);
     ConsoleAttributes.ForeColor = ConsoleColor.Gray;
     Console.WriteLine("CertificateServices BlackBox tests");
     #if (DEBUG)
         Console.WriteLine("   running in DEBUG mode");
     #else
         Console.WriteLine("   running in RELEASE mode");
     #endif
     Console.WriteLine("   on " + Environment.OSVersion.ToString());
     Console.WriteLine("   and .NET CLR " + Environment.Version.ToString() + "\r\n");
     for(int i = 0; i < tests.Length; i++) {
         HasSubItems = false;
         name = tests[i].Name;
         if (name.Length > 27)
             name = name.Substring(0, 27) + "...";
         else
             name = name + "..." + new String(' ', 27 - name.Length);
         Console.Write(name + "  ");
         sw.Reset();
         testcnt += tests[i].Start();
         time = sw.Peek();
         if (!HasSubItems) {
             if (tests[i].Errors + tests[i].Warnings > 0) {
                 WriteResult(false, time);
     /*						if (tests[i].Errors > 0)
                     Console.WriteLine("  " + tests[i].ErrorLog);
                 if (tests[i].Warnings > 0)
                     Console.WriteLine("  " + tests[i].WarningLog); */
             } else {
                 WriteResult(true, time);
             }
         }
         errors += tests[i].Errors;
         warnings += tests[i].Warnings;
     }
     string result = String.Format("\r\n\r\nAll tests complete\r\n  {0} error(s), {1} warning(s)\r\n  {2} tests performed\r\n\r\n", errors, warnings, testcnt);
     fs.Write(Encoding.ASCII.GetBytes(result), 0, result.Length);
     Console.WriteLine(result + "\r\n");
     fs.Close();
     Console.WriteLine("Output saved to " + Environment.CurrentDirectory.TrimEnd('\\') + @"\output.dbg");
     Console.WriteLine("\r\nPress ENTER to continue...");
     Console.ReadLine();
 }