Exemplo n.º 1
0
        private void BFS_FinishVertex(SENode vertex)
        {
            IEnumerable <SEEdge> edges = null;

            if (GraphControl.Graph.TryGetOutEdges(vertex, out edges))
            {
                if (edges.Count() > 0)
                {
                    foreach (var edge in edges)
                    {
                        currentSubtreeRoot.CollapsedSubtreeEdges.Add(edge);
                    }
                }
            }

            if (!currentSubtreeRoot.Equals(vertex))
            {
                if (vertex.IsSelected)
                {
                    vertex.Deselect();
                }
                vertex.IsCollapsed = true;
                currentSubtreeRoot.CollapsedSubtreeNodes.Add(vertex);
            }
        }
Exemplo n.º 2
0
 private void DecorateVertexBackground(SENode v)
 {
     if (GraphControl.GetVertexControl(v) != null)
     {
         GraphControl.GetVertexControl(v).Background = new SolidColorBrush(Converters.SevizColorToWpfColor(v.Color));
     }
 }
Exemplo n.º 3
0
        private void MapNodesToSourceLinesBookmarks(SENode node)
        {
            var dte     = _parent.GetVsService(typeof(SDTE)) as EnvDTE.DTE;
            var fileUrl = node.SourceCodeMappingString.Split(':')[0] + ":" + node.SourceCodeMappingString.Split(':')[1];
            var line    = node.SourceCodeMappingString.Split(':')[2];
            var window  = dte.ItemOperations.OpenFile(fileUrl);

            if (window != null)
            {
                window.Activate();
                var selection = window.Selection as TextSelection;
                selection.GotoLine(int.Parse(line), true);
                var objectEditPoint = selection.ActivePoint.CreateEditPoint();
                objectEditPoint.SetBookmark();
            }
        }
Exemplo n.º 4
0
        public void AfterRun(IPexPathComponent host, object data)
        {
            // Getting the executions nodes in the current path
            var nodesInPath = host.PathServices.CurrentExecutionNodeProvider.ReversedNodes.Reverse().ToArray();

            // Getting the sequence id of the current run
            var runId = host.ExplorationServices.Driver.Runs;

            // Iterating over the nodes in the path
            foreach (var node in nodesInPath)
            {
                var vertex = new SENode(node.UniqueIndex, null, null, null, null, null, false);

                // Adding the method name this early in order to color edges
                string methodName = null;
                int    offset     = 0;
                if (node.CodeLocation.Method == null)
                {
                    if (node.InCodeBranch.Method != null)
                    {
                        methodName = node.InCodeBranch.Method.FullName;
                    }
                }
                else
                {
                    methodName = node.CodeLocation.Method.FullName;
                    offset     = node.CodeLocation.Offset;
                }
                // Setting the method name
                vertex.MethodName = methodName;

                // Setting the offset
                vertex.ILOffset = offset;

                var nodeIndex = nodesInPath.ToList().IndexOf(node);
                if (nodeIndex > 0)
                {
                    var prevNode = nodesInPath[nodeIndex - 1];
                    // If there is no edge between the previous and the current node
                    if (!(Edges.ContainsKey(prevNode.UniqueIndex) && Edges[prevNode.UniqueIndex].ContainsKey(node.UniqueIndex)))
                    {
                        var prevVertex = Vertices[prevNode.UniqueIndex];

                        var edge = new SEEdge(new Random().Next(), prevVertex, vertex);

                        Dictionary <int, SEEdge> outEdges = null;
                        if (Edges.TryGetValue(prevNode.UniqueIndex, out outEdges))
                        {
                            outEdges.Add(node.UniqueIndex, edge);
                        }
                        else
                        {
                            Edges.Add(prevNode.UniqueIndex, new Dictionary <int, SEEdge>());
                            Edges[prevNode.UniqueIndex].Add(node.UniqueIndex, edge);
                        }

                        // Edge coloring based on unit border detection
                        if (UnitNamespace != null)
                        {
                            // Checking if pointing into the unit from outside
                            if (!(prevVertex.MethodName.StartsWith(UnitNamespace + ".") || prevVertex.MethodName.Equals(UnitNamespace)) && (vertex.MethodName.StartsWith(UnitNamespace + ".") || vertex.MethodName.Equals(UnitNamespace)))
                            {
                                edge.Color = SEEdge.EdgeColor.Green;
                            }

                            // Checking if pointing outside the unit from inside
                            if ((prevVertex.MethodName.StartsWith(UnitNamespace + ".") || prevVertex.MethodName.Equals(UnitNamespace)) && !(vertex.MethodName.StartsWith(UnitNamespace + ".") || vertex.MethodName.Equals(UnitNamespace)))
                            {
                                edge.Color = SEEdge.EdgeColor.Red;
                            }
                        }
                    }
                }

                // If the node is new then it is added to the list and the metadata is filled
                if (!Vertices.ContainsKey(node.UniqueIndex))
                {
                    Vertices.Add(node.UniqueIndex, vertex);

                    // Adding source code mapping
                    vertex.SourceCodeMappingString = MapToSourceCodeLocationString(host, node);

                    // Setting the border based on mapping existence
                    vertex.Border = vertex.SourceCodeMappingString == null ? SENode.NodeBorder.Single : SENode.NodeBorder.Double;

                    // Setting the color
                    if (nodesInPath.LastOrDefault() == node)
                    {
                        if (!EmittedTestResult.ContainsKey(runId))
                        {
                            vertex.Color = SENode.NodeColor.Orange;
                        }
                        else
                        {
                            if (EmittedTestResult[runId].Item1)
                            {
                                vertex.Color = SENode.NodeColor.Red;
                            }
                            else
                            {
                                vertex.Color = SENode.NodeColor.Green;
                            }
                            vertex.GenerateTestCode = EmittedTestResult[runId].Item2;
                        }
                    }
                    else
                    {
                        vertex.Color = SENode.NodeColor.White;
                    }

                    // Setting the default shape
                    vertex.Shape = SENode.NodeShape.Rectangle;

                    // Adding path condition tasks and getting the required services
                    TermEmitter       termEmitter      = new TermEmitter(host.GetService <TermManager>());
                    SafeStringWriter  safeStringWriter = new SafeStringWriter();
                    IMethodBodyWriter methodBodyWriter = host.GetService <IPexTestManager>().Language.CreateBodyWriter(safeStringWriter, VisibilityContext.Private, 2000);
                    PrettyPathConditionTasks.Add(vertex.Id, PrettyPrintPathCondition(termEmitter, methodBodyWriter, safeStringWriter, node));

                    // Setting the status
                    vertex.Status = node.ExhaustedReason.ToString();

                    // Collecting the parent nodes for the later incremental path condition calculation
                    if (nodeIndex > 0)
                    {
                        ParentNodes.Add(vertex.Id, nodesInPath[nodeIndex - 1].UniqueIndex);
                    }
                }

                // Adding the Id of the run
                Vertices[node.UniqueIndex].Runs += (runId + ";");
            }
        }
Exemplo n.º 5
0
        private void Node_OnRightClick(object sender, RoutedEventArgs e)
        {
            currentSubtreeRoot = ((sender as VertexControl).Vertex as SENode);

            if (currentSubtreeRoot.IsCollapsed)
            {
                return;
            }

            if (currentSubtreeRoot.CollapsedSubtreeNodes.Count == 0)
            {
                // In order to revert to original color!
                if (currentSubtreeRoot.IsSelected)
                {
                    currentSubtreeRoot.Deselect();
                    DecorateVertexBackground(currentSubtreeRoot);
                }

                // Collapsing
                // If there are edges going out of it
                IEnumerable <SEEdge> edges = null;
                if (GraphControl.Graph.TryGetOutEdges(currentSubtreeRoot, out edges))
                {
                    if (edges.Count() == 0)
                    {
                        // Has no out edges --> leaf node --> select the nodes of the matching run of the leaf node
                        var vm = (SEGraphViewModel)DataContext;
                        SelectNodesVisually(GetNodesOfRun(currentSubtreeRoot.Runs));
                    }
                }

                var search = new BreadthFirstSearchAlgorithm <SENode, SEEdge>(GraphControl.Graph);
                search.SetRootVertex(currentSubtreeRoot);
                search.FinishVertex += BFS_FinishVertex;
                search.Finished     += (p, args) =>
                {
                    if (currentSubtreeRoot.CollapsedSubtreeEdges.Count > 0 && currentSubtreeRoot.CollapsedSubtreeNodes.Count > 0)
                    {
                        foreach (var edge in currentSubtreeRoot.CollapsedSubtreeEdges)
                        {
                            GraphControl.Graph.HideEdge(edge);
                        }
                        foreach (var node in currentSubtreeRoot.CollapsedSubtreeNodes)
                        {
                            GraphControl.Graph.HideVertex(node);
                        }
                        SelectNodeWithProperties(currentSubtreeRoot);
                        currentSubtreeRoot.Collapse();
                        DecorateVerticesBackground();
                    }
                };

                search.Compute();
            }
            else
            {
                // Expanding
                foreach (var vertex in ((sender as VertexControl).Vertex as SENode).CollapsedSubtreeNodes)
                {
                    GraphControl.Graph.UnhideVertex(vertex);
                    vertex.IsCollapsed = false;
                }
                currentSubtreeRoot.CollapsedSubtreeNodes.Clear();

                GraphControl.Graph.UnhideEdges(((sender as VertexControl).Vertex as SENode).CollapsedSubtreeEdges);
                currentSubtreeRoot.CollapsedSubtreeEdges.Clear();

                currentSubtreeRoot.Expand();

                DecorateVerticesBackground();
            }
        }
Exemplo n.º 6
0
 private void VisuallySelectNode(SENode node)
 {
     node.Select();
     DecorateVerticesBackground();
 }
Exemplo n.º 7
0
        private void SelectNodeWithProperties(SENode node)
        {
            IVsWindowFrame frame = null;

            if (frame == null)
            {
                var shell = _parent.GetVsService(typeof(SVsUIShell)) as IVsUIShell;
                if (shell != null)
                {
                    var guidPropertyBrowser = new
                                              Guid(ToolWindowGuids.PropertyBrowser);
                    shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate,
                                         ref guidPropertyBrowser, out frame);
                }
            }

            if (frame != null)
            {
                frame.Show();
            }

            var selContainer = new Microsoft.VisualStudio.Shell.SelectionContainer();
            var items        = new List <SENode>();

            items.Add(node);
            selContainer.SelectedObjects = items;

            ITrackSelection track = _parent.GetVsService(typeof(STrackSelection)) as ITrackSelection;

            if (track != null)
            {
                track.OnSelectChange(selContainer);
            }

            if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
            {
                // If control is pressed then to nothing
            }
            else
            {
                foreach (var v in GraphControl.Graph.Vertices)
                {
                    if (v.IsSelected)
                    {
                        v.Deselect();
                    }
                }
                DecorateVerticesBackground();
            }


            IVsStatusbar statusBar = (IVsStatusbar)_parent.GetVsService(typeof(SVsStatusbar));

            // Make sure the status bar is not frozen
            int frozen;

            statusBar.IsFrozen(out frozen);

            if (frozen != 0)
            {
                statusBar.FreezeOutput(0);
            }

            // Set the status bar text and make its display static.
            statusBar.SetText(node.MethodName + " (" + node.SourceCodeMappingString + ")");

            // Freeze the status bar.
            statusBar.FreezeOutput(1);
        }