xamarin-macios/tests/introspection/ApiCoreImageFiltersTest.cs

225 строки
7.6 KiB
C#
Исходник Обычный вид История

//
// Test the generated API for all CoreImage filters
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013, 2015 Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if !__WATCHOS__
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using NUnit.Framework;
#if XAMCORE_2_0
using CoreImage;
using Foundation;
using ObjCRuntime;
#if !MONOMAC
using UIKit;
#endif
#elif MONOMAC
using MonoMac.CoreImage;
using MonoMac.Foundation;
#else
using MonoTouch.CoreImage;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
#endif
namespace Introspection {
[TestFixture]
// we want the tests to be available because we use the linker
[Preserve (AllMembers = true)]
public abstract class ApiCoreImageFiltersTest : ApiBaseTest {
static Type CIFilterType = typeof (CIFilter);
protected virtual bool Skip (Type type)
{
return Skip (type.Name) || SkipDueToAttribute (type);
}
protected virtual bool Skip (string nativeName)
{
switch (nativeName) {
// Both reported in radar #21548819
// NSUnknownKeyException [<CIDepthOfField 0x158586970> valueForUndefinedKey:]: this class is not key value coding-compliant for the key inputPoint2.
case "CIDepthOfField":
return true;
// TODO: https://github.com/xamarin/xamarin-macios/issues/6340
case "CIGaborGradients":
case "CIKeystoneCorrectionCombined":
case "CIKeystoneCorrectionHorizontal":
case "CIKeystoneCorrectionVertical":
case "CIPerspectiveRotate":
return true;
// Apple does **not** document filters as API (like we do)
// uncomment calls to `GenerateBinding` to use introspection code to generate the skeleton binding code and complete it
// e.g. picking better types like `bool` instead of `NSNumber'
default:
return false;
}
}
[Test]
// this test checks that all native filters have a managed peer, i.e. against missing filters
public void CheckNativeFilters ()
{
List<string> filters = new List<string> ();
int n = 0;
string qname = CIFilterType.AssemblyQualifiedName;
// that will give us only the list of filters supported by the executing version of iOS
foreach (var filter_name in CIFilter.FilterNamesInCategories (null)) {
if (Skip (filter_name))
continue;
string type_name = qname.Replace ("CIFilter", filter_name);
if (Type.GetType (type_name, false, true) == null) {
filters.Add (filter_name);
// uncomment to generate bindings for any new native filter
// GenerateBinding (CIFilter.FromName (filter_name), Console.Out);
}
n++;
}
Assert.That (filters.Count, Is.EqualTo (0), "{0} native filters missing: {1}", filters.Count, String.Join (", ", filters));
}
[Test]
// this test checks that all managed filters have a native peer, i.e. against extra filters
public void CheckManagedFilters ()
{
Bump to use Xcode 10 beta 1 (#4179) * Bump to use Xcode 10 beta 1 * Update Versions.plist * Add a dependency on Xcode 9.4. * [msbuild] Fix build with Xcode 10 beta 1. (#4182) Many years ago (in Xcode 7 according to code comment) Developer/Platforms/iPhoneOS.platform/Developer/usr disappeared, and we coped by looking at Developer/usr instead (and also the subsequent code to locate the bin directory was based on the location of the usr directory). Developer/Platforms/iPhoneOS.platform/Developer/usr reappeared in Xcode 10 beta 1, but it seems useless (for one it doesn't contain a bin directory), so in order to try to keep things sane don't look for this directory in Xcode 10 and instead go directly for Developer/usr (which is what we've been using as the usr directory for years anyway). Fixes this problem when building apps with Xcode 10 beta 1: /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(626,3): error : Could not locate SDK bin directory [/Users/rolf/Projects/TestApp/test-app.csproj] * [runtime] Build 32-bit mac executables using Xcode 9.4. * [mtouch] Work around broken tvOS headers in Xcode 10 beta 1. * [mtouch] Work around build problem with Apple's simd headers in Objective-C++ mode. * Use version-agnostic paths to sdk directories. * [tests][xtro] Add todo files (from unclassified) and adjust ignore files to avoid errors * [macos][security] Re-enable SSL[Get|Set]AlpnProtocols. Fixes #4001 (#4022) * [macos][security] Re-enable SSL[Get}Set]AlpnProtocols. Fixes #4001 This was fixed in macOS 10.13.4 https://github.com/xamarin/xamarin-macios/issues/4001 * [tests][monotouch-tests] Disable a few test cases (one crasher, other failures). Causes to be verified later * [xharness] Fix permission dialog suppression in Xcode 10. * [xharness] Ignore 32-bit macOS tests by default. * [tests] Execute mmp regression tests with Xcode 9.4 since many of them are 32-bit and needs porting to 64-bit. * [mmptest] Ignore 32-bit XM tests if we don't have a 32-bit-capable Xcode. * [registrar] Add workaround for broken headers in Xcode 10 beta 1 (radar 40824697). * [mtouch] Restrict another workaround for an Xcode 10 beta 1 bug to a specific Xcode version to remove it asap. * [tests] Fix some protocol changes (public or not) find by introspection tests * [tests][intro] Fix DefaultCtorAllowed failures * [Intents] Obsolete several Intents classes in watchOS. Several existing Intents classes have been marked as unavailable in watchOS in the headers in Xcode 10 beta 1, and corresponding tests are now failing. So obsolete the managed wrapper types, and fix tests accordingly. * Fix xtro wrt previous Ietents/intro changes * [tests] Minor adjustments to mtouch tests to work with Xcode 10. * [msbuild] Update tests to cope with additional files produced by the Core ML compiler. * [msbuild] Xcode 10 doesn't support building watchOS 1 apps, so show a clear error message explaining it. Also update tests accordingly. * [coreimage] Stub new filters and exclude ?removed? ones from tests * Update GameplayKit and SpriteKit NSSecureCoding _upgrade_ and fix other non-public cases (in tests) * [tests] Ignore some GameKit selectors that don't respond anymore (but seems to be available, at least in header files) * [tests] Fix intro 32bits testing for filters resutls * [msbuild] Slightly change error message to be better English.
2018-06-09 04:45:24 +03:00
ContinueOnFailure = true;
List<string> filters = new List<string> (CIFilter.FilterNamesInCategories (null));
var superFilters = new List<string> ();
var nspace = CIFilterType.Namespace;
var types = CIFilterType.Assembly.GetTypes ();
foreach (Type t in types) {
if (t.Namespace != nspace)
continue;
if (t.IsAbstract || !CIFilterType.IsAssignableFrom (t))
continue;
// we need to skip the filters that are not supported by the executing version of iOS
if (Skip (t))
continue;
var ctor = t.GetConstructor (Type.EmptyTypes);
if ((ctor == null) || ctor.IsAbstract)
continue;
NSObject obj = ctor.Invoke (null) as NSObject;
#if false
// check base type - we might have our own base type or different names, so it's debug only (not failure)
var super = new Class (obj.Class.SuperClass).Name;
var bt = t.BaseType.Name;
if ((super != bt) && (bt == "CIFilter")) { // check if we should (like Apple) use a non-default base type for filters
Console.WriteLine ("[WARN] {0}.SuperClass == {1} (native) and {2} managed", t.Name, super, bt);
if (!superFilters.Contains (super)) {
superFilters.Add (super);
Console.WriteLine ("[GENERATED] {0}", super);
GenerateBinding (CIFilter.FromName (super), Console.Out);
}
}
#endif
int result = filters.RemoveAll (s => StringComparer.OrdinalIgnoreCase.Compare (t.Name, s) == 0);
Bump to use Xcode 10 beta 1 (#4179) * Bump to use Xcode 10 beta 1 * Update Versions.plist * Add a dependency on Xcode 9.4. * [msbuild] Fix build with Xcode 10 beta 1. (#4182) Many years ago (in Xcode 7 according to code comment) Developer/Platforms/iPhoneOS.platform/Developer/usr disappeared, and we coped by looking at Developer/usr instead (and also the subsequent code to locate the bin directory was based on the location of the usr directory). Developer/Platforms/iPhoneOS.platform/Developer/usr reappeared in Xcode 10 beta 1, but it seems useless (for one it doesn't contain a bin directory), so in order to try to keep things sane don't look for this directory in Xcode 10 and instead go directly for Developer/usr (which is what we've been using as the usr directory for years anyway). Fixes this problem when building apps with Xcode 10 beta 1: /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(626,3): error : Could not locate SDK bin directory [/Users/rolf/Projects/TestApp/test-app.csproj] * [runtime] Build 32-bit mac executables using Xcode 9.4. * [mtouch] Work around broken tvOS headers in Xcode 10 beta 1. * [mtouch] Work around build problem with Apple's simd headers in Objective-C++ mode. * Use version-agnostic paths to sdk directories. * [tests][xtro] Add todo files (from unclassified) and adjust ignore files to avoid errors * [macos][security] Re-enable SSL[Get|Set]AlpnProtocols. Fixes #4001 (#4022) * [macos][security] Re-enable SSL[Get}Set]AlpnProtocols. Fixes #4001 This was fixed in macOS 10.13.4 https://github.com/xamarin/xamarin-macios/issues/4001 * [tests][monotouch-tests] Disable a few test cases (one crasher, other failures). Causes to be verified later * [xharness] Fix permission dialog suppression in Xcode 10. * [xharness] Ignore 32-bit macOS tests by default. * [tests] Execute mmp regression tests with Xcode 9.4 since many of them are 32-bit and needs porting to 64-bit. * [mmptest] Ignore 32-bit XM tests if we don't have a 32-bit-capable Xcode. * [registrar] Add workaround for broken headers in Xcode 10 beta 1 (radar 40824697). * [mtouch] Restrict another workaround for an Xcode 10 beta 1 bug to a specific Xcode version to remove it asap. * [tests] Fix some protocol changes (public or not) find by introspection tests * [tests][intro] Fix DefaultCtorAllowed failures * [Intents] Obsolete several Intents classes in watchOS. Several existing Intents classes have been marked as unavailable in watchOS in the headers in Xcode 10 beta 1, and corresponding tests are now failing. So obsolete the managed wrapper types, and fix tests accordingly. * Fix xtro wrt previous Ietents/intro changes * [tests] Minor adjustments to mtouch tests to work with Xcode 10. * [msbuild] Update tests to cope with additional files produced by the Core ML compiler. * [msbuild] Xcode 10 doesn't support building watchOS 1 apps, so show a clear error message explaining it. Also update tests accordingly. * [coreimage] Stub new filters and exclude ?removed? ones from tests * Update GameplayKit and SpriteKit NSSecureCoding _upgrade_ and fix other non-public cases (in tests) * [tests] Ignore some GameKit selectors that don't respond anymore (but seems to be available, at least in header files) * [tests] Fix intro 32bits testing for filters resutls * [msbuild] Slightly change error message to be better English.
2018-06-09 04:45:24 +03:00
if ((result == 0) && !Skip (t))
ReportError ($"Managed {t.Name} was not part of the native filter list");
}
// in case it's a buggy filter we need to try to remove it from the list too
for (int i = filters.Count - 1; i >= 0; i--) {
if (Skip (filters [i]))
filters.RemoveAt (i);
}
Assert.That (filters.Count, Is.EqualTo (0), "Managed filters not found for {0}", String.Join (", ", filters));
}
static void GenerateBinding (NSObject filter, TextWriter writer)
{
NSObject value;
var attributes = (filter as CIFilter).Attributes;
writer.WriteLine ("[CoreImageFilter]");
if (!attributes.TryGetValue ((NSString)"CIAttributeFilterAvailable_iOS", out value)) {
writer.WriteLine ("[NoiOS]");
} else {
var v = value.ToString ();
// in the (quite common) case we get "5" for iOS 5.0
if (v.IndexOf ('.') == -1)
v += ".0";
var ios = Version.Parse (v);
// we only document availability for iOS 6+
if (ios.Major > 5)
writer.WriteLine ("[iOS ({0},{1})]", ios.Major, ios.Minor);
}
if (!attributes.TryGetValue ((NSString)"CIAttributeFilterAvailable_Mac", out value)) {
writer.WriteLine ("[NoMac]");
} else {
try {
var mac = Version.Parse (value.ToString ());
// we only document availability for 10.7+
if (mac.Minor > 6)
writer.WriteLine ("[Mac ({0},{1})]", mac.Major, mac.Minor);
}
catch (FormatException) {
// 10.? is not a valid version - we'll assume it was added a long time ago (in a galaxy far away)
writer.WriteLine ("// incorrect version string for OSX: '{0}' Double-check documentation", value);
}
}
writer.WriteLine ("[BaseType (typeof (CIFilter))]");
var fname = attributes [(NSString)"CIAttributeFilterName"].ToString ();
writer.WriteLine ("interface {0} {{", fname);
foreach (var k in attributes.Keys) {
var key = k.ToString ();
if (key.StartsWith ("CIAttribute", StringComparison.Ordinal))
continue;
// CIFilter defines it for all filters
if (key == "inputImage")
continue;
writer.WriteLine ();
var dict = attributes [k] as NSDictionary;
var type = dict [(NSString) "CIAttributeClass"];
writer.WriteLine ("\t[CoreImageFilterProperty (\"{0}\")]", key);
// by default we drop the "input" prefix, but keep the "output" prefix to avoid confusion
if (key.StartsWith ("input", StringComparison.Ordinal))
key = Char.ToUpperInvariant (key [5]) + key.Substring (6);
var ptype = type.ToString ();
// Too many things ends up in NSNumber but we do a better job in our bindings
if (ptype == "NSNumber") {
ptype = "float";
writer.WriteLine ("\t// TODO: this was an NSNumber transformed to float, but maybe an int or bool is more appropriate");
}
writer.WriteLine ("\t{0} {1} {{ get; set; }}", ptype, key);
}
writer.WriteLine ("}");
writer.WriteLine ();
}
}
}
#endif // !__WATCHOS__