-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to explicitly include an enum by name
- Loading branch information
1 parent
7c7f543
commit 609e5cf
Showing
13 changed files
with
245 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"inputFilePath": "./main.c", | ||
"userIncludeDirectories": [ | ||
"../../../production/ffi_helper/include" | ||
], | ||
"ignoredIncludeFiles": [ | ||
"../../../production/ffi_helper/include/ffi_helper.h" | ||
], | ||
"includedNames": [ | ||
"enum_implicit" | ||
], | ||
"targetPlatforms": { | ||
"windows": { | ||
"i686-pc-windows-msvc": {}, | ||
"x86_64-pc-windows-msvc": {}, | ||
"aarch64-pc-windows-msvc": {} | ||
}, | ||
"macos": { | ||
"i686-apple-darwin": {}, | ||
"aarch64-apple-darwin": {}, | ||
"x86_64-apple-darwin": {}, | ||
"aarch64-apple-ios": {} | ||
}, | ||
"linux": { | ||
"i686-unknown-linux-gnu": {}, | ||
"x86_64-unknown-linux-gnu": {}, | ||
"aarch64-unknown-linux-gnu": {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
#include "ffi_helper.h" | ||
|
||
enum enum_implicit { | ||
ENUM_IMPLICIT_VALUE0 = 0, | ||
ENUM_IMPLICIT_VALUE1 = 255 | ||
} enum_implicit; | ||
|
||
FFI_API_DECL int function_implicit_enum(int value) | ||
{ | ||
return ENUM_IMPLICIT_VALUE1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/cs/tests/c2ffi.Tests.EndToEnd.Extract/Functions/function_implicit_enum/Test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. | ||
|
||
#pragma warning disable CA1707 | ||
|
||
namespace c2ffi.Tests.EndToEnd.Extract.Functions.function_implicit_enum; | ||
|
||
public class Test : ExtractFfiTest | ||
{ | ||
private const string FunctionName = "function_implicit_enum"; | ||
|
||
[Fact] | ||
public void Function() | ||
{ | ||
var ffis = GetTargetPlatformFfis( | ||
$"src/c/tests/functions/{FunctionName}/config.json"); | ||
Assert.True(ffis.Length > 0); | ||
|
||
foreach (var ffi in ffis) | ||
{ | ||
FfiFunctionExists(ffi); | ||
FfiEnumExists(ffi); | ||
} | ||
} | ||
|
||
private void FfiFunctionExists(CTestFfiTargetPlatform ffi) | ||
{ | ||
var function = ffi.GetFunction(FunctionName); | ||
function.CallingConvention.Should().Be("cdecl"); | ||
|
||
var returnType = function.ReturnType; | ||
returnType.Name.Should().Be("int"); | ||
returnType.NodeKind.Should().Be("primitive"); | ||
returnType.SizeOf.Should().Be(4); | ||
returnType.AlignOf.Should().Be(4); | ||
returnType.InnerType.Should().BeNull(); | ||
|
||
function.Parameters.Should().HaveCount(1); | ||
var parameter = function.Parameters[0]; | ||
parameter.Name.Should().Be("value"); | ||
parameter.Type.Name.Should().Be("int"); | ||
parameter.Type.NodeKind.Should().Be("primitive"); | ||
parameter.Type.SizeOf.Should().Be(4); | ||
parameter.Type.AlignOf.Should().Be(4); | ||
} | ||
|
||
private void FfiEnumExists(CTestFfiTargetPlatform ffi) | ||
{ | ||
var @enum = ffi.GetEnum("enum_implicit"); | ||
@enum.Values.Should().HaveCount(2); | ||
@enum.SizeOf.Should().Be(4); | ||
} | ||
} |
Oops, something went wrong.