예제 #1
0
        /// <summary>
        /// Compares XML files and logs result.
        /// </summary>
        /// <returns></returns>
        public bool CompareLogShow(Arguments arguments)
        {
            bool comparison = false;

            if (File.Exists(arguments.FilterPath))
            {
                this.Core.Filter.XmlFilterPath = arguments.FilterPath;
            }
            else if (File.Exists(arguments.DefaultFilterPath))
            {
                this.Core.Filter.XmlFilterPath = arguments.DefaultFilterPath;
            }
            else
            {
                GlobalLog.LogEvidence(new FileNotFoundException("Could not find " + arguments.FilterFile));
                return(false);
            }

            this.Core.SaveXmlDump(arguments.RenderedPath);

            GlobalLog.LogStatus(string.Format("Searching for {0}.....", arguments.MasterFile));

            arguments.MissingMaster = !SearchMaster(arguments);

            if (!arguments.MissingMaster)
            {
                comparison = this.Core.CompareXmlFiles(arguments.ComparePath, arguments.RenderedPath);

                if (comparison)
                {
                    GlobalLog.LogStatus("XML COMPARE SUCCEEDED.");
                }
                else
                {
                    GlobalLog.LogEvidence("XML COMPARE FAILED.");
                }
            }
            else
            {
                GlobalLog.LogEvidence("NO MASTER FOUND");
                arguments.MissingMaster = true;
                comparison = false;
            }

            if (!comparison)
            {
                DiffPackage failurePackage  = new DiffPackage(arguments.RenderedPath, arguments.ComparePath, arguments.MasterSdPath);
                string      packageLocation = failurePackage.Save(arguments);

                if (!arguments.MissingMaster)
                {
                    GlobalLog.LogEvidence(string.Format("FAILED MASTER : {0}", arguments.ComparePath));
                }

                GlobalLog.LogFile(packageLocation);
            }

            return(comparison);
        }
예제 #2
0
 /// <summary>
 /// saves bitmaps on disk
 /// </summary>
 /// <param name='image'> image for saving.</param>
 /// <param name='name'> image name.</param>
 private static void LogImageOnDisk(System.Drawing.Image image, string name)
 {
     new System.Security.Permissions.FileIOPermission(
         System.Security.Permissions.PermissionState.Unrestricted)
     .Assert();
     image.Save(name, System.Drawing.Imaging.ImageFormat.Png);
     GlobalLog.LogFile(name);
 }
예제 #3
0
        /// <summary>
        /// Executes the comparison operation with supporting services.
        /// </summary>
        /// <param name="prefixName">
        /// Prefix name for criteria and operation configuration arguments.
        /// </param>
        /// <returns>The results of the comparison operation.</returns>
        /// <remarks><p>
        /// This method implements the typical wrapping around
        /// the comparison API, where services are available to help
        /// with configuration and logging.
        /// </p><p>
        /// The operation is configured, and a new criteria object is
        /// configured and assigned unless the current criteria has
        /// already been modified in some way. If the criteria is not
        /// met, an exception is thrown. If LogImagesOnUnmet is true and
        /// the criteria is not met, the images will be logged.
        /// </p><p>
        /// The ComparisonOperation object and the ComparisonResult
        /// object are configured with the
        /// ConfigurationSettings.SetObjectProperties method; see
        /// this API for more information.
        /// </p></remarks>
        public ComparisonResult ExecuteServiced(string prefixName)
        {
#if (IGNORE_IMAGE_LOGGING)
            throw new NotImplementedException("ComparisonOperation.ExecuteServiced is not implemented when IGNORE_IMAGE_LOGGING is defined.");
#else
            if (prefixName == null)
            {
                throw new ArgumentNullException("prefixName");
            }
            GlobalLog.LogStatus("Performing {" + prefixName + "} comparison...");

            if (Criteria.Equals(ComparisonCriteria.PerfectMatch))
            {
                // Doing a SetObjectProperties call on this.criteria
                // would modify the properties of the shared perfect match
                // instance.
                ComparisonCriteria newCriteria = new ComparisonCriteria();
                //ConfigurationSettings.Current
                //    .SetObjectProperties(newCriteria, prefixName);
                Criteria = newCriteria;
                GlobalLog.LogStatus(criteria.ToString());
            }

            ComparisonResult result = Execute();

            if (!result.CriteriaMet)
            {
                if (LogImagesOnCriteriaUnmet)
                {
                    masterImage.Save(prefixName + "master", System.Drawing.Imaging.ImageFormat.Png);
                    GlobalLog.LogFile(prefixName + "master");
                    //l.LogImage(masterImage, prefixName + "master");
                    sampleImage.Save(prefixName + "sample", System.Drawing.Imaging.ImageFormat.Png);
                    GlobalLog.LogFile(prefixName + "sample");

                    //l.LogImage(sampleImage, prefixName + "sample");
                    Bitmap differences = new Bitmap(sampleImage);
                    result.HighlightDifferences(differences);

                    differences.Save(prefixName + "differences", System.Drawing.Imaging.ImageFormat.Png);
                    GlobalLog.LogFile(prefixName + "differences");
                    //l.LogImage(differences, prefixName + "differences");
                }

                string message = criteria.MismatchDescription +
                                 Environment.NewLine + result.ToString();
                throw new Exception(message);
            }
            else
            {
                GlobalLog.LogStatus(result.ToStringBrief());
            }
            return(result);
#endif
        }
예제 #4
0
        /// <summary>
        /// Saves the Color array to a .PNG file.
        /// </summary>
        /// <param name="bitmap">Bit matrix to save</param>
        /// <param name="filename">.PNG file name to save it as.</param>
        public static void SaveImageAs(BitmapSource bitmap, string filename)
        {
            PngBitmapEncoder encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bitmap));

            using (TrustedFileStream fs = new TrustedFileStream(filename, FileMode.Create))
            {
                encoder.Save(PT.Untrust(fs));
            }
            GlobalLog.LogFile(filename);
        }
예제 #5
0
        /// <summary>
        /// Generates and compiles the application.
        /// </summary>
        /// <param name="xamlFiles">The first in this array is main page.</param>
        /// <param name="hostType">Host type. Could be Application</param>
        /// <param name="uiCulture"></param>
        /// <param name="extraFiles"></param>
        /// <param name="supportingAssemblies"></param>
        /// <param name="language"></param>
        /// <param name="additionalAppMarkup"></param>
        /// <param name="resources"></param>
        /// <param name="contents"></param>
        /// <param name="debugBaml"></param>
        public void CompileApp(string[] xamlFiles, string hostType, string uiCulture, List <string> extraFiles, List <string> supportingAssemblies, Languages language, string additionalAppMarkup, List <Resource> resources, List <Content> contents, bool debugBaml)
        {
            // Cleanup temp. Xaml file, if necessary.
            string _tempXamlFile = "__XamlTestRunnerTempFile.xaml";

            if (FileSW.Exists(_tempXamlFile))
            {
                FileSW.Delete(_tempXamlFile);
            }



            // Some Xaml files (e.g. those which contain events, <x:Code>, x:Name attributes etc.)
            // need to specify an x:Class attribute on the root tag. We add that here.
            string xClassName = "MySubclass";

            // Load the original Xaml file into a DOM tree, add x:Class attribute to the root element,
            // and then save the DOM tree into a temporary Xaml file
            XmlDocumentSW doc = new XmlDocumentSW();

            doc.PreserveWhitespace = true;
            doc.Load(xamlFiles[0]);


            XmlElement rootElement = doc.DocumentElement;

            if (AddClassAttribute)
            {
                rootElement.SetAttribute("Class", "http://schemas.microsoft.com/winfx/2006/xaml", xClassName);
            }

            if (rootElement.NamespaceURI.IndexOf("schemas.microsoft.com") != -1) //&& !verifierFound)
            {
                AutoCloseWindow = true;
            }

            doc.Save(_tempXamlFile);

            xamlFiles[0] = _tempXamlFile;

            GlobalLog.LogStatus("Start compilation...");

            // Generate app definition file.
            GlobalLog.LogStatus("Generate app definition file...");
            GenerateAppdef(_tempXamlFile, hostType, "winexe", language, additionalAppMarkup);


            CompilerParams compilerParams = new CompilerParams(true);

            //
            // Generate the 'proj' file.
            //
            GlobalLog.LogStatus("Generate project file...");
            foreach (string xamlFile in xamlFiles)
            {
                compilerParams.XamlPages.Add(xamlFile);
            }

            compilerParams.OutputType            = "winexe";
            compilerParams.ApplicationDefinition = _appDefFileName;
            compilerParams.AssemblyName          = _assemblyName;
            compilerParams.RootNamespace         = "Avalon.Test.CoreUI.Parser.MyName";
            compilerParams.Language = language;

            // Put debugging info (line,position) in Baml.
            if (debugBaml)
            {
                compilerParams.XamlDebuggingInformation = true;
            }

            if (uiCulture != null)
            {
                compilerParams.UICulture = uiCulture;
            }

            // Add extraFiles.  They should be either xaml files or code files.
            for (int i = 0; extraFiles != null && i < extraFiles.Count; i++)
            {
                string fileName = extraFiles[i];

                if (PathSW.GetExtension(fileName) == "xaml")
                {
                    compilerParams.XamlPages.Add(fileName);
                }
                else
                {
                    compilerParams.CompileFiles.Add(fileName);
                }
            }

            // Add code-behind files if they exist and they weren't in the extraFiles.
            // Always assume they should be added.
            for (int i = 0; i < compilerParams.XamlPages.Count; i++)
            {
                string fileName = compilerParams.XamlPages[i] + ".cs";

                if (FileSW.Exists(fileName) && !compilerParams.CompileFiles.Contains(fileName))
                {
                    compilerParams.CompileFiles.Add(fileName);
                }
            }

            // Add supporting assemblies, if any, as references
            if (null != supportingAssemblies)
            {
                string currentDirectory = EnvironmentSW.CurrentDirectory;
                for (int i = 0; i < supportingAssemblies.Count; i++)
                {
                    string assemblyName = supportingAssemblies[i];
                    compilerParams.References.Add(new Reference(assemblyName, currentDirectory + "\\" + assemblyName + ".dll"));
                }
            }


            if (References.Count > 0)
            {
                compilerParams.References.AddRange(References);
            }

            // Add Resources, if any
            if (null != resources)
            {
                foreach (Resource r in resources)
                {
                    compilerParams.Resources.Add(r);
                }
            }

            // Add Contents, if any
            if (null != contents)
            {
                foreach (Content c in contents)
                {
                    compilerParams.Contents.Add(c);
                }
            }

            // Also add any loose files specified by TestCaseInfo.SupportFiles
            //



            //TestDefinition td = TestDefinition.Current;
            //td.
            //if (currentTestCaseInfo != null)
            //{
            //    string[] currentSupportFiles = currentTestCaseInfo.SupportFiles;
            //    if (currentSupportFiles != null)
            //    {
            //        foreach (string fileName in currentSupportFiles)
            //        {
            //            compilerParams.Contents.Add(new Content(fileName, "Always"));
            //        }
            //    }
            //}

            //
            // Compile project.
            //
            GlobalLog.LogStatus("Compiling project...");
            Compiler compiler = new Compiler(compilerParams);
            List <ErrorWarningCode> buildErrorsAndWarnings = compiler.Compile(true);

            //
            // Check if Compiling project is successful by verifying that compiled app exists.
            //
            GlobalLog.LogStatus("Check if compiling project was successful...");
            GlobalLog.LogStatus("Check if the BAML and the compiled app both exist.");
            string bamlPath        = _objPath + PathSW.DirectorySeparatorChar + PathSW.ChangeExtension(xamlFiles[0], "baml");
            bool   compilerFailure = false;

            GlobalLog.LogStatus("Baml Path: " + bamlPath);
            if (!FileSW.Exists(bamlPath))
            {
                GlobalLog.LogEvidence("Baml file did not exist");
                compilerFailure = true;
            }
            GlobalLog.LogStatus("Compiled path: " + _compiledPath);
            if (!FileSW.Exists(_compiledPath))
            {
                GlobalLog.LogEvidence("Compiled path did not exist");
                compilerFailure = true;
            }

            if (compilerFailure)
            {
                //Save files to be used for debugging
                GlobalLog.LogStatus("Saving files used in compilation...");
                GlobalLog.LogFile("__CompilerServicesSave.proj");
                foreach (string file in compilerParams.XamlPages)
                {
                    GlobalLog.LogFile(file);
                }
                foreach (string file in compilerParams.CompileFiles)
                {
                    GlobalLog.LogFile(file);
                }
                // Get compilation error message
                string compileErrors   = "Errors: \n";
                string compileWarnings = "Warnings \n";
                if ((null != buildErrorsAndWarnings) && (buildErrorsAndWarnings.Count > 0))
                {
                    // The list contains both errors and warnings.
                    // Get the first error and get its description.
                    foreach (ErrorWarningCode errAndWarn in buildErrorsAndWarnings)
                    {
                        if (errAndWarn.Type == ErrorType.Error)
                        {
                            compileErrors += errAndWarn.Description + "\n";
                            GlobalLog.LogStatus("\nBuild Error Found - " + errAndWarn.Description + "\n");
                            break;
                        }
                        else
                        {
                            compileWarnings += errAndWarn.Description + "\n";
                            GlobalLog.LogStatus("\nWarning - " + errAndWarn.Description + "\n");
                        }
                    }
                }

                TestSetupException setupException = new TestSetupException("Compilation failed: " + compileErrors + compileWarnings);
                // Add the list of build errors and warnings as custom Exception data.
                // This can be used by callers to retrive the errors and warnings list.
                setupException.Data.Add("buildErrorsAndWarnings", buildErrorsAndWarnings);
                throw setupException;
            }
        }