From d3d278e3674c2c01d382fbfaaa7385e10c3dcb56 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Thu, 8 Oct 2020 06:38:38 -0400 Subject: [PATCH] [CoreFoundation] Update bindings up to Xcode 12.2 Beta 2 (#9720) * [CoreFoundation] Update bindings to Xcode 12.2 * Fix NRE * Add tests for manual API * Oops, fix spacing --- src/CoreFoundation/CFBundle.cs | 41 +++++++++++++++++++ .../CoreFoundation/BundleTest.cs | 33 +++++++++++++++ tests/xtro-sharpie/macOS-CoreFoundation.todo | 3 -- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/CoreFoundation/CFBundle.cs b/src/CoreFoundation/CFBundle.cs index 581e73112a..d7c2e4e5a1 100644 --- a/src/CoreFoundation/CFBundle.cs +++ b/src/CoreFoundation/CFBundle.cs @@ -608,5 +608,46 @@ namespace CoreFoundation { } } } + +#if MONOMAC + [Introduced (PlatformName.MacOSX, 11, 0)] + [DllImport (Constants.CoreFoundationLibrary)] + [return: MarshalAs (UnmanagedType.I1)] + extern static bool CFBundleIsExecutableLoadable (IntPtr bundle); + + [Introduced (PlatformName.MacOSX, 11, 0)] + public static bool IsExecutableLoadable (CFBundle bundle) + { + if (bundle == null) + throw new ArgumentNullException (nameof (bundle)); + if (bundle.Handle == IntPtr.Zero) + throw new ObjectDisposedException (nameof (bundle)); + + return CFBundleIsExecutableLoadable (bundle.Handle); + } + + [Introduced (PlatformName.MacOSX, 11, 0)] + [DllImport (Constants.CoreFoundationLibrary)] + [return: MarshalAs (UnmanagedType.I1)] + extern static bool CFBundleIsExecutableLoadableForURL (IntPtr bundle); + + [Introduced (PlatformName.MacOSX, 11, 0)] + public static bool IsExecutableLoadable (NSUrl url) + { + if (url == null) + throw new ArgumentNullException (nameof (url)); + + return CFBundleIsExecutableLoadableForURL (url.Handle); + } + + [Introduced (PlatformName.MacOSX, 11, 0)] + [DllImport (Constants.CoreFoundationLibrary)] + [return: MarshalAs (UnmanagedType.I1)] + extern static bool CFBundleIsArchitectureLoadable (/*cpu_type_t => integer_t => int*/ Architecture architecture); + + [Introduced (PlatformName.MacOSX, 11, 0)] + public static bool IsArchitectureLoadable (Architecture architecture) => CFBundleIsArchitectureLoadable (architecture); + +#endif } } diff --git a/tests/monotouch-test/CoreFoundation/BundleTest.cs b/tests/monotouch-test/CoreFoundation/BundleTest.cs index 6cb07cb9f1..858ce8f95f 100644 --- a/tests/monotouch-test/CoreFoundation/BundleTest.cs +++ b/tests/monotouch-test/CoreFoundation/BundleTest.cs @@ -356,5 +356,38 @@ namespace MonoTouchFixtures.CoreFoundation { { CFBundle.GetInfoDictionary (null); } + +#if MONOMAC + [Test] + public void TestIsArchitectureLoadable () + { + TestRuntime.AssertXcodeVersion (12, 2); + + bool loadable_x86_64 = CFBundle.IsArchitectureLoadable (CFBundle.Architecture.X86_64); + if (global::System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == global::System.Runtime.InteropServices.Architecture.X64) + Assert.IsTrue (loadable_x86_64, "x86_64 Expected => true"); + else + Assert.IsFalse (loadable_x86_64, "x86_64 Expected => false"); + + bool loadable_arm64 = CFBundle.IsArchitectureLoadable (CFBundle.Architecture.ARM64); + if (global::System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == global::System.Runtime.InteropServices.Architecture.Arm64) + Assert.IsTrue (loadable_arm64, "arm64 Expected => true"); + else + Assert.IsFalse (loadable_arm64, "arm64 Expected => false"); + } + + [Test] + public void TestIsExecutableLoadable () + { + TestRuntime.AssertXcodeVersion (12, 2); + + var main = CFBundle.GetMain (); + var loadableBundle = CFBundle.IsExecutableLoadable (main); + Assert.IsTrue (loadableBundle, "loadableBundle"); + + var loadableBundleUrl = CFBundle.IsExecutableLoadable (main.ExecutableUrl); + Assert.IsTrue (loadableBundleUrl, "loadableBundleUrl"); + } +#endif } } diff --git a/tests/xtro-sharpie/macOS-CoreFoundation.todo b/tests/xtro-sharpie/macOS-CoreFoundation.todo index ca5685bf81..e69de29bb2 100644 --- a/tests/xtro-sharpie/macOS-CoreFoundation.todo +++ b/tests/xtro-sharpie/macOS-CoreFoundation.todo @@ -1,3 +0,0 @@ -!missing-pinvoke! CFBundleIsArchitectureLoadable is not bound -!missing-pinvoke! CFBundleIsExecutableLoadable is not bound -!missing-pinvoke! CFBundleIsExecutableLoadableForURL is not bound