From 06286a2416a630d53b128b22d0ebe89d925024cb Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 17 Sep 2024 17:31:43 +0200 Subject: [PATCH] [ScriptingBridge] Remove outdated tests and add documentation. Fixes #21242. (#21246) The test we had in our codebase for the SBApplication class was not only outdated, but also incorrect. With recent changes the test code doesn't work anymore, so delete it. Instead, add XML documentation that explains how to use the class in a way that works. Fixes https://github.com/xamarin/xamarin-macios/issues/21242. --- src/ScriptingBridge/SBApplication.cs | 57 ++++++++++++------- .../Documentation.KnownFailures.txt | 1 - tests/scriptingbridge/Makefile | 41 ------------- tests/scriptingbridge/finder.cs | 27 --------- tests/scriptingbridge/test.cs | 25 -------- 5 files changed, 37 insertions(+), 114 deletions(-) delete mode 100644 tests/scriptingbridge/Makefile delete mode 100644 tests/scriptingbridge/finder.cs delete mode 100644 tests/scriptingbridge/test.cs diff --git a/src/ScriptingBridge/SBApplication.cs b/src/ScriptingBridge/SBApplication.cs index 694203b7ce..d608d1ed11 100644 --- a/src/ScriptingBridge/SBApplication.cs +++ b/src/ScriptingBridge/SBApplication.cs @@ -7,6 +7,43 @@ using Foundation; using ObjCRuntime; namespace ScriptingBridge { + /// This class provides API to send Apple events to scriptable applications and get Apple events back. + /// + /// There are multiple steps to use this API successfully. + /// First step is to create a binding project, which will define a protocol for the specific application to interact with, and the corresponding API. The code in the API definition for the binding project should look something like this: + /// + /// + /// + /// The second step is to create an executable project, which references the binding project. Additionally, the executable project defines a class that mirrors the protocol from the binding project: + /// + /// + /// + /// Note that the FinderApplication class subclasses this class (), in addition to implementing the FinderApplication protocol (which has been generated as an interface, with an I prefix, in the binding project). + /// The final step is to call GetApplication, and cast the return value to the protocol interface. + /// + /// + /// + /// public partial class SBApplication { public static SBApplication? GetApplication (string ident) => Runtime.GetNSObject (_FromBundleIdentifier (ident)); @@ -19,25 +56,5 @@ namespace ScriptingBridge { public static SBApplication? GetApplication (int pid) => Runtime.GetNSObject (_FromProcessIdentifier (pid)); public static T? GetApplication (int pid) where T : SBApplication => Runtime.GetINativeObject (_FromProcessIdentifier (pid), forced_type: true, owns: false); - -#if !NET - [Obsolete ("Use 'GetApplication' instead.")] - public static SBApplication? FromBundleIdentifier (string ident) => Runtime.GetNSObject (_FromBundleIdentifier (ident)); - - [Obsolete ("Use 'GetApplication' instead.")] - public static T? FromBundleIdentifier (string ident) where T : SBApplication => Runtime.GetINativeObject (_FromBundleIdentifier (ident), forced_type: true, owns: false); - - [Obsolete ("Use 'GetApplication' instead.")] - public static SBApplication? FromURL (NSUrl url) => Runtime.GetNSObject (_FromURL (url)); - - [Obsolete ("Use 'GetApplication' instead.")] - public static T? FromURL (NSUrl url) where T : SBApplication => Runtime.GetINativeObject (_FromURL (url), forced_type: true, owns: false); - - [Obsolete ("Use 'GetApplication' instead.")] - public static SBApplication? FromProcessIdentifier (int pid) => Runtime.GetNSObject (_FromProcessIdentifier (pid)); - - [Obsolete ("Use 'GetApplication' instead.")] - public static T? FromProcessIdentifier (int pid) where T : SBApplication => Runtime.GetINativeObject (_FromProcessIdentifier (pid), forced_type: true, owns: false); -#endif } } diff --git a/tests/cecil-tests/Documentation.KnownFailures.txt b/tests/cecil-tests/Documentation.KnownFailures.txt index d099a281ea..7441061c17 100644 --- a/tests/cecil-tests/Documentation.KnownFailures.txt +++ b/tests/cecil-tests/Documentation.KnownFailures.txt @@ -81348,7 +81348,6 @@ T:ScreenTime.STWebpageController T:ScriptingBridge.AESendMode T:ScriptingBridge.ISBApplicationDelegate T:ScriptingBridge.LSLaunchFlags -T:ScriptingBridge.SBApplication T:ScriptingBridge.SBApplicationDelegate T:ScriptingBridge.SBApplicationError T:ScriptingBridge.SBElementArray diff --git a/tests/scriptingbridge/Makefile b/tests/scriptingbridge/Makefile deleted file mode 100644 index c6b57d0cdb..0000000000 --- a/tests/scriptingbridge/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -TOP = ../.. - -include $(TOP)/Make.config -include $(TOP)/mk/rules.mk - -MMP=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp -BMAC=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/bmac - -all-local:: build/compat/test.app build/mobile-32/test.app build/mobile-64/test.app - -exec-compat: build/compat/test.app - ./build/compat/test.app/Contents/MacOS/test | grep Passed - -exec-mobile-%: build/mobile-%/test.app - ./build/mobile-$*/test.app/Contents/MacOS/test | grep Passed - -run run-test run-tests: build/compat/test.app build/mobile-32/test.app build/mobile-64/test.app - @rm -f .$@-failure.stamp - @$(MAKE) exec-compat || echo "run-compat failed" >> .$@-failure.stamp - @$(MAKE) exec-mobile-32 || echo "run-mobile-32 failed" >> .$@-failure.stamp - @$(MAKE) exec-mobile-64 || echo "run-mobile-64 failed" >> .$@-failure.stamp - @if test -e .$@-failure.stamp; then cat .$@-failure.stamp; rm .$@-failure.stamp; exit 1; fi - -build/compat/test.app: build/compat/finder.dll - rm -Rf $@ - $(SYSTEM_CSC) "/out:build/compat/test.exe" "/r:build/compat/finder.dll" /r:$(TOP)/src/build/mac/compat/XamMac.dll /t:exe "test.cs" - $(MMP) -nolink "-minos=10.9" -o "build/compat" -n "test" --profile "4.5" -a $(TOP)/src/build/mac/compat/XamMac.dll -a "build/compat/finder.dll" "build/compat/test.exe" - -build/compat/finder.dll: - $(BMAC) --out=build/compat/finder.dll --outdir=build/compat/ -r:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/System.Drawing.dll -baselib:$(TOP)/src/build/mac/compat/XamMac.dll finder.cs - -build/mobile-%/test.app: build/mobile-%/finder.dll - rm -Rf $@ - $(SYSTEM_CSC) "/out:build/mobile-$*/test.exe" "/r:build/mobile-$*/finder.dll" /r:$(TOP)/src/build/mac/mobile-$*/Xamarin.Mac.dll /t:exe "test.cs" - $(MMP) -nolink "-minos=10.9" -o "build/mobile-$*" -n "test" --profile "4.5" -a $(TOP)/src/build/mac/mobile-$*/Xamarin.Mac.dll -a "build/mobile-$*/finder.dll" "build/mobile-$*/test.exe" --profile mobile --arch $(shell test '$*' == '32' && echo i386 || echo x86_64) - -build/mobile-%/finder.dll: - $(BMAC) --unified-mobile-profile --out=build/mobile-$*/finder.dll --outdir=build/mobile-$*/ -baselib:$(TOP)/src/build/mac/mobile-$*/Xamarin.Mac.dll finder.cs - -clean-local:: - @rm -rf build/ diff --git a/tests/scriptingbridge/finder.cs b/tests/scriptingbridge/finder.cs deleted file mode 100644 index ece84bcc9a..0000000000 --- a/tests/scriptingbridge/finder.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Foundation; -using ObjCRuntime; -using ScriptingBridge; - -namespace Finder { - [BaseType (typeof (SBObject))] - interface FinderItem { - [Export ("name")] - string Name { get; } - } - - [BaseType (typeof (FinderItem))] - interface FinderContainer { - } - - [BaseType (typeof (FinderContainer))] - interface FinderTrashObject { - [Export ("items")] - SBElementArray Items { get; } - } - - [BaseType (typeof (SBApplication))] - interface FinderApplication { - [Export ("trash")] - FinderTrashObject Trash { get; } - } -} diff --git a/tests/scriptingbridge/test.cs b/tests/scriptingbridge/test.cs deleted file mode 100644 index 71960c4e97..0000000000 --- a/tests/scriptingbridge/test.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using Finder; -using AppKit; -using ScriptingBridge; - -namespace ScriptingBridge.Tests { - public static class MainClass { - static int Main (string [] args) - { - FinderApplication app = SBApplication.FromBundleIdentifier ("com.apple.finder"); - - if ((int) app.Trash.Items.Count > 0) { - for (int i = 0; i < (int) app.Trash.Items.Count; ++i) { - FinderItem item = app.Trash.Items.GetItem ((nuint) i); - if (item.Name is null) - return 0; - } - } - - Console.WriteLine ("Passed"); - - return 0; - } - } -}