/// <summary> /// Handles whenever the text displayed in the view changes by adding the adornment to any reformatted lines /// </summary> /// <remarks><para>This event is raised whenever the rendered text displayed in the <see cref="ITextView"/> changes.</para> /// <para>It is raised whenever the view does a layout (which happens when DisplayTextLineContainingBufferPosition is called or in response to text or classification changes).</para> /// <para>It is also raised whenever the view scrolls horizontally or when its size changes.</para> /// </remarks> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> internal void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e) { CoverageState[] currentFile = new CoverageState[0]; ProfileVector currentProf = new Data.ProfileVector(0); string activeFilename = GetActiveFilename(); if (activeFilename != null) { Tuple <BitVector, ProfileVector> activeReport = null; DateTime activeFileLastWrite = File.GetLastWriteTimeUtc(activeFilename); var dataProvider = Data.ReportManagerSingleton.Instance(dte); if (dataProvider != null) { var coverageData = dataProvider.UpdateData(); if (coverageData != null && activeFilename != null) { if (coverageData.FileDate >= activeFileLastWrite) { activeReport = coverageData.GetData(activeFilename); } } } if (activeReport != null) { currentProf = activeReport.Item2; currentFile = new CoverageState[activeReport.Item1.Count]; foreach (var item in activeReport.Item1.Enumerate()) { if (item.Value) { currentFile[item.Key] = CoverageState.Covered; } else { currentFile[item.Key] = CoverageState.Uncovered; } } } } this.currentCoverage = currentFile; this.currentProfile = currentProf; foreach (ITextViewLine line in e.NewOrReformattedLines) { HighlightCoverage(currentCoverage, currentProfile, line); } // foreach (ITextViewLine line in e.NewOrReformattedLines) // { // this.CreateVisuals(line); // } }
public LineCoverage(int visitCount, CoverageState sequenceCoverageState, CoverageState branchCoverageState, bool[][] branchesVisited, LineSection[] uncoveredSections, HashSet <TestMethod> lineVisitors, HashSet <TestMethod>[][] branchVisitors) { VisitCount = visitCount; SequenceCoverageState = sequenceCoverageState; BranchCoverageState = branchCoverageState; BranchesVisited = branchesVisited; UncoveredSections = uncoveredSections; LineVisitors = lineVisitors; BranchVisitors = branchVisitors; }
/// <summary> /// Initializes the current coverage data /// </summary> private void InitCurrent() { CoverageState[] currentFile = new CoverageState[0]; ProfileVector currentProf = new Data.ProfileVector(0); // Check report exists if (CoverageEnvironment.ShowCodeCoverage && CoverageEnvironment.report != null) { string activeFilename = System.IO.Path.GetFullPath(GetActiveFilename()); if (activeFilename != null) { CoverageEnvironment.print("Coverage: Print report on " + activeFilename); Tuple <BitVector, ProfileVector> activeReport = null; DateTime activeFileLastWrite = File.GetLastWriteTimeUtc(activeFilename); if (CoverageEnvironment.report.FileDate >= activeFileLastWrite) { CoverageEnvironment.print("Coverage: Report is up to date"); activeReport = CoverageEnvironment.report.GetData(activeFilename); if (activeReport != null) { CoverageEnvironment.print("Coverage: File is inside report"); currentProf = activeReport.Item2; currentFile = new CoverageState[activeReport.Item1.Count]; foreach (var item in activeReport.Item1.Enumerate()) { if (item.Value) { currentFile[item.Key] = CoverageState.Covered; } else { currentFile[item.Key] = CoverageState.Uncovered; } } } else { CoverageEnvironment.print("Coverage: File " + activeFilename + " is not inside report"); } } else { CoverageEnvironment.print("Coverage: Report is too old compare to file."); } } } this.currentCoverage = currentFile; this.currentProfile = currentProf; }
/// <summary> /// Updates <c>State</c> property if /// </summary> /// <param name="state"> </param> public override void UpdateState(CoverageState state) { // Record(TrueOnly) _lastState = TrueOnly // foreach() { // Record(FalseOnly) ループ判定成立 (State |= FalseOnly) // statement; // Record(TrueOnly) _lastState = TrueOnly // } // Record(TrueOnly) ループ判定不成立 (State |= TrueOnly if _lastState == TrueOnly) if (state == CoverageState.FalseOnly || _lastState == state) { State |= state; } _lastState = state; }
/// <summary> /// Initializes the current coverage data /// </summary> private void InitCurrent() { CoverageState[] currentFile = new CoverageState[0]; ProfileVector currentProf = new Data.ProfileVector(0); if (Settings.Instance.ShowCodeCoverage) { string activeFilename = GetActiveFilename(); if (activeFilename != null) { Tuple <BitVector, ProfileVector> activeReport = null; DateTime activeFileLastWrite = File.GetLastWriteTimeUtc(activeFilename); var dataProvider = Data.ReportManagerSingleton.Instance(dte); if (dataProvider != null) { var coverageData = dataProvider.UpdateData(); if (coverageData != null && activeFilename != null) { if (coverageData.FileDate >= activeFileLastWrite) { activeReport = coverageData.GetData(activeFilename); } } } if (activeReport != null) { currentProf = activeReport.Item2; currentFile = new CoverageState[activeReport.Item1.Count]; foreach (var item in activeReport.Item1.Enumerate()) { if (item.Value) { currentFile[item.Key] = CoverageState.Covered; } else { currentFile[item.Key] = CoverageState.Uncovered; } } } } } this.currentCoverage = currentFile; this.currentProfile = currentProf; }
/// <summary> /// Adds the scarlet box behind the 'a' characters within the given line /// </summary> /// <param name="line">Line to add the adornments</param> /* * private void CreateVisuals(ITextViewLine line) * { * IWpfTextViewLineCollection textViewLines = this.view.TextViewLines; * * // Loop through each character, and place a box around any 'a' * for (int charIndex = line.Start; charIndex < line.End; charIndex++) * { * if (this.view.TextSnapshot[charIndex] == 'a') * { * SnapshotSpan span = new SnapshotSpan(this.view.TextSnapshot, Span.FromBounds(charIndex, charIndex + 1)); * Geometry geometry = textViewLines.GetMarkerGeometry(span); * if (geometry != null) * { * var drawing = new GeometryDrawing(this.brush, this.pen, geometry); * drawing.Freeze(); * * var drawingImage = new DrawingImage(drawing); * drawingImage.Freeze(); * * var image = new Image * { * Source = drawingImage, * }; * * // Align the image with the top of the bounds of the text geometry * Canvas.SetLeft(image, geometry.Bounds.Left); * Canvas.SetTop(image, geometry.Bounds.Top); * * this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null); * } * } * } * } */ private void HighlightCoverage(CoverageState[] coverdata, ProfileVector profiledata, ITextViewLine line) { if (view == null || profiledata == null || line == null || view.TextSnapshot == null) { return; } IWpfTextViewLineCollection textViewLines = view.TextViewLines; if (textViewLines == null || line.Extent == null) { return; } int lineno = 1 + view.TextSnapshot.GetLineNumberFromPosition(line.Extent.Start); CoverageState covered = lineno < coverdata.Length ? coverdata[lineno] : CoverageState.Irrelevant; if (covered != CoverageState.Irrelevant) { SnapshotSpan span = new SnapshotSpan(view.TextSnapshot, Span.FromBounds(line.Start, line.End)); Geometry g = textViewLines.GetMarkerGeometry(span); if (g != null) { g = new RectangleGeometry(new Rect(g.Bounds.X, g.Bounds.Y, view.ViewportWidth, g.Bounds.Height)); GeometryDrawing drawing = (covered == CoverageState.Covered) ? new GeometryDrawing(coveredBrush, coveredPen, g) : new GeometryDrawing(uncoveredBrush, uncoveredPen, g); drawing.Freeze(); DrawingImage drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); Image image = new Image(); image.Source = drawingImage; //Align the image with the top of the bounds of the text geometry Canvas.SetLeft(image, g.Bounds.Left); Canvas.SetTop(image, g.Bounds.Top); layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null); } } var profile = profiledata.Get(lineno); if (profile != null && profile.Item1 != 0 || profile.Item2 != 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(profile.Item1); sb.Append("%/"); sb.Append(profile.Item2); sb.Append("%"); SnapshotSpan span = new SnapshotSpan(view.TextSnapshot, Span.FromBounds(line.Start, line.End)); Geometry g = textViewLines.GetMarkerGeometry(span); if (g != null) // Yes, this apparently happens... { double x = g.Bounds.X + g.Bounds.Width + 20; if (x < view.ViewportWidth / 2) { x = view.ViewportWidth / 2; } g = new RectangleGeometry(new Rect(x, g.Bounds.Y, 30, g.Bounds.Height)); Label lbl = new Label(); lbl.FontSize = 7; lbl.Foreground = Brushes.Black; lbl.Background = Brushes.Transparent; lbl.FontFamily = new FontFamily("Verdana"); lbl.Content = sb.ToString(); Canvas.SetLeft(lbl, g.Bounds.Left); Canvas.SetTop(lbl, g.Bounds.Top); layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, lbl, null); } } }
private CoverageState[] UpdateCoverageData(List <KeyValuePair <int, int> > data) { List <Tuple <int, int, int> > newdata = new List <Tuple <int, int, int> >(); foreach (var item in data) { int line = item.Key; // case 1: // 10: 0 // 0xfeefee: 10 // --> 10: #=2, cov=1 // // case 2: // 10: 0 // 10: 10 // --> 10: 10. // // case 3: // 10: 0 // 12: 2 // --> 10: 0, 12: 2 if (newdata.Count > 0 && newdata[newdata.Count - 1].Item1 == line) { newdata.Add(new Tuple <int, int, int>(item.Key, 1, item.Value > 0 ? 1 : 0)); } else if (line >= 0xf00000) { var last = newdata[newdata.Count - 1]; newdata[newdata.Count - 1] = new Tuple <int, int, int>(last.Item1, last.Item2 + 1, last.Item3 + ((item.Value > 0) ? 1 : 0)); } else { newdata.Add(new Tuple <int, int, int>(item.Key, 1, item.Value > 0 ? 1 : 0)); } } if (newdata.Count == 0) { newdata.Add(new Tuple <int, int, int>(0, 1, 1)); } newdata.Sort(); int max = newdata[newdata.Count - 1].Item1 + 1; // Initialize everything to 'covered'. CoverageState[] lines = new CoverageState[max]; for (int i = 0; i < lines.Length; ++i) { lines[i] = CoverageState.Covered; } int lastline = 0; CoverageState lastState = CoverageState.Covered; foreach (var item in newdata) { for (int i = lastline; i < item.Item1; ++i) { lines[i] = lastState; } lastline = item.Item1; lastState = (item.Item3 == 0) ? CoverageState.Uncovered : (item.Item3 == item.Item2) ? CoverageState.Covered : CoverageState.Partially; } for (int i = lastline; i < lines.Length; ++i) { lines[i] = lastState; } return(lines); }
public virtual void UpdateState(CoverageState state) { State |= state; }
public void Execute(CoverageElement lastElement, CoverageState state) {}
public void Execute(CoverageElement lastElement, CoverageState state) { }