提交 3ca3f7ed 编写于 作者: C Charles Stoner

Function pointer tests

上级 acbfff1e
......@@ -91,6 +91,7 @@
<Compile Include="ExpansionTests.cs" />
<Compile Include="FormatSpecifierTests.cs" />
<Compile Include="FullNameTests.cs" />
<Compile Include="FunctionPointerTests.cs" />
<Compile Include="Helpers\TestTypeExtensions.cs" />
<Compile Include="NativeViewTests.cs" />
<Compile Include="ObjectIdTests.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.ExpressionEvaluator;
using Microsoft.VisualStudio.Debugger.Clr;
using Microsoft.VisualStudio.Debugger.Evaluation;
using System;
using System.Diagnostics;
using Xunit;
using Type = Microsoft.VisualStudio.Debugger.Metadata.Type;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public class FunctionPointerTests : CSharpResultProviderTestBase
{
[Fact]
public void Root()
{
const int ptr = 0x1234;
var value = CreateDkmClrValue(ptr, type: new DkmClrType(FunctionPointerType.Instance));
var evalResult = FormatResult("pfn", value);
Verify(evalResult,
EvalResult("pfn", PointerToString(new IntPtr(ptr)), "System.Object*", "pfn", DkmEvaluationResultFlags.None, DkmEvaluationResultCategory.Other));
}
[Fact]
public void Member()
{
var source =
@"class C
{
object pfn;
}";
const int ptr = 0x0;
GetMemberValueDelegate getMemberValue = (v, m) => (m == "pfn") ? CreateDkmClrValue(ptr, type: new DkmClrType(FunctionPointerType.Instance)) : null;
var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)), getMemberValue: getMemberValue);
using (runtime.Load())
{
var type = runtime.GetType("C");
var value = CreateDkmClrValue(type.Instantiate(), type: type);
var evalResult = FormatResult("o", value);
Verify(evalResult,
EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable, DkmEvaluationResultCategory.Other));
var children = GetChildren(evalResult);
Verify(children,
EvalResult("pfn", PointerToString(new IntPtr(ptr)), "object {System.Object*}", "o.pfn", DkmEvaluationResultFlags.None, DkmEvaluationResultCategory.Other));
}
}
// Function pointer type has IsPointer == true and GetElementType() == null.
private sealed class FunctionPointerType : TypeImpl
{
internal static readonly FunctionPointerType Instance = new FunctionPointerType();
private FunctionPointerType() : base(typeof(object).MakePointerType())
{
Debug.Assert(this.IsPointer);
}
public override Type GetElementType()
{
return null;
}
}
}
}
......@@ -61,9 +61,15 @@ internal string GetTypeName(TypeAndCustomInfo typeAndInfo, bool escapeKeywordIde
int pointerCount = 0;
while (type.IsPointer)
{
var elementType = type.GetElementType();
if (elementType == null)
{
// Null for function pointers.
break;
}
index++;
pointerCount++;
type = type.GetElementType();
type = elementType;
}
int nullableCount = 0;
......
......@@ -11,11 +11,11 @@
namespace Microsoft.CodeAnalysis.ExpressionEvaluator
{
internal sealed class TypeImpl : Type
internal class TypeImpl : Type
{
internal readonly System.Type Type;
private TypeImpl(System.Type type)
internal TypeImpl(System.Type type)
{
Debug.Assert(type != null);
this.Type = type;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册