diff --git a/src/c/tests/_container_library/main.c b/src/c/tests/_container_library/main.c index 5c5f4f42..ff25e9d8 100644 --- a/src/c/tests/_container_library/main.c +++ b/src/c/tests/_container_library/main.c @@ -1,6 +1,6 @@ -#pragma once #include #include "ffi_helper.h" #include "../enums/_index.h" +#include "../macro_objects/_index.h" #include "../function_pointers/_index.h" diff --git a/src/c/tests/enums/EnumForceUInt32.h b/src/c/tests/enums/EnumForceUInt32.h index f0f58d24..d56e9576 100644 --- a/src/c/tests/enums/EnumForceUInt32.h +++ b/src/c/tests/enums/EnumForceUInt32.h @@ -12,7 +12,7 @@ typedef enum EnumForceUInt32 { FFI_API_DECL void EnumForceUInt32__print_EnumForceUInt32(const EnumForceUInt32 e) { - printf("%d\n", e); // Print used for testing + printf("%lu\n", e); // Print used for testing } FFI_API_DECL EnumForceUInt32 EnumForceUInt32__return_EnumForceUInt32(const EnumForceUInt32 e) diff --git a/src/c/tests/macro_objects/MacroObjectIntValue.h b/src/c/tests/macro_objects/MacroObjectIntValue.h new file mode 100644 index 00000000..9c1963f8 --- /dev/null +++ b/src/c/tests/macro_objects/MacroObjectIntValue.h @@ -0,0 +1,8 @@ +#pragma once + +#define MACRO_OBJECT_INT_VALUE 42; + +FFI_API_DECL int MacroObjectInt__return_int() +{ + return MACRO_OBJECT_INT_VALUE; +} \ No newline at end of file diff --git a/src/c/tests/macro_objects/_index.h b/src/c/tests/macro_objects/_index.h new file mode 100644 index 00000000..af9edbf1 --- /dev/null +++ b/src/c/tests/macro_objects/_index.h @@ -0,0 +1 @@ +#include "MacroObjectIntValue.h" \ No newline at end of file diff --git a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs index 73669327..2031102a 100644 --- a/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs +++ b/src/cs/production/C2CS.Tool/Features/BuildCLibrary/Input/Unsanitized/BuildCLibraryOptions.cs @@ -13,25 +13,25 @@ namespace C2CS.Features.BuildCLibrary.Input.Unsanitized; public class BuildCLibraryOptions : ToolUnsanitizedInput { /// - /// The directory path to the CMakeLists.txt file. + /// Gets or sets the directory path to the CMakeLists.txt file. /// [JsonPropertyName("cMakeDirectoryPath")] public string? CMakeDirectoryPath { get; set; } /// - /// The directory path where to place the built C shared library (`.dll`/`.dylib`/`.so`). + /// Gets or sets the directory path where to place the built C shared library (`.dll`/`.dylib`/`.so`). /// [JsonPropertyName("outputDirectoryPath")] public string? OutputDirectoryPath { get; set; } /// - /// Additional CMake arguments when generating build files. + /// Gets or sets additional CMake arguments when generating build files. /// [JsonPropertyName("cMakeArguments")] public ImmutableArray? CMakeArguments { get; set; } /// - /// Determines whether to delete CMake build files after they are no longer required. + /// Gets or sets whether to delete CMake build files after they are no longer required. /// /// /// @@ -43,7 +43,7 @@ public class BuildCLibraryOptions : ToolUnsanitizedInput public bool? IsEnabledDeleteBuildFiles { get; set; } /// - /// Determines whether to build the C shared library with debug symbols. + /// Gets or sets whether to build the C shared library with debug symbols. /// /// /// diff --git a/src/cs/tests/C2CS.Tests/Data/Values/MacroObjects/MacroObjectIntValue.json b/src/cs/tests/C2CS.Tests/Data/Values/MacroObjects/MacroObjectIntValue.json new file mode 100644 index 00000000..68d94880 --- /dev/null +++ b/src/cs/tests/C2CS.Tests/Data/Values/MacroObjects/MacroObjectIntValue.json @@ -0,0 +1,5 @@ +{ + "name": "MACRO_OBJECT_INT_VALUE", + "type_name": "int", + "value": "42" +} \ No newline at end of file diff --git a/src/cs/tests/C2CS.Tests/Foundation/TestBase.cs b/src/cs/tests/C2CS.Tests/Foundation/TestBase.cs index dbc62ab8..95e7bfc3 100644 --- a/src/cs/tests/C2CS.Tests/Foundation/TestBase.cs +++ b/src/cs/tests/C2CS.Tests/Foundation/TestBase.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. using System; +using System.Globalization; using System.IO; using System.IO.Abstractions; using System.Text.Json; @@ -28,7 +29,8 @@ protected TestBase(string baseDataFilesDirectory, bool regenerateDataFiles = fal Services = TestHost.Services; _fileSystem = Services.GetService()!; - _sourceDirectoryPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../src/cs/tests/C2CS.Tests")); + + _sourceDirectoryPath = Path.Combine(GetGitDirectory(), "src/cs/tests/C2CS.Tests"); _regenerateDataFiles = regenerateDataFiles; _jsonSerializerOptions = new JsonSerializerOptions @@ -44,8 +46,18 @@ protected TestBase(string baseDataFilesDirectory, bool regenerateDataFiles = fal protected void AssertValue(string name, T value, string directory) { + var nameNormalized = name; + if (name.Contains('_', StringComparison.InvariantCulture)) + { +#pragma warning disable CA1308 + var nameAsWords = name.ToLowerInvariant().Replace("_", " ", StringComparison.InvariantCulture); +#pragma warning restore CA1308 + var nameAsWordsTitleCased = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(nameAsWords); + nameNormalized = nameAsWordsTitleCased.Replace(" ", string.Empty, StringComparison.InvariantCulture); + } + var relativeJsonFilePath = - _fileSystem.Path.Combine(_baseDataFilesDirectory, directory, $"{name}.json"); + _fileSystem.Path.Combine(_baseDataFilesDirectory, directory, $"{nameNormalized}.json"); string jsonFilePath; if (_regenerateDataFiles) { @@ -104,4 +116,23 @@ private void WriteValueToFile(string filePath, T value) textWriter.Close(); fileStream.Close(); } + + private static string GetGitDirectory() + { + Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../src/cs/tests/C2CS.Tests")); + + var currentDirectory = AppContext.BaseDirectory; + while (!string.IsNullOrEmpty(currentDirectory) && Directory.Exists(currentDirectory)) + { + var files = Directory.GetFiles(currentDirectory, "*.gitignore"); + if (files.Length == 1) + { + return currentDirectory; + } + + currentDirectory = Directory.GetParent(currentDirectory)?.FullName ?? string.Empty; + } + + throw new InvalidOperationException("Could not find Git root directory"); + } } diff --git a/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs b/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs index 0a17ee5c..74c761ff 100644 --- a/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs +++ b/src/cs/tests/C2CS.Tests/Generated/AssemblyAttributes.gen.cs @@ -1,7 +1,7 @@ // To disable generating this file set `isEnabledGenerateAssemblyAttributes` to `false` in the config file for generating C# code. // -// This code was generated by the following tool on 2023-07-23 05:51:56 GMT-04:00: -// https://github.com/bottlenoselabs/c2cs (v2.11.1.99) +// This code was generated by the following tool on 2023-11-15 18:22:18 GMT-05:00: +// https://github.com/bottlenoselabs/c2cs (v2.11.1.100) // // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. // diff --git a/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs b/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs index 8ed819d3..9f9d7e13 100644 --- a/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs +++ b/src/cs/tests/C2CS.Tests/Generated/Runtime.gen.cs @@ -2,8 +2,8 @@ // To disable generating this file set `isEnabledGeneratingRuntimeCode` to `false` in the config file for generating C# code. // -// This code was generated by the following tool on 2023-07-23 05:51:56 GMT-04:00: -// https://github.com/bottlenoselabs/c2cs (v2.11.1.99) +// This code was generated by the following tool on 2023-11-15 18:22:18 GMT-05:00: +// https://github.com/bottlenoselabs/c2cs (v2.11.1.100) // // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. // diff --git a/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs b/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs index 3b75862f..61e4be5a 100644 --- a/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs +++ b/src/cs/tests/C2CS.Tests/Generated/_container_library.gen.cs @@ -1,7 +1,7 @@ // -// This code was generated by the following tool on 2023-07-23 05:51:56 GMT-04:00: -// https://github.com/bottlenoselabs/c2cs (v2.11.1.99) +// This code was generated by the following tool on 2023-11-15 18:22:18 GMT-05:00: +// https://github.com/bottlenoselabs/c2cs (v2.11.1.100) // // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. // @@ -91,6 +91,10 @@ public static unsafe partial class _container_library [DllImport(LibraryName, EntryPoint = "EnumForceUInt8__return_EnumForceUInt8", CallingConvention = CallingConvention.Cdecl)] public static extern EnumForceUInt8 EnumForceUInt8__return_EnumForceUInt8(EnumForceUInt8 e); + [CNode(Kind = "Function")] + [DllImport(LibraryName, EntryPoint = "MacroObjectInt__return_int", CallingConvention = CallingConvention.Cdecl)] + public static extern int MacroObjectInt__return_int(); + [CNode(Kind = "Function")] [DllImport(LibraryName, EntryPoint = "TypeDef_FunctionPointer_ReturnVoid_ArgsVoid__invoke", CallingConvention = CallingConvention.Cdecl)] public static extern void TypeDef_FunctionPointer_ReturnVoid_ArgsVoid__invoke(TypeDef_FunctionPointer_ReturnVoid_ArgsVoid functionPointer); @@ -213,5 +217,8 @@ public struct TypeDef_FunctionPointer_ReturnVoid_ArgsVoid public static implicit operator TypeDef_FunctionPointer_ReturnVoid_ArgsVoid(FnPtr_Void data) => new() { Data = data }; } + [CNode(Kind = "MacroObject")] + public const int MACRO_OBJECT_INT_VALUE = 42; + #endregion } diff --git a/src/cs/tests/C2CS.Tests/TestCSharpCode.cs b/src/cs/tests/C2CS.Tests/TestCSharpCode.cs index 306a9c4d..f8ab6d80 100644 --- a/src/cs/tests/C2CS.Tests/TestCSharpCode.cs +++ b/src/cs/tests/C2CS.Tests/TestCSharpCode.cs @@ -11,7 +11,7 @@ namespace C2CS.Tests; [PublicAPI] public sealed class TestCSharpCode : TestBase { - public static TheoryData Enums() => new() + public static TheoryData EnumNames() => new() { "EnumForceSInt8", "EnumForceSInt16", @@ -25,13 +25,26 @@ public sealed class TestCSharpCode : TestBase }; [Theory] - [MemberData(nameof(Enums))] + [MemberData(nameof(EnumNames))] public void Enum(string name) { var value = _fixture.GetEnum(name); AssertValue(name, value, "Enums"); } + public static TheoryData MacroObjectNames() => new() + { + "MACRO_OBJECT_INT_VALUE" + }; + + [Theory] + [MemberData(nameof(MacroObjectNames))] + public void MacroObject(string name) + { + var value = _fixture.GetMacroObject(name); + AssertValue(name, value, "MacroObjects"); + } + [Fact] public void Compiles() { @@ -41,7 +54,7 @@ public void Compiles() private readonly TestFixtureCSharpCode _fixture; public TestCSharpCode() - : base("Data/Values", true) + : base("Data/Values", regenerateDataFiles: true) { var services = TestHost.Services; _fixture = services.GetService()!;