Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/PassKit/PKPaymentRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;
using Foundation;
using ObjCRuntime;
Expand All @@ -9,13 +11,13 @@ public partial class PKContactFieldsExtensions {
static public PKContactFields GetValue (NSSet set)
{
var fields = PKContactFields.None;
if (set == null)
if (set is null)
return fields;

foreach (PKContactFields value in Enum.GetValues (typeof (PKContactFields))) {
var constant = value.GetConstant ();
// None does not have an associated native value and Contains would throw an ANE
if ((constant != null) && set.Contains (constant))
if ((constant is not null) && set.Contains (constant))
fields |= value;
}
return fields;
Expand All @@ -31,7 +33,7 @@ static public NSSet GetSet (PKContactFields values)
if (values.HasFlag (value)) {
var constant = value.GetConstant ();
// None does not have an associated native value and Contains would throw an ANE
if (constant != null)
if (constant is not null)
set.Add (constant);
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/passkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface PKPassLibrary {
PKPass[] GetPasses ();

[Export ("passWithPassTypeIdentifier:serialNumber:")]
[return: NullAllowed]
PKPass GetPass (string identifier, string serialNumber);

[iOS (8,0)]
Expand Down Expand Up @@ -264,7 +265,7 @@ interface PKPayment {
[Deprecated (PlatformName.iOS, 9, 0, message: "Use 'ShippingContact' instead.")]
ABRecord ShippingAddress { get; }

[Export ("shippingMethod", ArgumentSemantic.Strong)]
[NullAllowed, Export ("shippingMethod", ArgumentSemantic.Strong)]
PKShippingMethod ShippingMethod { get; }


Expand Down Expand Up @@ -813,7 +814,7 @@ interface PKPass : NSSecureCoding, NSCopying {
[Export ("initWithData:error:")]
NativeHandle Constructor (NSData data, out NSError error);

[Export ("authenticationToken", ArgumentSemantic.Copy)]
[NullAllowed, Export ("authenticationToken", ArgumentSemantic.Copy)]
string AuthenticationToken { get; }

[NoWatch]
Expand All @@ -838,16 +839,17 @@ interface PKPass : NSSecureCoding, NSCopying {
[Export ("passURL", ArgumentSemantic.Copy)]
NSUrl PassUrl { get; }

[Export ("relevantDate", ArgumentSemantic.Copy)]
[NullAllowed, Export ("relevantDate", ArgumentSemantic.Copy)]
NSDate RelevantDate { get; }

[Export ("serialNumber", ArgumentSemantic.Copy)]
string SerialNumber { get; }

[Export ("webServiceURL", ArgumentSemantic.Copy)]
[NullAllowed, Export ("webServiceURL", ArgumentSemantic.Copy)]
NSUrl WebServiceUrl { get; }

[Export ("localizedValueForFieldKey:")]
[return: NullAllowed]
NSObject GetLocalizedValue (NSString key); // TODO: Should be enum for PKPassLibraryUserInfoKey

#if !NET
Expand All @@ -857,7 +859,7 @@ interface PKPass : NSSecureCoding, NSCopying {
#endif

[iOS (7,0)]
[Export ("userInfo", ArgumentSemantic.Copy)]
[NullAllowed, Export ("userInfo", ArgumentSemantic.Copy)]
NSDictionary UserInfo { get; }

[iOS (8,0)]
Expand Down Expand Up @@ -1334,7 +1336,7 @@ interface PKPaymentAuthorizationResult {
[Export ("status", ArgumentSemantic.Assign)]
PKPaymentAuthorizationStatus Status { get; set; }

[Export ("errors", ArgumentSemantic.Copy)]
[NullAllowed, Export ("errors", ArgumentSemantic.Copy)]
NSError[] Errors { get; set; }
}

Expand Down Expand Up @@ -1372,7 +1374,7 @@ interface PKPaymentRequestShippingContactUpdate {
[Export ("shippingMethods", ArgumentSemantic.Copy)]
PKShippingMethod[] ShippingMethods { get; set; }

[Export ("errors", ArgumentSemantic.Copy)]
[NullAllowed, Export ("errors", ArgumentSemantic.Copy)]
NSError[] Errors { get; set; }
}

Expand Down Expand Up @@ -1400,7 +1402,7 @@ interface PKPaymentRequestPaymentMethodUpdate {
NativeHandle Constructor ([NullAllowed] NSError[] errors, PKPaymentSummaryItem [] paymentSummaryItems);

[Watch (6,0), iOS (13,0)]
[Export ("errors", ArgumentSemantic.Copy)]
[NullAllowed, Export ("errors", ArgumentSemantic.Copy)]
NSError [] Errors { get; set; }

// inlined
Expand Down
24 changes: 24 additions & 0 deletions tests/monotouch-test/PassKit/PKPassTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if !__TVOS__ && !MONOMAC

using System;
using Foundation;
using UIKit;
using PassKit;
using NUnit.Framework;

namespace MonoTouchFixtures.PassKit {

[TestFixture]
[Preserve (AllMembers = true)]
public class PKPassTest {

[Test]
public void GetLocalizedValueNull ()
{
using var pass = new PKPass ();
Assert.IsNull (pass.GetLocalizedValue (new NSString ()), "'PKPass.GetLocalizedValue' is not returning a null value");
}
}
}

#endif
22 changes: 22 additions & 0 deletions tests/monotouch-test/PassKit/PKPaymentRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ public void WeakRequiredBillingContactFields ()
}
}
}

[Test]
public void CheckDefaultNulls ()
{
using var pr = new PKPaymentRequest ();
Assert.IsNull (pr.CountryCode, "'PKPaymentRequest.CountryCode' is not returning null by default.");
Assert.IsNull (pr.CurrencyCode, "'PKPaymentRequest.CurrencyCode' is not returning null by default.");
Assert.IsNull (pr.MerchantIdentifier, "'PKPaymentRequest.MerchantIdentifier' is not returning null by default.");
Assert.IsNull (pr.PaymentSummaryItems, "'PKPaymentRequest.PaymentSummaryItems' is not returning null by default.");
Assert.IsNull (pr.SupportedNetworks, "'PKPaymentRequest.SupportedNetworks' is not returning null by default.");

Assert.DoesNotThrow (delegate { pr.CountryCode = null; },
"'PKPaymentRequest.CountryCode' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.CurrencyCode = null; },
"'PKPaymentRequest.CurrencyCode' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.MerchantIdentifier = null; },
"'PKPaymentRequest.MerchantIdentifier' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.PaymentSummaryItems = null; },
"'PKPaymentRequest.PaymentSummaryItems' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.SupportedNetworks = null; },
"'PKPaymentRequest.SupportedNetworks' cannot be set to null.");
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions tests/monotouch-test/PassKit/PKPaymentSummaryItemTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if !__TVOS__ && !MONOMAC

using System;
using Foundation;
using UIKit;
using PassKit;
using NUnit.Framework;

namespace MonoTouchFixtures.PassKit {

[TestFixture]
[Preserve (AllMembers = true)]
public class PKPaymentSummaryItemTest {

[Test]
public void CheckDefaultNulls ()
{
using var ps = new PKPaymentSummaryItem ();
Assert.IsNull (ps.Amount, "'PKPaymentSummaryItem.Amount' is not returning null by default.");
Assert.IsNull (ps.Label, "'PKPaymentSummaryItem.Label' is not returning null by default.");

Assert.DoesNotThrow (delegate { ps.Amount = null; },
"'PKPaymentSummaryItem.Amount' cannot be set to null.");
Assert.DoesNotThrow (delegate { ps.Label = null; },
"'PKPaymentSummaryItem.Label' cannot be set to null.");
}
}
}

#endif
14 changes: 1 addition & 13 deletions tests/xtro-sharpie/api-annotations-dotnet/common-PassKit.ignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
# Initial result from new rule extra-null-allowed
# By default these are null
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_CountryCode(System.String)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_CurrencyCode(System.String)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_MerchantIdentifier(System.String)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_PaymentSummaryItems(PassKit.PKPaymentSummaryItem[])' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_SupportedNetworks(Foundation.NSString[])' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentSummaryItem::set_Amount(Foundation.NSDecimalNumber)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentSummaryItem::set_Label(System.String)' has a extraneous [NullAllowed] on parameter #0

# Initial result from new rule missing-null-allowed
!missing-null-allowed! 'Foundation.NSDate PassKit.PKPass::get_RelevantDate()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary PassKit.PKPass::get_UserInfo()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSObject PassKit.PKPass::GetLocalizedValue(Foundation.NSString)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSUrl PassKit.PKPass::get_WebServiceUrl()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'PassKit.PKPass PassKit.PKPassLibrary::GetPass(System.String,System.String)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'PassKit.PKShippingMethod PassKit.PKPayment::get_ShippingMethod()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'System.String PassKit.PKPass::get_AuthenticationToken()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'System.Void PassKit.PKPaymentAuthorizationResult::set_Errors(Foundation.NSError[])' is missing an [NullAllowed] on parameter #0
!missing-null-allowed! 'System.Void PassKit.PKPaymentRequestPaymentMethodUpdate::set_Errors(Foundation.NSError[])' is missing an [NullAllowed] on parameter #0
!missing-null-allowed! 'System.Void PassKit.PKPaymentRequestShippingContactUpdate::set_Errors(Foundation.NSError[])' is missing an [NullAllowed] on parameter #0
14 changes: 1 addition & 13 deletions tests/xtro-sharpie/common-PassKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,11 @@
!incorrect-protocol-member! PKPaymentAuthorizationControllerDelegate::paymentAuthorizationController:didAuthorizePayment:completion: is OPTIONAL and should NOT be abstract
!incorrect-protocol-member! PKPaymentAuthorizationViewControllerDelegate::paymentAuthorizationViewControllerWillAuthorizePayment: is OPTIONAL and should NOT be abstract

# Initial result from new rule extra-null-allowed
# By default these are null
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_CountryCode(System.String)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_CurrencyCode(System.String)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_MerchantIdentifier(System.String)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_PaymentSummaryItems(PassKit.PKPaymentSummaryItem[])' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentRequest::set_SupportedNetworks(Foundation.NSString[])' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentSummaryItem::set_Amount(Foundation.NSDecimalNumber)' has a extraneous [NullAllowed] on parameter #0
!extra-null-allowed! 'System.Void PassKit.PKPaymentSummaryItem::set_Label(System.String)' has a extraneous [NullAllowed] on parameter #0

# Initial result from new rule missing-null-allowed
!missing-null-allowed! 'Foundation.NSDate PassKit.PKPass::get_RelevantDate()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary PassKit.PKPass::get_UserInfo()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSObject PassKit.PKPass::GetLocalizedValue(Foundation.NSString)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSUrl PassKit.PKPass::get_WebServiceUrl()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'PassKit.PKPass PassKit.PKPassLibrary::GetPass(System.String,System.String)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'PassKit.PKShippingMethod PassKit.PKPayment::get_ShippingMethod()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'System.String PassKit.PKPass::get_AuthenticationToken()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'System.Void PassKit.PKPaymentAuthorizationResult::set_Errors(Foundation.NSError[])' is missing an [NullAllowed] on parameter #0
!missing-null-allowed! 'System.Void PassKit.PKPaymentRequestPaymentMethodUpdate::set_Errors(Foundation.NSError[])' is missing an [NullAllowed] on parameter #0
!missing-null-allowed! 'System.Void PassKit.PKPaymentRequestShippingContactUpdate::set_Errors(Foundation.NSError[])' is missing an [NullAllowed] on parameter #0