Skip to content

Commit

Permalink
Add test for optional pointer parameters
Browse files Browse the repository at this point in the history
Repro for microsoft#1081
  • Loading branch information
AArnott committed Jan 9, 2024
1 parent 18aafe6 commit efcbb48
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/Microsoft.Windows.CsWin32.Tests/COMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@ public void InterestingComInterfaces(
this.GenerateApi(api);
}

/// <summary>
/// Verifies that COM methods that accept `[Optional, In]` parameters are declared as pointers
/// rather than `in` parameters, since the marshaller will throw NRE if the reference is null (via <see cref="Unsafe.NullRef{T}"/>).
/// </summary>
/// <seealso href="https://github.com/microsoft/CsWin32/issues/1081"/>
[Fact]
public void OptionalInPointerParameterExposedAsPointer()
{
this.GenerateApi("IMMDevice");

MethodDeclarationSyntax comMethod = this.FindGeneratedMethod("Activate").First(m => !m.Modifiers.Any(SyntaxKind.StaticKeyword));
ParameterSyntax optionalInParam = comMethod.ParameterList.Parameters[2];
Assert.Empty(optionalInParam.Modifiers);
Assert.IsType<PointerTypeSyntax>(optionalInParam.Type);
}

[Fact]
public void EnvironmentFailFast()
{
Expand Down

0 comments on commit efcbb48

Please sign in to comment.