xamarin-macios/tests/generator
Rolf Bjarne Kvinge 3c2c3d062d
[generator] Fix the return type for blocks returning a type we've bound as an INativeObject. (#12941)
* Create all INativeObject subclasses using 'Runtime.GetINativeObject<T>' instead
  of 'new T ()'. Although it's somewhat slower, it automatically handles any IntPtr.Zero
  handles, and it also makes the generator code simpler. If something turns out to
  be a performance problem, we can always add custom static creation methods (like
  some of the existing types already have).

* This makes it so that the zero pointer check logic in the generator isn't necessary
  anymore.

* The most important part is where we use IntPtr as the marshalling type for returned
  INativeObjects in blocks (instead of the INativeObject class - which doesn't make
  sense really, because I have no idea how that's marshalled).

Example:

```diff
diff --git a/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs b/build-new/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs
index 97e58f3a91b..8a40748de8b 100644
--- a/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs
+++ b/build-new/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs
@@ -214,7 +214,7 @@ namespace ObjCRuntime {
    } /* class NIDAVAudioEngineManualRenderingBlock */
    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::AVFoundation.AVAudioIONodeInputBlock))]
-   internal delegate global::AudioToolbox.AudioBuffers DAVAudioIONodeInputBlock (IntPtr block, uint frameCount);
+   internal delegate IntPtr DAVAudioIONodeInputBlock (IntPtr block, uint frameCount);
    //
    // This class bridges native block invocations that call into C#
    //
@@ -223,11 +223,11 @@ namespace ObjCRuntime {
      [Preserve (Conditional = true)]
      [global::System.Diagnostics.CodeAnalysis.DynamicDependency ("Handler")]
      [MonoPInvokeCallback (typeof (DAVAudioIONodeInputBlock))]
-     static unsafe global::AudioToolbox.AudioBuffers Invoke (IntPtr block, uint frameCount) {
+     static unsafe IntPtr Invoke (IntPtr block, uint frameCount) {
        var descriptor = (BlockLiteral *) block;
        var del = (global::AVFoundation.AVAudioIONodeInputBlock) (descriptor->Target);
        AudioToolbox.AudioBuffers retval = del (frameCount);
-       return retval;
+       return retval.GetHandle ();
      }
    } /* class SDAVAudioIONodeInputBlock */
    internal sealed class NIDAVAudioIONodeInputBlock : TrampolineBlockBase {
@@ -249,7 +249,7 @@ namespace ObjCRuntime {
      [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
      unsafe global::AudioToolbox.AudioBuffers Invoke (uint frameCount)
      {
-       var ret = invoker (BlockPointer, frameCount);
+       var ret = Runtime.GetINativeObject<global::AudioToolbox.AudioBuffers> (invoker (BlockPointer, frameCount), false);
        return ret!;
      }
    } /* class NIDAVAudioIONodeInputBlock */
```
2021-10-11 19:13:17 +02:00
..
tests [generator] Fix the return type for blocks returning a type we've bound as an INativeObject. (#12941) 2021-10-11 19:13:17 +02:00
.gitignore [tests] Import 2016-05-26 15:06:52 +02:00
Asserts.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
BGenTests.cs [generator] Fix the return type for blocks returning a type we've bound as an INativeObject. (#12941) 2021-10-11 19:13:17 +02:00
BGenTool.cs [tests] Fix a thread synchronization issue in the generator tests. (#12775) 2021-09-20 13:39:24 +02:00
ErrorTests.cs Replace IKVM.Reflection with MetadataLoadContext (#9864) 2021-05-21 15:15:59 +02:00
GeneratorTests.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
Makefile [tests] Fix running several test suites from the command line. Fixes xamarin/maccore@2279. (#9348) 2020-08-12 10:34:55 +02:00
NSApplicationPublicEnsureMethods.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
README.md [tests] Import 2016-05-26 15:06:52 +02:00
arrayfromhandlebug.cs [tests] Remove Classic code from all tests. (#8702) 2020-05-28 16:35:09 +02:00
bi1036.cs [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
bi1046.cs [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
bi1059.cs [bgen] Avoid a NullReferenceException when reporting multiple attributes on a type. Fixes #10310. (#10311) 2020-12-17 15:12:32 +01:00
bindas1048error.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bindas1049error.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bindas1050modelerror.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bindas1050protocolerror.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bindastests.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bmac-with-hyphen-in-name.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bmac_smoke.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
btouch-with-hyphen-in-name.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug15283.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug15307.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug15799.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug16036.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug17232.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug23041.cs [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
bug24078-ignore-methods-events.cs [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
bug27428.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug27430.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug27986.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug29493.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug31788.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug34042.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug35176.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug36457.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug37527-missing-property.cs [tests] Remove Classic code from all tests. (#8702) 2020-05-28 16:35:09 +02:00
bug37527-wrong-property.cs [tests] Remove Classic code from all tests. (#8702) 2020-05-28 16:35:09 +02:00
bug39614.cs [tests] Port the makefile-based generator tests to NUnit. (#3019) 2017-11-20 14:55:16 +01:00
bug40282.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug42742.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug42855.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug43579.cs [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
bug46292.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug52570allowstaticmembers.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug52570classinternal.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug52570methodinternal.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug53076.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug53076withmodel.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
bug57531.cs [generator] Support [Async] inside categories, fixes bugzilla #57531 (#3229) 2018-01-16 08:41:25 -05:00
bug57870.cs [generator] Teach generator about WrapAttribute on Getters and Setters (#3388) 2018-02-05 21:14:08 -06:00
classNameCollision-enum.cs [tests] Remove Classic code from all tests. (#8702) 2020-05-28 16:35:09 +02:00
classNameCollision.cs [tests] Remove Classic code from all tests. (#8702) 2020-05-28 16:35:09 +02:00
desk63279A.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
desk63279B.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
desk79124.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
fieldenumtests.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
forcedtype.cs [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
forum54078.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
generator-tests.csproj [cecil] Update all package references to the latest 0.11.4 (#12379) 2021-08-09 10:18:16 -04:00
generic-strong-dictionary.cs [tests] Fix bgen test to compile by adding missing using. (#5932) 2019-04-23 16:26:38 +01:00
ghissue3869.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue5416a.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue5416b.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue5444.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue5692.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue6626.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue6863_method.cs [Generator] Provide clear error message on type mismatch with BindAs error (#7016) 2019-09-19 21:05:22 -04:00
ghissue6863_property.cs [Generator] Provide clear error message on type mismatch with BindAs error (#7016) 2019-09-19 21:05:22 -04:00
ghissue7304.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
ghissue9065.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
issue3875.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
issue3875B.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
issue3875C.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
missing-export-property.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
multiple-api-definitions1.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
multiple-api-definitions2-a.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
multiple-api-definitions2-b.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
noasyncinternalwrapper.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
noasyncwarningcs0219.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
nowarn.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
property-redefination-ios.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
property-redefination-mac.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
protocol-duplicate-abstract-error.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
protocol-duplicate-abstract.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
protocol-duplicate-method-diff-length.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
protocol-duplicate-method-diff-out.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
protocol-duplicate-method-diff-return.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
protocol-duplicate-method-diff-type.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
smartenumwithframework.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
sof20696157.cs [tests][generator] Remove references to iAd.framework types (#11953) 2021-06-16 14:58:45 -04:00
sof20696157.sh [tests][generator] Port XI/Classic tests to XI/Unified. (#1745) 2017-02-22 16:47:11 +01:00
strong-dict-native-enum.cs [generator] Add support for [Native] enums inside [StrongDictionaries] (#6763) 2019-08-13 18:36:36 -04:00
strong-dict-support-templated-dicts.cs [tests] Remove Classic code from all tests. (#8702) 2020-05-28 16:35:09 +02:00
virtualwrap.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
warnaserror.cs Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00

README.md

Tests for the binding generator

New test

  • Create a C# file with the api definition.
  • Add the C# file to the Makefile, like all the other tests. Remember to add it to the 'all' target.