-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PassKit] Finish implementation of PKPayLaterValidateAmount. Fixes #1…
- Loading branch information
1 parent
3db59cc
commit c4a5627
Showing
3 changed files
with
116 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,79 @@ | ||
// Can be uncommented when this issue is resolved: # https://github.com/xamarin/xamarin-macios/issues/19271 | ||
#nullable enable | ||
|
||
// #nullable enable | ||
#if IOS && !__MACCATALYST__ | ||
|
||
// #if IOS && !__MACCATALYST__ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.CompilerServices; | ||
|
||
// using System; | ||
// using System.Runtime.InteropServices; | ||
// using System.Runtime.CompilerServices; | ||
// using ObjCRuntime; | ||
// using Foundation; | ||
// using PassKit; | ||
using Foundation; | ||
using ObjCRuntime; | ||
using PassKit; | ||
|
||
// #if !NET | ||
// using NativeHandle = System.IntPtr; | ||
// #endif | ||
namespace PassKit { | ||
|
||
// namespace PassKit { | ||
/// <summary>The delegate that is called when <see cref="PKPayLaterView.ValidateAmount(System.Decimal,System.String,PassKit.PKPayLaterViewValidateAmountCallback)" /> has determined whether the Pay Later Merchandising information is valid.</summary> | ||
/// <param name="eligible">True if the Pay Later Merchandising information is valid, false otherwise.</param> | ||
public delegate void PKPayLaterViewValidateAmountCallback (bool eligible); | ||
|
||
// public partial class PKPayLaterView { | ||
public partial class PKPayLaterView { | ||
[UnmanagedCallersOnly] | ||
static void TrampolineValidateAmount (IntPtr block, byte eligible) | ||
{ | ||
var del = BlockLiteral.GetTarget<PKPayLaterViewValidateAmountCallback> (block); | ||
if (del is not null) { | ||
del (eligible != 0); | ||
} | ||
} | ||
|
||
// #if !NET | ||
// delegate void PKPayLaterValidateAmountCompletionHandler (IntPtr block, byte eligible); | ||
// static PKPayLaterValidateAmountCompletionHandler static_ValidateAmount = TrampolineValidateAmount; | ||
/// <summary>Checks whether the Pay Later Merchandising information is valid for the specified amount and currency.</summary> | ||
/// <param name="amount">The amount to check for.</param> | ||
/// <param name="currencyCode">The ISO 4217 currency code to use.</param> | ||
/// <param name="callback">The delegate that will be called with the result.</param> | ||
[SupportedOSPlatform ("ios17.0")] | ||
[UnsupportedOSPlatform ("maccatalyst")] | ||
[UnsupportedOSPlatform ("macos")] | ||
[UnsupportedOSPlatform ("tvos")] | ||
[BindingImpl (BindingImplOptions.Optimizable)] | ||
public static void ValidateAmount (NSDecimalNumber amount, string currencyCode, PKPayLaterViewValidateAmountCallback callback) | ||
{ | ||
if (callback is null) | ||
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback)); | ||
|
||
// [MonoPInvokeCallback (typeof (PKPayLaterValidateAmountCompletionHandler))] | ||
// #else | ||
// [UnmanagedCallersOnly] | ||
// #endif | ||
// static void TrampolineValidateAmount (IntPtr block, byte eligible) | ||
// { | ||
// var del = BlockLiteral.GetTarget<Action<bool>> (block); | ||
// if (del is not null) { | ||
// del (eligible != 0); | ||
// } | ||
// } | ||
unsafe { | ||
delegate* unmanaged<IntPtr, byte, void> trampoline = &TrampolineValidateAmount; | ||
using var block = new BlockLiteral (trampoline, callback, typeof (PKPayLaterView), nameof (TrampolineValidateAmount)); | ||
var nsCurrencyCodePtr = NSString.CreateNative (currencyCode); | ||
try { | ||
PKPayLaterValidateAmount (amount.Handle, nsCurrencyCodePtr, &block); | ||
} finally { | ||
NSString.ReleaseNative (nsCurrencyCodePtr); | ||
} | ||
} | ||
} | ||
|
||
// #if NET | ||
// [SupportedOSPlatform ("ios17.0")] | ||
// [UnsupportedOSPlatform ("maccatalyst")] | ||
// [UnsupportedOSPlatform ("macos")] | ||
// [UnsupportedOSPlatform ("tvos")] | ||
// #endif | ||
// [BindingImpl (BindingImplOptions.Optimizable)] | ||
// public static void ValidateAmount (NSDecimalNumber amount, string currencyCode, Action<bool> callback) | ||
// { | ||
// if (callback is null) | ||
// ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback)); | ||
/// <summary>Checks whether the Pay Later Merchandising information is valid for the specified amount and currency.</summary> | ||
/// <param name="amount">The amount to check for.</param> | ||
/// <param name="currencyCode">The ISO 4217 currency code to use.</param> | ||
/// <param name="callback">The delegate that will be called with the result.</param> | ||
[SupportedOSPlatform ("ios17.0")] | ||
[UnsupportedOSPlatform ("maccatalyst")] | ||
[UnsupportedOSPlatform ("macos")] | ||
[UnsupportedOSPlatform ("tvos")] | ||
[BindingImpl (BindingImplOptions.Optimizable)] | ||
public static void ValidateAmount (decimal amount, string currencyCode, PKPayLaterViewValidateAmountCallback callback) | ||
{ | ||
using var decimalAmount = new NSDecimalNumber ((NSDecimal) amount); | ||
ValidateAmount (decimalAmount, currencyCode, callback); | ||
} | ||
|
||
// unsafe { | ||
// #if NET | ||
// delegate* unmanaged<IntPtr, byte, void> trampoline = &TrampolineValidateAmount; | ||
// using var block = new BlockLiteral (trampoline, callback, typeof (PKPayLaterView), nameof (TrampolineValidateAmount)); | ||
// #else | ||
// using var block = new BlockLiteral (); | ||
// block.SetupBlockUnsafe (static_ValidateAmount, callback); | ||
// #endif | ||
// var nsCurrencyCodePtr = NSString.CreateNative (currencyCode); | ||
// try { | ||
// PKPayLaterValidateAmount (amount.Handle, nsCurrencyCodePtr, &block); | ||
// } finally { | ||
// NSString.ReleaseNative (nsCurrencyCodePtr); | ||
// } | ||
// } | ||
// } | ||
[SupportedOSPlatform ("ios17.0")] | ||
[UnsupportedOSPlatform ("maccatalyst")] | ||
[UnsupportedOSPlatform ("macos")] | ||
[UnsupportedOSPlatform ("tvos")] | ||
[DllImport (Constants.PassKitLibrary)] | ||
unsafe static extern void PKPayLaterValidateAmount (IntPtr /* NSDecimalNumber */ amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback); | ||
} | ||
} | ||
|
||
// [DllImport (Constants.PassKitLibrary)] | ||
// unsafe static extern void PKPayLaterValidateAmount (IntPtr /* NSDecimalNumber */ amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback); | ||
// } | ||
// } | ||
|
||
// #endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,55 @@ | ||
// Can be uncommented when this issue is resolved: # https://github.com/xamarin/xamarin-macios/issues/19271 | ||
#if __IOS__ && !__MACCATALYST__ | ||
|
||
// #if __IOS__ && !__MACCATALYST__ | ||
using System; | ||
using System.Threading; | ||
|
||
// using System; | ||
// using Foundation; | ||
// using UIKit; | ||
// using PassKit; | ||
// using NUnit.Framework; | ||
using Foundation; | ||
using UIKit; | ||
|
||
// namespace MonoTouchFixtures.PassKit { | ||
using PassKit; | ||
|
||
// [TestFixture] | ||
// [Preserve (AllMembers = true)] | ||
// public class PKPayLaterViewTest { | ||
using NUnit.Framework; | ||
|
||
// [Test] | ||
// public void ValidateAmountTest () | ||
// { | ||
// TestRuntime.AssertXcodeVersion (15, 0); | ||
namespace MonoTouchFixtures.PassKit { | ||
|
||
// for (int i = 0; i < 1000; i++){ | ||
// PKPayLaterView.ValidateAmount (new NSDecimalNumber (i), "USD", (eligible) => { | ||
// Assert.False (eligible); | ||
// }); | ||
// } | ||
// } | ||
// } | ||
// } | ||
[TestFixture] | ||
[Preserve (AllMembers = true)] | ||
public class PKPayLaterViewTest { | ||
|
||
// #endif | ||
[Test] | ||
public void ValidateAmountTest_NSDecimal () | ||
{ | ||
TestRuntime.AssertXcodeVersion (15, 0); | ||
|
||
var counter = 100; | ||
var cnt = 0; | ||
for (int i = 0; i < counter; i++) { | ||
PKPayLaterView.ValidateAmount (new NSDecimalNumber (i), "USD", (eligible) => { | ||
Interlocked.Increment (ref cnt); | ||
}); | ||
} | ||
// The callback is rarely called, so just assert that we don't get more callbacks than | ||
// actual validation requests. | ||
Assert.That (cnt, Is.Not.LessThan (0).And.Not.GreaterThan (counter), $"NSDecimalNumber overload"); | ||
} | ||
|
||
[Test] | ||
public void ValidateAmountTest_Decimal () | ||
{ | ||
TestRuntime.AssertXcodeVersion (15, 0); | ||
|
||
var counter = 100; | ||
var cnt = 0; | ||
for (int i = 0; i < counter; i++) { | ||
PKPayLaterView.ValidateAmount (i, "USD", (eligible) => { | ||
Interlocked.Increment (ref cnt); | ||
}); | ||
} | ||
// The callback is rarely called, so just assert that we don't get more callbacks than | ||
// actual validation requests. | ||
Assert.That (cnt, Is.Not.LessThan (0).And.Not.GreaterThan (counter), $"decimal overload"); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c4a5627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📚 [CI Build] Artifacts 📚
Artifacts were not provided.
Pipeline on Agent
Hash: [CI build]
c4a5627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💻 [CI Build] Windows Integration Tests passed 💻
✅ All Windows Integration Tests passed.
Pipeline on Agent
Hash: c4a5627f03e0555ed35395ac2e4207432c9ceb87 [CI build]
c4a5627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💻 [CI Build] Windows Integration Tests passed 💻
✅ All Windows Integration Tests passed.
Pipeline on Agent
Hash: c4a5627f03e0555ed35395ac2e4207432c9ceb87 [CI build]
c4a5627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 [CI Build] Test results 🔥
Test results
❌ Tests failed on VSTS: test results
2 tests crashed, 0 tests failed, 91 tests passed.
Failures
❌ msbuild tests
🔥 Failed catastrophically on VSTS: test results - msbuild (no summary found).
Html Report (VSDrops) Download
❌ xcframework tests
🔥 Failed catastrophically on VSTS: test results - xcframework (no summary found).
Html Report (VSDrops) Download
Successes
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 40 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 7 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 7 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 7 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download
Pipeline on Agent
Hash: c4a5627f03e0555ed35395ac2e4207432c9ceb87 [CI build]
c4a5627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 [CI Build] Test results 🔥
Test results
❌ Tests failed on VSTS: test results
9 tests crashed, 0 tests failed, 21 tests passed.
Failures
❌ dotnettests tests (MacCatalyst)
🔥 Failed catastrophically on VSTS: test results - dotnettests_maccatalyst (no summary found).
Html Report (VSDrops) Download
❌ dotnettests tests (tvOS)
🔥 Failed catastrophically on VSTS: test results - dotnettests_tvos (no summary found).
Html Report (VSDrops) Download
❌ generator tests
🔥 Failed catastrophically on VSTS: test results - generator (no summary found).
Html Report (VSDrops) Download
❌ interdependent-binding-projects tests
🔥 Failed catastrophically on VSTS: test results - interdependent-binding-projects (no summary found).
Html Report (VSDrops) Download
❌ linker tests
🔥 Failed catastrophically on VSTS: test results - linker (no summary found).
Html Report (VSDrops) Download
❌ monotouch tests (iOS)
🔥 Failed catastrophically on VSTS: test results - monotouch_ios (no summary found).
Html Report (VSDrops) Download
❌ monotouch tests (MacCatalyst)
🔥 Failed catastrophically on VSTS: test results - monotouch_maccatalyst (no summary found).
Html Report (VSDrops) Download
❌ monotouch tests (macOS)
🔥 Failed catastrophically on VSTS: test results - monotouch_macos (no summary found).
Html Report (VSDrops) Download
❌ monotouch tests (tvOS)
🔥 Failed catastrophically on VSTS: test results - monotouch_tvos (no summary found).
Html Report (VSDrops) Download
Successes
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download
Pipeline on Agent
Hash: c4a5627f03e0555ed35395ac2e4207432c9ceb87 [CI build]