From 2c3690fe7378c38b6705bdd2cdeebdace9588fac Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Sat, 10 Jun 2017 00:50:01 -0700 Subject: [PATCH] [EventKit] Fix a few issues found with iOS 11 (#2198) * [EventKit] Obsolete the EKAlarm constructor and update tests. Apple's documentation says "Use the alarmWithAbsoluteDate: and alarmWithRelativeOffset: class methods to create an alarm", and additionally calling the default constructor crashes, so obsolete the constructor and don't call it from tests either. * [EventKit] Make EKCalendarItem abstract according to Apple's documentation. Since EKCalendarItem is an abstract class, tests should obviously not create instances of it - and in fact it fails: [FAIL] CalendarItemTest.NullAllowedTest : Foundation.MonoTouchException : Objective-C exception thrown. Name: NSInvalidArgumentException Reason: +[EKCalendarItem frozenClass]: unrecognized selector sent to class 0x10e02bfa0 * [tests] Remove removed file from xammac tests as well. --- src/EventKit/EventKit.cs | 7 +++ src/eventkit.cs | 4 ++ tests/monotouch-test/EventKit/AlarmTest.cs | 2 +- .../EventKit/CalendarItemTest.cs | 43 ------------------- tests/monotouch-test/monotouch-test.csproj | 1 - tests/xammac_tests/xammac_tests.csproj | 3 -- 6 files changed, 12 insertions(+), 48 deletions(-) delete mode 100644 tests/monotouch-test/EventKit/CalendarItemTest.cs diff --git a/src/EventKit/EventKit.cs b/src/EventKit/EventKit.cs index 3c4553aa41..cb6b4e9377 100644 --- a/src/EventKit/EventKit.cs +++ b/src/EventKit/EventKit.cs @@ -72,6 +72,13 @@ namespace XamCore.EventKit { get { throw new NotSupportedException (); } set { throw new NotSupportedException (); } } +#endif + } + + partial class EKAlarm { +#if !XAMCORE_4_0 + [Obsolete ("Use the static methods FromDate or FromTimeInterval to create alarms")] + public EKAlarm () {} #endif } } diff --git a/src/eventkit.cs b/src/eventkit.cs index bc4d95c068..714904530b 100644 --- a/src/eventkit.cs +++ b/src/eventkit.cs @@ -54,6 +54,9 @@ namespace XamCore.EventKit { [Since (5,0)] [Mac (10,8, onlyOn64: true)] [BaseType (typeof (EKObject))] +#if XAMCORE_4_0 + [Abstract] // "The EKCalendarItem class is a an abstract superclass ..." from Apple docs. +#endif interface EKCalendarItem { #if !MONOMAC // Never made avaialble on MonoMac @@ -188,6 +191,7 @@ namespace XamCore.EventKit { [Since (4,0)] [Mac (10,8, onlyOn64: true)] [BaseType (typeof (EKObject))] + [DisableDefaultCtor] // Documentation says to use the static methods FromDate/FromTimeInterval to create instances interface EKAlarm : NSCopying { [Export ("relativeOffset")] double RelativeOffset { get; set; } diff --git a/tests/monotouch-test/EventKit/AlarmTest.cs b/tests/monotouch-test/EventKit/AlarmTest.cs index 79a8311418..9ebbcc3b96 100644 --- a/tests/monotouch-test/EventKit/AlarmTest.cs +++ b/tests/monotouch-test/EventKit/AlarmTest.cs @@ -33,7 +33,7 @@ namespace MonoTouchFixtures.EventKit { [Test] public void NullAllowedTest () { - using (var alarm = new EKAlarm ()) { + using (var alarm = EKAlarm.FromTimeInterval (1234)) { alarm.AbsoluteDate = null; alarm.StructuredLocation = null; } diff --git a/tests/monotouch-test/EventKit/CalendarItemTest.cs b/tests/monotouch-test/EventKit/CalendarItemTest.cs deleted file mode 100644 index 19cb09f09f..0000000000 --- a/tests/monotouch-test/EventKit/CalendarItemTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Unit tests for EKCalendarItem -// -// Authors: -// Rolf Bjarne Kvinge -// -// Copyright 2013 Xamarin Inc. All rights reserved. -// - -#if !__TVOS__ - -using System; -#if XAMCORE_2_0 -using Foundation; -using CoreGraphics; -using EventKit; -using ObjCRuntime; -#else -using MonoTouch.CoreGraphics; -using MonoTouch.EventKit; -using MonoTouch.Foundation; -using MonoTouch.ObjCRuntime; -using MonoTouch.UIKit; -#endif -using NUnit.Framework; - -namespace MonoTouchFixtures.EventKit { - - [TestFixture] - [Preserve (AllMembers = true)] - public class CalendarItemTest { - - [Test] - public void NullAllowedTest () - { - using (var item = new EKCalendarItem ()) { - item.Notes = null; - } - } - } -} - -#endif // !__TVOS__ diff --git a/tests/monotouch-test/monotouch-test.csproj b/tests/monotouch-test/monotouch-test.csproj index 7fc90a6784..08a2dc8304 100644 --- a/tests/monotouch-test/monotouch-test.csproj +++ b/tests/monotouch-test/monotouch-test.csproj @@ -349,7 +349,6 @@ - diff --git a/tests/xammac_tests/xammac_tests.csproj b/tests/xammac_tests/xammac_tests.csproj index acb49547b5..831b77e282 100644 --- a/tests/xammac_tests/xammac_tests.csproj +++ b/tests/xammac_tests/xammac_tests.csproj @@ -584,9 +584,6 @@ EventKit\AlarmTest.cs - - EventKit\CalendarItemTest.cs - EventKit\CalendarTest.cs