diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs index 9f08dc19..ce250a46 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs @@ -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() {