Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Baseline"></param>
        /// <param name="baselineStartLine">The line to start comparison in the baseline file</param>
        /// <param name="OutFile"></param>
        /// <param name="outFileStartLine">The line to start comparion in the output file</param>
        /// <param name="driverVersion"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        public static bool CompareChecksum(string Baseline, int baselineStartLine, string OutFile, int outFileStartLine, int driverVersion, DelayedWriteLogger logger)
        {
            // Keep people honest.
            if (driverVersion == 2)
            {
                if (logger != null)
                {
                    logger.LogMessage("Calculating checksum for baseline output {0}...", Baseline);
                }

                string expectedCheckSum = CalcChecksum(Baseline, baselineStartLine, logger);
                string actualChecksum   = CalcChecksum(OutFile, outFileStartLine, logger);

                if (expectedCheckSum.Equals(actualChecksum))
                {
                    return(true);
                }
                else
                {
                    if (logger != null)
                    {
                        logger.LogMessage("Actual checksum: {0}, Expected checksum: {1}", actualChecksum, expectedCheckSum);
                        logger.LogMessage("Actual result: ");
                        logger.WriteOutputFileToLog(OutFile);
                    }
                    return(false);
                }
            }
            else
            {
                throw new NotSupportedException("Not a supported driver version");
            }
        }
Exemple #2
0
        public static bool CompareXml(Stream expectedStream, Stream actualStream, string xmldiffoptionvalue, DelayedWriteLogger logger)
        {
            bool bResult = false;

            // Default Diff options used by XSLT V2 driver.
            int     defaultXmlDiffOptions = (int)(XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder);
            XmlDiff diff = new XmlDiff();

            if (xmldiffoptionvalue == null || xmldiffoptionvalue.Equals(string.Empty))
            {
                diff.Option = (XmlDiffOption)defaultXmlDiffOptions;
            }
            else
            {
                if (logger != null)
                {
                    logger.LogMessage("Custom XmlDiffOptions used. Value passed is " + xmldiffoptionvalue);
                }
                diff.Option = (XmlDiffOption)Int32.Parse(xmldiffoptionvalue);
            }

            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            try
            {
                bResult =
                    diff.Compare(new XmlTextReader(actualStream, XmlNodeType.Element, context),
                                 new XmlTextReader(expectedStream, XmlNodeType.Element, context));
            }
            catch (Exception e)
            {
                bResult = false;
                if (logger != null)
                {
                    logger.LogMessage("Exception thrown in XmlDiff compare!");
                    logger.LogXml(e.ToString());
                    throw;
                }
            }

            if (bResult)
            {
                return(true);
            }

            if (logger != null)
            {
                logger.LogMessage("Mismatch in XmlDiff");
                logger.LogMessage("Actual result: ");
            }

            return(false);
        }
Exemple #3
0
        public static bool VerifySingleAssemblyUsingPEVerify(string asmName, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            bool result = false;

            if (File.Exists(asmName))
            {
                //add double quotes for names with whitespace in them
                string processArguments = " /quiet " + "\"" + asmName + "\"";

                // Call PEVerify to verify persistant assembly.
                Process peVerifyProcess = new Process();
                peVerifyProcess.StartInfo.FileName  = SearchPath("peverify.exe");
                peVerifyProcess.StartInfo.Arguments = " " + processArguments;
                //peVerifyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                peVerifyProcess.StartInfo.CreateNoWindow         = true;
                peVerifyProcess.StartInfo.UseShellExecute        = false;
                peVerifyProcess.StartInfo.RedirectStandardOutput = true;

                peVerifyProcess.Start();
                output = peVerifyProcess.StandardOutput.ReadToEnd();
                peVerifyProcess.WaitForExit();

                // Check the output for the Assembly name, and the word "PASS"
                // For example:
                // C:>peverify /quiet 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll
                // 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll PASS
                if (peVerifyProcess.ExitCode == 0 && output.Contains(asmName) && output.Contains("PASS"))
                {
                    result = true;
                }
                else
                {
                    if (logger != null)
                    {
                        logger.LogMessage("PEVerify could not be run or FAILED : {0}", asmName + " " + output);
                    }
                    result = false;
                }
            }
            else
            {
                if (logger != null)
                {
                    logger.LogMessage("Assembly file could not be found : {0}", asmName);
                }
                result = false;
            }

            return(result);
        }
Exemple #4
0
        // Call PEVerify on the Assembly name, parse the output,
        // and return true if the output is PASS and false if the output is FAIL.
        public static bool VerifyAssemblyUsingPEVerify(string asmName, bool isValidCase, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            if (!asmName.Contains(".dll") || !asmName.Contains(".DLL"))
            {
                asmName = asmName + ".dll";
            }

            if (File.Exists(asmName))
            {
                return(VerifyAssemblyUsingPEVerify(asmName, logger, ref output));
            }
            else
            {
                if (isValidCase)
                {
                    string message = "PEVerify could not be run, no assembly present: " + asmName;
                    if (logger != null)
                    {
                        logger.LogMessage(message);
                    }
                    output = message;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemple #5
0
        public static bool CompareXml(Stream expectedStream, Stream actualStream, string xmldiffoptionvalue, DelayedWriteLogger logger)
        {
            bool bResult = false;

            // Default Diff options used by XSLT V2 driver.
            int defaultXmlDiffOptions = (int)(XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder);
            XmlDiff diff = new XmlDiff();

            if (xmldiffoptionvalue == null || xmldiffoptionvalue.Equals(string.Empty))
                diff.Option = (XmlDiffOption)defaultXmlDiffOptions;
            else
            {
                if (logger != null) logger.LogMessage("Custom XmlDiffOptions used. Value passed is " + xmldiffoptionvalue);
                diff.Option = (XmlDiffOption)Int32.Parse(xmldiffoptionvalue);
            }

            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            try
            {
                bResult =
                   diff.Compare(new XmlTextReader(actualStream, XmlNodeType.Element, context),
                             new XmlTextReader(expectedStream, XmlNodeType.Element, context));
            }
            catch (Exception e)
            {
                bResult = false;
                if (logger != null)
                {
                    logger.LogMessage("Exception thrown in XmlDiff compare!");
                    logger.LogXml(e.ToString());
                    throw;
                }
            }

            if (bResult)
                return true;

            if (logger != null)
            {
                logger.LogMessage("Mismatch in XmlDiff");
                logger.LogMessage("Actual result: ");
            }

            return false;
        }
Exemple #6
0
        public static bool VerifySingleAssemblyUsingPEVerify(string asmName, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            bool result = false;

            if (File.Exists(asmName))
            {
                //add double quotes for names with whitespace in them
                string processArguments = " /quiet " + "\"" + asmName + "\"";

                // Call PEVerify to verify persistant assembly.
                Process peVerifyProcess = new Process();
                peVerifyProcess.StartInfo.FileName = SearchPath("peverify.exe");
                peVerifyProcess.StartInfo.Arguments = " " + processArguments;
                //peVerifyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                peVerifyProcess.StartInfo.CreateNoWindow = true;
                peVerifyProcess.StartInfo.UseShellExecute = false;
                peVerifyProcess.StartInfo.RedirectStandardOutput = true;

                peVerifyProcess.Start();
                output = peVerifyProcess.StandardOutput.ReadToEnd();
                peVerifyProcess.WaitForExit();

                // Check the output for the Assembly name, and the word "PASS"
                // For example:
                // C:>peverify /quiet 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll
                // 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll PASS
                if (peVerifyProcess.ExitCode == 0 && output.Contains(asmName) && output.Contains("PASS"))
                    result = true;
                else
                {
                    if (logger != null)
                        logger.LogMessage("PEVerify could not be run or FAILED : {0}", asmName + " " + output);
                    result = false;
                }
            }
            else
            {
                if (logger != null)
                    logger.LogMessage("Assembly file could not be found : {0}", asmName);
                result = false;
            }

            return result;
        }
Exemple #7
0
        // Call PEVerify on the Assembly name, parse the output,
        // and return true if the output is PASS and false if the output is FAIL.
        public static bool VerifyAssemblyUsingPEVerify(string asmName, bool isValidCase, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            if (!asmName.Contains(".dll") || !asmName.Contains(".DLL"))
                asmName = asmName + ".dll";

            if (File.Exists(asmName))
            {
                return VerifyAssemblyUsingPEVerify(asmName, logger, ref output);
            }
            else
            {
                if (isValidCase)
                {
                    string message = "PEVerify could not be run, no assembly present: " + asmName;
                    if (logger != null)
                        logger.LogMessage(message);
                    output = message;
                    return false;
                }
                else return true;
            }
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Baseline"></param>
        /// <param name="baselineStartLine">The line to start comparison in the baseline file</param>
        /// <param name="OutFile"></param>
        /// <param name="outFileStartLine">The line to start comparion in the output file</param>
        /// <param name="driverVersion"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        public static bool CompareChecksum(string Baseline, int baselineStartLine, string OutFile, int outFileStartLine, int driverVersion, DelayedWriteLogger logger)
        {
            // Keep people honest.
            if (driverVersion == 2)
            {
                if (logger != null) logger.LogMessage("Calculating checksum for baseline output {0}...", Baseline);

                string expectedCheckSum = CalcChecksum(Baseline, baselineStartLine, logger);
                string actualChecksum = CalcChecksum(OutFile, outFileStartLine, logger);

                if (expectedCheckSum.Equals(actualChecksum))
                    return true;
                else
                {
                    if (logger != null)
                    {
                        logger.LogMessage("Actual checksum: {0}, Expected checksum: {1}", actualChecksum, expectedCheckSum);
                        logger.LogMessage("Actual result: ");
                        logger.WriteOutputFileToLog(OutFile);
                    }
                    return false;
                }
            }
            else throw new NotSupportedException("Not a supported driver version");
        }