From 1b09465acf36b9311e202103aefe8c796482972d Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 8 Jul 2020 09:26:54 -0400 Subject: [PATCH] [tests][xtro] Fix NSUrl-based categories (#9029) We were using the managed name, e.g. `NSUrl`, instead of the native name, e.g. `NSURL`, when dealing with categories. To fix this we must resolve the type and this caused issues as other assemblies (e.g. OpenTK) were not already loaded/cached and some type could not be resolved (and this throw exceptions) The runner now loads all assemblies before starting to visit them. The fix solved a known issue (iOS-NetworkExtension.ignore), some API that were already bound (common-Foundation.ignore) and also caught an additional API where we missed a `[NullAllowed]` on a return value --- src/foundation.cs | 1 + tests/xtro-sharpie/Helpers.cs | 2 +- tests/xtro-sharpie/Runner.cs | 32 +++++++++++++------ tests/xtro-sharpie/common-Foundation.ignore | 3 -- .../xtro-sharpie/iOS-NetworkExtension.ignore | 3 -- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/foundation.cs b/src/foundation.cs index 96a538f209..fac6eb279f 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -6226,6 +6226,7 @@ namespace Foundation [Mac (10,10), iOS (8,0)] [Export ("promisedItemResourceValuesForKeys:error:")] + [return: NullAllowed] NSDictionary GetPromisedItemResourceValues (NSString [] keys, out NSError error); } diff --git a/tests/xtro-sharpie/Helpers.cs b/tests/xtro-sharpie/Helpers.cs index 8628daeaba..effff46724 100644 --- a/tests/xtro-sharpie/Helpers.cs +++ b/tests/xtro-sharpie/Helpers.cs @@ -251,7 +251,7 @@ namespace Extrospection { // static types, e.g. categories, won't have a [Register] attribute if (type.IsStatic ()) { if (self.HasParameters) - tname = self.Parameters [0].ParameterType.Name; // extension method + tname = self.Parameters [0].ParameterType.Resolve ().GetName (); // extension method } if (tname == null) return null; diff --git a/tests/xtro-sharpie/Runner.cs b/tests/xtro-sharpie/Runner.cs index 68c59f911b..7c80d58980 100644 --- a/tests/xtro-sharpie/Runner.cs +++ b/tests/xtro-sharpie/Runner.cs @@ -44,6 +44,7 @@ namespace Extrospection { Helpers.Platform = Platforms.tvOS; managed_reader.Load (assemblyName); } + managed_reader.Process (); var reader = new AstReader (); foreach (var v in managed_reader) { @@ -62,17 +63,30 @@ namespace Extrospection { class AssemblyReader : IEnumerable { + HashSet assemblies = new HashSet (); + DefaultAssemblyResolver resolver = new DefaultAssemblyResolver (); + public void Load (string filename) { - var ad = AssemblyDefinition.ReadAssembly (filename); - foreach (var v in Visitors) { - v.VisitManagedAssembly (ad); - foreach (var module in ad.Modules) { - v.VisitManagedModule (module); - if (!module.HasTypes) - continue; - foreach (var td in module.Types) - ProcessType (v, td); + resolver.AddSearchDirectory (Path.GetDirectoryName (filename)); + ReaderParameters rp = new ReaderParameters () { + AssemblyResolver = resolver + }; + assemblies.Add (AssemblyDefinition.ReadAssembly (filename, rp)); + } + + public void Process () + { + foreach (var ad in assemblies) { + foreach (var v in Visitors) { + v.VisitManagedAssembly (ad); + foreach (var module in ad.Modules) { + v.VisitManagedModule (module); + if (!module.HasTypes) + continue; + foreach (var td in module.Types) + ProcessType (v, td); + } } } } diff --git a/tests/xtro-sharpie/common-Foundation.ignore b/tests/xtro-sharpie/common-Foundation.ignore index c686e9bc5f..0603301160 100644 --- a/tests/xtro-sharpie/common-Foundation.ignore +++ b/tests/xtro-sharpie/common-Foundation.ignore @@ -809,14 +809,11 @@ !missing-selector! NSTimeZone::isDaylightSavingTime not bound !missing-selector! NSTimeZone::isEqualToTimeZone: not bound !missing-selector! NSTimeZone::nextDaylightSavingTimeTransition not bound -!missing-selector! NSURL::checkPromisedItemIsReachableAndReturnError: not bound !missing-selector! NSURL::checkResourceIsReachableAndReturnError: not bound -!missing-selector! NSURL::getPromisedItemResourceValue:forKey:error: not bound !missing-selector! NSURL::initAbsoluteURLWithDataRepresentation:relativeToURL: not bound !missing-selector! NSURL::initFileURLWithPath: not bound !missing-selector! NSURL::initFileURLWithPath:relativeToURL: not bound !missing-selector! NSURL::initWithDataRepresentation:relativeToURL: not bound -!missing-selector! NSURL::promisedItemResourceValuesForKeys:error: not bound !missing-selector! NSURL::setResourceValues:error: not bound !missing-selector! NSURL::URLByAppendingPathComponent: not bound !missing-selector! NSURL::URLByResolvingSymlinksInPath not bound diff --git a/tests/xtro-sharpie/iOS-NetworkExtension.ignore b/tests/xtro-sharpie/iOS-NetworkExtension.ignore index 6878e7663f..3b4e70d9a9 100644 --- a/tests/xtro-sharpie/iOS-NetworkExtension.ignore +++ b/tests/xtro-sharpie/iOS-NetworkExtension.ignore @@ -1,6 +1,3 @@ -## bound as a category - needs debugging (URL capitalizarion?) -!missing-selector! NSMutableURLRequest::bindToHotspotHelperCommand: not bound - ## Native code has NWPathStatus in NetworkExtension and nw_path_status_t in Network (with the same elements). ## NetworkExtension.NWPathStatus is the oldest, but NetworkExtension isn't present on all the platforms Network ## is, which means we can't use the same managed enum for both cases (the native enums aren't entirely identical