Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 121 additions & 1 deletion src/ExpressionEvaluator/CSharp/Test/ResultProvider/ExpansionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.ExpressionEvaluator;
using Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.ExpressionEvaluator;
using Microsoft.VisualStudio.Debugger;
using Microsoft.VisualStudio.Debugger.Clr;
using Microsoft.VisualStudio.Debugger.ComponentInterfaces;
using Microsoft.VisualStudio.Debugger.Evaluation;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -2183,5 +2186,122 @@ public void NullableValue_Error()
EvalFailedResult("o.P", "Function evaluation timed out", "int?", "o.P"));
}
}

/// <summary>
/// Get many items synchronously.
/// </summary>
[Fact]
public void ManyItemsSync()
{
const int n = 10000;
var value = CreateDkmClrValue(Enumerable.Range(0, n).ToArray());
var evalResult = FormatResult("a", value);
IDkmClrResultProvider resultProvider = new CSharpResultProvider();
var workList = new DkmWorkList();

// GetChildren
var getChildrenResult = default(DkmGetChildrenAsyncResult);
resultProvider.GetChildren(evalResult, workList, n, DefaultInspectionContext, r => getChildrenResult = r);
Assert.Equal(workList.Length, 0);
Assert.Equal(getChildrenResult.InitialChildren.Length, n);

// GetItems
var getItemsResult = default(DkmEvaluationEnumAsyncResult);
resultProvider.GetItems(getChildrenResult.EnumContext, workList, 0, n, r => getItemsResult = r);
Assert.Equal(workList.Length, 0);
Assert.Equal(getItemsResult.Items.Length, n);
}

/// <summary>
/// Multiple items, some completed asynchronously.
/// </summary>
[Fact]
public void MultipleItemsAsync()
{
var source =
@"using System.Diagnostics;
[DebuggerDisplay(""{F}"")]
class C
{
object F;
}";
var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
using (runtime.Load())
{
int n = 10;
var type = runtime.GetType("C");
// C[] with alternating null and non-null values.
var value = CreateDkmClrValue(Enumerable.Range(0, n).Select(i => (i % 2) == 0 ? type.Instantiate() : null).ToArray());
var evalResult = FormatResult("a", value);

IDkmClrResultProvider resultProvider = new CSharpResultProvider();
var workList = new DkmWorkList();

// GetChildren
var getChildrenResult = default(DkmGetChildrenAsyncResult);
resultProvider.GetChildren(evalResult, workList, n, DefaultInspectionContext, r => getChildrenResult = r);
Assert.Equal(workList.Length, 1);
workList.Execute();
Assert.Equal(getChildrenResult.InitialChildren.Length, n);

// GetItems
var getItemsResult = default(DkmEvaluationEnumAsyncResult);
resultProvider.GetItems(getChildrenResult.EnumContext, workList, 0, n, r => getItemsResult = r);
Assert.Equal(workList.Length, 1);
workList.Execute();
Assert.Equal(getItemsResult.Items.Length, n);
}
}

[Fact]
public void MultipleItemsAndExceptions()
{
var source =
@"using System.Diagnostics;
[DebuggerDisplay(""{P}"")]
class C
{
public C(int f) { this.f = f; }
private readonly int f;
object P
{
get
{
if (this.f % 4 == 3) throw new System.ArgumentException();
return this.f;
}
}
}";
var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
using (runtime.Load())
{
int n = 10;
int nFailures = 2;
var type = runtime.GetType("C");
var value = CreateDkmClrValue(Enumerable.Range(0, n).Select(i => type.Instantiate(i)).ToArray());
var evalResult = FormatResult("a", value);

IDkmClrResultProvider resultProvider = new CSharpResultProvider();
var workList = new DkmWorkList();

// GetChildren
var getChildrenResult = default(DkmGetChildrenAsyncResult);
resultProvider.GetChildren(evalResult, workList, n, DefaultInspectionContext, r => getChildrenResult = r);
Assert.Equal(workList.Length, 1);
workList.Execute();
var items = getChildrenResult.InitialChildren;
Assert.Equal(items.Length, n);
Assert.Equal(items.OfType<DkmFailedEvaluationResult>().Count(), nFailures);

// GetItems
var getItemsResult = default(DkmEvaluationEnumAsyncResult);
resultProvider.GetItems(getChildrenResult.EnumContext, workList, 0, n, r => getItemsResult = r);
Assert.Equal(workList.Length, 1);
workList.Execute();
items = getItemsResult.Items;
Assert.Equal(items.Length, n);
Assert.Equal(items.OfType<DkmFailedEvaluationResult>().Count(), nFailures);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,6 @@ internal static DkmCustomUIVisualizerInfo[] GetDebuggerCustomUIVisualizerInfo(th
return result;
}

internal static void EvaluateDebuggerDisplayStringAndContinue(this DkmClrValue value, DkmWorkList workList, DkmInspectionContext inspectionContext, DkmClrType targetType, string str, DkmCompletionRoutine<DkmEvaluateDebuggerDisplayStringAsyncResult> completionRoutine)
{
if (str == null)
{
completionRoutine(default(DkmEvaluateDebuggerDisplayStringAsyncResult));
}
else
{
value.EvaluateDebuggerDisplayString(workList, inspectionContext, targetType, str, completionRoutine);
}
}

internal static DkmClrType GetProxyType(this DkmClrType type)
{
DkmClrType attributeTarget;
Expand Down
Loading