From fae6ceb70e1968b0208398efd927ee40eec7e6e1 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 30 Oct 2020 13:26:51 -0400 Subject: [PATCH] [appkit] Fix introspection tests for NSAccessibility on macOS 10.9 This reverts parts of https://github.com/xamarin/xamarin-macios/pull/9993 and add a special case to the test looking for duplicate attributes between members and the type. Why ? Introspection fails because `bgen` inline the `NSAccessibility` protocol (added in 10.10) into types that existed earlier. That's normally not a problem since the type-level attribute is there. However because of the 10.9 (type) vs 10.10 (protocol) issue that was moved into the manual bindings (so `bgen` does not know it) Even if built inside `COREBUILD` the issue exists since the protocol interface does not really exists at that point (by default), so it's the type (10.9) availability that is looked up. In retrospect we should have created a new type, like Swift did (a few years later), named `NSAccessibilityProtocol` for 10.10. Fix https://github.com/xamarin/xamarin-macios/issues/10009 --- src/AppKit/NSAccessibility.cs | 4 ++-- src/appkit.cs | 26 ++++++++++++++++++++++ tests/introspection/ApiAvailabilityTest.cs | 11 ++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/AppKit/NSAccessibility.cs b/src/AppKit/NSAccessibility.cs index 30d32b25132..5ca6531326b 100644 --- a/src/AppKit/NSAccessibility.cs +++ b/src/AppKit/NSAccessibility.cs @@ -69,13 +69,13 @@ public enum NSAccessibilityPriorityLevel : long High = 90 } -#if !COREBUILD [Mac (10,10)] // protocol added in 10.10 public partial interface INSAccessibility {} [Mac (10,9)] // but the field/notifications are in 10.9 public partial class NSAccessibility { +#if !COREBUILD [Mac (10,10)] [DllImport (Constants.AppKitLibrary)] static extern CGRect NSAccessibilityFrameInView (NSView parentView, CGRect frame); @@ -229,6 +229,6 @@ public static bool SetMayContainProtectedContent (bool flag) { return NSAccessibilitySetMayContainProtectedContent (flag); } - } #endif + } } diff --git a/src/appkit.cs b/src/appkit.cs index 8a8f2d4b461..b47c9be7646 100644 --- a/src/appkit.cs +++ b/src/appkit.cs @@ -23917,18 +23917,22 @@ interface NSAccessibility [NullAllowed, Export ("accessibilityVerticalUnitDescription")] string AccessibilityVerticalUnitDescription { get; set; } + [Mac (10,10)] [Abstract] [Export ("accessibilityLayoutPointForScreenPoint:")] CGPoint GetAccessibilityLayoutForScreen (CGPoint point); + [Mac (10,10)] [Abstract] [Export ("accessibilityLayoutSizeForScreenSize:")] CGSize GetAccessibilityLayoutForScreen (CGSize size); + [Mac (10,10)] [Abstract] [Export ("accessibilityScreenPointForLayoutPoint:")] CGPoint GetAccessibilityScreenForLayout (CGPoint point); + [Mac (10,10)] [Abstract] [Export ("accessibilityScreenSizeForLayoutSize:")] CGSize GetAccessibilityScreenForLayout (CGSize size); @@ -24123,6 +24127,7 @@ interface NSAccessibility [NullAllowed, Export ("accessibilityColumnHeaderUIElements", ArgumentSemantic.Copy)] NSObject[] AccessibilityColumnHeaderUIElements { get; set; } + [Mac (10,10)] [Abstract] [Export ("accessibilityCellForColumn:row:")] [return: NullAllowed] @@ -24178,41 +24183,50 @@ interface NSAccessibility [NullAllowed, Export ("accessibilitySelectedTextRanges", ArgumentSemantic.Copy)] NSValue[] AccessibilitySelectedTextRanges { get; set; } + [Mac (10,10)] [Abstract] [Export ("accessibilityAttributedStringForRange:")] [return: NullAllowed] NSAttributedString GetAccessibilityAttributedString (NSRange range); + [Mac (10,10)] [Abstract] [Export ("accessibilityRangeForLine:")] NSRange GetAccessibilityRangeForLine (nint line); + [Mac (10,10)] [Abstract] [Export ("accessibilityStringForRange:")] [return: NullAllowed] string GetAccessibilityString (NSRange range); + [Mac (10,10)] [Abstract] [Export ("accessibilityRangeForPosition:")] NSRange GetAccessibilityRange (CGPoint point); + [Mac (10,10)] [Abstract] [Export ("accessibilityRangeForIndex:")] NSRange GetAccessibilityRange (nint index); + [Mac (10,10)] [Abstract] [Export ("accessibilityFrameForRange:")] CGRect GetAccessibilityFrame (NSRange range); + [Mac (10,10)] [Abstract] [Export ("accessibilityRTFForRange:")] [return: NullAllowed] NSData GetAccessibilityRtf (NSRange range); + [Mac (10,10)] [Abstract] [Export ("accessibilityStyleRangeForIndex:")] NSRange GetAccessibilityStyleRange (nint index); + [Mac (10,10)] [Abstract] [Export ("accessibilityLineForIndex:")] nint GetAccessibilityLine (nint index); @@ -24277,50 +24291,62 @@ interface NSAccessibility [Export ("accessibilityMinimized")] bool AccessibilityMinimized { [Bind ("isAccessibilityMinimized")] get; set; } + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformCancel")] bool AccessibilityPerformCancel (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformConfirm")] bool AccessibilityPerformConfirm (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformDecrement")] bool AccessibilityPerformDecrement (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformDelete")] bool AccessibilityPerformDelete (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformIncrement")] bool AccessibilityPerformIncrement (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformPick")] bool AccessibilityPerformPick (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformPress")] bool AccessibilityPerformPress (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformRaise")] bool AccessibilityPerformRaise (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformShowAlternateUI")] bool AccessibilityPerformShowAlternateUI (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformShowDefaultUI")] bool AccessibilityPerformShowDefaultUI (); + [Mac (10, 10)] [Abstract] [Export ("accessibilityPerformShowMenu")] bool AccessibilityPerformShowMenu (); + [Mac (10,10)] [Abstract] [Export ("isAccessibilitySelectorAllowed:")] bool IsAccessibilitySelectorAllowed (Selector selector); diff --git a/tests/introspection/ApiAvailabilityTest.cs b/tests/introspection/ApiAvailabilityTest.cs index ce01dc854ad..7fca0025a9c 100644 --- a/tests/introspection/ApiAvailabilityTest.cs +++ b/tests/introspection/ApiAvailabilityTest.cs @@ -141,7 +141,16 @@ public void Introduced () // Duplicate checks, e.g. same attribute on member and type (extranous metadata) if (ma.Version == ta.Version) { - AddErrorLine ($"[FAIL] {ma.Version} ({m}) == {ta.Version} ({t})"); + switch (t.FullName) { + case "AppKit.INSAccessibility": + // special case for [I]NSAccessibility type (10.9) / protocol (10.10) mix up + // https://github.com/xamarin/xamarin-macios/issues/10009 + // better some dupes than being inaccurate when protocol members are inlined + break; + default: + AddErrorLine ($"[FAIL] {ma.Version} ({m}) == {ta.Version} ({t})"); + break; + } } // Consistency checks, e.g. member lower than type // note: that's valid in some cases, like a new base type being introduced