Ejemplo n.º 1
0
        private void SaveTestResults(XmlWriter writer)
        {
            if (writer == null)
            {
                return;
            }

            if (_testResults == null || _testResults.Count == 0)
            {
                return;
            }

            writer.WriteStartDocument();
            writer.WriteStartElement("results");

            for (int i = 0; i < _testResults.Count; i++)
            {
                SvgTestResult testResult = _testResults[i];
                if (testResult != null && testResult.IsValid)
                {
                    testResult.WriteXml(writer);
                }
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
Ejemplo n.º 2
0
 public static bool AreEqual(SvgTestResult left, SvgTestResult right)
 {
     if (left == null && right == null)
     {
         return(true);
     }
     if (left == null && right != null)
     {
         return(false);
     }
     if (left != null && right == null)
     {
         return(false);
     }
     return(left.IsEqualTo(right));
 }
Ejemplo n.º 3
0
        private void LoadTestResults(XmlReader reader)
        {
            if (_testResults == null || _testResults.Count != 0)
            {
                _testResults = new List <SvgTestResult>();
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element &&
                    string.Equals(reader.Name, "result", StringComparison.OrdinalIgnoreCase))
                {
                    SvgTestResult testResult = new SvgTestResult(reader);
                    if (testResult.IsValid)
                    {
                        _testResults.Add(testResult);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool IsEqualTo(SvgTestResult other)
        {
            if (other == null)
            {
                return(false);
            }
            if (!string.Equals(this._version, other._version))
            {
                return(false);
            }
            if (this._categories == null && other._categories == null)
            {
                return(true);
            }
            if (this._categories == null && other._categories != null)
            {
                return(false);
            }
            if (this._categories != null && other._categories == null)
            {
                return(false);
            }
            if (this._categories.Count != other._categories.Count)
            {
                return(false);
            }

            int itemCount = _categories.Count;

            for (int i = 0; i < itemCount; i++)
            {
                if (!SvgTestCategory.AreEqual(this._categories[i], other._categories[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        private void SaveTreeView(XmlWriter writer)
        {
            if (writer == null)
            {
                return;
            }

            TreeNodeCollection treeNodes = treeView.Nodes;

            if (treeNodes == null || treeNodes.Count == 0)
            {
                return;
            }

            SvgTestResult testResult = new SvgTestResult();

            writer.WriteStartDocument();
            writer.WriteStartElement("tests");

            var selectedSuite = _optionSettings.SelectedTestSuite;

            if (selectedSuite != null)
            {
                writer.WriteAttributeString("version", selectedSuite.Version);
                writer.WriteAttributeString("description", selectedSuite.Description);
            }

            for (int i = 0; i < treeNodes.Count; i++)
            {
                TreeNode categoryItem = treeNodes[i] as TreeNode;
                if (categoryItem != null)
                {
                    SvgTestCategory testCategory = new SvgTestCategory(categoryItem.Text);

                    this.SaveTreeViewCategory(writer, categoryItem, testCategory);

                    if (testCategory.IsValid)
                    {
                        testResult.Categories.Add(testCategory);
                    }
                }
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();

            if (_testResults == null)
            {
                _testResults = new List <SvgTestResult>();
            }

            if (testResult.IsValid)
            {
                if (_testResults.Count == 0)
                {
                    _testResults.Add(testResult);
                }
            }
            else
            {
                int foundAt = -1;
                for (int i = 0; i < _testResults.Count; i++)
                {
                    SvgTestResult nextResult = _testResults[i];
                    if (nextResult != null && nextResult.IsValid)
                    {
                        if (string.Equals(nextResult.Version, testResult.Version))
                        {
                            foundAt = i;
                            break;
                        }
                    }
                }

                if (foundAt >= 0)
                {
                    SvgTestResult nextResult = _testResults[foundAt];

                    if (!SvgTestResult.AreEqual(nextResult, testResult))
                    {
                        _testResults[foundAt] = testResult;
                    }
                }
                else
                {
                    _testResults.Add(testResult);
                }
            }
        }
Ejemplo n.º 6
0
        private void LoadTreeView(XmlReader reader)
        {
            SvgTestResult testResult = new SvgTestResult();

            // Suppress repainting the TreeView until all the objects have been created.
            treeView.BeginUpdate();
            // Clear the TreeView each time the method is called.
            treeView.Nodes.Clear();

            string selectedCategory = string.Empty;
            string selectedTest     = string.Empty;

            if (_optionSettings != null &&
                !string.IsNullOrWhiteSpace(_optionSettings.SelectedValuePath))
            {
                var selectedPaths = _optionSettings.SelectedValuePath.Split('/');
                if (selectedPaths != null && selectedPaths.Length == 2)
                {
                    selectedCategory = selectedPaths[0];
                    selectedTest     = selectedPaths[1];
                }
            }
            TreeNode selectedCategoryItem = null;

            var treeFont = this.treeView.Font;

            this.treeView.ItemHeight = 22;
            var categoryFont = new Font(treeFont.FontFamily, treeFont.Size + 1, FontStyle.Bold, GraphicsUnit.Pixel);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element &&
                    string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase))
                {
                    // <category label="Animations">
                    string categoryLabel = reader.GetAttribute("label");
                    if (!string.IsNullOrWhiteSpace(categoryLabel))
                    {
                        SvgTestCategory testCategory = new SvgTestCategory(categoryLabel);

                        TreeNode categoryItem = new TreeNode(categoryLabel);
                        categoryItem.NodeFont           = categoryFont;
                        categoryItem.ImageIndex         = 0;
                        categoryItem.SelectedImageIndex = 0;
                        categoryItem.Tag = testCategory;

                        treeView.Nodes.Add(categoryItem);

                        bool categorySelected = false;
                        if (!string.IsNullOrWhiteSpace(selectedCategory) &&
                            selectedCategory.Equals(categoryLabel, StringComparison.OrdinalIgnoreCase))
                        {
                            selectedCategoryItem = categoryItem;
                            categorySelected     = true;
                        }
                        LoadTreeViewCategory(reader, categoryItem, testCategory, categorySelected, selectedTest);

                        if (testCategory.IsValid)
                        {
                            testResult.Categories.Add(testCategory);
                        }
                    }
                }
            }

            if (_testResults == null)
            {
                _testResults = new List <SvgTestResult>();
            }

            bool saveResults = false;

            if (testResult.IsValid)
            {
                if (_testResults.Count == 0)
                {
                    _testResults.Add(testResult);

                    saveResults = true;
                }
                else
                {
                    int foundAt = -1;
                    for (int i = 0; i < _testResults.Count; i++)
                    {
                        SvgTestResult nextResult = _testResults[i];
                        if (nextResult != null && nextResult.IsValid)
                        {
                            if (string.Equals(nextResult.Version, testResult.Version))
                            {
                                foundAt = i;
                                break;
                            }
                        }
                    }

                    if (foundAt >= 0)
                    {
                        SvgTestResult nextResult = _testResults[foundAt];

                        if (!SvgTestResult.AreEqual(nextResult, testResult))
                        {
                            _testResults[foundAt] = testResult;
                            saveResults           = true;
                        }
                    }
                    else
                    {
                        _testResults.Add(testResult);

                        saveResults = true;
                    }
                }
            }
            if (saveResults)
            {
                if (!string.IsNullOrWhiteSpace(_testResultsPath))
                {
                    string backupFile = null;
                    if (File.Exists(_testResultsPath))
                    {
                        backupFile = Path.ChangeExtension(_testResultsPath, ".bak");
                        try
                        {
                            if (File.Exists(backupFile))
                            {
                                File.Delete(backupFile);
                            }
                            File.Move(_testResultsPath, backupFile);
                        }
                        catch (Exception ex)
                        {
                            if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile))
                            {
                                File.Delete(backupFile);
                            }
                            MessageBox.Show(ex.ToString(), MainForm.AppErrorTitle,
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    try
                    {
                        XmlWriterSettings settings = new XmlWriterSettings();
                        settings.Indent      = true;
                        settings.IndentChars = "    ";
                        settings.Encoding    = Encoding.UTF8;

                        using (XmlWriter writer = XmlWriter.Create(_testResultsPath, settings))
                        {
                            this.SaveTestResults(writer);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile))
                        {
                            File.Move(backupFile, _testResultsPath);
                        }

                        MessageBox.Show(ex.ToString(), MainForm.AppErrorTitle,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile))
                    {
                        File.Delete(backupFile);
                    }
                }
            }

            if (selectedCategoryItem != null)
            {
                selectedCategoryItem.ExpandAll();
            }

            // Begin repainting the TreeView.
            treeView.EndUpdate();
            treeView.Focus();
        }
        private string CreateSummaryTable()
        {
            int resultCount = _testResults.Count;

            var summaryTable = new StringBuilder();
            var tableStyle   = new StringBuilder();

            tableStyle.Append("border:1px solid gray;");
            tableStyle.AppendFormat("margin:{0}px {1}px {2}px {3}px;", 0, 16, 16, 16);
            tableStyle.Append("width:95%;");
            summaryTable.AppendLine(string.Format(
                                        "<table style=\"{0}\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">", tableStyle));

            tableStyle.Length = 0;
            var headerGroup = new StringBuilder();

            tableStyle.Append("border-color:lightgray;");
            headerGroup.AppendLine(string.Format("<tr style=\"{0}\">", tableStyle));

            headerGroup.AppendLine(CreateHeaderCell("Category", false, false, true));
            headerGroup.AppendLine(CreateHeaderCell("Total", false, false, true));

            for (int i = 0; i < resultCount; i++)
            {
                SvgTestResult testResult = _testResults[i];
                headerGroup.AppendLine(CreateHeaderCellEx(testResult.Version,
                                                          (i == (resultCount - 1)), false, true));
            }
            headerGroup.AppendLine("</tr>");

            summaryTable.AppendLine(headerGroup.ToString());

            int[] successValues = new int[resultCount];
            int   totalValue    = 0;

            // Start with color of newer vesions
            string[] changedBrushes =
            {
                "lightsalmon",    // Brushes.LightSalmon
                "lightseagreen",  // Brushes.LightSeaGreen  - Version 1.2
                "lightskyblue",   // Brushes.LightSkyBlue   - Version 1.1
                "lightpink",      // Brushes.LightPink
                "lightsteelblue", // Brushes.LightSteelBlue
                "lightskyblue",   // Brushes.LightSkyBlue
                "lightskyblue"    // Brushes.LightSkyBlue
            };

            for (int k = 0; k < _categoryLabels.Count; k++)
            {
                var resultCells = new List <string>();

                bool lastBottom = (k == (_categoryLabels.Count - 1));

                resultCells.Add(CreateCell(_categoryLabels[k], false, lastBottom));

                for (int i = 0; i < resultCount; i++)
                {
                    SvgTestResult testResult = _testResults[i];

                    IList <SvgTestCategory> testCategories = testResult.Categories;

                    SvgTestCategory testCategory = testCategories[k];
                    if (!testCategory.IsValid)
                    {
                        continue;
                    }

                    int total = testCategory.Total;

                    if (i == 0)
                    {
                        resultCells.Add(CreateCell(total, false, lastBottom));
                    }

                    successValues[i] = testCategory.Successes;
                    totalValue       = total;
                    bool lastRight = (i == (resultCount - 1));

                    double percentValue = Math.Round(testCategory.Successes * 100.0d / total, 2);

                    resultCells.Add(CreateCellSummary(percentValue.ToString("00.00"), lastRight, lastBottom));
                }

                int cellCount       = resultCells.Count;
                var cellBackgrounds = new string[cellCount];

                if (IsAllZero(successValues))
                {
                    for (int i = 1; i < cellCount; i++)
                    {
                        cellBackgrounds[i] = "background-color:palevioletred;"; // Brushes.PaleVioletRed;
                    }
                }
                else if (IsAllDone(successValues, totalValue))
                {
                    for (int i = 1; i < cellCount; i++)
                    {
                        cellBackgrounds[i] = "background-color:silver;"; // Brushes.Silver
                    }
                }
                else
                {
                    if (IsNowDone(successValues, totalValue))
                    {
                        for (int i = 1; i < cellCount; i++)
                        {
                            cellBackgrounds[i] = "background-color:silver;"; // Brushes.Silver
                        }
                    }

                    if (resultCount > 1)
                    {
                        int i = 0;
                        for (int j = (resultCount - 1); j >= 1; j--)
                        {
                            var selectedBrush = string.Format("background-color:{0};", changedBrushes[i]);

                            i++;
                            if (IsBetterResult(successValues, j))
                            {
                                cellBackgrounds[cellCount - i] = selectedBrush; // selectedBrush
                            }
                        }
                    }
                }

                var resultGroup = new StringBuilder();
                resultGroup.AppendLine("<tr>");
                for (int i = 0; i < cellCount; i++)
                {
                    string resultRow      = resultCells[i];
                    var    cellBackground = cellBackgrounds[i];
                    if (string.IsNullOrWhiteSpace(cellBackground))
                    {
                        resultRow = resultRow.Replace("background-color:transparent;", "");
                    }
                    else
                    {
                        resultRow = resultRow.Replace("background-color:transparent;", cellBackground);
                    }
                    resultGroup.AppendLine(resultRow);
                }
                resultGroup.AppendLine("</tr>");

                summaryTable.AppendLine(resultGroup.ToString());
            }

            summaryTable.AppendLine("</table>");
            return(summaryTable.ToString());
        }
        private void CreateDocument()
        {
            testDetailsDoc.Text = string.Empty;
            if (_testResults == null || _testResults.Count == 0)
            {
                return;
            }

            var documentBuilder = new StringBuilder(BeginDocument());

            var noteSection = new StringBuilder();

            noteSection.AppendLine(CreateAlert("NOTE: Test Suite",
                                               "These tests are based on SVG 1.1 First Edition Test Suite: 13 December 2006 (Full)."));

            noteSection.AppendLine(CreateHorzLine(false));

            documentBuilder.AppendLine(noteSection.ToString());

            _categoryLabels = new List <string>();

            int resultCount = _testResults.Count;

            for (int i = 0; i < resultCount; i++)
            {
                SvgTestResult testResult = _testResults[i];
                if (!testResult.IsValid)
                {
                    continue;
                }
                IList <SvgTestCategory> testCategories = testResult.Categories;
                if (testCategories == null || testCategories.Count == 0)
                {
                    continue;
                }

                if (i == 0)
                {
                    for (int j = 0; j < testCategories.Count; j++)
                    {
                        _categoryLabels.Add(testCategories[j].Label);
                    }
                }

                var titleSection = new StringBuilder();
                titleSection.AppendLine("<div style=\"padding:0px;margin:0px;\">");
                string headingText = string.Format("{0}. Test Results: SharpVectors Version {1}", (i + 1), testResult.Version);
                var    titlePara   = new StringBuilder();
                titlePara.AppendLine(string.Format("<h3 style=\"padding:0px;margin:0px;\">{0}</h3>", headingText));
                titleSection.AppendLine(titlePara.ToString());

                var datePara   = new StringBuilder();
                var tableStyle = new StringBuilder();
                tableStyle.Append("font-weight:bold;");
                tableStyle.Append("font-size:16px;");
                tableStyle.Append("border-width:1px;");
                tableStyle.Append("text-align:center;");
                tableStyle.Append("padding:3px;");
                datePara.AppendLine(string.Format("<p style=\"{0}\">{1}</p>",
                                                  tableStyle, "Test Date: " + testResult.Date.ToString()));

                titleSection.AppendLine(datePara.ToString());

                titleSection.AppendLine("</div>");

                documentBuilder.AppendLine(titleSection.ToString());

                var resultSection = new StringBuilder();
                var resultTable   = CreateResultTable(testCategories);

                resultSection.AppendLine(resultTable);

                if (resultCount > 1)
                {
                    resultSection.AppendLine(this.CreateHorzLine((i == (resultCount - 1))));
                }
                else
                {
                    resultSection.AppendLine(this.CreateHorzLine());
                }

                documentBuilder.AppendLine(resultSection.ToString());
            }

            if (resultCount > 1)
            {
                var summarySection = new StringBuilder();
                var summaryPara    = new StringBuilder();
                summaryPara.AppendLine("<h3>Test Results: Summary</h3>");

                summarySection.AppendLine(summaryPara.ToString());

                var summaryTable = CreateSummaryTable();

                summarySection.AppendLine(summaryTable);

                summarySection.AppendLine(CreateAlert("NOTE: Percentage",
                                                      "The percentage calculations do not include partial success cases."));

                summarySection.AppendLine(this.CreateHorzLine(true));

                documentBuilder.AppendLine(summarySection.ToString());
            }

            documentBuilder.AppendLine(this.EndDocument());

            testDetailsDoc.Text = documentBuilder.ToString();
        }