Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions tests/sharpie/Sharpie.Bind.Tests/OnDiskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ void ParseBindTestImpl (string path, string variant, string bindArguments)
binder.Massagers.Add ((massagerName.TrimStart ('+', '-'), enable));
i++;
break;
case "-custom-delegates":
binder.UseCustomDelegates = true;
break;
default:
clangArguments.Add (bindArgs [i]);
break;
Expand Down
21 changes: 21 additions & 0 deletions tests/sharpie/Tests/Nullability.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@

void Func (const char * __nullable str);

// Functions with nullable return types
extern NSObject * _Nullable NullableReturnObject (void);
extern NSString * _Nullable NullableReturnString (int code);

// Functions with nullable parameters
extern void FuncWithNullableObject (NSObject * _Nullable obj);
extern void FuncWithNullableString (NSString * _Nullable str);
extern void FuncWithMixedNullability (NSObject * _Nonnull required, NSObject * _Nullable optional);

// Functions with both nullable params and return
extern NSObject * _Nullable FuncNullableInAndOut (NSString * _Nullable input);

// Functions with nullable block parameters
extern void FuncWithNullableBlock (void (^ _Nullable block)(void));
extern void FuncWithNullableBlockParam (void (^ _Nullable block)(NSObject * _Nullable obj));
extern void FuncWithNonnullBlock (void (^ _Nonnull block)(void));

// Functions returning nullable block
typedef void (^SimpleBlock)(void);
extern SimpleBlock _Nullable FuncReturningNullableBlock (void);

@interface Foo

@property (nullable) SEL selector;
Expand Down
58 changes: 58 additions & 0 deletions tests/sharpie/Tests/Nullability.iphoneos.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
Expand All @@ -7,8 +8,65 @@ static class CFunctions {
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern unsafe void Func ([NullAllowed] sbyte* str);

// extern NSObject * _Nullable NullableReturnObject ();
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern NSObject NullableReturnObject ();

// extern NSString * _Nullable NullableReturnString (int code);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern NSString NullableReturnString (int code);

// extern void FuncWithNullableObject (NSObject * _Nullable obj);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableObject ([NullAllowed] NSObject obj);

// extern void FuncWithNullableString (NSString * _Nullable str);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableString ([NullAllowed] NSString str);

// extern void FuncWithMixedNullability (NSObject * _Nonnull required, NSObject * _Nullable optional);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithMixedNullability (NSObject required, [NullAllowed] NSObject optional);

// extern NSObject * _Nullable FuncNullableInAndOut (NSString * _Nullable input);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern NSObject FuncNullableInAndOut ([NullAllowed] NSString input);

// extern void FuncWithNullableBlock (void (^ _Nullable)(void) block);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableBlock ([NullAllowed] Action block);

// extern void FuncWithNullableBlockParam (void (^ _Nullable)(NSObject * _Nullable) block);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableBlockParam ([NullAllowed] Action<NSObject> block);

// extern void FuncWithNonnullBlock (void (^ _Nonnull)(void) block);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNonnullBlock (Action block);

// extern SimpleBlock _Nullable FuncReturningNullableBlock ();
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern SimpleBlock FuncReturningNullableBlock ();
}

// typedef void (^SimpleBlock)();
delegate void SimpleBlock ();

// @interface Foo
interface Foo {
// @property SEL _Nullable selector;
Expand Down
58 changes: 58 additions & 0 deletions tests/sharpie/Tests/Nullability.macosx.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
Expand All @@ -7,8 +8,65 @@ static class CFunctions {
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern unsafe void Func ([NullAllowed] sbyte* str);

// extern NSObject * _Nullable NullableReturnObject ();
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern NSObject NullableReturnObject ();

// extern NSString * _Nullable NullableReturnString (int code);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern NSString NullableReturnString (int code);

// extern void FuncWithNullableObject (NSObject * _Nullable obj);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableObject ([NullAllowed] NSObject obj);

// extern void FuncWithNullableString (NSString * _Nullable str);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableString ([NullAllowed] NSString str);

// extern void FuncWithMixedNullability (NSObject * _Nonnull required, NSObject * _Nullable optional);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithMixedNullability (NSObject required, [NullAllowed] NSObject optional);

// extern NSObject * _Nullable FuncNullableInAndOut (NSString * _Nullable input);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern NSObject FuncNullableInAndOut ([NullAllowed] NSString input);

// extern void FuncWithNullableBlock (void (^ _Nullable)(void) block);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableBlock ([NullAllowed] Action block);

// extern void FuncWithNullableBlockParam (void (^ _Nullable)(NSObject * _Nullable) block);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNullableBlockParam ([NullAllowed] Action<NSObject> block);

// extern void FuncWithNonnullBlock (void (^ _Nonnull)(void) block);
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern void FuncWithNonnullBlock (Action block);

// extern SimpleBlock _Nullable FuncReturningNullableBlock ();
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
[return: NullAllowed]
static extern SimpleBlock FuncReturningNullableBlock ();
}

// typedef void (^SimpleBlock)();
delegate void SimpleBlock ();

// @interface Foo
interface Foo {
// @property SEL _Nullable selector;
Expand Down
129 changes: 129 additions & 0 deletions tests/sharpie/Tests/Types/Blocks.custom_delegates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using Foundation;
using ObjCRuntime;

// typedef void (^Action)();
delegate void Action ();

// typedef int (^Anon_Func_Long_Int)(long long);
delegate int Anon_Func_Long_Int (long arg0);

// typedef int (^Named_Func_Long_Int)(long long);
delegate int Named_Func_Long_Int (long arg0);

// typedef void (^Variadic)(int, ...);
delegate void Variadic (int arg0, IntPtr varArgs);

// @interface TypedefBlockTests
interface TypedefBlockTests {
// -(Action)get_Action;
[Export ("get_Action")]
[Verify (MethodToProperty)]
Action Get_Action { get; }

// -(Anon_Func_Long_Int)get_Anon_Func_Long_Int;
[Export ("get_Anon_Func_Long_Int")]
[Verify (MethodToProperty)]
Anon_Func_Long_Int Get_Anon_Func_Long_Int { get; }

// -(Named_Func_Long_Int)get_Named_Func_Long_Int;
[Export ("get_Named_Func_Long_Int")]
[Verify (MethodToProperty)]
Named_Func_Long_Int Get_Named_Func_Long_Int { get; }
}

delegate void ActionHandler ();

delegate void Action_intHandler (int arg0);

delegate void Action_actionHandler (Action arg0);

delegate void Action_action_intHandler (Action<int> arg0);

delegate void Action_action_actionHandler (Action<Action> arg0);

delegate int Func_int_intHandler (int arg0);

delegate nint Func_short_nintHandler (short arg0);

// @interface PropertyBlockTests
interface PropertyBlockTests {
// @property (readonly, copy) void (^action)();
[Export ("action", ArgumentSemantic.Copy)]
ActionHandler Action { get; }

// @property (readonly, copy) void (^action_int)(int);
[Export ("action_int", ArgumentSemantic.Copy)]
Action_intHandler Action_int { get; }

// @property (readonly, copy) void (^action_action)(void (^)());
[Export ("action_action", ArgumentSemantic.Copy)]
Action_actionHandler Action_action { get; }

// @property (readonly, copy) void (^action_action_int)(void (^)(int));
[Export ("action_action_int", ArgumentSemantic.Copy)]
Action_action_intHandler Action_action_int { get; }

// @property (readonly, copy) void (^action_action_action)(void (^)(void (^)()));
[Export ("action_action_action", ArgumentSemantic.Copy)]
Action_action_actionHandler Action_action_action { get; }

// @property (readonly, copy) int (^func_int_int)(int);
[Export ("func_int_int", ArgumentSemantic.Copy)]
Func_int_intHandler Func_int_int { get; }

// @property (readonly, copy) long (^func_short_nint)(short);
[Export ("func_short_nint", ArgumentSemantic.Copy)]
Func_short_nintHandler Func_short_nint { get; }
}

delegate void Set_ActionHandler ();

delegate void Set_Action_intHandler (int arg0);

delegate void Set_Action_short_int_longHandler (short arg0, int arg1, long arg2);

delegate int Set_Func_intHandler ();

delegate int Set_Func_int_intHandler (int arg0);

delegate bool Set_Func_short_int_long_boolHandler (short arg0, int arg1, long arg2);

delegate bool Set_Func_Func_short_Action_long_short_boolHandler (Func<short, Action, long> arg0, short arg1);

delegate bool Set_Func_Func_short_Action_Action_int_nint_long_short_boolHandler (Func<short, Action<Action<int, nint>>, long> arg0, short arg1);

// @interface AnonymousBlockTests
interface AnonymousBlockTests {
// -(void)set_Action:(void (^)())handler;
[Export ("set_Action:")]
void Set_Action (Set_ActionHandler handler);

// -(void)set_Action_int:(void (^)(int))handler;
[Export ("set_Action_int:")]
void Set_Action_int (Set_Action_intHandler handler);

// -(void)set_Action_short_int_long:(void (^)(short, int, long long))handler;
[Export ("set_Action_short_int_long:")]
void Set_Action_short_int_long (Set_Action_short_int_longHandler handler);

// -(void)set_Func_int:(int (^)())handler;
[Export ("set_Func_int:")]
void Set_Func_int (Set_Func_intHandler handler);

// -(void)set_Func_int_int:(int (^)(int))handler;
[Export ("set_Func_int_int:")]
void Set_Func_int_int (Set_Func_int_intHandler handler);

// -(void)set_Func_short_int_long_bool:(_Bool (^)(short, int, long long))handler;
[Export ("set_Func_short_int_long_bool:")]
void Set_Func_short_int_long_bool (Set_Func_short_int_long_boolHandler handler);

// -(void)set_Func_Func_short_Action_long_short_bool:(_Bool (^)(long long (^)(short, void (^)()), short))handler;
[Export ("set_Func_Func_short_Action_long_short_bool:")]
void Set_Func_Func_short_Action_long_short_bool (Set_Func_Func_short_Action_long_short_boolHandler handler);

// -(void)set_Func_Func_short_Action_Action_int_nint_long_short_bool:(_Bool (^)(long long (^)(short, void (^)(void (^)(int, long))), short))handler;
[Export ("set_Func_Func_short_Action_Action_int_nint_long_short_bool:")]
void Set_Func_Func_short_Action_Action_int_nint_long_short_bool (Set_Func_Func_short_Action_Action_int_nint_long_short_boolHandler handler);
}
3 changes: 3 additions & 0 deletions tests/sharpie/Tests/Types/Blocks.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// RUN: -x objective-c
// RUN custom_delegates: -x objective-c -custom-delegates

typedef void (^Action)();
typedef int (^Anon_Func_Long_Int)(long long);
typedef int (^Named_Func_Long_Int)(long long longArg);
Expand Down
1 change: 1 addition & 0 deletions tests/xtro-sharpie/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ IGNORED_MACCATALYST_FRAMEWORKS = \
COMMON_SHARPIE_ARGUMENTS = \
-a arm64 \
-modules true \
--custom-delegates \
--clang-resource-dir $(TOP)/tools/sharpie/clang \

IOS_SHARPIE_ARGUMENTS = \
Expand Down
3 changes: 3 additions & 0 deletions tools/sharpie/Sharpie.Bind/BindingMassager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public BindingMassager (ObjectiveCBinder binder)
}

static readonly List<Type> defaultMassagers = new List<Type> {
typeof (CustomDelegateMassager),
typeof (DefaultConstructorMassager),
typeof (DelegateMassager),
typeof (MethodToPropertyMassager),
Expand Down Expand Up @@ -80,6 +81,8 @@ static MassagerBase CreateMassager (ObjectiveCBinder binder, string name)
name = name.Substring (ns.Length + 1);

switch (name) {
case nameof (CustomDelegateMassager):
return new CustomDelegateMassager (binder);
case nameof (DefaultConstructorMassager):
return new DefaultConstructorMassager (binder);
case nameof (DelegateMassager):
Expand Down
Loading
Loading