[Tests] Fix cecil tests. (#12853)
- Added the marshaling attr and a test to ensure it is ok. - Fix the cecil MarshalAs test to not skip over types when checking. This revealed multiple tests failures that needed fixing. fixes: https://github.com/xamarin/maccore/issues/2519 Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
This commit is contained in:
Родитель
5cd7c96dcf
Коммит
339936f457
|
@ -219,6 +219,7 @@ namespace CoreFoundation {
|
|||
}
|
||||
|
||||
[DllImport (Constants.CoreFoundationLibrary, CharSet=CharSet.Unicode)]
|
||||
[return: MarshalAs (UnmanagedType.U2)]
|
||||
extern static char CFStringGetCharacterAtIndex (IntPtr handle, nint p);
|
||||
|
||||
public char this [nint p] {
|
||||
|
|
|
@ -255,7 +255,7 @@ namespace Foundation {
|
|||
extern static void RegisterToggleRef (NSObject obj, IntPtr handle, bool isCustomType);
|
||||
|
||||
[DllImport ("__Internal")]
|
||||
static extern void xamarin_release_managed_ref (IntPtr handle, bool user_type);
|
||||
static extern void xamarin_release_managed_ref (IntPtr handle, [MarshalAs (UnmanagedType.I1)] bool user_type);
|
||||
|
||||
#if NET
|
||||
static void RegisterToggleRefMonoVM (NSObject obj, IntPtr handle, bool isCustomType)
|
||||
|
@ -338,6 +338,7 @@ namespace Foundation {
|
|||
}
|
||||
|
||||
[DllImport ("__Internal")]
|
||||
[return: MarshalAs (UnmanagedType.I1)]
|
||||
static extern bool xamarin_set_gchandle_with_flags_safe (IntPtr handle, IntPtr gchandle, XamarinGCHandleFlags flags);
|
||||
|
||||
void CreateManagedRef (bool retain)
|
||||
|
|
|
@ -147,6 +147,7 @@ namespace GLKit {
|
|||
public struct GLKVertexAttributeParameters {
|
||||
public uint Type;
|
||||
public uint Size;
|
||||
[MarshalAs (UnmanagedType.I1)]
|
||||
public bool Normalized;
|
||||
|
||||
#if !COREBUILD
|
||||
|
|
|
@ -154,6 +154,7 @@ namespace GameController {
|
|||
[SupportedOSPlatform ("tvos12.2")]
|
||||
[SupportedOSPlatform ("macos10.14.4")]
|
||||
#endif
|
||||
[MarshalAs (UnmanagedType.I1)]
|
||||
public bool SupportsClickableThumbsticks;
|
||||
|
||||
#if !NET
|
||||
|
@ -163,6 +164,7 @@ namespace GameController {
|
|||
[SupportedOSPlatform ("tvos12.2")]
|
||||
[SupportedOSPlatform ("macos10.14.4")]
|
||||
#endif
|
||||
[MarshalAs (UnmanagedType.I1)]
|
||||
bool LeftThumbstickButton;
|
||||
|
||||
#if !NET
|
||||
|
@ -172,6 +174,7 @@ namespace GameController {
|
|||
[SupportedOSPlatform ("tvos12.2")]
|
||||
[SupportedOSPlatform ("macos10.14.4")]
|
||||
#endif
|
||||
[MarshalAs (UnmanagedType.I1)]
|
||||
bool RightThumbstickButton;
|
||||
|
||||
[DllImport (Constants.GameControllerLibrary)]
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace HealthKit {
|
|||
{
|
||||
|
||||
[DllImport (Constants.HealthKitLibrary)]
|
||||
[return: MarshalAs (UnmanagedType.I1)]
|
||||
static extern bool HKAppleWalkingSteadinessClassificationForQuantity (HKQuantityRef value, out nint classificationOut, out NSErrorRef errorOut);
|
||||
|
||||
public static bool TryGetClassification (HKQuantity value, out HKAppleWalkingSteadinessClassification? classification, out NSError? error)
|
||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
|
@ -26,6 +27,7 @@ namespace Cecil.Tests {
|
|||
var checkedTypes = new List<TypeReference> ();
|
||||
foreach (var m in Helper.FilterMethods (assembly!, (m) => m.HasPInvokeInfo)) {
|
||||
failures = null;
|
||||
checkedTypes.Clear ();
|
||||
if (!CheckMarshalAs (checkedTypes, m, ref failures)) {
|
||||
failedMethods.Add ($"Found {failures!.Count} issues with {m.FullName}:\n\t{string.Join ("\n\t", failures)}");
|
||||
}
|
||||
|
@ -86,6 +88,9 @@ namespace Cecil.Tests {
|
|||
if (type.IsEnum)
|
||||
return true;
|
||||
|
||||
if ((type.Attributes & TypeAttributes.ExplicitLayout) == TypeAttributes.ExplicitLayout)
|
||||
return true;
|
||||
|
||||
foreach (var field in type.Fields) {
|
||||
if (field.IsStatic)
|
||||
continue;
|
||||
|
@ -100,7 +105,7 @@ namespace Cecil.Tests {
|
|||
|
||||
static string GetTypeName (TypeReference type)
|
||||
{
|
||||
return type.Name.ToLower ();
|
||||
return type.Resolve ().FullName;
|
||||
}
|
||||
|
||||
static bool IsDelegate (TypeReference tr)
|
||||
|
|
|
@ -31,5 +31,16 @@ namespace MonoTouchFixtures.CoreFoundation {
|
|||
{
|
||||
Assert.Throws<ArgumentNullException> (delegate { new CFString (null); }, "null");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Index ()
|
||||
{
|
||||
var str = "Ab🤔日ㅁ名";
|
||||
using var nativeStr = new CFString (str);
|
||||
var array = str.ToCharArray ();
|
||||
for (int i = 0; i < array.Length; i++) {
|
||||
Assert.AreEqual (str[i], nativeStr[i], $"{str[i]} != {nativeStr[i]}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче