Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report diagnostic for BestFitMapping, ThrowOnUnmappableChar, and LCIDConversion #291

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
50 changes: 45 additions & 5 deletions DllImportGenerator/DllImportGenerator.UnitTests/CodeSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ partial class Test
ThrowOnUnmappableChar = true)]
public static partial void Method();
}
";

/// <summary>
/// Declaration with all supported DllImport named arguments.
/// </summary>
public static readonly string AllSupportedDllImportNamedArguments = @"
using System.Runtime.InteropServices;
partial class Test
{
[GeneratedDllImport(""DoesNotExist"",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
EntryPoint = ""UserDefinedEntryPoint"",
ExactSpelling = true,
PreserveSig = false,
SetLastError = true)]
public static partial void Method();
}
";

/// <summary>
Expand All @@ -180,17 +198,26 @@ partial class Test
private const bool IsTrue = true;
private const bool IsFalse = false;
private const string EntryPointName = nameof(Test) + nameof(IsFalse);
private const int One = 1;
private const int Two = 2;

[GeneratedDllImport(nameof(Test),
BestFitMapping = 0 != 1,
CallingConvention = (CallingConvention)1,
CharSet = (CharSet)2,
EntryPoint = EntryPointName,
ExactSpelling = IsTrue,
ExactSpelling = 0 != 1,
PreserveSig = IsFalse,
SetLastError = !IsFalse,
ThrowOnUnmappableChar = !IsTrue)]
public static partial void Method();
SetLastError = IsTrue)]
public static partial void Method1();

[GeneratedDllImport(nameof(Test),
CallingConvention = (CallingConvention)One,
CharSet = (CharSet)Two,
EntryPoint = EntryPointName,
ExactSpelling = One != Two,
PreserveSig = !IsFalse,
SetLastError = !IsTrue)]
public static partial void Method2();
}
";

Expand All @@ -204,6 +231,19 @@ partial class Test
[GeneratedDllImport(""DoesNotExist"")]
public static partial void Method(int t = 0);
}
";

/// <summary>
/// Declaration with LCIDConversionAttribute.
/// </summary>
public static readonly string LCIDConversionAttribute = @"
using System.Runtime.InteropServices;
partial class Test
{
[LCIDConversion(0)]
[GeneratedDllImport(""DoesNotExist"")]
public static partial void Method();
}
";

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public static IEnumerable<object[]> CodeSnippetsToCompile()
// Unsupported MarshalAsAttribute usage
// * UnmanagedType.CustomMarshaler, MarshalTypeRef, MarshalType, MarshalCookie
yield return new object[] { CodeSnippets.MarshalAsCustomMarshalerOnTypes, 16, 0 };

// Unsupported named arguments
// * BestFitMapping, ThrowOnUnmappableChar
yield return new object[] { CodeSnippets.AllDllImportNamedArguments, 2, 0 };

// LCIDConversion
yield return new object[] { CodeSnippets.LCIDConversionAttribute, 1, 0 };
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompile_NoDiagnostics()
yield return new[] { CodeSnippets.NestedNamespace };
yield return new[] { CodeSnippets.NestedTypes };
yield return new[] { CodeSnippets.UserDefinedEntryPoint };
yield return new[] { CodeSnippets.AllDllImportNamedArguments };
yield return new[] { CodeSnippets.AllSupportedDllImportNamedArguments };
yield return new[] { CodeSnippets.DefaultParameters };
yield return new[] { CodeSnippets.UseCSharpFeaturesForConstants };
yield return new[] { CodeSnippets.BasicParametersAndModifiers<byte>() };
Expand Down
Loading