-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dev/mandel/transformer-thread-safe-data
- Loading branch information
Showing
16 changed files
with
158 additions
and
15 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
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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
// 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 TestDataCastToNativeTests : 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 (TestDataCastToNativeTests))] | ||
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 ()); | ||
} | ||
} | ||
|
||
[Fact] | ||
void CastToByteTests () | ||
{ | ||
var boolParameter = new Parameter (0, ReturnTypeForBool (), "myParameter"); | ||
var conditionalExpr = CastToByte (boolParameter); | ||
Assert.NotNull (conditionalExpr); | ||
Assert.Equal ("myParameter ? (byte) 1 : (byte) 0", conditionalExpr.ToString ()); | ||
|
||
var intParameter = new Parameter (1, ReturnTypeForInt (), "myParameter"); | ||
conditionalExpr = CastToByte (intParameter); | ||
Assert.Null (conditionalExpr); | ||
} | ||
} |
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