private void OnTreeBeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (_optionSettings != null)
            {
                _optionSettings.SelectedValuePath = string.Empty;
            }
            // Prompt for any un-applied modifications to avoid lost.
            if (_isTreeChangedPending)
            {
                TreeNode treeItem = e.Node as TreeNode;
                if (treeItem == null)
                {
                    return;
                }

                if (treeItem != null && treeItem.Tag != null)
                {
                    SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;
                    if (testInfo != null)
                    {
                        DialogResult boxResult = MessageBox.Show(
                            "The previously selected test item was modified.\nDo you want to apply the current modifications?",
                            "Svg Test Suite",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                        if (boxResult == DialogResult.Yes || boxResult == DialogResult.OK)
                        {
                            this.OnApplyTestState(treeItem);
                        }
                    }
                }

                _isTreeChangedPending = false;
            }
        }
        private void OnApplyTestState(TreeNode treeItem)
        {
            SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;

            if (testInfo == null)
            {
                return;
            }

            int selIndex = stateComboBox.SelectedIndex;

            if (selIndex < 0)
            {
                return;
            }

            testInfo.State   = (SvgTestState)selIndex;
            testInfo.Comment = testComment.Text;

            treeItem.ImageIndex         = testInfo.ImageIndex;
            treeItem.SelectedImageIndex = testInfo.ImageIndex;

            if (!_isTreeModified)
            {
                this.Text = this.Text + " *";

                _isTreeModified = true;
            }

            _isTreeChangedPending   = false;
            testApplyButton.Enabled = false;
        }
Exemple #3
0
        public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            if (string.IsNullOrWhiteSpace(documentFilePath) || File.Exists(documentFilePath) == false)
            {
                return(false);
            }

            this.LoadFile(documentFilePath);

            return(true);
        }
        private void SaveTreeViewCategory(XmlWriter writer, TreeNode categoryItem, SvgTestCategory testCategory)
        {
            int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0;

            writer.WriteStartElement("category");

            writer.WriteAttributeString("label", testCategory.Label);

            TreeNodeCollection treeItems = categoryItem.Nodes;

            for (int j = 0; j < treeItems.Count; j++)
            {
                TreeNode treeItem = treeItems[j] as TreeNode;
                if (treeItem != null)
                {
                    SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;
                    if (testInfo != null)
                    {
                        testInfo.WriteXml(writer);

                        total++;
                        SvgTestState testState = testInfo.State;

                        switch (testState)
                        {
                        case SvgTestState.Unknown:
                            unknowns++;
                            break;

                        case SvgTestState.Failure:
                            failures++;
                            break;

                        case SvgTestState.Success:
                            successes++;
                            break;

                        case SvgTestState.Partial:
                            partials++;
                            break;
                        }
                    }
                }
            }

            writer.WriteEndElement();

            testCategory.SetValues(total, unknowns, failures, successes, partials);
        }
Exemple #5
0
        public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            this.UnloadDocument();

            if (string.IsNullOrWhiteSpace(documentFilePath) || testInfo == null)
            {
                return(false);
            }

            _svgFilePath = documentFilePath;

            bool isLoaded = false;

            string fileExt = Path.GetExtension(documentFilePath);

            if (string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase))
            {
                using (FileStream fileStream = File.OpenRead(documentFilePath))
                {
                    using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        // Text Editor does not work with this stream, so we read the data to memory stream...
                        MemoryStream memoryStream = new MemoryStream();
                        // Use this method is used to read all bytes from a stream.
                        int    totalCount = 0;
                        int    bufferSize = 512;
                        byte[] buffer     = new byte[bufferSize];
                        while (true)
                        {
                            int bytesRead = zipStream.Read(buffer, 0, bufferSize);
                            if (bytesRead == 0)
                            {
                                break;
                            }

                            memoryStream.Write(buffer, 0, bytesRead);
                            totalCount += bytesRead;
                        }

                        if (totalCount > 0)
                        {
                            memoryStream.Position = 0;
                        }

                        isLoaded = this.LoadFile(memoryStream, testInfo);

                        memoryStream.Close();
                    }
                }
            }
            else
            {
                using (FileStream stream = File.OpenRead(documentFilePath))
                {
                    isLoaded = this.LoadFile(stream, testInfo);
                }
            }

            btnFilePath.Enabled = isLoaded;

            testDetailsDoc.Focus();

            return(isLoaded);
        }
Exemple #6
0
        private bool LoadFile(Stream stream, SvgTestInfo testInfo)
        {
            Regex rgx = new Regex("\\s+");

            testTitle.Text      = testInfo.Title;
            testDescrition.Text = rgx.Replace(testInfo.Description, " ").Trim();
            testFilePath.Text   = _svgFilePath;

            btnFilePath.Enabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace             = false;
            settings.IgnoreComments               = true;
            settings.IgnoreProcessingInstructions = true;
            settings.DtdProcessing = DtdProcessing.Parse;

            StringBuilder textBuilder = new StringBuilder();

            textBuilder.AppendLine("<html>");
            textBuilder.AppendLine("<head>");
            textBuilder.AppendLine("<title>About Test</title>");
            textBuilder.AppendLine("</head>");
            textBuilder.AppendLine("<body>");
            textBuilder.AppendLine("<div style=\"padding:0px;margin:0px 0px 15px 0px;\">");

            SvgTestSuite selectedTestSuite = null;

            if (_optionSettings != null)
            {
                selectedTestSuite = _optionSettings.SelectedTestSuite;
            }
            if (selectedTestSuite == null)
            {
                selectedTestSuite = SvgTestSuite.GetDefault(SvgTestSuite.Create());
            }

            int majorVersion = selectedTestSuite.MajorVersion;
            int minorVersion = selectedTestSuite.MinorVersion;

            var paraStyle = new StringBuilder();

            paraStyle.Append("padding:3px;");
            paraStyle.Append("margin:0px;");

            var paraTag = string.Format("<p style=\"{0}\">", paraStyle);

            var tableStyle = new StringBuilder();

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

            tableStyle.Length = 0;
            //            tableStyle.Append("border:1px solid gray;");
            tableStyle.Append("font-weight:bold;");
            tableStyle.Append("font-size:16px;");
            tableStyle.Append("text-align:center;");
            var cellTag = string.Format("<td style=\"{0}\">", tableStyle);

            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                if (majorVersion == 1 && minorVersion == 1)
                {
                    var titleStyle = new StringBuilder();
                    titleStyle.Append("font-weight:bold;");
                    titleStyle.Append("font-size:14px;");
                    titleStyle.Append("padding:10px 0px 10px 0px;");
                    titleStyle.Append("margin:0px;");

                    if (reader.ReadToFollowing("d:SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "d:operatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(string.Format("<p style=\"{0}\">Operator Script</p>", titleStyle));
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:passCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(string.Format("<p style=\"{0}\">Pass Criteria</p>", titleStyle));
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:testDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(string.Format("<p style=\"{0}\">Test Description</p>", titleStyle));
                                    textBuilder.AppendLine(inputText);

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
                else if (majorVersion == 1 && minorVersion == 2)
                {
                    if (reader.ReadToFollowing("SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "d:OperatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:PassCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(inputText);
                                }
                                else if (string.Equals(nodeName, "d:TestDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);
                                    inputText = inputText.Replace("<p>", paraTag);
                                    inputText = inputText.Replace("<table>", tableTag);
                                    inputText = inputText.Replace("<th>", cellTag);
                                    inputText = inputText.Replace("</th>", "</td>");
                                    textBuilder.AppendLine(inputText);

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (reader.ReadToFollowing("SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "OperatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string revisionText = reader.GetAttribute("version");
                                    if (!string.IsNullOrWhiteSpace(revisionText))
                                    {
                                        revisionText       = revisionText.Replace("$", "");
                                        _testCase.Revision = revisionText.Trim();
                                    }
                                    string nameText = reader.GetAttribute("testname");
                                    if (!string.IsNullOrWhiteSpace(nameText))
                                    {
                                        _testCase.Name = nameText.Trim();
                                    }
                                }
                                else if (string.Equals(nodeName, "Paragraph", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml().Replace(NamespaceText, string.Empty);

                                    string paraText = rgx.Replace(inputText, " ").Trim();

                                    textBuilder.AppendLine("<p>" + paraText + "</p>");
                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            textBuilder.AppendLine("</div>");
            textBuilder.AppendLine("</body>");
            textBuilder.AppendLine("</html>");
            testDetailsDoc.Text = textBuilder.ToString();

            return(true);
        }
        private void LoadTreeViewCategory(XmlReader reader, TreeNode categoryItem,
                                          SvgTestCategory testCategory, bool categorySelected, string selectedTest)
        {
            int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0;

            int itemCount = 0;

            var comparer = StringComparison.OrdinalIgnoreCase;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "test", comparer))
                    {
                        SvgTestInfo testInfo = new SvgTestInfo(reader);
                        if (!testInfo.IsEmpty)
                        {
                            testInfo.Category = testCategory.Label;

                            var      itemLabel = string.Format("({0:D3}) - {1}", itemCount, testInfo.Title);
                            TreeNode treeItem  = new TreeNode(itemLabel);
                            treeItem.ImageIndex         = testInfo.ImageIndex;
                            treeItem.SelectedImageIndex = testInfo.ImageIndex;
                            treeItem.Tag = testInfo;

                            categoryItem.Nodes.Add(treeItem);

                            if (categorySelected &&
                                string.Equals(testInfo.Title, selectedTest, comparer))
                            {
                                treeItem.Expand();

                                treeView.SelectedNode = treeItem;
                            }

                            itemCount++;

                            total++;
                            SvgTestState testState = testInfo.State;

                            switch (testState)
                            {
                            case SvgTestState.Unknown:
                                unknowns++;
                                break;

                            case SvgTestState.Failure:
                                failures++;
                                break;

                            case SvgTestState.Success:
                                successes++;
                                break;

                            case SvgTestState.Partial:
                                partials++;
                                break;
                            }
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (string.Equals(reader.Name, "category", comparer))
                    {
                        break;
                    }
                }
            }

            testCategory.SetValues(total, unknowns, failures, successes, partials);
        }
        private void OnTreeAfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selItem = treeView.SelectedNode as TreeNode;

            if (selItem == null || selItem.Tag == null)
            {
                EnableTestPanel(false);
                return;
            }

            SvgTestInfo testItem = selItem.Tag as SvgTestInfo;

            if (testItem == null)
            {
                EnableTestPanel(false);
                return;
            }

            if (!_isSuiteAvailable)
            {
                EnableTestPanel(false);
                return;
            }

            string svgFilePath = Path.Combine(_suitePath, "svg\\" + testItem.FileName);

            if (!File.Exists(svgFilePath))
            {
                EnableTestPanel(false);
                return;
            }
            string pngFilePath = Path.Combine(_suitePath,
                                              "png\\" + Path.ChangeExtension(testItem.FileName, ".png"));

            if (!File.Exists(pngFilePath))
            {
                EnableTestPanel(false);
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            try
            {
                if (_testPages != null && _testPages.Count != 0)
                {
                    foreach (var page in _testPages)
                    {
                        if (page != null && page.IsDisposed == false)
                        {
                            page.LoadDocument(svgFilePath, testItem, pngFilePath);
                        }
                    }
                }

                stateComboBox.SelectedIndex = (int)testItem.State;
                testComment.Text            = testItem.Comment;

                _isTreeChangedPending   = false;
                testApplyButton.Enabled = false;
                EnableTestPanel(true);

                if (_optionSettings != null)
                {
                    _optionSettings.SelectedValuePath = testItem.Path;
                }
            }
            catch (Exception ex)
            {
                _isTreeChangedPending = false;
                this.Cursor           = Cursors.Default;

                MessageBox.Show(ex.ToString(), MainForm.AppErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                _isTreeChangedPending = false;
                this.Cursor           = Cursors.Default;

                treeView.Focus();
            }
        }
Exemple #9
0
 public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo)
 {
     return(true);
 }
Exemple #10
0
        private bool LoadFile(Stream stream, SvgTestInfo testInfo)
        {
            Regex rgx = new Regex("\\s+");

            testTitle.Text      = testInfo.Title;
            testDescrition.Text = rgx.Replace(testInfo.Description, " ").Trim();
            testFilePath.Text   = _svgFilePath;

            btnFilePath.Enabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace             = false;
            settings.IgnoreComments               = true;
            settings.IgnoreProcessingInstructions = true;
            settings.DtdProcessing = DtdProcessing.Ignore;

            StringBuilder textBuilder = new StringBuilder();

            textBuilder.AppendLine("<html>");
            textBuilder.AppendLine("<head>");
            textBuilder.AppendLine("<title>About Test</title>");
            textBuilder.AppendLine("</head>");
            textBuilder.AppendLine("<body>");
            textBuilder.AppendLine("<div style=\"padding:0px;margin:0px 0px 15px 0px;\">");

            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                if (reader.ReadToFollowing("SVGTestCase"))
                {
                    _testCase = new SvgTestCase();

                    while (reader.Read())
                    {
                        string      nodeName = reader.Name;
                        XmlNodeType nodeType = reader.NodeType;
                        if (nodeType == XmlNodeType.Element)
                        {
                            if (string.Equals(nodeName, "OperatorScript", StringComparison.OrdinalIgnoreCase))
                            {
                                string revisionText = reader.GetAttribute("version");
                                if (!string.IsNullOrWhiteSpace(revisionText))
                                {
                                    revisionText       = revisionText.Replace("$", "");
                                    _testCase.Revision = revisionText.Trim();
                                }
                                string nameText = reader.GetAttribute("testname");
                                if (!string.IsNullOrWhiteSpace(nameText))
                                {
                                    _testCase.Name = nameText.Trim();
                                }
                            }
                            else if (string.Equals(nodeName, "Paragraph", StringComparison.OrdinalIgnoreCase))
                            {
                                string inputText = reader.ReadInnerXml();

                                string paraText = rgx.Replace(inputText, " ").Trim();

                                textBuilder.AppendLine("<p>" + paraText + "</p>");
                                _testCase.Paragraphs.Add(inputText);
                            }
                        }
                        else if (nodeType == XmlNodeType.EndElement &&
                                 string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                        {
                            break;
                        }
                    }
                }
            }

            textBuilder.AppendLine("</div>");
            textBuilder.AppendLine("</body>");
            textBuilder.AppendLine("</html>");
            testDetailsDoc.Text = textBuilder.ToString();

            return(true);
        }
Exemple #11
0
        public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            this.UnloadDocument();

            if (extraInfo == null)
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(documentFilePath) || File.Exists(documentFilePath) == false)
            {
                return(false);
            }

            var pngFilePath = extraInfo.ToString();

            if (string.IsNullOrWhiteSpace(pngFilePath) || File.Exists(pngFilePath) == false)
            {
                return(false);
            }

            Image pngImage = null;

            try
            {
                pngImage = Image.FromFile(pngFilePath);
                if (pngImage == null)
                {
                    return(false);
                }
                viewerExpected.Image  = pngImage;
                viewerExpected.Width  = pngImage.Width + 10;
                viewerExpected.Height = pngImage.Height + 10;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                return(false);
            }

            try
            {
                _svgWindow        = new SvgPictureBoxWindow(pngImage.Width, pngImage.Height, _svgRenderer);
                _svgWindow.Source = documentFilePath;

                var svgImage = new Bitmap(pngImage.Width, pngImage.Height);

                using (var graWrapper = GdiGraphicsWrapper.FromImage(svgImage, true))
                {
                    _svgRenderer.GraphicsWrapper = graWrapper;
                    _svgRenderer.Render(_svgWindow.Document);
                    _svgRenderer.GraphicsWrapper = null;
                }

                viewerConverted.Image  = svgImage;
                viewerConverted.Width  = svgImage.Width + 10;
                viewerConverted.Height = svgImage.Height + 10;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                return(false);
            }

            return(true);
        }
Exemple #12
0
        public bool LoadDocument(string documentFilePath, SvgTestInfo testInfo, object extraInfo)
        {
            this.UnloadDocument();

            if (extraInfo == null)
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(documentFilePath) || File.Exists(documentFilePath) == false)
            {
                return(false);
            }

            var pngFilePath = extraInfo.ToString();

            if (string.IsNullOrWhiteSpace(pngFilePath) || File.Exists(pngFilePath) == false)
            {
                return(false);
            }

            Image pngImage = null;

            try
            {
                pngImage = Image.FromFile(pngFilePath);
                if (pngImage == null)
                {
                    return(false);
                }
                viewerExpected.Image  = pngImage;
                viewerExpected.Width  = pngImage.Width + 10;
                viewerExpected.Height = pngImage.Height + 10;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                return(false);
            }

            try
            {
                using (var svgRenderer = new GdiGraphicsRenderer(pngImage.Width, pngImage.Height))
                {
                    var svgWindow = svgRenderer.Window;

                    svgWindow.Source = documentFilePath;
                    svgRenderer.Render(svgWindow.Document);

                    var svgImage = svgRenderer.RasterImage;

                    viewerConverted.Image  = svgImage;
                    viewerConverted.Width  = svgImage.Width + 10;
                    viewerConverted.Height = svgImage.Height + 10;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                return(false);
            }

            return(true);
        }