-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rgen] Generate casting expressions for native enums.
- Loading branch information
1 parent
fba23cf
commit 7a347a9
Showing
6 changed files
with
104 additions
and
7 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
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
65 changes: 65 additions & 0 deletions
65
tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryObjCRuntimeTests.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,65 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Macios.Generator.DataModel; | ||
using Xunit; | ||
using static Microsoft.Macios.Generator.Emitters.BindingSyntaxFactory; | ||
using static Microsoft.Macios.Generator.Tests.TestDataFactory; | ||
|
||
namespace Microsoft.Macios.Generator.Tests.Emitters; | ||
|
||
public class BindingSyntaxFactoryObjCRuntimeTests { | ||
|
||
class TestDataCodeChangesFromClassDeclaration : IEnumerable<object []> { | ||
public IEnumerator<object []> GetEnumerator () | ||
{ | ||
|
||
// not enum parameter | ||
var boolParam = new Parameter ( | ||
position: 0, | ||
type: ReturnTypeForBool (), | ||
name: "myParam"); | ||
yield return [boolParam, null!]; | ||
|
||
// not smart enum parameter | ||
var enumParam = new Parameter ( | ||
position: 0, | ||
type: ReturnTypeForEnum ("MyEnum", isNativeEnum: false), | ||
name: "myParam"); | ||
|
||
yield return [enumParam, null!]; | ||
|
||
// int64 | ||
var byteEnum = new Parameter ( | ||
position: 0, | ||
type: ReturnTypeForEnum ("MyEnum", isNativeEnum: true, underlyingType: SpecialType.System_Int64), | ||
name: "myParam"); | ||
yield return [byteEnum, "(IntPtr) (long) myParam"]; | ||
|
||
// uint64 | ||
var int64Enum = new Parameter ( | ||
position: 0, | ||
type: ReturnTypeForEnum ("MyEnum", isNativeEnum: true, underlyingType: SpecialType.System_UInt64), | ||
name: "myParam"); | ||
yield return [int64Enum, "(UIntPtr) (ulong) myParam"]; | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TestDataCodeChangesFromClassDeclaration))] | ||
void CastToNativeTests (Parameter parameter, string? expectedCast) | ||
{ | ||
var expression = CastToNative (parameter); | ||
if (expectedCast is null) { | ||
Assert.Null (expression); | ||
} else { | ||
Assert.NotNull (expression); | ||
Assert.Equal (expectedCast, expression?.ToString ()); | ||
} | ||
} | ||
} |
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