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

Add a test covering a nested anonymous union #497

Merged
merged 2 commits into from
Nov 19, 2023
Merged
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
73 changes: 73 additions & 0 deletions tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,79 @@ public partial struct MyStruct
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, language: "c", languageStandard: DefaultCStandard);
}

[Test]
public Task EnumTest()
{
var inputContents = @"enum {
VALUE1 = 0,
VALUE2,
VALUE3
};

struct MyStruct {
enum {
VALUEA = 0,
VALUEB,
VALUEC
} field;
};
";
string expectedOutputContents;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct
{
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
public int field;

public const int VALUEA = 0;
public const int VALUEB = 1;
public const int VALUEC = 2;
}

public static partial class Methods
{
public const int VALUE1 = 0;
public const int VALUE2 = 1;
public const int VALUE3 = 2;
}
}
";
}
else
{
expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct
{
[NativeTypeName(""__AnonymousEnum_ClangUnsavedFile_L8_C5"")]
public uint field;

public const uint VALUEA = 0;
public const uint VALUEB = 1;
public const uint VALUEC = 2;
}

public static partial class Methods
{
public const uint VALUE1 = 0;
public const uint VALUE2 = 1;
public const uint VALUE3 = 2;
}
}
";
}

var diagnostics = new[] {
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L1_C1. Mapping values as constants in: Methods", "Line 1, Column 1 in ClangUnsavedFile.h"),
new Diagnostic(DiagnosticLevel.Info, "Found anonymous enum: __AnonymousEnum_ClangUnsavedFile_L8_C5. Mapping values as constants in: Methods", "Line 8, Column 5 in ClangUnsavedFile.h")
};
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: DefaultCClangCommandLineArgs, expectedDiagnostics: diagnostics, language: "c", languageStandard: DefaultCStandard);
}

[Test]
public Task StructTest()
{
Expand Down