diff --git a/src/generator-enums.cs b/src/generator-enums.cs index 0ab9374b7007..8768804a58fa 100644 --- a/src/generator-enums.cs +++ b/src/generator-enums.cs @@ -95,7 +95,7 @@ void GenerateEnum (Type type) // skip value__ field if (f.IsSpecialName) continue; - PrintPlatformAttributes (f, is_enum: true); + PrintPlatformAttributes (f); PrintObsoleteAttributes (f); print ("{0} = {1},", f.Name, f.GetRawConstantValue ()); var fa = AttributeManager.GetCustomAttribute (f); diff --git a/src/generator.cs b/src/generator.cs index a820c7423b71..30a46e518ede 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -3677,7 +3677,7 @@ List GetAllParentAttributes (MemberInfo context) } } - AvailabilityBaseAttribute [] GetPlatformAttributesToPrint (MemberInfo mi, Type type, MemberInfo inlinedType) + AvailabilityBaseAttribute [] GetPlatformAttributesToPrint (MemberInfo mi, MemberInfo context, MemberInfo inlinedType) { // Attributes are directly on the member List memberAvailability = AttributeManager.GetCustomAttributes (mi).ToList (); @@ -3685,7 +3685,8 @@ AvailabilityBaseAttribute [] GetPlatformAttributesToPrint (MemberInfo mi, Type t // Due to differences between Xamarin and NET6 availability attributes, we have to synthesize many duplicates for NET6 // See https://github.com/xamarin/xamarin-macios/issues/10170 for details #if NET - MemberInfo context = type ?? FindContainingContext (mi); + if (context is null) + context = FindContainingContext (mi); // Attributes on the _target_ context, the class itself or the target of the protocol inlining List parentContextAvailability = GetAllParentAttributes (context); // (Optional) Attributes from the inlined protocol type itself @@ -3761,7 +3762,7 @@ AvailabilityBaseAttribute [] GetPlatformAttributesToPrint (MemberInfo mi, Type t return memberAvailability.ToArray (); } - public bool PrintPlatformAttributes (MemberInfo mi, Type type = null, bool is_enum = false) + public bool PrintPlatformAttributes (MemberInfo mi, Type inlinedType = null) { bool printed = false; if (mi == null) @@ -3769,8 +3770,8 @@ public bool PrintPlatformAttributes (MemberInfo mi, Type type = null, bool is_en AvailabilityBaseAttribute [] type_ca = null; - foreach (var availability in GetPlatformAttributesToPrint (mi, is_enum ? mi.DeclaringType : type, is_enum ? null : mi.DeclaringType)) { - var t = type ?? (mi as TypeInfo) ?? mi.DeclaringType; + foreach (var availability in GetPlatformAttributesToPrint (mi, null, inlinedType)) { + var t = inlinedType ?? (mi as TypeInfo) ?? mi.DeclaringType; if (type_ca == null) { if (t != null) type_ca = AttributeManager.GetCustomAttributes (t); @@ -5289,7 +5290,7 @@ void PrintPropertyAttributes (PropertyInfo pi, Type type, bool skipTypeInjection PrintPlatformAttributes (pi.DeclaringType, type); } } else { - PrintPlatformAttributes (pi, type); + PrintPlatformAttributes (pi); } foreach (var sa in AttributeManager.GetCustomAttributes (pi)) diff --git a/tests/cecil-tests/ApiAvailabilityTest.cs b/tests/cecil-tests/ApiAvailabilityTest.cs index 9802be083dec..747fb3d04c03 100644 --- a/tests/cecil-tests/ApiAvailabilityTest.cs +++ b/tests/cecil-tests/ApiAvailabilityTest.cs @@ -89,14 +89,7 @@ public void FindMissingObsoleteAttributes () "AppKit.NSCursor.IsSetOnMouseExited()", "AppKit.NSCursor.SetOnMouseEntered(System.Boolean)", "AppKit.NSCursor.SetOnMouseExited(System.Boolean)", - "AppKit.NSImage.get_Flipped()", - "AppKit.NSImage.get_ImageFileTypes()", "AppKit.NSImage.ImageUnfilteredFileTypes()", - "AppKit.NSImage.set_Flipped(System.Boolean)", - "AppKit.NSToolbarItem.get_MaxSize()", - "AppKit.NSToolbarItem.get_MinSize()", - "AppKit.NSToolbarItem.set_MaxSize(CoreGraphics.CGSize)", - "AppKit.NSToolbarItem.set_MinSize(CoreGraphics.CGSize)", "AudioToolbox.AudioFormatFlags AudioToolbox.AudioStreamBasicDescription::AudioFormatFlagsAudioUnitCanonical", "AudioToolbox.AudioFormatProperty AudioToolbox.AudioFormatProperty::HardwareCodecCapabilities", "AudioToolbox.AudioSessionActiveFlags", @@ -110,23 +103,8 @@ public void FindMissingObsoleteAttributes () "AudioUnit.AUGraph", "AudioUnit.SpatialMixerRenderingFlags AudioUnit.SpatialMixerRenderingFlags::DistanceAttenuation", "AVFoundation.AVAssetDownloadUrlSession.GetAssetDownloadTask(AVFoundation.AVUrlAsset, Foundation.NSUrl, Foundation.NSDictionary)", - "AVFoundation.AVCaptureConnection.get_SupportsVideoMaxFrameDuration()", - "AVFoundation.AVCaptureConnection.get_SupportsVideoMinFrameDuration()", - "AVFoundation.AVCaptureConnection.get_VideoMaxFrameDuration()", - "AVFoundation.AVCaptureConnection.get_VideoMinFrameDuration()", - "AVFoundation.AVCaptureConnection.set_VideoMaxFrameDuration(CoreMedia.CMTime)", - "AVFoundation.AVCaptureConnection.set_VideoMinFrameDuration(CoreMedia.CMTime)", - "AVFoundation.AVCaptureDevice.get_FlashMode()", "AVFoundation.AVCaptureDevice.IsFlashModeSupported(AVFoundation.AVCaptureFlashMode)", - "AVFoundation.AVCaptureDevice.set_FlashMode(AVFoundation.AVCaptureFlashMode)", "AVFoundation.AVCaptureFlashMode AVFoundation.AVCaptureDevice::FlashMode()", - "AVFoundation.AVCapturePhotoSettings.get_AutoDualCameraFusionEnabled()", - "AVFoundation.AVCapturePhotoSettings.get_DualCameraDualPhotoDeliveryEnabled()", - "AVFoundation.AVCapturePhotoSettings.set_AutoDualCameraFusionEnabled(System.Boolean)", - "AVFoundation.AVCapturePhotoSettings.set_DualCameraDualPhotoDeliveryEnabled(System.Boolean)", - "AVFoundation.AVCaptureResolvedPhotoSettings.get_DualCameraFusionEnabled()", - "AVFoundation.AVCaptureVideoDataOutput.get_MinFrameDuration()", - "AVFoundation.AVCaptureVideoDataOutput.set_MinFrameDuration(CoreMedia.CMTime)", "CFNetwork.CFHTTPStream", "CoreBluetooth.CBCentralManagerState", "CoreBluetooth.CBPeripheralManagerState", @@ -190,34 +168,23 @@ public void FindMissingObsoleteAttributes () "GameController.GCMicroGamepadSnapshotData.ToNSData()", "GameController.GCMicroGamepadSnapShotDataV100", "GameKit.GKVoiceChatService", - "HealthKit.HKActivitySummary.get_AppleExerciseTimeGoal()", - "HealthKit.HKActivitySummary.get_AppleStandHoursGoal()", - "HealthKit.HKActivitySummary.set_AppleExerciseTimeGoal(HealthKit.HKQuantity)", - "HealthKit.HKActivitySummary.set_AppleStandHoursGoal(HealthKit.HKQuantity)", "HealthKit.HKAnchoredObjectQuery..ctor(HealthKit.HKSampleType, Foundation.NSPredicate, System.UIntPtr, System.UIntPtr, HealthKit.HKAnchoredObjectResultHandler)", "HealthKit.HKCategoryValueOvulationTestResult HealthKit.HKCategoryValueOvulationTestResult::Positive", "HealthKit.HKCumulativeQuantitySeriesSample", - "HealthKit.HKCumulativeQuantitySeriesSample.get_Sum()", "HealthKit.HKHealthStore.GetDateOfBirth(out Foundation.NSError&)", "HealthKit.HKHealthStore.SplitTotalEnergy(HealthKit.HKQuantity, Foundation.NSDate, Foundation.NSDate, System.Action`3)", - "HealthKit.HKObject.get_Source()", "HealthKit.HKQuantity HealthKit.HKActivitySummary::AppleExerciseTimeGoal()", "HealthKit.HKQuantity HealthKit.HKActivitySummary::AppleStandHoursGoal()", - "HealthKit.HKQuantity HealthKit.HKCumulativeQuantitySeriesSample::Sum()", "HealthKit.HKQuantityAggregationStyle HealthKit.HKQuantityAggregationStyle::Discrete", "HealthKit.HKQuantitySeriesSampleQuery..ctor(HealthKit.HKQuantitySample, HealthKit.HKQuantitySeriesSampleQueryQuantityDelegate)", - "HealthKit.HKQuery.get_SampleType()", "HealthKit.HKSampleType HealthKit.HKQuery::SampleType()", "HealthKit.HKSource HealthKit.HKObject::Source()", "HealthKit.HKUnit HealthKit.HKUnit::Calorie()", - "HealthKit.HKUnit.get_Calorie()", - "HealthKit.HKVerifiableClinicalRecord.get_JwsRepresentation()", "HealthKit.HKWorkoutActivityType HealthKit.HKWorkoutActivityType::DanceInspiredTraining", "HealthKit.HKWorkoutActivityType HealthKit.HKWorkoutActivityType::MixedMetabolicCardioTraining", "HealthKit.HKWorkoutEvent.Create(HealthKit.HKWorkoutEventType, Foundation.NSDate)", "HealthKit.HKWorkoutEvent.Create(HealthKit.HKWorkoutEventType, Foundation.NSDate, Foundation.NSDictionary)", "HealthKit.HKWorkoutEvent.Create(HealthKit.HKWorkoutEventType, Foundation.NSDate, HealthKit.HKMetadata)", - "HealthKit.HKWorkoutEvent.get_Date()", "HomeKit.HMEventTrigger.CreatePredicateForEvaluatingTriggerOccurringAfterSignificantEvent(HomeKit.HMSignificantEvent, Foundation.NSDateComponents)", "HomeKit.HMEventTrigger.CreatePredicateForEvaluatingTriggerOccurringBeforeSignificantEvent(HomeKit.HMSignificantEvent, Foundation.NSDateComponents)", "Intents.INCallRecord..ctor(System.String, Foundation.NSDate, Intents.INPerson, Intents.INCallRecordType, Intents.INCallCapability, System.Nullable`1, System.Nullable`1, System.Nullable`1)", @@ -228,7 +195,6 @@ public void FindMissingObsoleteAttributes () "Intents.INSetProfileInCarIntent..ctor(Foundation.NSNumber, System.String, System.Nullable`1)", "Intents.INSetSeatSettingsInCarIntent..ctor(System.Nullable`1, System.Nullable`1, System.Nullable`1, Intents.INCarSeat, Foundation.NSNumber, Intents.INRelativeSetting)", "Intents.INStartCallIntent..ctor(Intents.INCallAudioRoute, Intents.INCallDestinationType, Intents.INPerson[], Intents.INCallRecordType, Intents.INCallCapability)", - "Intents.INStartCallIntent.get_RecordTypeForRedialing()", "MapKit.MKOverlayView", "MapKit.MKPinAnnotationColor", "MediaPlayer.MPMoviePlayerController", @@ -237,11 +203,7 @@ public void FindMissingObsoleteAttributes () "MediaPlayer.MPVolumeSettings.AlertIsVisible()", "MediaPlayer.MPVolumeSettings.AlertShow()", "Metal.IMTLResource Metal.MTLTextureWrapper::RootResource()", - "Metal.MTLTextureWrapper.get_RootResource()", - "MetalPerformanceShaders.MPSCnnConvolution.get_Neuron()", - "MetalPerformanceShaders.MPSCnnConvolutionDescriptor.get_Neuron()", "MetalPerformanceShaders.MPSCnnConvolutionDescriptor.GetConvolutionDescriptor(System.UIntPtr, System.UIntPtr, System.UIntPtr, System.UIntPtr, MetalPerformanceShaders.MPSCnnNeuron)", - "MetalPerformanceShaders.MPSCnnConvolutionDescriptor.set_Neuron(MetalPerformanceShaders.MPSCnnNeuron)", "MetalPerformanceShaders.MPSCnnFullyConnected..ctor(Metal.IMTLDevice, MetalPerformanceShaders.MPSCnnConvolutionDescriptor, System.Single[], System.Single[], MetalPerformanceShaders.MPSCnnConvolutionFlags)", "MetalPerformanceShaders.MPSCnnNeuron MetalPerformanceShaders.MPSCnnConvolution::Neuron()", "MetalPerformanceShaders.MPSCnnNeuron MetalPerformanceShaders.MPSCnnConvolutionDescriptor::Neuron()", @@ -253,15 +215,8 @@ public void FindMissingObsoleteAttributes () "MobileCoreServices.UTType.get_UniversalSceneDescriptionMobile()", "MobileCoreServices.UTType.IsDeclared(System.String)", "MobileCoreServices.UTType.IsDynamic(System.String)", - "NetworkExtension.NEFilterProviderConfiguration.get_FilterBrowsers()", - "NetworkExtension.NEFilterProviderConfiguration.set_FilterBrowsers(System.Boolean)", - "PassKit.PKAddShareablePassConfiguration.get_ProvisioningPolicyIdentifier()", "PassKit.PKShareablePassMetadata..ctor(System.String, System.String, CoreGraphics.CGImage, System.String, System.String, System.String, System.String, System.String, System.Boolean)", "PassKit.PKShareablePassMetadata..ctor(System.String, System.String, System.String, CoreGraphics.CGImage, System.String, System.String)", - "PassKit.PKShareablePassMetadata.get_LocalizedDescription()", - "PassKit.PKShareablePassMetadata.get_OwnerDisplayName()", - "PassKit.PKShareablePassMetadata.get_PassThumbnailImage()", - "PassKit.PKShareablePassMetadata.get_TemplateIdentifier()", "Security.Authorization.ExecuteWithPrivileges(System.String, Security.AuthorizationFlags, System.String[])", "Security.SecAccessible Security.SecAccessible::Always", "Security.SecAccessible Security.SecAccessible::AlwaysThisDeviceOnly", @@ -290,18 +245,12 @@ public void FindMissingObsoleteAttributes () "Security.SslContext.SetSessionStrengthPolicy(Security.SslSessionStrengthPolicy)", "Security.SslContext.SetSessionTickets(System.Boolean)", "Security.SslProtocol Security.SecProtocolMetadata::NegotiatedProtocolVersion()", - "Speech.SFSpeechRecognitionRequest.get_InteractionIdentifier()", - "Speech.SFSpeechRecognitionRequest.set_InteractionIdentifier(System.String)", - "Speech.SFTranscription.get_AveragePauseDuration()", - "Speech.SFTranscription.get_SpeakingRate()", - "Speech.SFTranscriptionSegment.get_VoiceAnalytics()", "Speech.SFVoiceAnalytics Speech.SFTranscriptionSegment::VoiceAnalytics()", "StoreKit.SKCloudServiceController.RequestPersonalizationToken(System.String, System.Action`2)", "StoreKit.SKCloudServiceController.RequestPersonalizationTokenAsync(System.String)", "StoreKit.SKDownload.DeleteContentForProduct(System.String)", "StoreKit.SKDownload.GetContentUrlForProduct(System.String)", "StoreKit.SKMutablePayment.PaymentWithProduct(System.String)", - "StoreKit.SKProduct.get_ContentVersion()", "StoreKit.SKStoreReviewController.RequestReview()", "System.Boolean AppKit.NSImage::Flipped()", "System.Boolean AVFoundation.AVCaptureConnection::SupportsVideoMaxFrameDuration()", @@ -332,8 +281,6 @@ public void FindMissingObsoleteAttributes () "SystemConfiguration.CaptiveNetwork.TryGetSupportedInterfaces(out System.String[]&)", "UIKit.UIGestureRecognizer UIKit.UIScrollView::DirectionalPressGestureRecognizer()", "UIKit.UIGraphicsRendererFormat UIKit.UIGraphicsRendererFormat::DefaultFormat()", - "UIKit.UIGraphicsRendererFormat.get_DefaultFormat()", - "UIKit.UIScrollView.get_DirectionalPressGestureRecognizer()", "UIKit.UIStringDrawing.DrawString(System.String, CoreGraphics.CGPoint, System.Runtime.InteropServices.NFloat, UIKit.UIFont, System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat&, UIKit.UILineBreakMode, UIKit.UIBaselineAdjustment)", "UIKit.UIStringDrawing.DrawString(System.String, CoreGraphics.CGPoint, System.Runtime.InteropServices.NFloat, UIKit.UIFont, System.Runtime.InteropServices.NFloat, UIKit.UILineBreakMode, UIKit.UIBaselineAdjustment)", "UIKit.UIStringDrawing.DrawString(System.String, CoreGraphics.CGPoint, System.Runtime.InteropServices.NFloat, UIKit.UIFont, UIKit.UILineBreakMode)", @@ -346,12 +293,6 @@ public void FindMissingObsoleteAttributes () "UIKit.UIStringDrawing.StringSize(System.String, UIKit.UIFont, CoreGraphics.CGSize, UIKit.UILineBreakMode)", "UIKit.UIStringDrawing.StringSize(System.String, UIKit.UIFont, System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat&, System.Runtime.InteropServices.NFloat, UIKit.UILineBreakMode)", "UIKit.UIStringDrawing.StringSize(System.String, UIKit.UIFont, System.Runtime.InteropServices.NFloat, UIKit.UILineBreakMode)", - "UserNotifications.UNMutableNotificationContent.get_SummaryArgument()", - "UserNotifications.UNMutableNotificationContent.get_SummaryArgumentCount()", - "UserNotifications.UNMutableNotificationContent.set_SummaryArgument(System.String)", - "UserNotifications.UNMutableNotificationContent.set_SummaryArgumentCount(System.UIntPtr)", - "UserNotifications.UNNotificationContent.get_SummaryArgument()", - "UserNotifications.UNNotificationContent.get_SummaryArgumentCount()", }; // This test verifies that the SupportedOSPlatform and UnavailableOSPlatform/ObsoletedOSplatform attributes are consistent. diff --git a/tests/common/Configuration.cs b/tests/common/Configuration.cs index 7c96e256cf58..0c59e5768f77 100644 --- a/tests/common/Configuration.cs +++ b/tests/common/Configuration.cs @@ -498,6 +498,8 @@ static string GetSdkNuGetName (ApplePlatform platform) return "Microsoft.watchOS.Sdk"; case ApplePlatform.MacOSX: return "Microsoft.macOS.Sdk"; + case ApplePlatform.MacCatalyst: + return "Microsoft.MacCatalyst.Sdk"; default: throw new InvalidOperationException (platform.ToString ()); } diff --git a/tests/common/Profile.cs b/tests/common/Profile.cs index f7513f3203b9..837f63350cc5 100644 --- a/tests/common/Profile.cs +++ b/tests/common/Profile.cs @@ -29,6 +29,8 @@ public static ApplePlatform AsPlatform (this Profile profile) case Profile.macOSMobile: case Profile.macOSSystem: return ApplePlatform.MacOSX; + case Profile.MacCatalyst: + return ApplePlatform.MacCatalyst; case Profile.None: default: throw new NotImplementedException (profile.ToString ()); diff --git a/tests/generator/BGenTests.cs b/tests/generator/BGenTests.cs index e8816fe1e266..012bffccec0f 100644 --- a/tests/generator/BGenTests.cs +++ b/tests/generator/BGenTests.cs @@ -250,6 +250,40 @@ static string RenderArgument (CustomAttributeArgument arg) throw new NotImplementedException (obj.GetType ().FullName); } + static IEnumerable GetAvailabilityAttributes (ICustomAttributeProvider provider) + { + if (!provider.HasCustomAttributes) + yield break; + + foreach (var ca in provider.CustomAttributes) { + switch (ca.AttributeType.Name) { +#if NET + case "SupportedOSPlatformAttribute": + case "UnsupportedOSPlatformAttribute": + case "ObsoletedOSPlatformAttribute": +#else + case "IntroducedAttribute": + case "ObsoletedAttribute": + case "DeprecatedAttribute": +#endif + yield return ca; + break; + } + } + } + + static string RenderSupportedOSPlatformAttributes (ICustomAttributeProvider provider) + { + var attributes = GetAvailabilityAttributes (provider).ToArray (); + if (attributes is null || attributes.Length == 0) + return string.Empty; + var lines = new List (); + foreach (var ca in attributes) + lines.Add (RenderSupportedOSPlatformAttribute (ca)); + lines.Sort (); + return string.Join ("\n", lines); + } + static string RenderSupportedOSPlatformAttribute (CustomAttribute ca) { return "[" + ca.AttributeType.Name.Replace ("Attribute", "") + "(" + string.Join (", ", ca.ConstructorArguments.Select (arg => RenderArgument (arg))) + ")]"; @@ -274,18 +308,11 @@ public void Bug35176 () var renderedSupportedAttributes = allSupportedAttributes.Select (v => v.Item1.ToString () + ": " + RenderSupportedOSPlatformAttribute (v.Item2) + ""); var preserves = allSupportedAttributes.Count (); var renderedAttributes = "\t" + string.Join ("\n\t", renderedSupportedAttributes.OrderBy (v => v)) + "\n"; - Console.WriteLine (renderedAttributes); #if NET const string expectedAttributes = @" Bug35176.IFooInterface: [SupportedOSPlatform(""ios14.3"")] Bug35176.IFooInterface: [SupportedOSPlatform(""maccatalyst14.3"")] Bug35176.IFooInterface: [SupportedOSPlatform(""macos11.2"")] - System.Void Bug35176.BarObject::set_FooView(UIKit.UIView): [SupportedOSPlatform(""ios14.3"")] - System.Void Bug35176.BarObject::set_FooView(UIKit.UIView): [SupportedOSPlatform(""maccatalyst14.3"")] - System.Void Bug35176.BarObject::set_FooView(UIKit.UIView): [SupportedOSPlatform(""macos11.2"")] - System.Void Bug35176.FooInterfaceWrapper::set_FooView(UIKit.UIView): [SupportedOSPlatform(""ios14.3"")] - System.Void Bug35176.FooInterfaceWrapper::set_FooView(UIKit.UIView): [SupportedOSPlatform(""maccatalyst14.3"")] - System.Void Bug35176.FooInterfaceWrapper::set_FooView(UIKit.UIView): [SupportedOSPlatform(""macos11.2"")] UIKit.UIView Bug35176.BarObject::BarView(): [SupportedOSPlatform(""ios14.3"")] UIKit.UIView Bug35176.BarObject::BarView(): [SupportedOSPlatform(""maccatalyst14.3"")] UIKit.UIView Bug35176.BarObject::BarView(): [SupportedOSPlatform(""macos11.2"")] @@ -295,24 +322,12 @@ public void Bug35176 () UIKit.UIView Bug35176.BarObject::get_BarView(): [SupportedOSPlatform(""ios14.4"")] UIKit.UIView Bug35176.BarObject::get_BarView(): [SupportedOSPlatform(""maccatalyst14.4"")] UIKit.UIView Bug35176.BarObject::get_BarView(): [SupportedOSPlatform(""macos11.2"")] - UIKit.UIView Bug35176.BarObject::get_FooView(): [SupportedOSPlatform(""ios14.3"")] - UIKit.UIView Bug35176.BarObject::get_FooView(): [SupportedOSPlatform(""maccatalyst14.3"")] - UIKit.UIView Bug35176.BarObject::get_FooView(): [SupportedOSPlatform(""macos11.2"")] UIKit.UIView Bug35176.BarObject::GetBarMember(System.Int32): [SupportedOSPlatform(""ios14.3"")] UIKit.UIView Bug35176.BarObject::GetBarMember(System.Int32): [SupportedOSPlatform(""maccatalyst14.3"")] UIKit.UIView Bug35176.BarObject::GetBarMember(System.Int32): [SupportedOSPlatform(""macos11.2"")] - UIKit.UIView Bug35176.FooInterface_Extensions::GetBarMember(Bug35176.IFooInterface,System.Int32): [SupportedOSPlatform(""ios14.3"")] - UIKit.UIView Bug35176.FooInterface_Extensions::GetBarMember(Bug35176.IFooInterface,System.Int32): [SupportedOSPlatform(""maccatalyst14.3"")] - UIKit.UIView Bug35176.FooInterface_Extensions::GetBarMember(Bug35176.IFooInterface,System.Int32): [SupportedOSPlatform(""macos11.2"")] UIKit.UIView Bug35176.FooInterface_Extensions::GetBarView(Bug35176.IFooInterface): [SupportedOSPlatform(""ios14.4"")] UIKit.UIView Bug35176.FooInterface_Extensions::GetBarView(Bug35176.IFooInterface): [SupportedOSPlatform(""maccatalyst14.4"")] UIKit.UIView Bug35176.FooInterface_Extensions::GetBarView(Bug35176.IFooInterface): [SupportedOSPlatform(""macos11.2"")] - UIKit.UIView Bug35176.FooInterfaceWrapper::FooView(): [SupportedOSPlatform(""ios14.3"")] - UIKit.UIView Bug35176.FooInterfaceWrapper::FooView(): [SupportedOSPlatform(""maccatalyst14.3"")] - UIKit.UIView Bug35176.FooInterfaceWrapper::FooView(): [SupportedOSPlatform(""macos11.2"")] - UIKit.UIView Bug35176.FooInterfaceWrapper::get_FooView(): [SupportedOSPlatform(""ios14.3"")] - UIKit.UIView Bug35176.FooInterfaceWrapper::get_FooView(): [SupportedOSPlatform(""maccatalyst14.3"")] - UIKit.UIView Bug35176.FooInterfaceWrapper::get_FooView(): [SupportedOSPlatform(""macos11.2"")] "; #else const string expectedAttributes = @@ -329,10 +344,17 @@ public void Bug35176 () "; #endif + if (renderedAttributes != expectedAttributes) { + Console.WriteLine ($"Expected:"); + Console.WriteLine (expectedAttributes); + Console.WriteLine ($"Actual:"); + Console.WriteLine (renderedAttributes); + } + Assert.AreEqual (expectedAttributes, renderedAttributes, "Introduced attributes"); Assert.AreEqual ( #if NET - 36, // This number should be lower - https://github.com/xamarin/xamarin-macios/issues/14802 + 18, // This number should be lower - https://github.com/xamarin/xamarin-macios/issues/14802 #else 10, #endif @@ -1113,6 +1135,55 @@ public void NoAvailabilityForAccessors (Profile profile) bgen.AssertPublicMethodCount ("NS.IProtocol_Extensions", 2); } +#if !NET + [Ignore ("This test only applies to .NET")] +#endif + [Test] + public void GeneratedAttributeOnPropertyAccessors () + { + var bgen = BuildFile (Profile.MacCatalyst, "tests/generated-attribute-on-property-accessors.cs"); + + var messaging = bgen.ApiAssembly.MainModule.Types.First (v => v.Name == "ISomething"); + var property = messaging.Properties.First (v => v.Name == "IsLoadedInProcess"); + var getter = messaging.Methods.First (v => v.Name == "get_IsLoadedInProcess"); + var expectedPropertyAttributes = +@"[SupportedOSPlatform(""maccatalyst"")] +[SupportedOSPlatform(""macos10.15"")] +[UnsupportedOSPlatform(""ios"")] +[UnsupportedOSPlatform(""tvos"")]"; + Assert.AreEqual (expectedPropertyAttributes, RenderSupportedOSPlatformAttributes (property), "Property attributes"); + Assert.AreEqual (string.Empty, RenderSupportedOSPlatformAttributes (getter), "Getter Attributes"); + } + +#if !NET + [Ignore ("This test only applies to .NET")] +#endif + [Test] + public void GeneratedAttributeOnPropertyAccessors2 () + { + var bgen = BuildFile (Profile.MacCatalyst, "tests/generated-attribute-on-property-accessors2.cs"); + + var messaging = bgen.ApiAssembly.MainModule.Types.First (v => v.Name == "ISomething"); + var property = messaging.Properties.First (v => v.Name == "MicrophoneEnabled"); + var getter = messaging.Methods.First (v => v.Name == "get_MicrophoneEnabled"); + var setter = messaging.Methods.First (v => v.Name == "set_MicrophoneEnabled"); + + var expectedPropertyAttributes = +@"[SupportedOSPlatform(""ios"")] +[SupportedOSPlatform(""maccatalyst"")] +[SupportedOSPlatform(""macos11.0"")] +[UnsupportedOSPlatform(""tvos"")]"; + var expectedSetterAttributes = +@"[SupportedOSPlatform(""ios"")] +[SupportedOSPlatform(""maccatalyst"")] +[SupportedOSPlatform(""macos11.0"")] +[UnsupportedOSPlatform(""tvos"")]"; + + Assert.AreEqual (expectedPropertyAttributes, RenderSupportedOSPlatformAttributes (property), "Property attributes"); + Assert.AreEqual (string.Empty, RenderSupportedOSPlatformAttributes (getter), "Getter Attributes"); + Assert.AreEqual (expectedSetterAttributes, RenderSupportedOSPlatformAttributes (setter), "Setter Attributes"); + } + BGenTool BuildFile (Profile profile, params string [] filenames) { return BuildFile (profile, true, false, filenames); diff --git a/tests/generator/BGenTool.cs b/tests/generator/BGenTool.cs index 548559748e40..ccda4c3fde47 100644 --- a/tests/generator/BGenTool.cs +++ b/tests/generator/BGenTool.cs @@ -81,6 +81,8 @@ public static string GetTargetFramework (Profile profile) return TargetFramework.DotNet_tvOS_String; case Profile.watchOS: return TargetFramework.DotNet_watchOS_String; + case Profile.MacCatalyst: + return TargetFramework.DotNet_MacCatalyst_String; case Profile.macOSMobile: return TargetFramework.DotNet_macOS_String; case Profile.macOSFull: @@ -421,6 +423,8 @@ public static string [] GetDefaultDefines (Profile profile) return new string [] { "MONOMAC" }; case Profile.iOS: return new string [] { "IOS", "XAMCORE_2_0" }; + case Profile.MacCatalyst: + return new string [] { "MACCATALYST" }; default: throw new NotImplementedException (profile.ToString ()); } diff --git a/tests/generator/tests/generated-attribute-on-property-accessors.cs b/tests/generator/tests/generated-attribute-on-property-accessors.cs new file mode 100644 index 000000000000..125bd434d98d --- /dev/null +++ b/tests/generator/tests/generated-attribute-on-property-accessors.cs @@ -0,0 +1,17 @@ +using System; +using Foundation; +using ObjCRuntime; + +namespace NS { + [Introduced (PlatformName.iOS, 9, 0)] + [Introduced (PlatformName.MacOSX, 10, 11)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + public interface ISomething { + [Introduced (PlatformName.MacCatalyst, 13, 0)] // needed since it's not in iOS + [Introduced (PlatformName.MacOSX, 10, 15)] + [NoWatch, NoTV, NoiOS] + [Export ("isLoadedInProcess")] + bool IsLoadedInProcess { get; } + } +} diff --git a/tests/generator/tests/generated-attribute-on-property-accessors2.cs b/tests/generator/tests/generated-attribute-on-property-accessors2.cs new file mode 100644 index 000000000000..4ad5c1675b9b --- /dev/null +++ b/tests/generator/tests/generated-attribute-on-property-accessors2.cs @@ -0,0 +1,25 @@ +using System; +using Foundation; +using ObjCRuntime; + +namespace NS { + [Introduced (PlatformName.iOS, 9, 0)] + [Introduced (PlatformName.TvOS, 10, 0)] + [Introduced (PlatformName.MacOSX, 11, 0)] + [Introduced (PlatformName.MacCatalyst, 13, 1)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + [Sealed] + interface ISomething { + [NoTV] + [Introduced (PlatformName.MacCatalyst, 13, 1)] + [Export ("microphoneEnabled", ArgumentSemantic.Assign)] + bool MicrophoneEnabled { + [Bind ("isMicrophoneEnabled")] + get; + [Introduced (PlatformName.iOS, 10, 0)] + [Introduced (PlatformName.MacCatalyst, 13, 1)] + set; + } + } +}